diff --git a/src/main/java/com/example/mate/common/error/ErrorCode.java b/src/main/java/com/example/mate/common/error/ErrorCode.java index 86a3de47..8a12de81 100644 --- a/src/main/java/com/example/mate/common/error/ErrorCode.java +++ b/src/main/java/com/example/mate/common/error/ErrorCode.java @@ -59,13 +59,11 @@ public enum ErrorCode { INVALID_MATE_POST_PARTICIPANT_IDS(HttpStatus.BAD_REQUEST, "MP013", "존재하지 않는 회원이 참여자 목록에 포함되어 있습니다"), // Goods - GOODS_IMAGES_ARE_EMPTY(HttpStatus.BAD_REQUEST, "G001", "굿즈 이미지는 최소 1개 이상을 업로드 할 수 있습니다."), - GOODS_NOT_FOUND_BY_ID(HttpStatus.NOT_FOUND, "G002", "해당 ID의 굿즈 판매글 정보를 찾을 수 없습니다."), - GOODS_MODIFICATION_NOT_ALLOWED(HttpStatus.FORBIDDEN, "G003", "판매글의 판매자가 아니라면, 판매글을 수정하거나 삭제할 수 없습니다."), - GOODS_MAIN_IMAGE_IS_EMPTY(HttpStatus.NOT_FOUND, "G004", "굿즈 게시물의 대표사진을 찾을 수 없습니다."), - GOODS_DELETE_NOT_ALLOWED(HttpStatus.BAD_REQUEST, "G005", "거래완료 상태에서 판매글을 삭제할 수 없습니다."), - GOODS_ALREADY_COMPLETED(HttpStatus.BAD_REQUEST, "G006", "이미 거래완료 상태인 굿즈는 거래를 완료할 수 없습니다."), - SELLER_CANNOT_BE_BUYER(HttpStatus.BAD_REQUEST, "G007", "판매자와 구매자는 동일할 수 없습니다."), + GOODS_NOT_FOUND_BY_ID(HttpStatus.NOT_FOUND, "G001", "해당 ID의 굿즈 판매글 정보를 찾을 수 없습니다."), + GOODS_MODIFICATION_NOT_ALLOWED(HttpStatus.FORBIDDEN, "G002", "판매글의 판매자가 아니라면, 판매글을 수정하거나 삭제할 수 없습니다."), + GOODS_DELETE_NOT_ALLOWED(HttpStatus.BAD_REQUEST, "G003", "거래완료 상태에서 판매글을 삭제할 수 없습니다."), + GOODS_ALREADY_COMPLETED(HttpStatus.BAD_REQUEST, "G004", "이미 거래완료 상태인 굿즈는 거래를 완료할 수 없습니다."), + SELLER_CANNOT_BE_BUYER(HttpStatus.BAD_REQUEST, "G005", "판매자와 구매자는 동일할 수 없습니다."), // Goods Review GOODS_REVIEW_STATUS_NOT_CLOSED(HttpStatus.BAD_REQUEST, "GR001", "굿즈거래 후기는 거래완료 상태에서만 작성할 수 있습니다."), diff --git a/src/main/java/com/example/mate/common/validator/ValidPageableArgumentResolver.java b/src/main/java/com/example/mate/common/validator/ValidPageableArgumentResolver.java index 5330e867..9e194f44 100644 --- a/src/main/java/com/example/mate/common/validator/ValidPageableArgumentResolver.java +++ b/src/main/java/com/example/mate/common/validator/ValidPageableArgumentResolver.java @@ -15,32 +15,44 @@ @Component public class ValidPageableArgumentResolver extends PageableHandlerMethodArgumentResolver { + // @ValidPageable 이 있을 때만 실행 @Override - public Pageable resolveArgument(MethodParameter methodParameter, - ModelAndViewContainer mavContainer, - NativeWebRequest webRequest, - WebDataBinderFactory binderFactory) { + public boolean supportsParameter(MethodParameter parameter) { + return parameter.hasParameterAnnotation(ValidPageable.class); + } - // 기본 Pageable 생성 - Pageable pageable = super.resolveArgument(methodParameter, mavContainer, webRequest, binderFactory); + @Override + public Pageable resolveArgument(MethodParameter methodParameter, ModelAndViewContainer mavContainer, + NativeWebRequest webRequest, WebDataBinderFactory binderFactory) { + // 클라이언트 요청값 생성 + String pageRequest = webRequest.getParameter(this.getParameterNameToUse(this.getPageParameterName(), methodParameter)); + String sizeRequest = webRequest.getParameter(this.getParameterNameToUse(this.getSizeParameterName(), methodParameter)); // @ValidPageable 어노테이션 확인 ValidPageable validPageable = methodParameter.getParameterAnnotation(ValidPageable.class); + assert validPageable != null; - // 클라이언트가 page 파라미터를 제공했는지 확인 - String pageParam = webRequest.getParameter("page"); + int page = extractPageValue(pageRequest, validPageable); + int size = extractSizeValue(sizeRequest, validPageable); - // pageParam이 존재하면 pageable.getPageNumber() 사용 - // pageParam이 없고 validPageable이 존재하면 validPageable.page() 사용 - // 둘 다 없으면 0을 사용 - int pageNumber = pageParam != null ? - pageable.getPageNumber() : - (validPageable != null ? validPageable.page() : 0); + return PageRequest.of(page, size); + } - int pageSize = pageable.getPageSize() > 0 - ? pageable.getPageSize() - : validPageable != null ? validPageable.size() : 10; + // parameter 에 page 값이 있을 경우, 유효성 검증 + private int extractPageValue(String pageRequest, ValidPageable validPageable) { + try { + return pageRequest != null ? Math.max(0, Integer.parseInt(pageRequest)) : validPageable.page(); + } catch (NumberFormatException e) { + return validPageable.page(); + } + } - return PageRequest.of(pageNumber, pageSize, pageable.getSort()); + // parameter 에 size 값이 있을 경우, 유효성 검증 + private int extractSizeValue(String sizeRequest, ValidPageable validPageable) { + try { + return sizeRequest != null ? Math.max(1, Integer.parseInt(sizeRequest)) : validPageable.size(); + } catch (NumberFormatException e) { + return validPageable.size(); + } } } \ No newline at end of file diff --git a/src/main/java/com/example/mate/domain/goods/dto/request/GoodsPostRequest.java b/src/main/java/com/example/mate/domain/goods/dto/request/GoodsPostRequest.java index 542b6152..599844dc 100644 --- a/src/main/java/com/example/mate/domain/goods/dto/request/GoodsPostRequest.java +++ b/src/main/java/com/example/mate/domain/goods/dto/request/GoodsPostRequest.java @@ -1,7 +1,7 @@ package com.example.mate.domain.goods.dto.request; import com.example.mate.common.validator.ValidEnum; -import com.example.mate.domain.goods.dto.LocationInfo; +import com.example.mate.domain.goods.dto.response.LocationInfo; import com.example.mate.domain.goods.entity.Category; import com.example.mate.domain.goods.entity.GoodsPost; import com.example.mate.domain.member.entity.Member; diff --git a/src/main/java/com/example/mate/domain/goods/dto/response/GoodsPostResponse.java b/src/main/java/com/example/mate/domain/goods/dto/response/GoodsPostResponse.java index 1e7b40ec..c290fa3c 100644 --- a/src/main/java/com/example/mate/domain/goods/dto/response/GoodsPostResponse.java +++ b/src/main/java/com/example/mate/domain/goods/dto/response/GoodsPostResponse.java @@ -1,8 +1,6 @@ package com.example.mate.domain.goods.dto.response; import com.example.mate.domain.constant.TeamInfo; -import com.example.mate.domain.goods.dto.LocationInfo; -import com.example.mate.domain.goods.dto.MemberInfo; import com.example.mate.domain.goods.entity.GoodsPost; import com.example.mate.domain.goods.entity.GoodsPostImage; import com.example.mate.domain.goods.entity.Role; diff --git a/src/main/java/com/example/mate/domain/goods/dto/LocationInfo.java b/src/main/java/com/example/mate/domain/goods/dto/response/LocationInfo.java similarity index 96% rename from src/main/java/com/example/mate/domain/goods/dto/LocationInfo.java rename to src/main/java/com/example/mate/domain/goods/dto/response/LocationInfo.java index dffbc74f..7778be93 100644 --- a/src/main/java/com/example/mate/domain/goods/dto/LocationInfo.java +++ b/src/main/java/com/example/mate/domain/goods/dto/response/LocationInfo.java @@ -1,4 +1,4 @@ -package com.example.mate.domain.goods.dto; +package com.example.mate.domain.goods.dto.response; import com.example.mate.domain.goods.entity.Location; import jakarta.validation.constraints.NotEmpty; diff --git a/src/main/java/com/example/mate/domain/goods/dto/MemberInfo.java b/src/main/java/com/example/mate/domain/goods/dto/response/MemberInfo.java similarity index 95% rename from src/main/java/com/example/mate/domain/goods/dto/MemberInfo.java rename to src/main/java/com/example/mate/domain/goods/dto/response/MemberInfo.java index 23b1494d..39833345 100644 --- a/src/main/java/com/example/mate/domain/goods/dto/MemberInfo.java +++ b/src/main/java/com/example/mate/domain/goods/dto/response/MemberInfo.java @@ -1,4 +1,4 @@ -package com.example.mate.domain.goods.dto; +package com.example.mate.domain.goods.dto.response; import com.example.mate.domain.goods.entity.Role; import com.example.mate.domain.member.entity.Member; diff --git a/src/main/java/com/example/mate/domain/goods/entity/GoodsPost.java b/src/main/java/com/example/mate/domain/goods/entity/GoodsPost.java index 1234f2b1..7224b556 100644 --- a/src/main/java/com/example/mate/domain/goods/entity/GoodsPost.java +++ b/src/main/java/com/example/mate/domain/goods/entity/GoodsPost.java @@ -1,8 +1,6 @@ package com.example.mate.domain.goods.entity; import com.example.mate.common.BaseTimeEntity; -import com.example.mate.common.error.CustomException; -import com.example.mate.common.error.ErrorCode; import com.example.mate.domain.member.entity.Member; import jakarta.persistence.CascadeType; import jakarta.persistence.Column; @@ -26,13 +24,11 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.ToString; @Entity @Table(name = "goods_post") @Getter @Builder -@ToString @AllArgsConstructor(access = AccessLevel.PRIVATE) @NoArgsConstructor(access = AccessLevel.PROTECTED) public class GoodsPost extends BaseTimeEntity { @@ -53,10 +49,13 @@ public class GoodsPost extends BaseTimeEntity { private Long teamId; @OneToMany(mappedBy = "post", cascade = CascadeType.ALL, orphanRemoval = true) - @OrderBy("isMainImage DESC, id ASC") + @OrderBy("id ASC") @Builder.Default private List goodsPostImages = new ArrayList<>(); + @Column(name = "main_image_url", columnDefinition = "TEXT") + private String mainImageUrl; + @Column(nullable = false, length = 100) private String title; @@ -78,23 +77,20 @@ public class GoodsPost extends BaseTimeEntity { @Builder.Default private Status status = Status.OPEN; - // 굿즈 판매글 이미지 업로드 및 수정 메서드 public void changeImages(List goodsPostImages) { - if (goodsPostImages.isEmpty()) { - throw new CustomException(ErrorCode.GOODS_IMAGES_ARE_EMPTY); - } - - // 기존 이미지 전부 삭제 this.goodsPostImages.clear(); for (GoodsPostImage goodsPostImage : goodsPostImages) { this.goodsPostImages.add(goodsPostImage); goodsPostImage.changePost(this); } - this.goodsPostImages.get(0).setAsMainImage(); + changeMainImage(); + } + + private void changeMainImage() { + this.mainImageUrl = goodsPostImages.get(0).getImageUrl(); } - // 굿즈 판매글 수정 메서드 public void updatePostDetails(GoodsPost post) { this.teamId = post.getTeamId(); this.title = post.getTitle(); @@ -104,17 +100,8 @@ public void updatePostDetails(GoodsPost post) { this.location = post.getLocation(); } - // 거래 완료 메서드 public void completeTransaction(Member buyer) { this.buyer = buyer; this.status = Status.CLOSED; } - - public String getMainImageUrl() { - return goodsPostImages.stream() - .filter(GoodsPostImage::getIsMainImage) - .findFirst() - .map(GoodsPostImage::getImageUrl) - .orElse("upload/default.jpg"); - } } diff --git a/src/main/java/com/example/mate/domain/goods/entity/GoodsPostImage.java b/src/main/java/com/example/mate/domain/goods/entity/GoodsPostImage.java index 0488d61a..11a4ae5f 100644 --- a/src/main/java/com/example/mate/domain/goods/entity/GoodsPostImage.java +++ b/src/main/java/com/example/mate/domain/goods/entity/GoodsPostImage.java @@ -34,15 +34,7 @@ public class GoodsPostImage { @Column(name = "image_url", nullable = false, columnDefinition = "TEXT") private String imageUrl; - @Column(name = "is_main_image", nullable = false) - @Builder.Default - private Boolean isMainImage = false; - public void changePost(GoodsPost post) { this.post = post; } - - public void setAsMainImage() { - this.isMainImage = true; - } } diff --git a/src/main/java/com/example/mate/domain/goods/repository/GoodsPostRepositoryCustomImpl.java b/src/main/java/com/example/mate/domain/goods/repository/GoodsPostRepositoryCustomImpl.java index 6b15d7cf..2995e8c7 100644 --- a/src/main/java/com/example/mate/domain/goods/repository/GoodsPostRepositoryCustomImpl.java +++ b/src/main/java/com/example/mate/domain/goods/repository/GoodsPostRepositoryCustomImpl.java @@ -1,7 +1,6 @@ package com.example.mate.domain.goods.repository; import static com.example.mate.domain.goods.entity.QGoodsPost.goodsPost; -import static com.example.mate.domain.goods.entity.QGoodsPostImage.goodsPostImage; import com.example.mate.domain.goods.entity.Category; import com.example.mate.domain.goods.entity.GoodsPost; @@ -22,13 +21,11 @@ public class GoodsPostRepositoryCustomImpl implements GoodsPostRepositoryCustom @Override public Page findPageGoodsPosts(Long teamId, Status status, Category category, Pageable pageable) { - BooleanBuilder conditions = createConditions(teamId, status, category); + BooleanBuilder conditions = buildConditions(teamId, status, category); List fetch = queryFactory .selectFrom(goodsPost) - .join(goodsPost.goodsPostImages, goodsPostImage).fetchJoin() .where(conditions) - .where(goodsPostImage.isMainImage.eq(true)) .orderBy(goodsPost.createdAt.desc()) .offset(pageable.getOffset()) .limit(pageable.getPageSize()) @@ -42,7 +39,7 @@ public Page findPageGoodsPosts(Long teamId, Status status, Category c return PageableExecutionUtils.getPage(fetch, pageable, total::fetchOne); } - private BooleanBuilder createConditions(Long teamId, Status status, Category category) { + private BooleanBuilder buildConditions(Long teamId, Status status, Category category) { BooleanBuilder builder = new BooleanBuilder(); builder.and(goodsPost.status.eq(status)); diff --git a/src/main/java/com/example/mate/domain/goods/repository/GoodsReviewRepositoryCustomImpl.java b/src/main/java/com/example/mate/domain/goods/repository/GoodsReviewRepositoryCustomImpl.java index df43778c..0d0e8b03 100644 --- a/src/main/java/com/example/mate/domain/goods/repository/GoodsReviewRepositoryCustomImpl.java +++ b/src/main/java/com/example/mate/domain/goods/repository/GoodsReviewRepositoryCustomImpl.java @@ -1,5 +1,7 @@ package com.example.mate.domain.goods.repository; +import static com.example.mate.domain.goods.entity.QGoodsReview.*; + import com.example.mate.domain.goods.entity.QGoodsPost; import com.example.mate.domain.goods.entity.QGoodsReview; import com.example.mate.domain.member.dto.response.MyReviewResponse; diff --git a/src/main/java/com/example/mate/domain/goods/service/GoodsService.java b/src/main/java/com/example/mate/domain/goods/service/GoodsService.java index f15279f1..ad2d8cc3 100644 --- a/src/main/java/com/example/mate/domain/goods/service/GoodsService.java +++ b/src/main/java/com/example/mate/domain/goods/service/GoodsService.java @@ -11,12 +11,18 @@ import com.example.mate.domain.goods.dto.response.GoodsPostResponse; import com.example.mate.domain.goods.dto.response.GoodsPostSummaryResponse; import com.example.mate.domain.goods.dto.response.GoodsReviewResponse; -import com.example.mate.domain.goods.entity.*; +import com.example.mate.domain.goods.entity.Category; +import com.example.mate.domain.goods.entity.GoodsPost; +import com.example.mate.domain.goods.entity.GoodsPostImage; +import com.example.mate.domain.goods.entity.GoodsReview; +import com.example.mate.domain.goods.entity.Status; import com.example.mate.domain.goods.repository.GoodsPostImageRepository; import com.example.mate.domain.goods.repository.GoodsPostRepository; import com.example.mate.domain.goods.repository.GoodsReviewRepository; import com.example.mate.domain.member.entity.Member; import com.example.mate.domain.member.repository.MemberRepository; +import java.util.ArrayList; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -25,9 +31,6 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; -import java.util.ArrayList; -import java.util.List; - @Service @Transactional @RequiredArgsConstructor @@ -52,8 +55,7 @@ public GoodsPostResponse registerGoodsPost(Long memberId, GoodsPostRequest reque return GoodsPostResponse.of(savedPost); } - public GoodsPostResponse updateGoodsPost(Long memberId, Long goodsPostId, GoodsPostRequest request, - List files) { + public GoodsPostResponse updateGoodsPost(Long memberId, Long goodsPostId, GoodsPostRequest request, List files) { Member seller = findMemberById(memberId); GoodsPost goodsPost = findGoodsPostById(goodsPostId); @@ -87,25 +89,17 @@ public GoodsPostResponse getGoodsPost(Long goodsPostId) { @Transactional(readOnly = true) public List getMainGoodsPosts(Long teamId) { validateTeamInfo(teamId); - - return goodsPostRepository.findMainGoodsPosts(teamId, Status.OPEN, PageRequest.of(0, 4)) - .stream() - .map(this::convertToSummaryResponse) - .toList(); + return mapToGoodsPostSummaryResponses( + goodsPostRepository.findMainGoodsPosts(teamId, Status.OPEN, PageRequest.of(0, 4)) + ); } @Transactional(readOnly = true) - public PageResponse getPageGoodsPosts(Long teamId, String categoryVal, - Pageable pageable) { + public PageResponse getPageGoodsPosts(Long teamId, String categoryVal, Pageable pageable) { validateTeamInfo(teamId); Category category = Category.from(categoryVal); - - Page pageGoodsPosts = goodsPostRepository.findPageGoodsPosts(teamId, Status.OPEN, category, - pageable); - List responses = pageGoodsPosts.getContent().stream() - .map(this::convertToSummaryResponse).toList(); - - return PageResponse.from(pageGoodsPosts, responses); + Page pageGoodsPosts = goodsPostRepository.findPageGoodsPosts(teamId, Status.OPEN, category, pageable); + return PageResponse.from(pageGoodsPosts, mapToGoodsPostSummaryResponses(pageGoodsPosts.getContent())); } public void completeTransaction(Long sellerId, Long goodsPostId, Long buyerId) { @@ -151,9 +145,10 @@ private void deleteExistingImageFiles(Long goodsPostId) { imageRepository.deleteAllByPostId(goodsPostId); } - private GoodsPostSummaryResponse convertToSummaryResponse(GoodsPost goodsPost) { - String mainImageUrl = goodsPost.getMainImageUrl(); - return GoodsPostSummaryResponse.of(goodsPost, mainImageUrl); + private List mapToGoodsPostSummaryResponses(List goodsPosts) { + return goodsPosts.stream() + .map(goodsPost -> GoodsPostSummaryResponse.of(goodsPost, goodsPost.getMainImageUrl())) + .toList(); } private GoodsPost findGoodsPostById(Long goodsPostId) { diff --git a/src/main/java/com/example/mate/domain/goodsChat/controller/GoodsChatRoomController.java b/src/main/java/com/example/mate/domain/goodsChat/controller/GoodsChatRoomController.java index 75f10e40..6cb85166 100644 --- a/src/main/java/com/example/mate/domain/goodsChat/controller/GoodsChatRoomController.java +++ b/src/main/java/com/example/mate/domain/goodsChat/controller/GoodsChatRoomController.java @@ -48,7 +48,7 @@ public ResponseEntity> createGoodsChatRoom( public ResponseEntity>> getGoodsChatRoomMessages( @AuthenticationPrincipal AuthMember member, @Parameter(description = "채팅방 ID", required = true) @PathVariable Long chatRoomId, - @Parameter(description = "페이징 정보") @ValidPageable(page = 1) Pageable pageable + @Parameter(description = "페이징 정보") @ValidPageable(page = 1, size = 20) Pageable pageable ) { PageResponse response = goodsChatService.getMessagesForChatRoom(chatRoomId, member.getMemberId(), pageable); return ResponseEntity.ok(ApiResponse.success(response)); diff --git a/src/test/java/com/example/mate/domain/goods/controller/GoodsControllerTest.java b/src/test/java/com/example/mate/domain/goods/controller/GoodsControllerTest.java index 7ec1df6c..882ceb3e 100644 --- a/src/test/java/com/example/mate/domain/goods/controller/GoodsControllerTest.java +++ b/src/test/java/com/example/mate/domain/goods/controller/GoodsControllerTest.java @@ -18,7 +18,7 @@ import com.example.mate.common.security.filter.JwtCheckFilter; import com.example.mate.config.WithAuthMember; import com.example.mate.domain.constant.Rating; -import com.example.mate.domain.goods.dto.LocationInfo; +import com.example.mate.domain.goods.dto.response.LocationInfo; import com.example.mate.domain.goods.dto.request.GoodsPostRequest; import com.example.mate.domain.goods.dto.request.GoodsReviewRequest; import com.example.mate.domain.goods.dto.response.GoodsPostResponse; diff --git a/src/test/java/com/example/mate/domain/goods/entity/GoodsPostTest.java b/src/test/java/com/example/mate/domain/goods/entity/GoodsPostTest.java index 0d66ce48..553b8e22 100644 --- a/src/test/java/com/example/mate/domain/goods/entity/GoodsPostTest.java +++ b/src/test/java/com/example/mate/domain/goods/entity/GoodsPostTest.java @@ -1,10 +1,7 @@ package com.example.mate.domain.goods.entity; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import com.example.mate.common.error.CustomException; -import com.example.mate.common.error.ErrorCode; import java.util.List; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -26,8 +23,7 @@ void upload_post_Images() { List actualPostImages = goodsPost.getGoodsPostImages(); assertThat(actualPostImages).hasSize(2); assertThat(actualPostImages).containsExactlyInAnyOrder(image, image2); - assertThat(actualPostImages.get(0).getIsMainImage()).isTrue(); - assertThat(actualPostImages.get(1).getIsMainImage()).isFalse(); + assertThat(goodsPost.getMainImageUrl()).isEqualTo(image.getImageUrl()); assertThat(image.getPost()).isEqualTo(goodsPost); } @@ -50,20 +46,7 @@ void change_post_Images() { List actualPostImages = goodsPost.getGoodsPostImages(); assertThat(actualPostImages).hasSize(2); assertThat(actualPostImages).containsExactlyInAnyOrder(newImage, newImage2); - assertThat(actualPostImages.get(0).getIsMainImage()).isTrue(); - assertThat(actualPostImages.get(1).getIsMainImage()).isFalse(); + assertThat(goodsPost.getMainImageUrl()).isEqualTo(newImage.getImageUrl()); assertThat(newImage.getPost()).isEqualTo(goodsPost); } - - @Test - @DisplayName("비어 있는 이미지를 업로드하면 CustomException 이 발생한다.") - void should_throw_CustomException_when_post_Images_are_null() { - // given - GoodsPost goodsPost = GoodsPost.builder().title("title").price(10_000).build(); - - // when & then - assertThatThrownBy(() -> goodsPost.changeImages(List.of())) - .isInstanceOf(CustomException.class) - .hasMessage(ErrorCode.GOODS_IMAGES_ARE_EMPTY.getMessage()); - } } \ No newline at end of file diff --git a/src/test/java/com/example/mate/domain/goods/integration/GoodsIntegrationTest.java b/src/test/java/com/example/mate/domain/goods/integration/GoodsIntegrationTest.java index ecc4758e..58df2993 100644 --- a/src/test/java/com/example/mate/domain/goods/integration/GoodsIntegrationTest.java +++ b/src/test/java/com/example/mate/domain/goods/integration/GoodsIntegrationTest.java @@ -14,8 +14,8 @@ import com.example.mate.domain.constant.Gender; import com.example.mate.domain.constant.Rating; import com.example.mate.domain.constant.TeamInfo; -import com.example.mate.domain.goods.dto.LocationInfo; -import com.example.mate.domain.goods.dto.MemberInfo; +import com.example.mate.domain.goods.dto.response.LocationInfo; +import com.example.mate.domain.goods.dto.response.MemberInfo; import com.example.mate.domain.goods.dto.request.GoodsPostRequest; import com.example.mate.domain.goods.dto.request.GoodsReviewRequest; import com.example.mate.domain.goods.dto.response.GoodsPostResponse; diff --git a/src/test/java/com/example/mate/domain/goods/service/GoodsServiceTest.java b/src/test/java/com/example/mate/domain/goods/service/GoodsServiceTest.java index 9f84f753..5f8d69da 100644 --- a/src/test/java/com/example/mate/domain/goods/service/GoodsServiceTest.java +++ b/src/test/java/com/example/mate/domain/goods/service/GoodsServiceTest.java @@ -1,22 +1,36 @@ package com.example.mate.domain.goods.service; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + import com.example.mate.common.error.CustomException; import com.example.mate.common.error.ErrorCode; import com.example.mate.common.response.PageResponse; import com.example.mate.domain.constant.Rating; import com.example.mate.domain.file.FileService; -import com.example.mate.domain.goods.dto.LocationInfo; import com.example.mate.domain.goods.dto.request.GoodsPostRequest; import com.example.mate.domain.goods.dto.request.GoodsReviewRequest; import com.example.mate.domain.goods.dto.response.GoodsPostResponse; import com.example.mate.domain.goods.dto.response.GoodsPostSummaryResponse; import com.example.mate.domain.goods.dto.response.GoodsReviewResponse; -import com.example.mate.domain.goods.entity.*; +import com.example.mate.domain.goods.dto.response.LocationInfo; +import com.example.mate.domain.goods.entity.Category; +import com.example.mate.domain.goods.entity.GoodsPost; +import com.example.mate.domain.goods.entity.GoodsPostImage; +import com.example.mate.domain.goods.entity.GoodsReview; +import com.example.mate.domain.goods.entity.Status; import com.example.mate.domain.goods.repository.GoodsPostImageRepository; import com.example.mate.domain.goods.repository.GoodsPostRepository; import com.example.mate.domain.goods.repository.GoodsReviewRepository; import com.example.mate.domain.member.entity.Member; import com.example.mate.domain.member.repository.MemberRepository; +import java.util.List; +import java.util.Optional; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; @@ -31,15 +45,6 @@ import org.springframework.mock.web.MockMultipartFile; import org.springframework.web.multipart.MultipartFile; -import java.util.List; -import java.util.Optional; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.*; - @ExtendWith(MockitoExtension.class) class GoodsServiceTest { @@ -109,7 +114,6 @@ private void createGoodsPostImage(GoodsPost post) { .post(post) .build(); - goodsPostImage.setAsMainImage(); goodsPost.changeImages(List.of(goodsPostImage)); } @@ -426,43 +430,6 @@ void get_main_goods_posts_success() { verify(goodsPostRepository).findMainGoodsPosts(1L, Status.OPEN, PageRequest.of(0, 4)); } - - @Test - @DisplayName("메인페이지 굿즈거래 판매글 조회 성공 - 대표 이미지가 없는 경우 기본 이미지를 반환") - void get_main_goods_posts_success_with_no_main_image() { - // given - Long teamId = 1L; - List imagesWithoutMain = List.of( - GoodsPostImage.builder().imageUrl("upload/test_img_url_1").post(goodsPost).build(), - GoodsPostImage.builder().imageUrl("upload/test_img_url_2").post(goodsPost).build() - ); - // 직접 엔티티에 추가하여, 대표 사진 마설정 - GoodsPost post = GoodsPost.builder() - .id(1L) - .teamId(1L) - .title("test title") - .category(Category.ACCESSORY) - .price(10_000) - .goodsPostImages(imagesWithoutMain).build(); - - List goodsPosts = List.of(post); - given(goodsPostRepository.findMainGoodsPosts(teamId, Status.OPEN, PageRequest.of(0, 4))).willReturn( - goodsPosts); - - // when - List responses = goodsService.getMainGoodsPosts(teamId); - - // then - assertThat(responses).isNotEmpty(); - assertThat(responses.size()).isEqualTo(goodsPosts.size()); - - GoodsPostSummaryResponse goodsPostSummaryResponse = responses.get(0); - assertThat(goodsPostSummaryResponse.getTitle()).isEqualTo(goodsPost.getTitle()); - assertThat(goodsPostSummaryResponse.getPrice()).isEqualTo(goodsPost.getPrice()); - assertThat(goodsPostSummaryResponse.getImageUrl()).isEqualTo("upload/default.jpg"); - - verify(goodsPostRepository).findMainGoodsPosts(1L, Status.OPEN, PageRequest.of(0, 4)); - } } @Nested diff --git a/src/test/java/com/example/mate/domain/goodsChat/integration/GoodsChatIntegrationTest.java b/src/test/java/com/example/mate/domain/goodsChat/integration/GoodsChatIntegrationTest.java index b8b922f8..c4ea3e7c 100644 --- a/src/test/java/com/example/mate/domain/goodsChat/integration/GoodsChatIntegrationTest.java +++ b/src/test/java/com/example/mate/domain/goodsChat/integration/GoodsChatIntegrationTest.java @@ -14,7 +14,7 @@ import com.example.mate.config.WithAuthMember; import com.example.mate.domain.constant.Gender; import com.example.mate.domain.constant.MessageType; -import com.example.mate.domain.goods.dto.LocationInfo; +import com.example.mate.domain.goods.dto.response.LocationInfo; import com.example.mate.domain.goods.entity.Category; import com.example.mate.domain.goods.entity.GoodsPost; import com.example.mate.domain.goods.entity.GoodsPostImage; diff --git a/src/test/java/com/example/mate/domain/member/integration/MemberIntegrationTest.java b/src/test/java/com/example/mate/domain/member/integration/MemberIntegrationTest.java index 2d356f30..52ed331e 100644 --- a/src/test/java/com/example/mate/domain/member/integration/MemberIntegrationTest.java +++ b/src/test/java/com/example/mate/domain/member/integration/MemberIntegrationTest.java @@ -4,7 +4,7 @@ import com.example.mate.config.WithAuthMember; import com.example.mate.domain.constant.Gender; import com.example.mate.domain.constant.Rating; -import com.example.mate.domain.goods.dto.LocationInfo; +import com.example.mate.domain.goods.dto.response.LocationInfo; import com.example.mate.domain.goods.entity.Category; import com.example.mate.domain.goods.entity.GoodsPost; import com.example.mate.domain.goods.entity.GoodsReview; diff --git a/src/test/java/com/example/mate/domain/member/integration/ProfileIntegrationTest.java b/src/test/java/com/example/mate/domain/member/integration/ProfileIntegrationTest.java index d25ef51f..67857f66 100644 --- a/src/test/java/com/example/mate/domain/member/integration/ProfileIntegrationTest.java +++ b/src/test/java/com/example/mate/domain/member/integration/ProfileIntegrationTest.java @@ -10,7 +10,7 @@ import com.example.mate.common.security.util.JwtUtil; import com.example.mate.domain.constant.Gender; import com.example.mate.domain.constant.Rating; -import com.example.mate.domain.goods.dto.LocationInfo; +import com.example.mate.domain.goods.dto.response.LocationInfo; import com.example.mate.domain.goods.entity.Category; import com.example.mate.domain.goods.entity.GoodsPost; import com.example.mate.domain.goods.entity.GoodsPostImage; diff --git a/src/test/java/com/example/mate/domain/member/service/ProfileServiceTest.java b/src/test/java/com/example/mate/domain/member/service/ProfileServiceTest.java index 3880d4cf..4133a195 100644 --- a/src/test/java/com/example/mate/domain/member/service/ProfileServiceTest.java +++ b/src/test/java/com/example/mate/domain/member/service/ProfileServiceTest.java @@ -11,7 +11,7 @@ import com.example.mate.domain.constant.Gender; import com.example.mate.domain.constant.Rating; import com.example.mate.domain.constant.TeamInfo; -import com.example.mate.domain.goods.dto.LocationInfo; +import com.example.mate.domain.goods.dto.response.LocationInfo; import com.example.mate.domain.goods.entity.Category; import com.example.mate.domain.goods.entity.GoodsPost; import com.example.mate.domain.goods.entity.GoodsPostImage; @@ -151,7 +151,6 @@ private void createGoodsPostImage(GoodsPost post) { .post(post) .build(); - goodsPostImage.setAsMainImage(); goodsPost.changeImages(List.of(goodsPostImage)); }