Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
import com.somemore.domains.review.usecase.CreateReviewUseCase;
import com.somemore.domains.review.usecase.DeleteReviewUseCase;
import com.somemore.domains.review.usecase.UpdateReviewUseCase;
import com.somemore.global.auth.annotation.CurrentUser;
import com.somemore.global.auth.annotation.RoleId;
import com.somemore.global.common.response.ApiResponse;
import com.somemore.global.imageupload.dto.ImageUploadRequestDto;
import com.somemore.global.imageupload.usecase.ImageUploadUseCase;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.DeleteMapping;
Expand All @@ -20,13 +19,7 @@
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;

import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE;

@Tag(name = "Review Command API", description = "리뷰 생성 수정 삭제 API")
@RequiredArgsConstructor
Expand All @@ -37,20 +30,17 @@ public class ReviewCommandApiController {
private final CreateReviewUseCase createReviewUseCase;
private final UpdateReviewUseCase updateReviewUseCase;
private final DeleteReviewUseCase deleteReviewUseCase;
private final ImageUploadUseCase imageUploadUseCase;

@Secured("ROLE_VOLUNTEER")
@Operation(summary = "리뷰 등록", description = "리뷰를 등록합니다.")
@PostMapping(value = "/review", consumes = MULTIPART_FORM_DATA_VALUE)
@PostMapping(value = "/review")
public ApiResponse<Long> createReview(
@CurrentUser UUID userId,
@Valid @RequestPart("data") ReviewCreateRequestDto requestDto,
@RequestPart(value = "img_file", required = false) MultipartFile image) {
@RoleId UUID volunteerId,
@Valid @RequestBody ReviewCreateRequestDto requestDto) {

String imgUrl = imageUploadUseCase.uploadImage(new ImageUploadRequestDto(image));
return ApiResponse.ok(
201,
createReviewUseCase.createReview(requestDto, userId, imgUrl),
createReviewUseCase.createReview(requestDto, volunteerId),
"리뷰 등록 성공"
);
}
Expand All @@ -59,42 +49,26 @@ public ApiResponse<Long> createReview(
@Operation(summary = "리뷰 수정", description = "리뷰를 수정합니다.")
@PutMapping(value = "/review/{id}")
public ApiResponse<String> updateReview(
@CurrentUser UUID userId,
@RoleId UUID volunteerId,
@PathVariable Long id,
@Valid @RequestBody ReviewUpdateRequestDto requestDto) {

updateReviewUseCase.updateReview(id, userId, requestDto);
updateReviewUseCase.updateReview(id, volunteerId, requestDto);

return ApiResponse.ok(
200,
"리뷰 수정 성공"
);
}

@Secured("ROLE_VOLUNTEER")
@Operation(summary = "리뷰 이미지 수정", description = "리뷰 이미지를 수정합니다.")
@PutMapping(value = "/review/{id}", consumes = MULTIPART_FORM_DATA_VALUE)
public ApiResponse<String> updateReviewImage(
@CurrentUser UUID userId,
@PathVariable Long id,
@RequestPart(value = "img_file", required = false) MultipartFile image) {

String newImgUrl = imageUploadUseCase.uploadImage(new ImageUploadRequestDto(image));
updateReviewUseCase.updateReviewImageUrl(id, userId, newImgUrl);
return ApiResponse.ok(
200,
"리뷰 이미지 수정 성공"
);
}

@Secured("ROLE_VOLUNTEER")
@Operation(summary = "리뷰 삭제", description = "리뷰를 삭제합니다.")
@DeleteMapping(value = "/review/{id}")
public ApiResponse<String> createReview(
@CurrentUser UUID userId,
@RoleId UUID volunteerId,
@PathVariable Long id
) {
deleteReviewUseCase.deleteReview(userId, id);
deleteReviewUseCase.deleteReview(volunteerId, id);
return ApiResponse.ok("리뷰 삭제 성공");
}

Expand Down
19 changes: 5 additions & 14 deletions src/main/java/com/somemore/domains/review/domain/Review.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.somemore.domains.review.domain;

import static jakarta.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PROTECTED;

import com.somemore.domains.review.dto.request.ReviewUpdateRequestDto;
import com.somemore.global.common.entity.BaseEntity;
import jakarta.persistence.Column;
Expand All @@ -8,15 +11,11 @@
import jakarta.persistence.Id;
import jakarta.persistence.Lob;
import jakarta.persistence.Table;
import java.util.UUID;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.UUID;

import static jakarta.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PROTECTED;

@Getter
@NoArgsConstructor(access = PROTECTED)
@Entity
Expand All @@ -40,17 +39,12 @@ public class Review extends BaseEntity {
@Column(name = "content", length = 1000, nullable = false)
private String content;

@Column(name = "img_url", nullable = false)
private String imgUrl;

@Builder
public Review(Long volunteerApplyId, UUID volunteerId, String title,
String content, String imgUrl) {
public Review(Long volunteerApplyId, UUID volunteerId, String title, String content) {
this.volunteerApplyId = volunteerApplyId;
this.volunteerId = volunteerId;
this.title = title;
this.content = content;
this.imgUrl = imgUrl;
}

public boolean isWriter(UUID volunteerId) {
Expand All @@ -62,7 +56,4 @@ public void updateWith(ReviewUpdateRequestDto dto) {
this.content = dto.content();
}

public void updateWith(String imgUrl) {
this.imgUrl = imgUrl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ public record ReviewCreateRequestDto(
String content
) {

public Review toEntity(UUID volunteerId, String imgUrl) {
public Review toEntity(UUID volunteerId) {
return Review.builder()
.volunteerApplyId(volunteerApplyId)
.volunteerId(volunteerId)
.title(title)
.content(content)
.imgUrl(imgUrl)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ public record ReviewDetailResponseDto(
String title,
@Schema(description = "리뷰 내용", example = "정말 유익했습니다. 더보기..")
String content,
@Schema(description = "이미지 링크", example = "https://image.domain.com/links")
String imgUrl,
@Schema(description = "작성 일자", example = "2024-12-01T09:00:00", type = "string")
LocalDateTime createdAt,
@Schema(description = "수정 일자", example = "2024-12-01T09:00:00", type = "string")
Expand All @@ -35,7 +33,6 @@ public static ReviewDetailResponseDto from(Review review) {
.volunteerId(review.getVolunteerId())
.title(review.getTitle())
.content(review.getContent())
.imgUrl(review.getImgUrl())
.createdAt(review.getCreatedAt())
.updatedAt(review.getUpdatedAt())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ public record ReviewDetailWithNicknameResponseDto(
String title,
@Schema(description = "리뷰 내용", example = "정말 유익했습니다. 더보기..")
String content,
@Schema(description = "이미지 링크", example = "https://image.domain.com/links")
String imgUrl,
@Schema(description = "작성 일자", example = "2024-12-01T09:00:00", type = "string")
LocalDateTime createdAt,
@Schema(description = "수정 일자", example = "2024-12-01T09:00:00", type = "string")
Expand All @@ -38,7 +36,6 @@ public static ReviewDetailWithNicknameResponseDto from(Review review, String vol
.volunteerNickname(volunteerNickname)
.title(review.getTitle())
.content(review.getContent())
.imgUrl(review.getImgUrl())
.createdAt(review.getCreatedAt())
.updateAt(review.getUpdatedAt())
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.somemore.domains.review.service;

import static com.somemore.global.exception.ExceptionMessage.REVIEW_ALREADY_EXISTS;
import static com.somemore.global.exception.ExceptionMessage.REVIEW_RESTRICTED_TO_ATTENDED;

import com.somemore.domains.review.domain.Review;
import com.somemore.domains.review.dto.request.ReviewCreateRequestDto;
import com.somemore.domains.review.repository.ReviewRepository;
Expand All @@ -9,15 +12,11 @@
import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryUseCase;
import com.somemore.global.exception.BadRequestException;
import com.somemore.global.exception.DuplicateException;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.UUID;

import static com.somemore.global.exception.ExceptionMessage.REVIEW_ALREADY_EXISTS;
import static com.somemore.global.exception.ExceptionMessage.REVIEW_RESTRICTED_TO_ATTENDED;

@RequiredArgsConstructor
@Transactional
@Service
Expand All @@ -28,13 +27,13 @@ public class CreateReviewService implements CreateReviewUseCase {
private final VolunteerApplyQueryUseCase volunteerApplyQueryUseCase;

@Override
public Long createReview(ReviewCreateRequestDto requestDto, UUID volunteerId, String imgUrl) {
public Long createReview(ReviewCreateRequestDto requestDto, UUID volunteerId) {
validateDuplicateReview(requestDto.volunteerApplyId());

VolunteerApply apply = volunteerApplyQueryUseCase.getById(requestDto.volunteerApplyId());
validateActivityCompletion(apply);

Review review = requestDto.toEntity(volunteerId, imgUrl);
Review review = requestDto.toEntity(volunteerId);
reviewRepository.save(review);

return review.getId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
import com.somemore.domains.review.service.validator.ReviewValidator;
import com.somemore.domains.review.usecase.ReviewQueryUseCase;
import com.somemore.domains.review.usecase.UpdateReviewUseCase;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.UUID;

@RequiredArgsConstructor
@Transactional
@Service
Expand All @@ -26,11 +25,4 @@ public void updateReview(Long id, UUID volunteerId, ReviewUpdateRequestDto reque
review.updateWith(requestDto);
}

@Override
public void updateReviewImageUrl(Long id, UUID volunteerId, String imgUrl) {
Review review = reviewQueryUseCase.getById(id);
reviewValidator.validateWriter(review, volunteerId);
review.updateWith(imgUrl);
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.somemore.domains.review.usecase;

import com.somemore.domains.review.dto.request.ReviewCreateRequestDto;

import java.util.UUID;

public interface CreateReviewUseCase {

Long createReview(ReviewCreateRequestDto requestDto, UUID volunteerId, String imgUrl);

Long createReview(ReviewCreateRequestDto requestDto, UUID volunteerId);

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.somemore.domains.review.usecase;

import com.somemore.domains.review.dto.request.ReviewUpdateRequestDto;

import java.util.UUID;

public interface UpdateReviewUseCase {

void updateReview(Long id, UUID volunteerId, ReviewUpdateRequestDto requestDto);

void updateReviewImageUrl(Long id, UUID volunteerId, String imgUrl);
}
Loading
Loading