From d89162456c320b10d36b87abfd4b250760c8999b Mon Sep 17 00:00:00 2001 From: ariimo Date: Sat, 9 Nov 2024 00:57:29 +0900 Subject: [PATCH 01/53] =?UTF-8?q?[Weekly/11/Test/like]=20Like=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=84=B0=EB=A7=81=20=EB=B0=8F=20Event=20Unit=20Test?= =?UTF-8?q?=20=EC=88=98=EC=A0=95=20(#97)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * test: Event Unit Test 리팩터링 * feat: Like 리팩터링 --- .../wouldyouin/like/api/LikeController.java | 37 +++++++------- .../like/application/LikeService.java | 51 +++++++++---------- .../application/{ => dto}/LikeResponse.java | 2 +- .../application/dto/LikeToggleResponse.java | 20 ++++++++ .../like/persist/LikeRepository.java | 14 ++++- .../event/EventControllerUnitTest.java | 12 +++-- .../event/EventServiceUnitTest.java | 14 ++--- .../like/LikeControllerUnitTest.java | 6 +++ 8 files changed, 98 insertions(+), 58 deletions(-) rename src/main/java/org/ktc2/cokaen/wouldyouin/like/application/{ => dto}/LikeResponse.java (93%) create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/like/application/dto/LikeToggleResponse.java create mode 100644 src/test/java/org/ktc2/cokaen/wouldyouin/like/LikeControllerUnitTest.java diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/LikeController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/LikeController.java index 02a434bc..75792e55 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/LikeController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/LikeController.java @@ -1,17 +1,18 @@ package org.ktc2.cokaen.wouldyouin.like.api; -import java.util.List; import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponse; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponseBody; +import org.ktc2.cokaen.wouldyouin._common.config.ParamDefaults; import org.ktc2.cokaen.wouldyouin.auth.Authorize; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; -import org.ktc2.cokaen.wouldyouin.like.application.LikeResponse; import org.ktc2.cokaen.wouldyouin.like.application.LikeServiceFactory; +import org.ktc2.cokaen.wouldyouin.like.application.dto.LikeResponse; +import org.ktc2.cokaen.wouldyouin.like.application.dto.LikeToggleResponse; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; -import org.springframework.http.HttpStatus; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Slice; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -26,22 +27,24 @@ public class LikeController { private final LikeServiceFactory likeServiceFactory; - // Todo: 와일드카드 수정 - // Todo: api 요청시 create, delete를 분리하지말고 토글방식으로 하면 어떨지 - @GetMapping - public ResponseEntity>> getLikes(@Authorize(MemberType.normal) MemberIdentifier identifier, @RequestParam("type") MemberType memberType) { - return ApiResponse.ok(likeServiceFactory.getLikeServiceFrom(memberType).getLikes(identifier.id())); + public ResponseEntity>> getLikes( + @Authorize(MemberType.normal) MemberIdentifier identifier, + @RequestParam("type") MemberType memberType, + @RequestParam(defaultValue = ParamDefaults.PAGE) Integer page, + @RequestParam(defaultValue = ParamDefaults.PAGE_SIZE) Integer size, + @RequestParam(defaultValue = ParamDefaults.LAST_ID) Long lastId + ) { + return ApiResponse.ok( + likeServiceFactory.getLikeServiceFrom(memberType) + .getLikes(identifier.id(), PageRequest.of(page, size), lastId)); } @PostMapping("/{targetMemberId}") - public ResponseEntity> createLike(@Authorize(MemberType.normal) MemberIdentifier identifier, @PathVariable("targetMemberId") Long targetId) { - return ApiResponse.created(likeServiceFactory.getLikeServiceFrom(targetId).create(identifier.id(), targetId)); - } - - @DeleteMapping("/{targetMemberId}") - public ResponseEntity> deleteLike(@Authorize(MemberType.normal) MemberIdentifier identifier, @PathVariable("targetMemberId") Long targetId) { - likeServiceFactory.getLikeServiceFrom(targetId).delete(identifier.id(), targetId); - return ApiResponse.noContent(); + public ResponseEntity> createOrDeleteLike( + @Authorize(MemberType.normal) MemberIdentifier identifier, + @PathVariable("targetMemberId") Long targetId) { + return ApiResponse.created( + likeServiceFactory.getLikeServiceFrom(targetId).toggleLike(identifier.id(), targetId)); } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/LikeService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/LikeService.java index 01e2b32d..7b2393ab 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/LikeService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/LikeService.java @@ -1,7 +1,8 @@ package org.ktc2.cokaen.wouldyouin.like.application; -import java.util.List; import lombok.RequiredArgsConstructor; +import org.ktc2.cokaen.wouldyouin.like.application.dto.LikeResponse; +import org.ktc2.cokaen.wouldyouin.like.application.dto.LikeToggleResponse; import org.ktc2.cokaen.wouldyouin.like.persist.Like; import org.ktc2.cokaen.wouldyouin.like.persist.LikeRepository; import org.ktc2.cokaen.wouldyouin.member.application.LikeableMemberGetterFactory; @@ -9,6 +10,8 @@ import org.ktc2.cokaen.wouldyouin.member.persist.LikeableMember; import org.ktc2.cokaen.wouldyouin.member.persist.Member; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -20,44 +23,38 @@ public abstract class LikeService getLikeRepository(); + protected abstract LikeType toEntity(Member member, LikeableMember targetLikableMember); + public abstract MemberType getTargetLikeableMemberType(); @Transactional(readOnly = true) - public List getLikes(Long memberId) { - return getLikeRepository().findAllByMember(memberService.getByIdOrThrow(memberId)) - .stream() - .map(Like::getLikeableMember) - .map(LikeResponse::from) - .toList(); + public Slice getLikes(Long memberId, Pageable pageable, Long lastId) { + return getLikeRepository().findAllByMember( + memberService.getByIdOrThrow(memberId), lastId, pageable) + .map(like -> LikeResponse.from(like.getLikeableMember())); } @Transactional - public LikeResponse create(Long memberId, Long targetMemberId) { + public LikeToggleResponse toggleLike(Long memberId, Long targetMemberId) { Member member = memberService.getByIdOrThrow(memberId); LikeableMember targetLikeableMember = getLikeableMemberByIdOrThrow(targetMemberId); - getLikeRepository().findByMemberAndLikeableMember(member, targetLikeableMember) - .ifPresent(x -> { throw new RuntimeException("이미 좋아요한 사용자입니다."); }); - - targetLikeableMember.increaseLikes(); - return LikeResponse.from(getLikeRepository() - .save(toEntity(member, targetLikeableMember)) - .getLikeableMember()); - } - - @Transactional - public void delete(Long memberId, Long targetMemberId) { - Member member = memberService.getByIdOrThrow(memberId); - LikeableMember targetLikeableMember = getLikeableMemberByIdOrThrow(targetMemberId); - LikeType like = getLikeRepository().findByMemberAndLikeableMember(member, targetLikeableMember) - .orElseThrow(() -> new RuntimeException("해당 사용자를 좋아요하지 않았습니다.")); - - targetLikeableMember.decreaseLikes(); - getLikeRepository().delete(like); + return getLikeRepository().findByMemberAndLikeableMember(member, targetLikeableMember) + .map(like -> { + targetLikeableMember.decreaseLikes(); + getLikeRepository().delete(like); + return LikeToggleResponse.from(false); + }) + .orElseGet(() -> { + targetLikeableMember.increaseLikes(); + getLikeRepository().save(toEntity(member, targetLikeableMember)); + return LikeToggleResponse.from(true); + }); } @Transactional(readOnly = true) protected LikeableMember getLikeableMemberByIdOrThrow(Long likeableMemberId) { - return likeableMemberGetterFactory.get(getTargetLikeableMemberType()).getByIdOrThrow(likeableMemberId); + return likeableMemberGetterFactory.get(getTargetLikeableMemberType()) + .getByIdOrThrow(likeableMemberId); } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/LikeResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/dto/LikeResponse.java similarity index 93% rename from src/main/java/org/ktc2/cokaen/wouldyouin/like/application/LikeResponse.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/like/application/dto/LikeResponse.java index c4150bb6..cc749208 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/LikeResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/dto/LikeResponse.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin.like.application; +package org.ktc2.cokaen.wouldyouin.like.application.dto; import java.util.List; import lombok.AccessLevel; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/dto/LikeToggleResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/dto/LikeToggleResponse.java new file mode 100644 index 00000000..d5181d72 --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/dto/LikeToggleResponse.java @@ -0,0 +1,20 @@ +package org.ktc2.cokaen.wouldyouin.like.application.dto; + +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.ktc2.cokaen.wouldyouin.member.persist.LikeableMember; + +@Getter +@RequiredArgsConstructor(access = AccessLevel.PROTECTED) +@Builder +public class LikeToggleResponse { + private final boolean isLiked; + + public static LikeToggleResponse from(boolean state) { + return LikeToggleResponse.builder() + .isLiked(state) + .build(); + } +} diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/LikeRepository.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/LikeRepository.java index 3bb61ce8..97936c97 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/LikeRepository.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/LikeRepository.java @@ -1,15 +1,25 @@ package org.ktc2.cokaen.wouldyouin.like.persist; + import java.util.List; import java.util.Optional; import org.ktc2.cokaen.wouldyouin.member.persist.LikeableMember; import org.ktc2.cokaen.wouldyouin.member.persist.Member; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.NoRepositoryBean; @NoRepositoryBean public interface LikeRepository > extends JpaRepository { - Optional findByMemberAndLikeableMember(Member member, LikeableMember likeableMember); - List findAllByMember(Member member); + + @Query("SELECT l FROM #{#entityName} l " + + "JOIN FETCH l.member m " + + "JOIN FETCH l.likeableMember lm " + + "WHERE l.member.id = :member " + + "AND l.id < :lastId " + + "ORDER BY l.id DESC") + Slice findAllByMember(Member member, Long lastId, Pageable pageable); } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java index e9267358..5d14ba40 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java @@ -91,16 +91,18 @@ void getEventsByFilterOrderByDistanceAsc() throws Exception { // given LocationFilter locationFilter = new LocationFilter(0.0, 0.0, 10.0, 10.0); Location currentLocation = new Location(3.0, 2.0); + String title = "testTitle"; Category category = Category.공예; Area area = Area.광주; - int pageNumber = 1; // 교수님 - int pageSize = 10; // + int pageNumber = 1; + int pageSize = 10; Long lastId = 1L; Pageable pageable = PageRequest.of(pageNumber, pageSize); given(eventService.getAllByFilterOrderByDistanceAsc( locationFilter, currentLocation, + title, category, area, pageable, @@ -115,8 +117,9 @@ void getEventsByFilterOrderByDistanceAsc() throws Exception { .param("endLongitude", locationFilter.getEndLongitude().toString()) .param("latitude", currentLocation.getLatitude().toString()) .param("longitude", currentLocation.getLongitude().toString()) - .param("category", category.toString()) // enum을 문자열로 변환하여 설정 - .param("area", area.toString()) // enum을 문자열로 변환하여 설정 + .param("title", title) + .param("category", category.toString()) + .param("area", area.toString()) .param("page", String.valueOf(pageNumber)) .param("size", String.valueOf(pageSize)) .param("lastId", String.valueOf(lastId)) @@ -127,6 +130,7 @@ void getEventsByFilterOrderByDistanceAsc() throws Exception { then(eventService).should(times(1)).getAllByFilterOrderByDistanceAsc( any(LocationFilter.class), any(Location.class), + eq(title), eq(category), eq(area), eq(pageable), diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java index a5e5eaa7..7a9cea4d 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java @@ -19,15 +19,14 @@ import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; import org.ktc2.cokaen.wouldyouin._common.vo.Location; +import org.ktc2.cokaen.wouldyouin._global.TestData.EventDomain; import org.ktc2.cokaen.wouldyouin.curation.api.dto.LocationFilter; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; import org.ktc2.cokaen.wouldyouin.event.application.EventService; import org.ktc2.cokaen.wouldyouin.event.persist.Event; import org.ktc2.cokaen.wouldyouin.event.persist.EventRepository; -import org.ktc2.cokaen.wouldyouin._global.TestData.EventDomain; import org.ktc2.cokaen.wouldyouin.member.application.HostService; -import org.ktc2.cokaen.wouldyouin.member.application.MemberService; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.domain.PageRequest; @@ -62,6 +61,7 @@ void getAllByFilterOrderByDistanceAsc() { // given LocationFilter location = new LocationFilter(); Location currentLocation = new Location(3.0, 2.0); + String title = "testTitle"; Category category = Category.공예; Area area = Area.광주; int pageNumber = 1; @@ -71,18 +71,18 @@ void getAllByFilterOrderByDistanceAsc() { given(eventRepository.findAllByFilterOrderByDistance(location.getStartLatitude(), location.getStartLongitude(), location.getEndLatitude(), location.getEndLongitude(), currentLocation.getLatitude(), - currentLocation.getLongitude(), - category, area, pageable)).willReturn(new SliceImpl<>(List.of())); + currentLocation.getLongitude(), title, category, area, pageable)).willReturn( + new SliceImpl<>(List.of())); // when - eventService.getAllByFilterOrderByDistanceAsc(location, currentLocation, category, area, - pageable, lastId); + eventService.getAllByFilterOrderByDistanceAsc(location, currentLocation, title, category, + area, pageable, lastId); // then then(eventRepository).should(times(1)) .findAllByFilterOrderByDistance(any(Double.class), any(Double.class), any(Double.class), any(Double.class), any(Double.class), any(Double.class), - any(Category.class), any(Area.class), any(Pageable.class)); + any(String.class), any(Category.class), any(Area.class), any(Pageable.class)); } @Test diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/like/LikeControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/like/LikeControllerUnitTest.java new file mode 100644 index 00000000..f3777b3b --- /dev/null +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/like/LikeControllerUnitTest.java @@ -0,0 +1,6 @@ +package org.ktc2.cokaen.wouldyouin.like; + +public class LikeControllerUnitTest +{ + +} From 327c4f0dd529c3c3e9e50bad3c02ff46df382ddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=99=8D=EC=8B=9D?= <90020593+Daolove0323@users.noreply.github.com> Date: Sat, 9 Nov 2024 01:03:09 +0900 Subject: [PATCH 02/53] =?UTF-8?q?[Weekly/11/Test/Image]=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=20=EC=97=85=EB=A1=9C=EB=93=9C=20=EC=B5=9C?= =?UTF-8?q?=EB=8C=80=EC=82=AC=EC=9D=B4=EC=A6=88=20=EC=A0=9C=ED=95=9C=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20(#96)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 이미지 업로드 최대사이즈 제한 설정 * feat: objectMapper autowired * [Weekly/11/Test/like] Like리팩터링 및 Event Unit Test 수정 (#97) * test: Event Unit Test 리팩터링 * feat: Like 리팩터링 * feat: 이미지 업로드 최대사이즈 제한 설정 * feat: objectMapper autowired * Update AdvertisementController.java --------- Co-authored-by: ariimo --- .../wouldyouin/Image/application/ImageStorage.java | 13 +++++++------ .../Image/application/MemberImageService.java | 5 +---- .../_common/config/ObjectMapperConfig.java | 14 ++++++++++++++ .../advertisement/api/AdvertisementController.java | 6 +++--- src/main/resources/application.yml | 5 +++++ .../curation/CurationControllerUnitTest.java | 13 +++---------- 6 files changed, 33 insertions(+), 23 deletions(-) create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/_common/config/ObjectMapperConfig.java diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorage.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorage.java index 046aea29..569c92a2 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorage.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorage.java @@ -4,10 +4,10 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.UUID; +import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageRequest; import org.ktc2.cokaen.wouldyouin._common.exception.FailedToDeleteImageException; import org.ktc2.cokaen.wouldyouin._common.exception.FailedToUploadImageException; import org.springframework.beans.factory.annotation.Value; @@ -36,19 +36,19 @@ public String save(MultipartFile image, String subPath) { } // Todo: payment랑 이부분 restclient 유틸로 빼기 - public String save(String imageUrl, String subPath) { + public ImageRequest save(String imageUrl, String subPath) { RestClient client = RestClient.builder().build(); String fileName = ""; + Long size = 0L; try { ResponseEntity response = client.get() .uri(imageUrl) .retrieve() .toEntity(byte[].class); - if (Optional.ofNullable(response).isPresent() && response.getStatusCode().is2xxSuccessful()) { - byte[] imageBytes = response.getBody(); - + if (Optional.ofNullable(response.getBody()).isPresent() && response.getStatusCode().is2xxSuccessful()) { fileName = generateUuidName() + "." + getExtension(imageUrl); + size = (long) response.getBody().length; Path path = Paths.get(commonPath, subPath, fileName); Files.createDirectories(path.getParent()); Files.write(path, response.getBody()); @@ -56,7 +56,8 @@ public String save(String imageUrl, String subPath) { } catch (IOException ex) { throw new FailedToUploadImageException(); } - return subPath + "/" + fileName; + String url = subPath + "/" + fileName; + return ImageRequest.of(url, size, getExtension(imageUrl)); } public void delete(String imagePath) { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java index 621679b3..ba009567 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java @@ -60,10 +60,7 @@ public void setBaseMember(MemberImage image, BaseMember member) { image.setBaseMember(member); } - // TODO: imageUrl을 MemberImage로 변환하는 로직 추가 필요 - // Todo: extension과 size 불러오기 public MemberImage convert(String imageUrl) { - var request = ImageRequest.of(imageStorage.save(imageUrl, subPath), 123123L, "jpg"); - return memberImageRepository.save(toEntity(request)); + return memberImageRepository.save(toEntity(imageStorage.save(imageUrl, subPath))); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/config/ObjectMapperConfig.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/config/ObjectMapperConfig.java new file mode 100644 index 00000000..861847a4 --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/config/ObjectMapperConfig.java @@ -0,0 +1,14 @@ +package org.ktc2.cokaen.wouldyouin._common.config; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class ObjectMapperConfig { + + @Bean + ObjectMapper objectMapper() { + return new ObjectMapper(); + } +} \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/AdvertisementController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/AdvertisementController.java index e8beda9e..89c66f07 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/AdvertisementController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/AdvertisementController.java @@ -45,7 +45,7 @@ public ResponseEntity> getAdvertisementBy public ResponseEntity> createAdvertisement( @Valid @RequestPart AdvertisementRequest advertisementRequest, @RequestPart(required = false) MultipartFile image, - @Authorize(MemberType.admin) MemberIdentifier memberIdentifier) { + @Authorize(MemberType.admin) MemberIdentifier admin) { return ApiResponse.created(advertisementService.create(advertisementRequest, image)); } @@ -54,14 +54,14 @@ public ResponseEntity> updateAdvertisemen @PathVariable Long adId, @Valid @RequestPart AdvertisementRequest advertisementRequest, @RequestPart(required = false) MultipartFile image, - @Authorize(MemberType.admin) MemberIdentifier memberIdentifier) { + @Authorize(MemberType.admin) MemberIdentifier admin) { return ApiResponse.ok(advertisementService.update(adId, advertisementRequest, image)); } @DeleteMapping("/{adId}") public ResponseEntity> deleteAdvertisement( @PathVariable Long adId, - @Authorize(MemberType.admin) MemberIdentifier memberIdentifier) { + @Authorize(MemberType.admin) MemberIdentifier admin) { advertisementService.delete(adId); return ApiResponse.noContent(); } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index e76ba79b..446aa5a9 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -4,6 +4,11 @@ spring: application.name: WouldYouIn + servlet: + multipart: + max-file-size: 10MB + max-request-size: 10MB + # 임시 프로젝트 url wouldyouin-domain-name: http://52.78.71.136/ profiles: diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java index d6fcb308..7ee0bf05 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java @@ -19,7 +19,6 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import java.util.List; import java.util.Random; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -31,7 +30,6 @@ import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember; import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; import org.ktc2.cokaen.wouldyouin.curation.api.CurationController; -import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCardRequest; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCreateRequest; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationEditRequest; import org.ktc2.cokaen.wouldyouin.curation.application.CurationService; @@ -48,7 +46,8 @@ @WebMvcTest(CurationController.class) class CurationControllerUnitTest { - private static ObjectMapper objectMapper; + @Autowired + private ObjectMapper objectMapper; @MockBean private CurationService curationService; @@ -63,15 +62,9 @@ class CurationControllerUnitTest { private WebApplicationContext context; private static final long randomId = abs(new Random().nextLong()); - - @BeforeAll - public static void init() { - objectMapper = new ObjectMapper(); - objectMapper.registerModule(new JavaTimeModule()); - } - @BeforeEach public void setup() throws Exception { + objectMapper.registerModule(new JavaTimeModule()); mockMvc = MockMvcBuilders .webAppContextSetup(context) .apply(springSecurity()) From b7144a175c399699b4ec7b318b043872245b2824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=99=8D=EC=8B=9D?= <90020593+Daolove0323@users.noreply.github.com> Date: Sat, 9 Nov 2024 11:34:31 +0900 Subject: [PATCH 03/53] =?UTF-8?q?[Weekly/11/Config]=20feat:=20objectmapeer?= =?UTF-8?q?=20bean=EB=93=B1=EB=A1=9D=20(#98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/ktc2/cokaen/wouldyouin/Image/persist/Image.java | 1 + .../cokaen/wouldyouin/_common/config/ObjectMapperConfig.java | 5 ++++- .../wouldyouin/advertisement/persist/Advertisement.java | 1 + .../ktc2/cokaen/wouldyouin/curation/persist/Curation.java | 1 + .../cokaen/wouldyouin/curation/persist/CurationCard.java | 1 + .../java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java | 1 + .../java/org/ktc2/cokaen/wouldyouin/like/persist/Like.java | 1 + .../ktc2/cokaen/wouldyouin/member/persist/BaseMember.java | 1 + .../cokaen/wouldyouin/reservation/persist/Reservation.java | 1 + .../org/ktc2/cokaen/wouldyouin/review/persist/Review.java | 1 + 10 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/Image.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/Image.java index 73fd421f..608b30f3 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/Image.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/Image.java @@ -23,6 +23,7 @@ public abstract class Image { @Id @GeneratedValue + @Setter(AccessLevel.NONE) @Column(name = "image_id") protected Long id; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/config/ObjectMapperConfig.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/config/ObjectMapperConfig.java index 861847a4..630ab851 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/config/ObjectMapperConfig.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/config/ObjectMapperConfig.java @@ -1,6 +1,7 @@ package org.ktc2.cokaen.wouldyouin._common.config; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -9,6 +10,8 @@ public class ObjectMapperConfig { @Bean ObjectMapper objectMapper() { - return new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper(); + mapper.registerModule(new JavaTimeModule()); + return mapper; } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/persist/Advertisement.java b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/persist/Advertisement.java index a22b1bd5..f154f5a4 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/persist/Advertisement.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/persist/Advertisement.java @@ -27,6 +27,7 @@ public class Advertisement { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "advertisement_id") + @Setter(AccessLevel.NONE) private Long id; @NotNull diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java index 90462f05..3eb150e1 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java @@ -44,6 +44,7 @@ public class Curation { @Id @Column(name = "curation_id") @GeneratedValue(strategy = GenerationType.IDENTITY) + @Setter(AccessLevel.NONE) private Long id; @JoinColumn(name = "curator_id") diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCard.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCard.java index ba78a2d7..56403eee 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCard.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCard.java @@ -27,6 +27,7 @@ public class CurationCard { @Id @Column(name = "curation_card_id") @GeneratedValue(strategy = GenerationType.IDENTITY) + @Setter(AccessLevel.NONE) private Long id; @Column(name = "subtitle") diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java index 98efe2a3..205df036 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java @@ -43,6 +43,7 @@ public class Event { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + @Setter(AccessLevel.NONE) @Column(name = "event_id") private Long id; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/Like.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/Like.java index 31ae8ff1..0bc22682 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/Like.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/Like.java @@ -23,6 +23,7 @@ public abstract class Like { @Id + @Setter(AccessLevel.NONE) @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java index 2fb3ad56..2d7afb34 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java @@ -28,6 +28,7 @@ public abstract class BaseMember { @Id + @Setter(AccessLevel.NONE) @GeneratedValue(strategy = GenerationType.IDENTITY) private Long Id; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/Reservation.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/Reservation.java index fc6ae657..1ca8f6e9 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/Reservation.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/Reservation.java @@ -31,6 +31,7 @@ public class Reservation { @Id + @Setter(AccessLevel.NONE) @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "reservation_id") private Long id; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/review/persist/Review.java b/src/main/java/org/ktc2/cokaen/wouldyouin/review/persist/Review.java index d61b0c86..bc0a7d6e 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/review/persist/Review.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/review/persist/Review.java @@ -28,6 +28,7 @@ public class Review { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + @Setter(AccessLevel.NONE) @Column(name = "review_id") private Long id; From 09e19577482b5c7653b8f2a9ab8c79d8aa2485f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=99=8D=EC=8B=9D?= <90020593+Daolove0323@users.noreply.github.com> Date: Sat, 9 Nov 2024 12:02:41 +0900 Subject: [PATCH 04/53] [Weekly11/Image/IdSetting] feat: id generation type setting (#99) --- .../java/org/ktc2/cokaen/wouldyouin/Image/persist/Image.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/Image.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/Image.java index 608b30f3..436c436d 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/Image.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/Image.java @@ -3,6 +3,7 @@ import jakarta.persistence.Column; import jakarta.persistence.EntityListeners; import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.MappedSuperclass; import jakarta.validation.constraints.NotNull; @@ -22,7 +23,7 @@ public abstract class Image { @Id - @GeneratedValue + @GeneratedValue(strategy = GenerationType.IDENTITY) @Setter(AccessLevel.NONE) @Column(name = "image_id") protected Long id; From 3d1d3da96a66e72a75d520ff9bdda06257deb4b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=99=8D=EC=8B=9D?= <90020593+Daolove0323@users.noreply.github.com> Date: Sat, 9 Nov 2024 12:14:11 +0900 Subject: [PATCH 05/53] [Weekly/11/Config] feat: ddl create strategy (#100) --- src/main/resources/application-create.yml | 2 +- src/main/resources/application-deploy.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application-create.yml b/src/main/resources/application-create.yml index 72e6a118..019b5eda 100644 --- a/src/main/resources/application-create.yml +++ b/src/main/resources/application-create.yml @@ -9,4 +9,4 @@ spring: jpa: show-sql: true hibernate: - ddl-auto: update + ddl-auto: create diff --git a/src/main/resources/application-deploy.yml b/src/main/resources/application-deploy.yml index 99a9f9e6..d7b6971f 100644 --- a/src/main/resources/application-deploy.yml +++ b/src/main/resources/application-deploy.yml @@ -9,7 +9,7 @@ spring: jpa: show-sql: false hibernate: - ddl-auto: none + ddl-auto: create # log4j log level setting logging.level.org.ktc2.cokaen.wouldyouin: info \ No newline at end of file From 3bf1c14eda70dbbac8dcef0102092b83ccda9899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=99=8D=EC=8B=9D?= <90020593+Daolove0323@users.noreply.github.com> Date: Sat, 9 Nov 2024 12:25:35 +0900 Subject: [PATCH 06/53] [Weekly/11] feat: image path (#101) --- .../org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java index cc4fa869..669e7844 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java @@ -41,10 +41,11 @@ public ResponseEntity>> uploadImages( return ApiResponse.ok(imageServiceFactory.getImageServiceByImageType(imageDomain).saveAndCreateImages(images)); } + // Todo: path 수정 @GetMapping(value = "{path}", produces = {MediaType.IMAGE_PNG_VALUE, MediaType.IMAGE_JPEG_VALUE}) public ResponseEntity getImage(@PathVariable String path) { try { - return ResponseEntity.status(HttpStatus.OK).body(Files.readAllBytes(Paths.get(path))); + return ResponseEntity.status(HttpStatus.OK).body(Files.readAllBytes(Paths.get("src/main/resources/static", path))); } catch (IOException e) { throw new FailToReadImageException(); } From 688a9f6ff7b4ca9b61507e7e2712f60aa95bee89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=99=8D=EC=8B=9D?= <90020593+Daolove0323@users.noreply.github.com> Date: Sat, 9 Nov 2024 14:41:17 +0900 Subject: [PATCH 07/53] [Weekly/11] Image/path (#102) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: image path * feat: 불필요한 출력문 제거 --- .../org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java | 4 ---- .../ktc2/cokaen/wouldyouin/Image/api/dto/ImageResponse.java | 1 - 2 files changed, 5 deletions(-) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java index 669e7844..e767d577 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java @@ -7,13 +7,9 @@ import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageResponse; import org.ktc2.cokaen.wouldyouin.Image.application.ImageServiceFactory; -import org.ktc2.cokaen.wouldyouin.Image.application.ImageStorage; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponse; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponseBody; import org.ktc2.cokaen.wouldyouin._common.exception.FailToReadImageException; -import org.ktc2.cokaen.wouldyouin.auth.Authorize; -import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; -import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageResponse.java index 5c219943..fa9856b6 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageResponse.java @@ -15,7 +15,6 @@ public class ImageResponse { private Long size; public static ImageResponse from(Image image, String domainName) { - System.out.println("도메인" + domainName); return ImageResponse.builder() .id(image.getId()) .url(domainName + image.getUrl()) From 8d3068f53fd85c101d22151125b429d2b259808b Mon Sep 17 00:00:00 2001 From: daolove0323 Date: Sat, 9 Nov 2024 15:21:30 +0900 Subject: [PATCH 08/53] =?UTF-8?q?[Weekly/11/Feature/ImageController]=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20=EC=98=88=EC=99=B8=EC=88=98=EC=A0=95=20(#103)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit feat: image controller 수정 feat: 이미지 컨트롤러 예외수정 (#103) --- .../cokaen/wouldyouin/Image/api/ImageController.java | 12 ++++++++---- .../_common/exception/FailToReadImageException.java | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java index e767d577..9f5ba36b 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java @@ -10,6 +10,8 @@ import org.ktc2.cokaen.wouldyouin._common.api.ApiResponse; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponseBody; import org.ktc2.cokaen.wouldyouin._common.exception.FailToReadImageException; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -37,11 +39,13 @@ public ResponseEntity>> uploadImages( return ApiResponse.ok(imageServiceFactory.getImageServiceByImageType(imageDomain).saveAndCreateImages(images)); } - // Todo: path 수정 - @GetMapping(value = "{path}", produces = {MediaType.IMAGE_PNG_VALUE, MediaType.IMAGE_JPEG_VALUE}) - public ResponseEntity getImage(@PathVariable String path) { + // Todo: path 수정, service로 로직이동 + @GetMapping(value = "images/{domain}/{path}", produces = {MediaType.IMAGE_PNG_VALUE, MediaType.IMAGE_JPEG_VALUE}) + public ResponseEntity getImage(@PathVariable String domain, @PathVariable String path) { try { - return ResponseEntity.status(HttpStatus.OK).body(Files.readAllBytes(Paths.get("src/main/resources/static", path))); + Resource resource = new ClassPathResource("static/images/" + domain + "/" + path); + System.out.println(Paths.get("static/images", domain, path)); + return ResponseEntity.status(HttpStatus.OK).body(Files.readAllBytes(resource.getFile().toPath())); } catch (IOException e) { throw new FailToReadImageException(); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailToReadImageException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailToReadImageException.java index 99c73fbd..a3c674ad 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailToReadImageException.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailToReadImageException.java @@ -5,6 +5,6 @@ public class FailToReadImageException extends BusinessException { public FailToReadImageException() { - super(ErrorCode.ENTITY_NOT_FOUND); + super(ErrorCode.FAIL_TO_READ_IMAGE); } } From 0acde4c85e671fd957f936a71a7cdece4e79539e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=99=8D=EC=8B=9D?= <90020593+Daolove0323@users.noreply.github.com> Date: Sat, 9 Nov 2024 21:55:57 +0900 Subject: [PATCH 09/53] =?UTF-8?q?[Weekly/11/All/refactor=20]=20=20?= =?UTF-8?q?=EC=A0=84=EB=B0=98=EC=A0=81=EC=9D=B8=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wouldyouin/Image/api/ImageController.java | 2 +- .../AdvertisementImageService.java | 4 - .../application/CurationImageService.java | 4 - .../Image/application/EventImageService.java | 4 - .../Image/application/ImageService.java | 10 +- .../Image/application/ImageStorage.java | 6 +- .../Image/application/MemberImageService.java | 10 - .../wouldyouin/_common/error/ErrorCode.java | 8 +- .../_common/error/GlobalExceptionHandler.java | 2 +- .../_common/exception/BusinessException.java | 5 - .../CurrentLocationEmptyException.java | 10 - .../exception/EntityNotFoundException.java | 4 +- .../exception/EntityParamIsNullException.java | 10 - .../exception/FailToReadImageException.java | 6 +- .../FailedToDeleteImageException.java | 4 +- .../exception/FailedToPayException.java | 2 +- .../FailedToUploadImageException.java | 4 +- .../exception/NoLeftSeatException.java | 4 +- .../exception/UnauthorizedException.java | 2 +- .../wouldyouin/_common/vo/UserLocation.java | 26 + .../application/AdvertisementService.java | 22 +- .../api/dto/CurationSliceResponse.java | 13 +- .../application/CurationCardService.java | 19 +- .../curation/application/CurationService.java | 44 +- .../wouldyouin/event/api/EventController.java | 3 +- .../event/api/dto/EventSliceResponse.java | 16 +- .../event/application/EventService.java | 103 ++-- .../wouldyouin/event/persist/Event.java | 3 - .../payment/application/PaymentService.java | 5 +- .../api/ReservationController.java | 3 +- .../api/dto/ReservationRequest.java | 10 +- .../api/dto/ReservationSliceResponse.java | 7 +- .../application/ReservationService.java | 49 +- .../reservation/persist/Reservation.java | 2 +- .../cokaen/wouldyouin/_global/TestData.java | 3 +- .../curation/CurationControllerUnitTest.java | 25 +- .../event/EventControllerUnitTest.java | 5 +- .../event/EventServiceUnitTest.java | 4 +- .../ReservationControllerUnitTest.java | 504 +++++++++++++----- 39 files changed, 597 insertions(+), 370 deletions(-) delete mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/CurrentLocationEmptyException.java delete mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/EntityParamIsNullException.java create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/_common/vo/UserLocation.java diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java index 9f5ba36b..9ca3a74d 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java @@ -47,7 +47,7 @@ public ResponseEntity getImage(@PathVariable String domain, @PathVariabl System.out.println(Paths.get("static/images", domain, path)); return ResponseEntity.status(HttpStatus.OK).body(Files.readAllBytes(resource.getFile().toPath())); } catch (IOException e) { - throw new FailToReadImageException(); + throw new FailToReadImageException("이미지를 읽어오는데 실패했습니다."); } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java index 967b22a1..1c8a87df 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java @@ -1,13 +1,11 @@ package org.ktc2.cokaen.wouldyouin.Image.application; -import java.util.Optional; import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin.Image.api.ImageDomain; import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageRequest; import org.ktc2.cokaen.wouldyouin.Image.persist.AdvertisementImage; import org.ktc2.cokaen.wouldyouin.Image.persist.AdvertisementImageRepository; import org.ktc2.cokaen.wouldyouin.Image.persist.ImageRepository; -import org.ktc2.cokaen.wouldyouin._common.exception.EntityParamIsNullException; import org.ktc2.cokaen.wouldyouin.advertisement.persist.Advertisement; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -54,8 +52,6 @@ public AdvertisementImage saveAndCreateImage(MultipartFile image) { @Transactional public void setAd(AdvertisementImage image, Advertisement ad) { - Optional.ofNullable(image).orElseThrow(() -> new EntityParamIsNullException(getImageDomain().name() + " image")); - Optional.ofNullable(ad).orElseThrow(() -> new EntityParamIsNullException("advertisement")); image.setAdvertisement(ad); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/CurationImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/CurationImageService.java index 518c2a58..54d141de 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/CurationImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/CurationImageService.java @@ -1,13 +1,11 @@ package org.ktc2.cokaen.wouldyouin.Image.application; -import java.util.Optional; import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin.Image.api.ImageDomain; import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageRequest; import org.ktc2.cokaen.wouldyouin.Image.persist.CurationImage; import org.ktc2.cokaen.wouldyouin.Image.persist.CurationImageRepository; import org.ktc2.cokaen.wouldyouin.Image.persist.ImageRepository; -import org.ktc2.cokaen.wouldyouin._common.exception.EntityParamIsNullException; import org.ktc2.cokaen.wouldyouin.curation.persist.CurationCard; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -47,8 +45,6 @@ protected CurationImage toEntity(ImageRequest imageRequest) { @Transactional public void setCuration(CurationImage image, CurationCard curationCard) { - Optional.ofNullable(image).orElseThrow(() -> new EntityParamIsNullException(getImageDomain().name() + " image")); - Optional.ofNullable(curationCard).orElseThrow(() -> new EntityParamIsNullException("curationCard")); image.setCurationCard(curationCard); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/EventImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/EventImageService.java index ecfc2a77..c650bafe 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/EventImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/EventImageService.java @@ -1,13 +1,11 @@ package org.ktc2.cokaen.wouldyouin.Image.application; -import java.util.Optional; import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin.Image.api.ImageDomain; import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageRequest; import org.ktc2.cokaen.wouldyouin.Image.persist.EventImage; import org.ktc2.cokaen.wouldyouin.Image.persist.EventImageRepository; import org.ktc2.cokaen.wouldyouin.Image.persist.ImageRepository; -import org.ktc2.cokaen.wouldyouin._common.exception.EntityParamIsNullException; import org.ktc2.cokaen.wouldyouin.event.persist.Event; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -44,8 +42,6 @@ protected EventImage toEntity(ImageRequest imageRequest) { @Transactional public void setEvent(EventImage image, Event event) { - Optional.ofNullable(image).orElseThrow(() -> new EntityParamIsNullException(getImageDomain().name() + " image")); - Optional.ofNullable(event).orElseThrow(() -> new EntityParamIsNullException("event")); image.setEvent(event); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java index aaac70b4..5b9f1eea 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java @@ -34,7 +34,7 @@ public abstract class ImageService { public T getById(Long id) { return getImageRepository().findById(id) - .orElseThrow(() -> new EntityNotFoundException(getImageDomain().name() + " Image")); + .orElseThrow(() -> new EntityNotFoundException(getImageDomain().name() + " 이미지를 찾을 수 없습니다.")); } protected ImageResponse create(ImageRequest imageRequest) { @@ -42,8 +42,7 @@ protected ImageResponse create(ImageRequest imageRequest) { } protected void delete(Long id) { - getImageRepository().findById(id) - .orElseThrow(() -> new EntityNotFoundException(getImageDomain().name() + " Image")); + getById(id); getImageRepository().deleteById(id); } @@ -59,9 +58,8 @@ public List saveAndCreateImages(List images) { @Transactional public void deleteAndDelete(Long id) { - String url = getImageRepository().findById(id) - .orElseThrow(() -> new EntityNotFoundException(getImageDomain().name() + " Image")).getUrl(); + T image = getById(id); delete(id); - imageStorage.delete(url); + imageStorage.delete(image.getUrl()); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorage.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorage.java index 569c92a2..dc953d58 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorage.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorage.java @@ -30,7 +30,7 @@ public String save(MultipartFile image, String subPath) { Files.createDirectories(path.getParent()); Files.write(path, image.getBytes()); } catch (IOException ex) { - throw new FailedToUploadImageException(); + throw new FailedToUploadImageException("이미지를 업로드하는데 실패했습니다."); } return subPath + "/" + fileName; } @@ -54,7 +54,7 @@ public ImageRequest save(String imageUrl, String subPath) { Files.write(path, response.getBody()); } } catch (IOException ex) { - throw new FailedToUploadImageException(); + throw new FailedToUploadImageException("URL을 통해 이미지를 저장하는데 실패했습니다."); } String url = subPath + "/" + fileName; return ImageRequest.of(url, size, getExtension(imageUrl)); @@ -64,7 +64,7 @@ public void delete(String imagePath) { try { Files.deleteIfExists(Paths.get(imagePath)); } catch (IOException ex) { - throw new FailedToDeleteImageException(); + throw new FailedToDeleteImageException("이미지를 삭제하는데 실패했습니다."); } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java index ba009567..01772b1a 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java @@ -1,24 +1,16 @@ package org.ktc2.cokaen.wouldyouin.Image.application; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Optional; import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin.Image.api.ImageDomain; import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageRequest; import org.ktc2.cokaen.wouldyouin.Image.persist.ImageRepository; import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImageRepository; -import org.ktc2.cokaen.wouldyouin._common.exception.EntityParamIsNullException; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMember; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMemberRepository; import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.client.RestClient; @Service @RequiredArgsConstructor @@ -55,8 +47,6 @@ protected MemberImage toEntity(ImageRequest imageRequest) { @Transactional public void setBaseMember(MemberImage image, BaseMember member) { - Optional.ofNullable(image).orElseThrow(() -> new EntityParamIsNullException(getImageDomain().name() + " image")); - Optional.ofNullable(member).orElseThrow(() -> new EntityParamIsNullException("baseMember")); image.setBaseMember(member); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/ErrorCode.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/ErrorCode.java index 1e52d1d9..16824078 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/ErrorCode.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/ErrorCode.java @@ -6,11 +6,11 @@ @Getter public enum ErrorCode { - UNEXPECTED(HttpStatus.BAD_REQUEST.value(), "-1", "Unexpected exception occurred"), + UNEXPECTED(HttpStatus.BAD_REQUEST.value(), "-1", "예상치 못한 오류가 발생했습니다."), - ENTITY_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "-10404", "Can not find a %s Entity"), + ENTITY_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "-10404", "엔티티를 찾을 수 없습니다."), - NO_LEFT_SEAT(HttpStatus.BAD_REQUEST.value(), "-10400", "No left seat"), + NO_LEFT_SEAT(HttpStatus.BAD_REQUEST.value(), "-10400", "남은 좌석이 부족합니다."), INVALID_INPUT_VALUE(HttpStatus.BAD_REQUEST.value(), "-20400", "Invalid Input Value"), @@ -20,8 +20,6 @@ public enum ErrorCode { UNAUTHORIZED(HttpStatus.UNAUTHORIZED.value(), "-20400", "Unauthorized, %s."), - ENTITY_PARAM_IS_NULL(HttpStatus.BAD_REQUEST.value(), "-20400", "%s is null"), - FAIL_TO_UPLOAD_IMAGE(HttpStatus.CONFLICT.value(), "-20400", "Fail to upload image"), FAIL_TO_DELETE_IMAGE(HttpStatus.CONFLICT.value(), "-20400", "Fail to delete image"), diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/GlobalExceptionHandler.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/GlobalExceptionHandler.java index 14949f8e..4c62df26 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/GlobalExceptionHandler.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/GlobalExceptionHandler.java @@ -16,7 +16,7 @@ public class GlobalExceptionHandler { @ExceptionHandler(BusinessException.class) public ResponseEntity> handleBusinessException(BusinessException e) { - return ApiResponse.error(e.getErrorCode()); + return ApiResponse.error(e.getErrorCode(), e.getMessage()); } @ExceptionHandler(MethodArgumentNotValidException.class) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/BusinessException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/BusinessException.java index 00993644..b9eaff4d 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/BusinessException.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/BusinessException.java @@ -14,9 +14,4 @@ public BusinessException(String message, ErrorCode errorCode) { super(message); this.errorCode = errorCode; } - - public BusinessException(ErrorCode errorCode, Object... args) { - super(String.format(errorCode.getMessage(), args)); - this.errorCode = errorCode; - } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/CurrentLocationEmptyException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/CurrentLocationEmptyException.java deleted file mode 100644 index 28e1effd..00000000 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/CurrentLocationEmptyException.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.ktc2.cokaen.wouldyouin._common.exception; - -import org.ktc2.cokaen.wouldyouin._common.error.ErrorCode; - -public class CurrentLocationEmptyException extends BusinessException { - - public CurrentLocationEmptyException() { - super(ErrorCode.CURRENT_LOCATION_EMPTY, "현재 위치 정보를 찾을 수 없습니다."); - } -} diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/EntityNotFoundException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/EntityNotFoundException.java index e242366d..3399f1f4 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/EntityNotFoundException.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/EntityNotFoundException.java @@ -4,7 +4,7 @@ public class EntityNotFoundException extends BusinessException { - public EntityNotFoundException(String notFoundedEntityName) { - super(ErrorCode.ENTITY_NOT_FOUND, notFoundedEntityName); + public EntityNotFoundException(String message) { + super(message, ErrorCode.ENTITY_NOT_FOUND); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/EntityParamIsNullException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/EntityParamIsNullException.java deleted file mode 100644 index 4df395ed..00000000 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/EntityParamIsNullException.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.ktc2.cokaen.wouldyouin._common.exception; - -import org.ktc2.cokaen.wouldyouin._common.error.ErrorCode; - -public class EntityParamIsNullException extends BusinessException{ - - public EntityParamIsNullException(String entityName) { - super(ErrorCode.ENTITY_PARAM_IS_NULL, entityName); - } -} \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailToReadImageException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailToReadImageException.java index a3c674ad..69e4acd4 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailToReadImageException.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailToReadImageException.java @@ -4,7 +4,7 @@ public class FailToReadImageException extends BusinessException { - public FailToReadImageException() { - super(ErrorCode.FAIL_TO_READ_IMAGE); + public FailToReadImageException(String message) { + super(message, ErrorCode.FAIL_TO_READ_IMAGE); } -} +} \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailedToDeleteImageException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailedToDeleteImageException.java index e470f6d1..1989d4ee 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailedToDeleteImageException.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailedToDeleteImageException.java @@ -4,7 +4,7 @@ public class FailedToDeleteImageException extends BusinessException { - public FailedToDeleteImageException() { - super(ErrorCode.FAIL_TO_DELETE_IMAGE, ErrorCode.FAIL_TO_DELETE_IMAGE.getMessage()); + public FailedToDeleteImageException(String message) { + super(message, ErrorCode.FAIL_TO_DELETE_IMAGE); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailedToPayException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailedToPayException.java index 76aa3a3d..11307f78 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailedToPayException.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailedToPayException.java @@ -5,6 +5,6 @@ public class FailedToPayException extends BusinessException { public FailedToPayException(String message) { - super(ErrorCode.FAIL_TO_PAY, message); + super(message, ErrorCode.FAIL_TO_PAY); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailedToUploadImageException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailedToUploadImageException.java index 813b211a..53314a64 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailedToUploadImageException.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailedToUploadImageException.java @@ -4,7 +4,7 @@ public class FailedToUploadImageException extends BusinessException { - public FailedToUploadImageException() { - super(ErrorCode.FAIL_TO_UPLOAD_IMAGE, ErrorCode.FAIL_TO_UPLOAD_IMAGE.getMessage()); + public FailedToUploadImageException(String message) { + super(message, ErrorCode.FAIL_TO_UPLOAD_IMAGE); } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/NoLeftSeatException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/NoLeftSeatException.java index e23d0ae5..e2690850 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/NoLeftSeatException.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/NoLeftSeatException.java @@ -4,7 +4,7 @@ public class NoLeftSeatException extends BusinessException { - public NoLeftSeatException() { - super(ErrorCode.NO_LEFT_SEAT); + public NoLeftSeatException(String message) { + super(message, ErrorCode.NO_LEFT_SEAT); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/UnauthorizedException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/UnauthorizedException.java index b7abfe7f..7a17c69f 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/UnauthorizedException.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/UnauthorizedException.java @@ -7,4 +7,4 @@ public class UnauthorizedException extends BusinessException { public UnauthorizedException(String message) { super(message, ErrorCode.UNAUTHORIZED); } -} +} \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/vo/UserLocation.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/vo/UserLocation.java new file mode 100644 index 00000000..32dfa4aa --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/vo/UserLocation.java @@ -0,0 +1,26 @@ +package org.ktc2.cokaen.wouldyouin._common.vo; + +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +public class UserLocation { + + @NotNull(message = "위도 값은 필수입니다.") + @Min(value = -90, message = "위도는 -90 이상이어야 합니다.") + @Max(value = 90, message = "위도는 90 이하여야 합니다.") + private Double latitude; + + @NotNull(message = "경도 값은 필수입니다.") + @Min(value = -180, message = "경도는 -180 이상이어야 합니다.") + @Max(value = 180, message = "경도는 180 이하여야 합니다.") + private Double longitude; +} diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java index f0f63274..4004da27 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java @@ -22,15 +22,21 @@ public class AdvertisementService { private final AdvertisementRepository adRepository; private final AdvertisementImageService adImageService; - @Transactional(readOnly = true) - public List getAllActiveAdvertisements() { - return adRepository.findAllActiveAdvertisements(LocalDateTime.now()).stream() - .map(AdvertisementResponse::from).toList(); + @Transactional + public Advertisement getByIdOrThrow(Long adId) { + return adRepository.findById(adId) + .orElseThrow(() -> new EntityNotFoundException("해당하는 광고를 찾을 수 없습니다.")); } @Transactional(readOnly = true) public AdvertisementResponse getAdvertisementByAdId(Long adId) { - return AdvertisementResponse.from(adRepository.findById(adId).orElseThrow(() -> new EntityNotFoundException("Advertisement"))); + return AdvertisementResponse.from(getByIdOrThrow(adId)); + } + + @Transactional(readOnly = true) + public List getAllActiveAdvertisements() { + return adRepository.findAllActiveAdvertisements(LocalDateTime.now()).stream() + .map(AdvertisementResponse::from).toList(); } // Todo: 롤백될 경우, 저장한 이미지 삭제 @@ -38,7 +44,7 @@ public AdvertisementResponse getAdvertisementByAdId(Long adId) { public AdvertisementResponse create(AdvertisementRequest adRequest, MultipartFile image) { AdvertisementImage adImage = adImageService.saveAndCreateImage(image); Advertisement ad = adRepository.save(adRequest.toEntity(adImage)); - adImage.setAdvertisement(ad); + adImageService.setAd(adImage, ad); return AdvertisementResponse.from(ad); } @@ -46,7 +52,7 @@ public AdvertisementResponse create(AdvertisementRequest adRequest, MultipartFil // Todo: 롤백될 경우, 저장한 이미지 삭제 @Transactional public AdvertisementResponse update(Long adId, AdvertisementRequest adRequest, MultipartFile multipartFile) { - Advertisement ad = adRepository.findById(adId).orElseThrow(() -> new EntityNotFoundException("Advertisement")); + Advertisement ad = getByIdOrThrow(adId); Optional.ofNullable(multipartFile).ifPresentOrElse( image -> { adImageService.deleteAndDelete(ad.getAdvertisementImage().getId()); @@ -64,7 +70,7 @@ public AdvertisementResponse update(Long adId, AdvertisementRequest adRequest, M @Transactional public void delete(Long adId) { - Advertisement ad = adRepository.findById(adId).orElseThrow(() -> new EntityNotFoundException("Advertisement")); + Advertisement ad = getByIdOrThrow(adId); adImageService.deleteAndDelete(ad.getAdvertisementImage().getId()); adRepository.deleteById(adId); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationSliceResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationSliceResponse.java index 1e426d05..ad3de907 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationSliceResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationSliceResponse.java @@ -4,19 +4,22 @@ import lombok.Builder; import lombok.Getter; import org.ktc2.cokaen.wouldyouin._common.api.SliceInfo; +import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; +import org.springframework.data.domain.Slice; @Getter @Builder public class CurationSliceResponse { private final List curations; - private final SliceInfo slice; + private final SliceInfo sliceInfo; - public static CurationSliceResponse of(List curationResponses, int sliceSize, long lastId) { + public static CurationSliceResponse from(Slice curations, int size, Long lastId) { return CurationSliceResponse.builder() - .curations(curationResponses) - .slice(SliceInfo.builder() - .sliceSize(sliceSize) + .curations(curations.stream() + .map(CurationResponse::from).toList()) + .sliceInfo(SliceInfo.builder() + .sliceSize(size) .lastId(lastId) .build()) .build(); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java index de13ad0e..55f9b835 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java @@ -1,12 +1,10 @@ package org.ktc2.cokaen.wouldyouin.curation.application; import java.util.List; -import java.util.Optional; import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin.Image.application.CurationImageService; import org.ktc2.cokaen.wouldyouin.Image.persist.CurationImage; import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; -import org.ktc2.cokaen.wouldyouin._common.exception.EntityParamIsNullException; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCardRequest; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCardResponse; import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; @@ -23,23 +21,17 @@ public class CurationCardService { private final CurationImageService curationImageService; @Transactional(readOnly = true) - public CurationCardResponse getById(Long id) { - return CurationCardResponse.from( - curationCardRepository.findById(id).orElseThrow(() -> new EntityNotFoundException("CurationCard")) - ); + public CurationCard getByIdOrThrow(Long id) { + return curationCardRepository.findById(id).orElseThrow(() -> new EntityNotFoundException("해당하는 큐레이션 카드를 찾을 수 없습니다.")); } @Transactional(readOnly = true) - public List getByCurationId(Curation curation) { - Optional.ofNullable(curation).orElseThrow(() -> new EntityParamIsNullException("Curation")); - return curationCardRepository.findAllByCurationOrderByIdAsc(curation).stream() - .map(CurationCardResponse::from).toList(); + public CurationCardResponse getById(Long id) { + return CurationCardResponse.from(getByIdOrThrow(id)); } @Transactional public void setCuration(CurationCard curationCard, Curation curation) { - Optional.ofNullable(curationCard).orElseThrow(() -> new EntityParamIsNullException("CurationCard")); - Optional.ofNullable(curation).orElseThrow(() -> new EntityParamIsNullException("Curation")); curationCard.setCuration(curation); } @@ -55,8 +47,7 @@ public CurationCard create(CurationCardRequest request) { @Transactional public void delete(Long id) { - CurationCard target = curationCardRepository.findById(id) - .orElseThrow(() -> new EntityNotFoundException("CurationCard")); + CurationCard target = getByIdOrThrow(id); target.getCurationImages().forEach(image -> curationImageService.deleteAndDelete(image.getId())); curationCardRepository.deleteById(id); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationService.java index 162b1cf9..c1988cc2 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationService.java @@ -32,7 +32,7 @@ public class CurationService { @Transactional(readOnly = true) public Curation getByIdOrThrow(Long id) throws EntityNotFoundException { - return curationRepository.findById(id).orElseThrow(() -> new EntityNotFoundException("Curation")); + return curationRepository.findById(id).orElseThrow(() -> new EntityNotFoundException("해당하는 큐레이션을 찾을 수 없습니다.")); } @Transactional(readOnly = true) @@ -41,25 +41,18 @@ public CurationResponse getById(Long curationId) { } @Transactional(readOnly = true) - public CurationSliceResponse getAllByAreaOrderByCreatedDateDesc(Area area, Pageable pageable, Long lastId) { - return getCurationSliceResponse( - curationRepository.findAllByAreaOrderByCreatedDateDesc(area, lastId, pageable), lastId); + public CurationSliceResponse getAllByAreaOrderByCreatedDateDesc(Area area, Pageable pageable, Long oldLastId) { + Slice curations = curationRepository.findAllByAreaOrderByCreatedDateDesc(area, oldLastId, pageable); + Long newLastId = getLastId(curations, oldLastId); + return CurationSliceResponse.from(curations, curations.getSize(), newLastId); } @Transactional(readOnly = true) public CurationSliceResponse getAllByCuratorIdOrderByCreatedDateDesc(Long curatorId, Pageable pageable, Long lastId) { - return getCurationSliceResponse( - curationRepository.findAllByCuratorOrderByCreatedDateDesc( - curatorService.getByIdOrThrow(curatorId), lastId, pageable), lastId); - } - - private CurationSliceResponse getCurationSliceResponse(Slice curationSlice, Long lastId) { - List curations = curationSlice.stream().map(CurationResponse::from).toList(); - if (!curationSlice.hasContent()) { - Long id = curationSlice.getContent().getLast().getId(); - return CurationSliceResponse.of(curations, curationSlice.getSize(), id); - } - return CurationSliceResponse.of(curations, curationSlice.getSize(), lastId); + Slice curations = curationRepository.findAllByCuratorOrderByCreatedDateDesc( + curatorService.getByIdOrThrow(curatorId), lastId, pageable); + Long newLastId = getLastId(curations, lastId); + return CurationSliceResponse.from(curations, curations.getSize(), newLastId); } @Transactional @@ -76,12 +69,6 @@ public CurationResponse create(Long curatorId, CurationCreateRequest curationCre return CurationResponse.from(curation); } - public void validateCuratorId(Long curatorId, Curation curation) { - if (!curatorId.equals(curation.getCurator().getId())) { - throw new UnauthorizedException("큐레이터 ID가 큐레이션의 큐레이터 ID와 일치하지 않습니다."); - } - } - @Transactional public CurationResponse update(Long curatorId, Long curationId, CurationEditRequest curationEditRequest) { Curation curation = getByIdOrThrow(curationId); @@ -106,4 +93,17 @@ public void delete(Long curatorId, Long curationId) { .forEach(curationCard -> curationCardService.delete(curationCard.getId())); curationRepository.deleteById(curationId); } + + private Long getLastId(Slice curations, Long oldLastId) { + if (curations.hasContent()) { + return curations.getContent().getLast().getId(); + } + return oldLastId; + } + + public void validateCuratorId(Long curatorId, Curation curation) { + if (!curatorId.equals(curation.getCurator().getId())) { + throw new UnauthorizedException("큐레이터 ID가 큐레이션의 큐레이터 ID와 일치하지 않습니다."); + } + } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/EventController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/EventController.java index abf24bd9..9230416a 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/EventController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/EventController.java @@ -8,6 +8,7 @@ import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; import org.ktc2.cokaen.wouldyouin._common.vo.Location; +import org.ktc2.cokaen.wouldyouin._common.vo.UserLocation; import org.ktc2.cokaen.wouldyouin.auth.Authorize; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.curation.api.dto.LocationFilter; @@ -40,7 +41,7 @@ public class EventController { @GetMapping public ResponseEntity> getEventsByFilterOrderByDistanceAsc( @ModelAttribute LocationFilter locationFilter, - @ModelAttribute Location currentLocation, + @Valid @ModelAttribute UserLocation currentLocation, @RequestParam(defaultValue = ParamDefaults.TITLE) String title, @RequestParam(defaultValue = ParamDefaults.CATEGORY) Category category, @RequestParam(defaultValue = ParamDefaults.AREA) Area area, diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventSliceResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventSliceResponse.java index 51889b9a..64929632 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventSliceResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventSliceResponse.java @@ -4,19 +4,25 @@ import lombok.Builder; import lombok.Getter; import org.ktc2.cokaen.wouldyouin._common.api.SliceInfo; +import org.ktc2.cokaen.wouldyouin.event.persist.Event; +import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationResponse; +import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationSliceResponse; +import org.ktc2.cokaen.wouldyouin.reservation.persist.Reservation; +import org.springframework.data.domain.Slice; @Getter @Builder public class EventSliceResponse { private List events; - private SliceInfo slice; + private SliceInfo sliceInfo; - public static EventSliceResponse of(List eventResponses, int sliceSize, long lastId) { + public static EventSliceResponse from(Slice reservations, int size, Long lastId) { return EventSliceResponse.builder() - .events(eventResponses) - .slice(SliceInfo.builder() - .sliceSize(sliceSize) + .events(reservations.stream() + .map(EventResponse::from).toList()) + .sliceInfo(SliceInfo.builder() + .sliceSize(size) .lastId(lastId) .build()) .build(); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java index 8a31d149..07ac64aa 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java @@ -3,12 +3,13 @@ import java.util.List; import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin.Image.application.EventImageService; -import org.ktc2.cokaen.wouldyouin._common.exception.CurrentLocationEmptyException; +import org.ktc2.cokaen.wouldyouin.Image.persist.EventImage; import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; +import org.ktc2.cokaen.wouldyouin._common.exception.NoLeftSeatException; import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; -import org.ktc2.cokaen.wouldyouin._common.vo.Location; +import org.ktc2.cokaen.wouldyouin._common.vo.UserLocation; import org.ktc2.cokaen.wouldyouin.curation.api.dto.LocationFilter; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; @@ -17,6 +18,7 @@ import org.ktc2.cokaen.wouldyouin.event.persist.Event; import org.ktc2.cokaen.wouldyouin.event.persist.EventRepository; import org.ktc2.cokaen.wouldyouin.member.application.HostService; +import org.ktc2.cokaen.wouldyouin.member.persist.Host; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; import org.springframework.stereotype.Service; @@ -30,81 +32,82 @@ public class EventService { private final HostService hostService; private final EventImageService eventImageService; - @Transactional(readOnly = true) - public EventSliceResponse getAllByFilterOrderByDistanceAsc(LocationFilter location, Location currentLocation, String title, - Category category, Area area, Pageable pageable, Long lastId) { - validateCurrentLocation(currentLocation); - return getEventSliceResponse( - eventRepository.findAllByFilterOrderByDistance(location.getStartLatitude(), location.getStartLongitude(), - location.getEndLatitude(), location.getEndLongitude(), currentLocation.getLatitude(), currentLocation.getLongitude(), - title, category, area, pageable), lastId); - } - - private void validateCurrentLocation(Location currentLocation) { - if (currentLocation.getLatitude() == null || currentLocation.getLongitude() == null) { - throw new CurrentLocationEmptyException(); - } + @Transactional + public Event getByIdOrThrow(Long id) throws EntityNotFoundException { + return eventRepository.findById(id).orElseThrow(() -> new EntityNotFoundException("해당하는 이벤트를 찾을 수 없습니다.")); } @Transactional(readOnly = true) - public EventSliceResponse getAllByHostIdOrderByCreatedDateDesc(Long hostId, Pageable pageable, Long lastId) { - return getEventSliceResponse( - eventRepository.findAllByHostIdOrderByEventIdDesc(hostId, lastId, pageable), lastId); - } - - private EventSliceResponse getEventSliceResponse(Slice eventSlice, Long lastId) { - List events = eventSlice.stream().map(EventResponse::from).toList(); - if (eventSlice.hasContent()) { - Long id = eventSlice.getContent().getLast().getId(); - return EventSliceResponse.of(events, eventSlice.getSize(), id); - } - return EventSliceResponse.of(events, eventSlice.getSize(), lastId); + public EventResponse getById(Long id) { + return EventResponse.from(getByIdOrThrow(id)); } @Transactional(readOnly = true) - public EventResponse getById(Long id) { - return EventResponse.from(getByIdOrThrow(id)); + public EventSliceResponse getAllByFilterOrderByDistanceAsc(LocationFilter location, UserLocation currentLocation, String title, + Category category, Area area, Pageable pageable, Long beforeLastId) { + Slice events = eventRepository.findAllByFilterOrderByDistance( + location.getStartLatitude(), location.getStartLongitude(), location.getEndLatitude(), + location.getEndLongitude(), currentLocation.getLatitude(), currentLocation.getLongitude(), + title, category, area, pageable + ); + Long newLastId = getLastId(events, beforeLastId); + return EventSliceResponse.from(events, events.getSize(), newLastId); } - public Event getByIdOrThrow(Long id) throws EntityNotFoundException { - return eventRepository.findById(id).orElseThrow(() -> new EntityNotFoundException("Event")); + @Transactional(readOnly = true) + public EventSliceResponse getAllByHostIdOrderByCreatedDateDesc(Long hostId, Pageable pageable, Long beforeLastId) { + Slice events = eventRepository.findAllByHostIdOrderByEventIdDesc(hostId, beforeLastId, pageable); + Long newLastId = getLastId(events, beforeLastId); + return EventSliceResponse.from(events, events.getSize(), newLastId); } @Transactional public EventResponse create(Long hostId, EventCreateRequest eventCreateRequest) { - return EventResponse.from( - eventRepository.save(eventCreateRequest.toEntity( - hostService.getByIdOrThrow(hostId), - eventCreateRequest.getImageIds().stream() - .map(eventImageService::getById) - .toList()))); - } - - private void validateHostId(Long hostId, Event event) { - if (!hostId.equals(event.getHost().getId())) { - throw new UnauthorizedException("호스트 ID가 행사의 호스트 ID와 일치하지 않습니다."); - } + Host host = hostService.getByIdOrThrow(hostId); + List images = eventCreateRequest.getImageIds().stream() + .map(eventImageService::getById).toList(); + Event event = eventRepository.save(eventCreateRequest.toEntity(host, images)); + images.forEach(image -> eventImageService.setEvent(image, event)); + return EventResponse.from(event); } @Transactional public EventResponse update(Long hostId, Long eventId, EventEditRequest eventEditRequest) { Event event = getByIdOrThrow(eventId); validateHostId(hostId, event); - event.updateFrom(eventEditRequest, eventEditRequest.getImageIds().stream() - .map(eventImageService::getById) - .toList()); + event.getImages().forEach(image -> eventImageService.deleteAndDelete(image.getId())); + List images = eventEditRequest.getImageIds().stream() + .map(eventImageService::getById).toList(); + event.updateFrom(eventEditRequest, images); + images.forEach(image -> eventImageService.setEvent(image, event)); return EventResponse.from(event); } @Transactional public void delete(Long hostId, Long eventId) { - Event event = getByIdOrThrow(eventId); - validateHostId(hostId, event); + validateHostId(hostId, getByIdOrThrow(eventId)); eventRepository.deleteById(eventId); } @Transactional public void decreaseLeftSeat(Long eventId, Integer count) { - getByIdOrThrow(eventId).decreaseLeftSeat(count); + Event event = getByIdOrThrow(eventId); + if (event.getLeftSeat() < count) { + throw new NoLeftSeatException("남은 좌석이 부족합니다."); + } + event.decreaseLeftSeat(count); + } + + private static Long getLastId(Slice events, Long oldLastId) { + if (events.hasContent()) { + return events.getContent().getLast().getId(); + } + return oldLastId; + } + + public void validateHostId(Long hostId, Event event) { + if (!hostId.equals(event.getHost().getId())) { + throw new UnauthorizedException("호스트 ID가 행사의 호스트 ID와 일치하지 않습니다."); + } } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java index 205df036..205688ef 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java @@ -136,9 +136,6 @@ public void updateFrom(EventEditRequest eventEditRequest, List image } public void decreaseLeftSeat(Integer count) { - if (this.leftSeat < count) { - throw new NoLeftSeatException(); - } this.leftSeat -= count; } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/payment/application/PaymentService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/payment/application/PaymentService.java index 70cb9ca3..0506aab3 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/payment/application/PaymentService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/payment/application/PaymentService.java @@ -15,7 +15,8 @@ @Service public class PaymentService { - // Todo: util로 이동하여 재사용 + // Todo: pay 취소 기능 추가 + // Todo: RestClient 관련 로직 유틸로 분리 private final RestClient client = RestClient.builder().build(); @Value("${oauth.payment.kakao_pay_request_host}") @@ -45,7 +46,7 @@ public KakaoPayResponse createPayment(KakaoPayRequest kakaoPayRequest) { .retrieve() .body(KakaoPayResponse.class); } catch (Exception ex) { - throw new FailedToPayException("Kakao Pay"); + throw new FailedToPayException("결제에 실패했습니다."); } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/ReservationController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/ReservationController.java index 8bdc91ea..4199bfea 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/ReservationController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/ReservationController.java @@ -42,11 +42,12 @@ public ResponseEntity> getReservations @GetMapping("/events/{eventId}") public ResponseEntity> getReservationsByEventId( + @Authorize(MemberType.host) MemberIdentifier host, @PathVariable Long eventId, @RequestParam(defaultValue = ParamDefaults.PAGE) Integer page, @RequestParam(defaultValue = ParamDefaults.PAGE_SIZE) Integer size, @RequestParam(defaultValue = ParamDefaults.LAST_ID) Long lastId) { - return ApiResponse.ok(reservationService.getAllByEventId(eventId, PageRequest.of(page, size), lastId)); + return ApiResponse.ok(reservationService.getAllByEventId(host.id(), eventId, PageRequest.of(page, size), lastId)); } @GetMapping("/{reservationId}") diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/ReservationRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/ReservationRequest.java index aa7c11e1..0ca28bf2 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/ReservationRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/ReservationRequest.java @@ -4,6 +4,7 @@ import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotNull; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; import org.ktc2.cokaen.wouldyouin.event.persist.Event; import org.ktc2.cokaen.wouldyouin.member.persist.Member; @@ -11,24 +12,21 @@ @Getter @Builder(toBuilder = true) +@EqualsAndHashCode public class ReservationRequest { @NotNull(message = "이벤트 ID는 필수입니다.") private Long eventId; - @NotNull(message = "가격은 필수입니다.") - @Min(value = 0, message = "가격은 0 이상이어야 합니다.") - @Max(value = 1000000, message = "가격은 1,000,000원 이하이어야 합니다.") - private Integer price; - @NotNull(message = "수량은 필수입니다.") + @Min(value = 1, message = "수량은 1개 이상이어야 합니다.") private Integer quantity; public Reservation toEntity(Member member, Event event) { return Reservation.builder() .member(member) .event(event) - .price(price) + .price(event.getPrice() * quantity) .quantity(quantity) .build(); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/ReservationSliceResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/ReservationSliceResponse.java index 61c076dc..0431a703 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/ReservationSliceResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/ReservationSliceResponse.java @@ -4,6 +4,8 @@ import lombok.Builder; import lombok.Getter; import org.ktc2.cokaen.wouldyouin._common.api.SliceInfo; +import org.ktc2.cokaen.wouldyouin.reservation.persist.Reservation; +import org.springframework.data.domain.Slice; @Getter @Builder @@ -12,9 +14,10 @@ public class ReservationSliceResponse { private List reservations; private SliceInfo sliceInfo; - public static ReservationSliceResponse of(List reservations, int size, Long lastId) { + public static ReservationSliceResponse from(Slice reservations, int size, Long lastId) { return ReservationSliceResponse.builder() - .reservations(reservations) + .reservations(reservations.stream() + .map(ReservationResponse::from).toList()) .sliceInfo(SliceInfo.builder() .sliceSize(size) .lastId(lastId) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java index c94af33a..73d26a72 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java @@ -28,51 +28,56 @@ public class ReservationService { private final MemberService memberService; private final EventService eventService; - @Transactional(readOnly = true) - public ReservationSliceResponse getAllByMemberId(Long memberId, Pageable pageable, Long lastId) { - return getReservationSliceResponse( - reservationRepository.findByMemberIdOrderByReservationIdDesc(memberId, lastId, pageable), lastId); + @Transactional + public Reservation getByIdOrThrow(Long id) { + return reservationRepository.findById(id) + .orElseThrow(() -> new EntityNotFoundException("해당하는 예약을 찾을 수 없습니다.")); } @Transactional(readOnly = true) - public ReservationSliceResponse getAllByEventId(Long eventId, Pageable pageable, Long lastId) { - return getReservationSliceResponse( - reservationRepository.findByEventIdOrderByReservationIdDesc(eventId, lastId, pageable), lastId); + public ReservationResponse getById(Long id) { + return ReservationResponse.from(getByIdOrThrow(id)); } - private ReservationSliceResponse getReservationSliceResponse(Slice reservationSlice, Long lastId) { - List reservations = reservationSlice.stream().map(ReservationResponse::from).toList(); - if (!reservationSlice.hasContent()) { - Long id = reservationSlice.getContent().getLast().getId(); - return ReservationSliceResponse.of(reservations, reservationSlice.getSize(), id); - } - return ReservationSliceResponse.of(reservations, reservationSlice.getSize(), lastId); + @Transactional(readOnly = true) + public ReservationSliceResponse getAllByMemberId(Long memberId, Pageable pageable, Long oldLastId) { + Slice reservations = reservationRepository.findByMemberIdOrderByReservationIdDesc(memberId, oldLastId, pageable); + Long newLastId = getLastId(reservations, oldLastId); + return ReservationSliceResponse.from(reservations, reservations.getSize(), newLastId); } @Transactional(readOnly = true) - public ReservationResponse getById(Long id) { - Reservation target = reservationRepository.findById(id).orElseThrow(() -> new EntityNotFoundException("reservation ")); - return ReservationResponse.from(target); + public ReservationSliceResponse getAllByEventId(Long hostId, Long eventId, Pageable pageable, Long oldLastId) { + eventService.validateHostId(hostId, eventService.getByIdOrThrow(eventId)); + Slice reservations = reservationRepository.findByEventIdOrderByReservationIdDesc(eventId, oldLastId, pageable); + Long newLastId = getLastId(reservations, oldLastId); + return ReservationSliceResponse.from(reservations, reservations.getSize(), newLastId); + } + + private Long getLastId(Slice reservations, Long oldLastId) { + if (reservations.hasContent()) { + return reservations.getContent().getLast().getId(); + } + return oldLastId; } @Transactional public KakaoPayResponse create(Long memberId, ReservationRequest reservationRequest) { Reservation reservation = reservationRepository.save(reservationRequest.toEntity( memberService.getByIdOrThrow(memberId), - eventService.getByIdOrThrow(reservationRequest.getEventId()))); + eventService.getByIdOrThrow(reservationRequest.getEventId())) + ); eventService.decreaseLeftSeat(reservation.getEvent().getId(), reservationRequest.getQuantity()); return paymentService.createPayment(KakaoPayRequest.from(reservation)); } @Transactional public void delete(Long memberId, Long reservationId) { - Reservation reservation = reservationRepository.findById(reservationId) - .orElseThrow(() -> new EntityNotFoundException("reservation ")); - validateMemberId(memberId, reservation); + validateMemberId(memberId, getByIdOrThrow(reservationId)); reservationRepository.deleteById(reservationId); } - public void validateMemberId(Long memberId, Reservation reservation) { + private void validateMemberId(Long memberId, Reservation reservation) { if (!memberId.equals(reservation.getMember().getId())) { throw new UnauthorizedException("member ID가 예약의 member ID와 일치하지 않습니다."); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/Reservation.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/Reservation.java index 1ca8f6e9..14d3bbf6 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/Reservation.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/Reservation.java @@ -31,8 +31,8 @@ public class Reservation { @Id - @Setter(AccessLevel.NONE) @GeneratedValue(strategy = GenerationType.IDENTITY) + @Setter(AccessLevel.NONE) @Column(name = "reservation_id") private Long id; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java index d1bdbf13..a021fb23 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java @@ -237,7 +237,6 @@ public static class ReservationDomain { public static ReservationRequest createValidReservationRequest() { return ReservationRequest.builder() .eventId(1L) - .price(15000) .quantity(2) .build(); } @@ -368,7 +367,7 @@ public static CurationResponse createValidCurationResponse() { public static CurationSliceResponse createValidCurationSliceResponse() { return CurationSliceResponse.builder() .curations(List.of(createValidCurationResponse())) - .slice(TestData.createSliceInfo()) + .sliceInfo(TestData.createSliceInfo()) .build(); } } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java index 7ee0bf05..716f14a9 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java @@ -64,7 +64,6 @@ class CurationControllerUnitTest { @BeforeEach public void setup() throws Exception { - objectMapper.registerModule(new JavaTimeModule()); mockMvc = MockMvcBuilders .webAppContextSetup(context) .apply(springSecurity()) @@ -173,7 +172,9 @@ void createCuration2() throws Exception { .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(CurationDomain.createValidCurationCreateRequest()))) .andDo(print()) - .andExpect(status().isUnauthorized()); + .andExpect(status().isUnauthorized()) + .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); + // then then(curationService).shouldHaveNoInteractions(); @@ -189,7 +190,9 @@ void createCuration3() throws Exception { .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(CurationDomain.createValidCurationCreateRequest()))) .andDo(print()) - .andExpect(status().isUnauthorized()); + .andExpect(status().isUnauthorized()) + .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); + // then then(curationService).shouldHaveNoInteractions(); @@ -400,7 +403,9 @@ void updateCuration2() throws Exception { .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(CurationDomain.createValidCurationEditRequest()))) .andDo(print()) - .andExpect(status().isUnauthorized()); + .andExpect(status().isUnauthorized()) + .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); + // then then(curationService).shouldHaveNoInteractions(); @@ -416,7 +421,9 @@ void updateCuration3() throws Exception { .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(CurationDomain.createValidCurationEditRequest()))) .andDo(print()) - .andExpect(status().isUnauthorized()); + .andExpect(status().isUnauthorized()) + .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); + // then then(curationService).shouldHaveNoInteractions(); @@ -599,7 +606,9 @@ void deleteCuration2() throws Exception { mockMvc.perform(delete("/api/curations/" + randomId) .with(csrf())) .andDo(print()) - .andExpect(status().isUnauthorized()); + .andExpect(status().isUnauthorized()) + .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); + // then then(curationService).shouldHaveNoInteractions(); @@ -613,7 +622,9 @@ void deleteCuration3() throws Exception { mockMvc.perform(delete("/api/curations/" + randomId) .with(csrf())) .andDo(print()) - .andExpect(status().isUnauthorized()); + .andExpect(status().isUnauthorized()) + .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); + // then then(curationService).shouldHaveNoInteractions(); diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java index 5d14ba40..d930cbf0 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java @@ -26,6 +26,7 @@ import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; import org.ktc2.cokaen.wouldyouin._common.vo.Location; +import org.ktc2.cokaen.wouldyouin._common.vo.UserLocation; import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; import org.ktc2.cokaen.wouldyouin.auth.application.JwtService; import org.ktc2.cokaen.wouldyouin.curation.api.dto.LocationFilter; @@ -90,7 +91,7 @@ public void setup() throws Exception { void getEventsByFilterOrderByDistanceAsc() throws Exception { // given LocationFilter locationFilter = new LocationFilter(0.0, 0.0, 10.0, 10.0); - Location currentLocation = new Location(3.0, 2.0); + UserLocation currentLocation = new UserLocation(3.0, 2.0); String title = "testTitle"; Category category = Category.공예; Area area = Area.광주; @@ -129,7 +130,7 @@ void getEventsByFilterOrderByDistanceAsc() throws Exception { // then then(eventService).should(times(1)).getAllByFilterOrderByDistanceAsc( any(LocationFilter.class), - any(Location.class), + any(UserLocation.class), eq(title), eq(category), eq(area), diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java index 7a9cea4d..e38a6596 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java @@ -11,6 +11,7 @@ import java.util.List; import java.util.Optional; +import org.h2.engine.User; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -19,6 +20,7 @@ import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; import org.ktc2.cokaen.wouldyouin._common.vo.Location; +import org.ktc2.cokaen.wouldyouin._common.vo.UserLocation; import org.ktc2.cokaen.wouldyouin._global.TestData.EventDomain; import org.ktc2.cokaen.wouldyouin.curation.api.dto.LocationFilter; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; @@ -60,7 +62,7 @@ void setUp() { void getAllByFilterOrderByDistanceAsc() { // given LocationFilter location = new LocationFilter(); - Location currentLocation = new Location(3.0, 2.0); + UserLocation currentLocation = new UserLocation(3.0, 2.0); String title = "testTitle"; Category category = Category.공예; Area area = Area.광주; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java index 7b9124ff..8c9711ee 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java @@ -1,140 +1,364 @@ -//package org.ktc2.cokaen.wouldyouin.reservation; -// -//import static java.lang.Math.abs; -//import static org.mockito.ArgumentMatchers.eq; -//import static org.mockito.BDDMockito.then; -//import static org.mockito.Mockito.times; -//import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; -//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -//import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -// -//import com.fasterxml.jackson.databind.ObjectMapper; -//import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -//import java.util.Random; -//import org.junit.jupiter.api.BeforeAll; -//import org.junit.jupiter.api.BeforeEach; -//import org.junit.jupiter.api.DisplayName; -//import org.junit.jupiter.api.Test; -//import org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain; -//import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockCurator; -//import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost; -//import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember; -//import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; -//import org.ktc2.cokaen.wouldyouin.reservation.api.ReservationController; -//import org.ktc2.cokaen.wouldyouin.reservation.application.ReservationService; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -//import org.springframework.boot.test.mock.mockito.MockBean; -//import org.springframework.data.domain.PageRequest; -//import org.springframework.test.web.servlet.MockMvc; -//import org.springframework.test.web.servlet.setup.MockMvcBuilders; -//import org.springframework.web.context.WebApplicationContext; -// -//@WebMvcTest(ReservationController.class) -//class ReservationControllerUnitTest { -// -// private static ObjectMapper objectMapper; -// -// @MockBean -// private ReservationService reservationService; -// -// @MockBean -// private JwtAuthFilter jwtAuthFilter; -// -// @Autowired -// private MockMvc mockMvc; -// -// @Autowired -// private WebApplicationContext context; -// private static final long randomId = abs(new Random().nextLong()); -// -// @BeforeAll -// public static void init() { -// objectMapper = new ObjectMapper(); -// objectMapper.registerModule(new JavaTimeModule()); -// } -// -// @BeforeEach -// public void setup() throws Exception { -// mockMvc = MockMvcBuilders -// .webAppContextSetup(context) -// .apply(springSecurity()) -// .build(); -// } -// -// @Test -// @DisplayName("jwt 토큰 정보에 해당하는 member의 예약 목록을 조회한다.") -// @WithMockMember -// void getReservationsByMemberId1() throws Exception { -// // given, when -// mockMvc.perform(get("/api/reservations") -// .param("page", "5") -// .param("size", "20") -// .param("lastId", "100")).andDo(print()) -// .andExpect(status().isOk()); -// -// // then -// then(reservationService).should(times(1)).getAllByMemberId( -// eq(MemberDomain.validMemberId), eq(PageRequest.of(5, 20)), eq(100L)); -// } -// -// @Test -// @DisplayName("RequestParam으로 페이지 정보가 주어지지 않으면 기본값으로 페이지를 생성한다") -// @WithMockMember -// void getReservationsByMemberId2() throws Exception { -// // given, when -// mockMvc.perform(get("/api/reservations")).andDo(print()) -// .andExpect(status().isOk()); -// -// // then -// then(reservationService).should(times(1)).getAllByMemberId( -// eq(MemberDomain.validMemberId), eq(PageRequest.of(0, 10)), eq(Long.MAX_VALUE)); -// } -// -// @Test -// @DisplayName("jwt 토큰 정보에 해당하는 curator의 예약 목록을 조회한다.") -// @WithMockCurator -// void getReservationsByMemberId3() throws Exception { -// // given, when -// mockMvc.perform(get("/api/reservations") -// .param("page", "5") -// .param("size", "20") -// .param("lastId", "100")).andDo(print()) -// .andExpect(status().isOk()); -// -// // then -// then(reservationService).should(times(1)).getAllByMemberId( -// eq(MemberDomain.validMemberId), eq(PageRequest.of(5, 20)), eq(100L)); -// } -// -// @Test -// @DisplayName("Host의 권한으로 자신의 예약을 조회할 수 없다.") -// @WithMockHost -// void getReservationsByMemberId4() throws Exception { -// // given, when -// mockMvc.perform(get("/api/reservations") -// .param("page", "5") -// .param("size", "20") -// .param("lastId", "100")).andDo(print()) -// .andExpect(status().isUnauthorized()); -// -// // then -// then(reservationService).shouldHaveNoInteractions(); -// } -// -// @Test -// @DisplayName("PathVariable로 이벤트 ID를 받아 해당하는 이벤트를 조회한다.") -// @WithMockHost -// void getReservationsByMemberId4() throws Exception { -// // given, when -// mockMvc.perform(get("/api/reservations") -// .param("page", "5") -// .param("size", "20") -// .param("lastId", "100")).andDo(print()) -// .andExpect(status().isUnauthorized()); -// -// // then -// then(reservationService).shouldHaveNoInteractions(); -// } -//} \ No newline at end of file +package org.ktc2.cokaen.wouldyouin.reservation; + +import static java.lang.Math.abs; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.BDDMockito.then; +import static org.mockito.Mockito.times; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; +import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.Random; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain; +import org.ktc2.cokaen.wouldyouin._global.TestData.ReservationDomain; +import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockCurator; +import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost; +import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember; +import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; +import org.ktc2.cokaen.wouldyouin.reservation.api.ReservationController; +import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationRequest; +import org.ktc2.cokaen.wouldyouin.reservation.application.ReservationService; +import org.mockito.ArgumentCaptor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.data.domain.PageRequest; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +@WebMvcTest(ReservationController.class) +class ReservationControllerUnitTest { + + @Autowired + private ObjectMapper objectMapper; + + @MockBean + private ReservationService reservationService; + + @MockBean + private JwtAuthFilter jwtAuthFilter; + + @Autowired + private MockMvc mockMvc; + + @Autowired + private WebApplicationContext context; + private static final long randomId = abs(new Random().nextLong()); + + @BeforeEach + public void setup() throws Exception { + mockMvc = MockMvcBuilders + .webAppContextSetup(context) + .apply(springSecurity()) + .build(); + } + + @Test + @DisplayName("jwt 토큰 정보에 해당하는 member의 예약 목록을 조회한다.") + @WithMockMember + void getReservationsByMemberId1() throws Exception { + // given, when + mockMvc.perform(get("/api/reservations") + .param("page", "5") + .param("size", "20") + .param("lastId", "100")).andDo(print()) + .andExpect(status().isOk()); + + // then + then(reservationService).should(times(1)).getAllByMemberId( + eq(MemberDomain.validMemberId), eq(PageRequest.of(5, 20)), eq(100L)); + } + + @Test + @DisplayName("RequestParam으로 페이지 정보가 주어지지 않으면 기본값으로 예약을 조회한다.") + @WithMockMember + void getReservationsByMemberId2() throws Exception { + // given, when + mockMvc.perform(get("/api/reservations")).andDo(print()) + .andExpect(status().isOk()); + + // then + then(reservationService).should(times(1)).getAllByMemberId( + eq(MemberDomain.validMemberId), eq(PageRequest.of(0, 10)), eq(Long.MAX_VALUE)); + } + + @Test + @DisplayName("jwt 토큰 정보에 해당하는 curator의 예약 목록을 조회한다.") + @WithMockCurator + void getReservationsByMemberId3() throws Exception { + // given, when + mockMvc.perform(get("/api/reservations") + .param("page", "5") + .param("size", "20") + .param("lastId", "100")).andDo(print()) + .andExpect(status().isOk()); + + // then + then(reservationService).should(times(1)).getAllByMemberId( + eq(MemberDomain.validCuratorId), eq(PageRequest.of(5, 20)), eq(100L)); + } + + @Test + @DisplayName("Host의 권한으로 자신의 예약을 조회할 수 없다.") + @WithMockHost + void getReservationsByMemberId4() throws Exception { + // given, when + mockMvc.perform(get("/api/reservations") + .param("page", "5") + .param("size", "20") + .param("lastId", "100")).andDo(print()) + .andExpect(status().isUnauthorized()) + .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); + + // then + then(reservationService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("PathVariable로 이벤트 ID를 받아 해당하는 이벤트를 조회한다.") + @WithMockHost + void getReservationByEventId1() throws Exception { + // given, when + mockMvc.perform(get("/api/reservations/events/" + randomId) + .param("page", "5") + .param("size", "20") + .param("lastId", "100")).andDo(print()) + .andExpect(status().isOk()); + + // then + then(reservationService).should(times(1)).getAllByEventId( + eq(MemberDomain.validHostId), eq(randomId), eq(PageRequest.of(5, 20)), eq(100L)); + } + + @Test + @DisplayName("RequestParam으로 페이지 정보가 주어지지 않으면 기본값으로 예약을 조회한다.") + @WithMockHost + void getReservationByEventId2() throws Exception { + // given, when + mockMvc.perform(get("/api/reservations/events/" + randomId)) + .andDo(print()) + .andExpect(status().isOk()); + + // then + then(reservationService).should(times(1)).getAllByEventId( + eq(MemberDomain.validHostId), eq(randomId), eq(PageRequest.of(0, 10)), eq(Long.MAX_VALUE)); + } + + @Test + @DisplayName("Member의 권한으로 이벤트 ID를 통해 이벤트의 예약을 조회할 수 없다.") + @WithMockMember + void getReservationByEventId3() throws Exception { + // given, when + mockMvc.perform(get("/api/reservations/events/" + randomId)) + .andDo(print()) + .andExpect(status().isUnauthorized()) + .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); + + // then + then(reservationService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("Curator의 권한으로 이벤트 ID를 통해 이벤트의 예약을 조회할 수 없다.") + @WithMockCurator + void getReservationByEventId4() throws Exception { + // given, when + mockMvc.perform(get("/api/reservations/events/" + randomId)) + .andDo(print()) + .andExpect(status().isUnauthorized()) + .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); + + // then + then(reservationService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("예약 ID를 통해 예약을 조회한다.") + @WithMockCurator + void getReservationById1() throws Exception { + // given, when + mockMvc.perform(get("/api/reservations/" + randomId)) + .andDo(print()) + .andExpect(status().isOk()); + + // then + then(reservationService).should(times(1)).getById(randomId); + } + + @Test + @DisplayName("Member 권한으로 RequestBody를 통해 예약을 생성한다.") + @WithMockMember + void createReservation1() throws Exception { + // given + ArgumentCaptor captor = ArgumentCaptor.forClass(ReservationRequest.class); + ReservationRequest request = ReservationDomain.createValidReservationRequest(); + + // when + mockMvc.perform(post("/api/reservations") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isCreated()); + + // then + then(reservationService).should(times(1)).create(eq(MemberDomain.validMemberId), captor.capture()); + assertThat(captor.getValue()).isEqualTo(request); + } + + @Test + @DisplayName("Curator 권한으로 RequestBody를 통해 예약을 생성한다.") + @WithMockCurator + void createReservation2() throws Exception { + // given + ArgumentCaptor captor = ArgumentCaptor.forClass(ReservationRequest.class); + ReservationRequest request = ReservationDomain.createValidReservationRequest(); + + // when + mockMvc.perform(post("/api/reservations") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isCreated()); + + // then + then(reservationService).should(times(1)).create(eq(MemberDomain.validCuratorId), captor.capture()); + assertThat(captor.getValue()).isEqualTo(request); + } + + @Test + @DisplayName("Host 권한으로 예약을 생성할 수 없다.") + @WithMockHost + void createReservation3() throws Exception { + // given, when + mockMvc.perform(post("/api/reservations") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(ReservationDomain.createValidReservationRequest()))) + .andDo(print()) + .andExpect(status().isUnauthorized()) + .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); + + // then + then(reservationService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("예약 생성 시 이벤트 ID는 빈 값이 될 수 없다.") + @WithMockMember + void createReservation4() throws Exception { + // given + ReservationRequest request = ReservationDomain.createValidReservationRequest().toBuilder() + .eventId(null).build(); + + // when + mockMvc.perform(post("/api/reservations") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("이벤트 ID는 필수입니다.")); + + // then + then(reservationService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("예약 생성 시 수량은 빈 값이 될 수 없다.") + @WithMockMember + void createReservation5() throws Exception { + // given + ReservationRequest request = ReservationDomain.createValidReservationRequest().toBuilder() + .quantity(null).build(); + + // when + mockMvc.perform(post("/api/reservations") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("수량은 필수입니다.")); + + // then + then(reservationService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("예약 생성 시 수량은 1개 이상이어야 한다.") + @WithMockMember + void createReservation6() throws Exception { + // given + ReservationRequest request = ReservationDomain.createValidReservationRequest().toBuilder() + .quantity(0).build(); + + // when + mockMvc.perform(post("/api/reservations") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("수량은 1개 이상이어야 합니다.")); + + // then + then(reservationService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("Member 권한으로 예약 ID를 통해 예약을 삭제한다.") + @WithMockMember + void deleteReservation1() throws Exception { + // given, when + mockMvc.perform(delete("/api/reservations/" + randomId) + .with(csrf())) + .andDo(print()) + .andExpect(status().isNoContent()); + + // then + then(reservationService).should(times(1)).delete(MemberDomain.validMemberId, randomId); + } + + @Test + @DisplayName("Curator 권한으로 예약 ID를 통해 예약을 삭제한다.") + @WithMockCurator + void deleteReservation2() throws Exception { + // given, when + mockMvc.perform(delete("/api/reservations/" + randomId) + .with(csrf())) + .andDo(print()) + .andExpect(status().isNoContent()); + + // then + then(reservationService).should(times(1)).delete(MemberDomain.validCuratorId, randomId); + } + + @Test + @DisplayName("Host 권한으로 예약 ID를 통해 예약을 삭제한다.") + @WithMockHost + void deleteReservation3() throws Exception { + // given, when + mockMvc.perform(delete("/api/reservations/" + randomId) + .with(csrf())) + .andDo(print()) + .andExpect(status().isUnauthorized()) + .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); + + // then + then(reservationService).shouldHaveNoInteractions(); + } +} \ No newline at end of file From 8e5ecefa76d9ddfb5ff867b44ad731760619cea8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=99=8D=EC=8B=9D?= <90020593+Daolove0323@users.noreply.github.com> Date: Sun, 10 Nov 2024 21:51:47 +0900 Subject: [PATCH 10/53] =?UTF-8?q?[Weekly/11/Feature/RestClientUtil]=20?= =?UTF-8?q?=EC=9C=A0=ED=8B=B8=EC=B6=94=EA=B0=80,=20=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=EC=A7=80=20=EC=82=AD=EC=A0=9C=20(#106)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: restClient, objectMapper util로 이동 * fix: 이미지 삭제 * feat: applicationTest 임시주석 --- .../wouldyouin/Image/api/ImageController.java | 34 +++----- .../AdvertisementImageService.java | 17 ++-- .../application/CurationImageService.java | 9 +- .../Image/application/EventImageService.java | 14 ++-- .../Image/application/ImageService.java | 13 ++- .../application/ImageServiceFactory.java | 11 +-- .../Image/application/ImageStorage.java | 83 ------------------- .../application/ImageStorageService.java | 54 ++++++++++++ .../Image/application/MemberImageService.java | 14 ++-- .../{config => api}/ParamDefaults.java | 2 +- .../_common/config/RestClientConfig.java | 14 ++++ .../wouldyouin/_common/error/ErrorCode.java | 2 + .../exception/ExtensionParsingException.java | 10 +++ .../wouldyouin/_common/persist/Area.java | 21 ----- .../wouldyouin/_common/persist/Category.java | 12 --- .../wouldyouin/_common/persist/Location.java | 17 ---- .../wouldyouin/_common/util/FileUtil.java | 69 +++++++++++++++ .../wouldyouin/_common/util/KakaoPayUtil.java | 33 ++++++++ .../_common/util/RestClientUtil.java | 30 +++++++ .../application/AdvertisementService.java | 6 +- .../advertisement/persist/Advertisement.java | 1 - .../wouldyouin/auth/api/AuthController.java | 10 +-- .../dto/LocalLoginRequest.java | 2 +- .../auth/api/dto/LocalSignupRequest.java | 6 ++ .../dto/SocialTokenResponse.java | 2 +- .../dto/TokenResponse.java | 2 +- .../auth/application/AuthService.java | 14 ++-- .../application/dto/LocalSignupRequest.java | 6 -- .../curation/api/CurationController.java | 2 +- .../curation/api/dto/CurationResponse.java | 2 +- .../wouldyouin/event/api/EventController.java | 7 +- .../event/api/dto/EventResponse.java | 2 +- .../event/api/dto/EventSliceResponse.java | 3 - .../api/dto/LocationFilter.java | 2 +- .../vo => event/api/dto}/UserLocation.java | 2 +- .../event/application/EventService.java | 4 +- .../wouldyouin/event/persist/Event.java | 5 +- .../wouldyouin/like/api/LikeController.java | 6 +- .../dto/LikeResponse.java | 2 +- .../dto/LikeToggleResponse.java | 3 +- .../like/application/LikeService.java | 4 +- .../member/api/CuratorController.java | 4 +- .../wouldyouin/member/api/HostController.java | 4 +- .../member/api/MemberController.java | 8 +- .../dto/MemberResponse.java | 2 +- .../dto/relation/EventHostResponse.java | 2 +- .../relation/ReservationMemberResponse.java | 2 +- .../CurationCuratorResponse.java | 2 +- .../ReviewMemberResponse.java | 2 +- .../request/MemberAdditionalInfoRequest.java | 2 +- .../dto/request/create/HostCreateRequest.java | 3 +- .../request/create/MemberCreateRequest.java | 2 +- .../create/MemberCreateRequestBase.java | 2 +- .../dto/request/edit/CuratorEditRequest.java | 2 +- .../dto/request/edit/HostEditRequest.java | 2 +- .../dto/request/edit/MemberEditRequest.java | 2 +- .../request/edit/MemberEditRequestBase.java | 2 +- .../member/application/BaseMemberService.java | 2 +- .../member/application/CuratorService.java | 4 +- .../member/application/HostService.java | 8 +- .../member/application/MemberService.java | 8 +- .../MemberServiceCommonBehavior.java | 2 +- .../wouldyouin/member/persist/Member.java | 2 +- .../payment/application/PaymentService.java | 63 ++++---------- .../api/ReservationController.java | 2 +- .../api/dto/ReservationResponse.java | 2 +- .../application/ReservationService.java | 1 - .../review/api/ReviewController.java | 6 +- .../dto/ReviewCreateRequest.java | 2 +- .../dto/ReviewEditRequest.java | 2 +- .../dto/ReviewResponse.java | 4 +- .../review/application/ReviewService.java | 6 +- .../wouldyouin/review/persist/Review.java | 2 +- src/main/resources/application.yml | 14 ++-- .../WouldYouInApplicationTests.java | 7 +- .../cokaen/wouldyouin/_global/TestData.java | 4 +- .../curation/CurationControllerUnitTest.java | 1 - .../event/EventControllerUnitTest.java | 5 +- .../event/EventServiceUnitTest.java | 6 +- .../BaseMemberServiceUnitTest.java | 2 +- .../application/CuratorServiceUnitTest.java | 2 +- .../application/HostServiceUnitTest.java | 6 +- .../application/MemberServiceUnitTest.java | 6 +- 83 files changed, 394 insertions(+), 370 deletions(-) delete mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorage.java create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorageService.java rename src/main/java/org/ktc2/cokaen/wouldyouin/_common/{config => api}/ParamDefaults.java (86%) create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/_common/config/RestClientConfig.java create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/ExtensionParsingException.java delete mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/_common/persist/Area.java delete mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/_common/persist/Category.java delete mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/_common/persist/Location.java create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/FileUtil.java create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/KakaoPayUtil.java create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/RestClientUtil.java rename src/main/java/org/ktc2/cokaen/wouldyouin/auth/{application => api}/dto/LocalLoginRequest.java (54%) create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/LocalSignupRequest.java rename src/main/java/org/ktc2/cokaen/wouldyouin/auth/{application => api}/dto/SocialTokenResponse.java (66%) rename src/main/java/org/ktc2/cokaen/wouldyouin/auth/{application => api}/dto/TokenResponse.java (79%) delete mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/dto/LocalSignupRequest.java rename src/main/java/org/ktc2/cokaen/wouldyouin/{curation => event}/api/dto/LocationFilter.java (87%) rename src/main/java/org/ktc2/cokaen/wouldyouin/{_common/vo => event/api/dto}/UserLocation.java (94%) rename src/main/java/org/ktc2/cokaen/wouldyouin/like/{application => api}/dto/LikeResponse.java (93%) rename src/main/java/org/ktc2/cokaen/wouldyouin/like/{application => api}/dto/LikeToggleResponse.java (77%) rename src/main/java/org/ktc2/cokaen/wouldyouin/member/{application => api}/dto/MemberResponse.java (97%) rename src/main/java/org/ktc2/cokaen/wouldyouin/member/{application => api}/dto/relation/EventHostResponse.java (92%) rename src/main/java/org/ktc2/cokaen/wouldyouin/member/{application => api}/dto/relation/ReservationMemberResponse.java (77%) rename src/main/java/org/ktc2/cokaen/wouldyouin/member/{application => api}/dto/relationResponse/CurationCuratorResponse.java (92%) rename src/main/java/org/ktc2/cokaen/wouldyouin/member/{application => api}/dto/relationResponse/ReviewMemberResponse.java (66%) rename src/main/java/org/ktc2/cokaen/wouldyouin/member/{application => api}/dto/request/MemberAdditionalInfoRequest.java (81%) rename src/main/java/org/ktc2/cokaen/wouldyouin/member/{application => api}/dto/request/create/HostCreateRequest.java (90%) rename src/main/java/org/ktc2/cokaen/wouldyouin/member/{application => api}/dto/request/create/MemberCreateRequest.java (94%) rename src/main/java/org/ktc2/cokaen/wouldyouin/member/{application => api}/dto/request/create/MemberCreateRequestBase.java (82%) rename src/main/java/org/ktc2/cokaen/wouldyouin/member/{application => api}/dto/request/edit/CuratorEditRequest.java (88%) rename src/main/java/org/ktc2/cokaen/wouldyouin/member/{application => api}/dto/request/edit/HostEditRequest.java (88%) rename src/main/java/org/ktc2/cokaen/wouldyouin/member/{application => api}/dto/request/edit/MemberEditRequest.java (87%) rename src/main/java/org/ktc2/cokaen/wouldyouin/member/{application => api}/dto/request/edit/MemberEditRequestBase.java (81%) rename src/main/java/org/ktc2/cokaen/wouldyouin/review/{application => api}/dto/ReviewCreateRequest.java (87%) rename src/main/java/org/ktc2/cokaen/wouldyouin/review/{application => api}/dto/ReviewEditRequest.java (74%) rename src/main/java/org/ktc2/cokaen/wouldyouin/review/{application => api}/dto/ReviewResponse.java (88%) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java index 9ca3a74d..951dc481 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java @@ -1,17 +1,13 @@ package org.ktc2.cokaen.wouldyouin.Image.api; -import java.io.IOException; -import java.nio.file.Files; import java.nio.file.Paths; import java.util.List; import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageResponse; import org.ktc2.cokaen.wouldyouin.Image.application.ImageServiceFactory; +import org.ktc2.cokaen.wouldyouin.Image.application.ImageStorageService; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponse; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponseBody; -import org.ktc2.cokaen.wouldyouin._common.exception.FailToReadImageException; -import org.springframework.core.io.ClassPathResource; -import org.springframework.core.io.Resource; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -26,37 +22,31 @@ @RestController @RequiredArgsConstructor -@RequestMapping("/api") +@RequestMapping("/api/images") public class ImageController { private final ImageServiceFactory imageServiceFactory; + private final ImageStorageService imageStorageService; + + @GetMapping(value = "/{directory}/{file}", produces = {MediaType.IMAGE_PNG_VALUE, MediaType.IMAGE_JPEG_VALUE}) + public ResponseEntity getImage(@PathVariable String directory, @PathVariable String file) { + return ResponseEntity.status(HttpStatus.OK).body(imageStorageService.readFromDirectory(Paths.get(directory, file))); + } // Todo: authorize - @PostMapping("/images") + @PostMapping public ResponseEntity>> uploadImages( @RequestParam List images, @RequestParam(value = "type") ImageDomain imageDomain) { - return ApiResponse.ok(imageServiceFactory.getImageServiceByImageType(imageDomain).saveAndCreateImages(images)); - } - - // Todo: path 수정, service로 로직이동 - @GetMapping(value = "images/{domain}/{path}", produces = {MediaType.IMAGE_PNG_VALUE, MediaType.IMAGE_JPEG_VALUE}) - public ResponseEntity getImage(@PathVariable String domain, @PathVariable String path) { - try { - Resource resource = new ClassPathResource("static/images/" + domain + "/" + path); - System.out.println(Paths.get("static/images", domain, path)); - return ResponseEntity.status(HttpStatus.OK).body(Files.readAllBytes(resource.getFile().toPath())); - } catch (IOException e) { - throw new FailToReadImageException("이미지를 읽어오는데 실패했습니다."); - } + return ApiResponse.ok(imageServiceFactory.getImageService(imageDomain).saveImages(images)); } // Todo: authorize - @DeleteMapping("/images/{id}") + @DeleteMapping("/{id}") public ResponseEntity> deleteImage( @PathVariable Long id, @RequestParam(value = "type") ImageDomain imageDomain) { - imageServiceFactory.getImageServiceByImageType(imageDomain).deleteAndDelete(id); + imageServiceFactory.getImageService(imageDomain).deleteAndDelete(id); return ApiResponse.noContent(); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java index 1c8a87df..413d75e4 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java @@ -16,10 +16,10 @@ @RequiredArgsConstructor public class AdvertisementImageService extends ImageService { - private final ImageStorage imageStorage; + @Value("${image.upload.ad.child-path}") + private String childPath; + private final ImageStorageService imageStorageService; private final AdvertisementImageRepository adImageRepository; - @Value("${image.upload.ad.sub-path}") - private String subPath; @Override protected ImageRepository getImageRepository() { @@ -32,8 +32,8 @@ protected ImageDomain getImageDomain() { } @Override - protected String getSubPath() { - return subPath; + protected String getChildPath() { + return childPath; } @Override @@ -45,13 +45,12 @@ protected AdvertisementImage toEntity(ImageRequest imageRequest) { } @Transactional - public AdvertisementImage saveAndCreateImage(MultipartFile image) { - String path = imageStorage.save(image, getSubPath()); - return adImageRepository.save(toEntity(ImageRequest.of(path, image.getSize(), ImageStorage.getExtension(image)))); + public AdvertisementImage saveImage(MultipartFile image) { + return adImageRepository.save(toEntity(imageStorageService.saveToDirectory(image, getChildPath()))); } @Transactional - public void setAd(AdvertisementImage image, Advertisement ad) { + public void setAdvertisement(AdvertisementImage image, Advertisement ad) { image.setAdvertisement(ad); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/CurationImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/CurationImageService.java index 54d141de..2af86340 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/CurationImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/CurationImageService.java @@ -15,11 +15,10 @@ @RequiredArgsConstructor public class CurationImageService extends ImageService { + @Value("${image.upload.curation.child-path}") + private String childPath; private final CurationImageRepository curationImageRepository; - @Value("${image.upload.curation.sub-path}") - private String subPath; - @Override public ImageRepository getImageRepository() { return curationImageRepository; @@ -31,8 +30,8 @@ protected ImageDomain getImageDomain() { } @Override - protected String getSubPath() { - return subPath; + protected String getChildPath() { + return childPath; } @Override diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/EventImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/EventImageService.java index c650bafe..821c433e 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/EventImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/EventImageService.java @@ -15,11 +15,10 @@ @Service public class EventImageService extends ImageService { + @Value("${image.upload.event.child-path}") + private String childPath; private final EventImageRepository eventImageRepository; - @Value("${image.upload.event.sub-path}") - private String subPath; - @Override public ImageRepository getImageRepository() { return eventImageRepository; @@ -31,13 +30,16 @@ protected ImageDomain getImageDomain() { } @Override - protected String getSubPath() { - return subPath; + protected String getChildPath() { + return childPath; } @Override protected EventImage toEntity(ImageRequest imageRequest) { - return EventImage.builder().url(imageRequest.getUrl()).size(imageRequest.getSize()).build(); + return EventImage.builder() + .url(imageRequest.getUrl()) + .size(imageRequest.getSize()) + .build(); } @Transactional diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java index 5b9f1eea..b4f1506e 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java @@ -19,7 +19,7 @@ public abstract class ImageService { @Autowired - protected ImageStorage imageStorage; + protected ImageStorageService imageStorageService; @Value("${spring.wouldyouin-domain-name}") private String domainName; @@ -28,7 +28,7 @@ public abstract class ImageService { protected abstract ImageDomain getImageDomain(); - protected abstract String getSubPath(); + protected abstract String getChildPath(); protected abstract T toEntity(ImageRequest imageRequest); @@ -47,12 +47,9 @@ protected void delete(Long id) { } @Transactional - public List saveAndCreateImages(List images) { + public List saveImages(List images) { return images.stream() - .map(image -> { - String path = imageStorage.save(image, getSubPath()); - return create(ImageRequest.of(path, image.getSize(), ImageStorage.getExtension(image))); - }) + .map(image -> create(imageStorageService.saveToDirectory(image, getChildPath()))) .toList(); } @@ -60,6 +57,6 @@ public List saveAndCreateImages(List images) { public void deleteAndDelete(Long id) { T image = getById(id); delete(id); - imageStorage.delete(image.getUrl()); + imageStorageService.delete(image.getUrl()); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageServiceFactory.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageServiceFactory.java index 329a411b..6c825456 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageServiceFactory.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageServiceFactory.java @@ -2,6 +2,7 @@ import java.util.List; import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Function; import java.util.stream.Collectors; import org.ktc2.cokaen.wouldyouin.Image.api.ImageDomain; import org.ktc2.cokaen.wouldyouin.Image.persist.Image; @@ -10,14 +11,14 @@ @Component public class ImageServiceFactory { - private final ConcurrentHashMap> imageTypeToImageServiceMap; + private final ConcurrentHashMap> imageServiceMap; public ImageServiceFactory(List> imageServices) { - imageTypeToImageServiceMap = new ConcurrentHashMap<>(imageServices.stream() - .collect(Collectors.toConcurrentMap(ImageService::getImageDomain, imageService -> imageService))); + imageServiceMap = new ConcurrentHashMap<>(imageServices.stream() + .collect(Collectors.toConcurrentMap(ImageService::getImageDomain, Function.identity()))); } - public ImageService getImageServiceByImageType(ImageDomain imageDomain) { - return imageTypeToImageServiceMap.get(imageDomain); + public ImageService getImageService(ImageDomain imageDomain) { + return imageServiceMap.get(imageDomain); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorage.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorage.java deleted file mode 100644 index dc953d58..00000000 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorage.java +++ /dev/null @@ -1,83 +0,0 @@ -package org.ktc2.cokaen.wouldyouin.Image.application; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Objects; -import java.util.Optional; -import java.util.UUID; -import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageRequest; -import org.ktc2.cokaen.wouldyouin._common.exception.FailedToDeleteImageException; -import org.ktc2.cokaen.wouldyouin._common.exception.FailedToUploadImageException; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Component; -import org.springframework.web.client.RestClient; -import org.springframework.web.multipart.MultipartFile; - -@Component -public class ImageStorage { - - @Value("${image.upload.common-path}") - private String commonPath; - - public String save(MultipartFile image, String subPath) { - String fileName = ""; - try { - fileName = generateUuidName() + "." + getExtension(image); - Path path = Paths.get(commonPath, subPath, fileName); - Files.createDirectories(path.getParent()); - Files.write(path, image.getBytes()); - } catch (IOException ex) { - throw new FailedToUploadImageException("이미지를 업로드하는데 실패했습니다."); - } - return subPath + "/" + fileName; - } - - // Todo: payment랑 이부분 restclient 유틸로 빼기 - public ImageRequest save(String imageUrl, String subPath) { - RestClient client = RestClient.builder().build(); - String fileName = ""; - Long size = 0L; - try { - ResponseEntity response = client.get() - .uri(imageUrl) - .retrieve() - .toEntity(byte[].class); - - if (Optional.ofNullable(response.getBody()).isPresent() && response.getStatusCode().is2xxSuccessful()) { - fileName = generateUuidName() + "." + getExtension(imageUrl); - size = (long) response.getBody().length; - Path path = Paths.get(commonPath, subPath, fileName); - Files.createDirectories(path.getParent()); - Files.write(path, response.getBody()); - } - } catch (IOException ex) { - throw new FailedToUploadImageException("URL을 통해 이미지를 저장하는데 실패했습니다."); - } - String url = subPath + "/" + fileName; - return ImageRequest.of(url, size, getExtension(imageUrl)); - } - - public void delete(String imagePath) { - try { - Files.deleteIfExists(Paths.get(imagePath)); - } catch (IOException ex) { - throw new FailedToDeleteImageException("이미지를 삭제하는데 실패했습니다."); - } - } - - protected static String getExtension(MultipartFile image) { - return Objects.requireNonNull(image.getContentType()).split("/")[1]; - } - - protected static String getExtension(String imageUrl) { - String[] splitted = imageUrl.split("\\."); - return splitted[splitted.length - 1]; - } - - private static String generateUuidName() { - return UUID.randomUUID().toString().replace("-", ""); - } -} \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorageService.java new file mode 100644 index 00000000..5b68d448 --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorageService.java @@ -0,0 +1,54 @@ +package org.ktc2.cokaen.wouldyouin.Image.application; + +import java.nio.file.Path; +import java.nio.file.Paths; +import lombok.RequiredArgsConstructor; +import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageRequest; +import org.ktc2.cokaen.wouldyouin._common.exception.FailedToUploadImageException; +import org.ktc2.cokaen.wouldyouin._common.util.FileUtil; +import org.ktc2.cokaen.wouldyouin._common.util.RestClientUtil; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; +import org.springframework.web.multipart.MultipartFile; + +@Component +@RequiredArgsConstructor +public class ImageStorageService { + + @Value("${image.upload.parent-path}") + private String parentPath; + private final RestClientUtil client; + + public byte[] readFromDirectory(Path path) { + return FileUtil.readFile(Paths.get(parentPath).resolve(path)); + } + + public ImageRequest saveToDirectory(MultipartFile image, String subPath) { + String extension = FileUtil.getExtension(image); + String fileName = FileUtil.generateUuidName() + "." + extension; + Path path = Paths.get(parentPath, subPath, fileName); + FileUtil.saveFile(image, path); + return ImageRequest.of(path.toString(), image.getSize(), FileUtil.getExtension(image)); + } + + public ImageRequest saveToDirectory(String imageUrl, String subPath) { + ResponseEntity response = client.get(imageUrl, byte[].class); + if (response.getBody() == null) { + throw new FailedToUploadImageException("응답 본문이 비어있어 이미지를 가져올 수 없습니다."); + } + if (!response.getStatusCode().is2xxSuccessful()) { + throw new FailedToUploadImageException("이미지 URL에 대한 요청을 실패하였습니다."); + } + String extension = FileUtil.getExtension(imageUrl); + String fileName = FileUtil.generateUuidName() + "." + extension; + Path path = Paths.get(parentPath, subPath, fileName); + FileUtil.saveFile(response.getBody(), path); + long size = response.getBody().length; + return ImageRequest.of(path.toString(), size, extension); + } + + public void delete(String imagePath) { + FileUtil.deleteFile(Paths.get(imagePath)); + } +} \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java index 01772b1a..c791b08e 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java @@ -7,7 +7,6 @@ import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImageRepository; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMember; -import org.ktc2.cokaen.wouldyouin.member.persist.BaseMemberRepository; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,11 +15,9 @@ @RequiredArgsConstructor public class MemberImageService extends ImageService { + @Value("${image.upload.member.child-path}") + private String childPath; private final MemberImageRepository memberImageRepository; - private final BaseMemberRepository baseMemberRepository; - - @Value("${image.upload.member.sub-path}") - private String subPath; @Override public ImageRepository getImageRepository() { @@ -33,8 +30,8 @@ protected ImageDomain getImageDomain() { } @Override - protected String getSubPath() { - return subPath; + protected String getChildPath() { + return childPath; } @Override @@ -51,6 +48,7 @@ public void setBaseMember(MemberImage image, BaseMember member) { } public MemberImage convert(String imageUrl) { - return memberImageRepository.save(toEntity(imageStorage.save(imageUrl, subPath))); + ImageRequest imageRequest = imageStorageService.saveToDirectory(imageUrl, childPath); + return memberImageRepository.save(toEntity(imageRequest)); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/config/ParamDefaults.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/api/ParamDefaults.java similarity index 86% rename from src/main/java/org/ktc2/cokaen/wouldyouin/_common/config/ParamDefaults.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/_common/api/ParamDefaults.java index 5e4bfdd3..e317393f 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/config/ParamDefaults.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/api/ParamDefaults.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin._common.config; +package org.ktc2.cokaen.wouldyouin._common.api; public class ParamDefaults { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/config/RestClientConfig.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/config/RestClientConfig.java new file mode 100644 index 00000000..a4655caa --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/config/RestClientConfig.java @@ -0,0 +1,14 @@ +package org.ktc2.cokaen.wouldyouin._common.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.client.RestClient; + +@Configuration +public class RestClientConfig { + + @Bean + RestClient restClient() { + return RestClient.builder().build(); + } +} \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/ErrorCode.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/ErrorCode.java index 16824078..9140ed01 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/ErrorCode.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/ErrorCode.java @@ -24,6 +24,8 @@ public enum ErrorCode { FAIL_TO_DELETE_IMAGE(HttpStatus.CONFLICT.value(), "-20400", "Fail to delete image"), + URL_PARSING_FAILED(HttpStatus.BAD_REQUEST.value(), "-20400", "URL 파싱에 실패했습니다."), + CURRENT_LOCATION_EMPTY(HttpStatus.BAD_REQUEST.value(), "-20400", "현재 위치 정보를 찾을 수 없습니다."); private final Integer status; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/ExtensionParsingException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/ExtensionParsingException.java new file mode 100644 index 00000000..b07099b7 --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/ExtensionParsingException.java @@ -0,0 +1,10 @@ +package org.ktc2.cokaen.wouldyouin._common.exception; + +import org.ktc2.cokaen.wouldyouin._common.error.ErrorCode; + +public class ExtensionParsingException extends BusinessException { + + public ExtensionParsingException(String message) { + super(message, ErrorCode.URL_PARSING_FAILED); + } +} diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/persist/Area.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/persist/Area.java deleted file mode 100644 index 7c9dcf98..00000000 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/persist/Area.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.ktc2.cokaen.wouldyouin._common.persist; - -public enum Area { - 전체, - 서울, - 인천, - 경기도, - 강원도, - 충청남도, - 충청북도, - 경상북도, - 대전, - 대구, - 울산, - 전라북도, - 경상남도, - 부산, - 광주, - 전라남도, - 제주도 -} \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/persist/Category.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/persist/Category.java deleted file mode 100644 index 5d30389b..00000000 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/persist/Category.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.ktc2.cokaen.wouldyouin._common.persist; - -public enum Category { - 전체, - 밴드, - 연극, - 뮤지컬, - 원데이클래스, - 전시회, - 공예, - 축제 -} \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/persist/Location.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/persist/Location.java deleted file mode 100644 index ab3cfe59..00000000 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/persist/Location.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.ktc2.cokaen.wouldyouin._common.persist; - -import jakarta.persistence.Embeddable; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -@Getter -@Setter -@NoArgsConstructor -@AllArgsConstructor -@Embeddable -public class Location { - Double longitude; - Double latitude; -} \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/FileUtil.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/FileUtil.java new file mode 100644 index 00000000..d4ff27db --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/FileUtil.java @@ -0,0 +1,69 @@ +package org.ktc2.cokaen.wouldyouin._common.util; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.UUID; +import org.ktc2.cokaen.wouldyouin._common.exception.ExtensionParsingException; +import org.ktc2.cokaen.wouldyouin._common.exception.FailToReadImageException; +import org.ktc2.cokaen.wouldyouin._common.exception.FailedToUploadImageException; +import org.springframework.web.multipart.MultipartFile; + +public class FileUtil { + + public static byte[] readFile(Path path) { + try { + return Files.readAllBytes(path); + } catch (IOException e) { + throw new FailToReadImageException("파일을 읽어오는데 실패했습니다."); + } + } + + public static void saveFile(MultipartFile file, Path path) { + try { + Files.createDirectories(path.getParent()); + Files.write(path, file.getBytes()); + } catch (IOException e) { + throw new FailedToUploadImageException("디렉토리에 파일을 저장하는데 실패했습니다."); + } + } + + public static void saveFile(byte[] file, Path path) { + try { + Files.createDirectories(path.getParent()); + Files.write(path, file); + } catch (IOException e) { + throw new FailedToUploadImageException("디렉토리에 파일을 저장하는데 실패했습니다."); + } + } + + public static void deleteFile(Path path) { + try { + Files.deleteIfExists(path); + } catch (IOException e) { + throw new FailedToUploadImageException("해당 경로의 파일을 삭제하는데 실패했습니다."); + } + } + + public static String generateUuidName() { + return UUID.randomUUID().toString().replace("-", ""); + } + + public static String getExtension(MultipartFile file) { + if (file == null || file.getContentType() == null) { + throw new ExtensionParsingException("파일이 존재하지 않거나 콘텐츠 타입이 없습니다."); + } + try { + return file.getContentType().split("/")[1]; + } catch (ArrayIndexOutOfBoundsException e) { + throw new ExtensionParsingException("파일의 확장자를 찾을 수 없습니다."); + } + } + + public static String getExtension(String url) { + if (url == null || !url.contains(".")) { + throw new ExtensionParsingException("URL이 존재하지 않거나 확장자가 없습니다."); + } + return url.substring(url.lastIndexOf('.') + 1); + } +} \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/KakaoPayUtil.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/KakaoPayUtil.java new file mode 100644 index 00000000..5d160970 --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/KakaoPayUtil.java @@ -0,0 +1,33 @@ +package org.ktc2.cokaen.wouldyouin._common.util; + +import java.util.HashMap; +import java.util.Map; +import org.ktc2.cokaen.wouldyouin.payment.dto.KakaoPayRequest; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; + +public class KakaoPayUtil { + + public static HttpHeaders createKakaoPayRequestHeaders(String kakaoPayRequestHost, String secretKey) { + HttpHeaders headers = new HttpHeaders(); + headers.add("Host", kakaoPayRequestHost); + headers.add("Authorization", "SECRET_KEY " + secretKey); + headers.setContentType(MediaType.APPLICATION_JSON); + return headers; + } + + public static Map createKakaoPayRequestBody(KakaoPayRequest kakaoPayRequest, String approvalUrl, String cancelUrl, String failUrl) { + Map body = new HashMap<>(); + body.put("cid", "TC0ONETIME"); + body.put("partner_order_id", kakaoPayRequest.getReservationId()); + body.put("partner_user_id", kakaoPayRequest.getHostId()); + body.put("item_name", kakaoPayRequest.getEventName()); + body.put("quantity", kakaoPayRequest.getQuantity()); + body.put("total_amount", kakaoPayRequest.getTotalAmount()); + body.put("tax_free_amount", kakaoPayRequest.getTaxFreeAmount()); + body.put("approval_url", approvalUrl); + body.put("cancel_url", cancelUrl); + body.put("fail_url", failUrl); + return body; + } +} \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/RestClientUtil.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/RestClientUtil.java new file mode 100644 index 00000000..464d4200 --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/RestClientUtil.java @@ -0,0 +1,30 @@ +package org.ktc2.cokaen.wouldyouin._common.util; + +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpHeaders; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestClient; + +@Component +@RequiredArgsConstructor +public class RestClientUtil { + + private final RestClient client; + + public ResponseEntity get(String url, Class classType) { + return client.get() + .uri(url) + .retrieve() + .toEntity(classType); + } + + public ResponseEntity post(String url, HttpHeaders headers, B body, Class classType) { + return client.post() + .uri(url) + .headers(httpHeaders -> httpHeaders.addAll(headers)) + .body(body) + .retrieve() + .toEntity(classType); + } +} \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java index 4004da27..2bf7a1f4 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java @@ -42,9 +42,9 @@ public List getAllActiveAdvertisements() { // Todo: 롤백될 경우, 저장한 이미지 삭제 @Transactional public AdvertisementResponse create(AdvertisementRequest adRequest, MultipartFile image) { - AdvertisementImage adImage = adImageService.saveAndCreateImage(image); + AdvertisementImage adImage = adImageService.saveImage(image); Advertisement ad = adRepository.save(adRequest.toEntity(adImage)); - adImageService.setAd(adImage, ad); + adImageService.setAdvertisement(adImage, ad); return AdvertisementResponse.from(ad); } @@ -56,7 +56,7 @@ public AdvertisementResponse update(Long adId, AdvertisementRequest adRequest, M Optional.ofNullable(multipartFile).ifPresentOrElse( image -> { adImageService.deleteAndDelete(ad.getAdvertisementImage().getId()); - AdvertisementImage adImage = adImageService.saveAndCreateImage(image); + AdvertisementImage adImage = adImageService.saveImage(image); ad.updateFrom(adRequest, adImage); adImage.setAdvertisement(ad); }, diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/persist/Advertisement.java b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/persist/Advertisement.java index f154f5a4..f6fef66f 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/persist/Advertisement.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/persist/Advertisement.java @@ -14,7 +14,6 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import org.hibernate.annotations.Comment; import org.ktc2.cokaen.wouldyouin.Image.persist.AdvertisementImage; import org.ktc2.cokaen.wouldyouin.advertisement.api.dto.AdvertisementRequest; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/AuthController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/AuthController.java index 3c886902..f7ca6699 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/AuthController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/AuthController.java @@ -6,11 +6,11 @@ import org.ktc2.cokaen.wouldyouin.auth.Authorize; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.auth.application.AuthService; -import org.ktc2.cokaen.wouldyouin.auth.application.dto.LocalLoginRequest; -import org.ktc2.cokaen.wouldyouin.auth.application.dto.LocalSignupRequest; -import org.ktc2.cokaen.wouldyouin.auth.application.dto.SocialTokenResponse; -import org.ktc2.cokaen.wouldyouin.auth.application.dto.TokenResponse; -import org.ktc2.cokaen.wouldyouin.member.application.dto.request.MemberAdditionalInfoRequest; +import org.ktc2.cokaen.wouldyouin.auth.api.dto.LocalLoginRequest; +import org.ktc2.cokaen.wouldyouin.auth.api.dto.LocalSignupRequest; +import org.ktc2.cokaen.wouldyouin.auth.api.dto.SocialTokenResponse; +import org.ktc2.cokaen.wouldyouin.auth.api.dto.TokenResponse; +import org.ktc2.cokaen.wouldyouin.member.api.dto.request.MemberAdditionalInfoRequest; import org.ktc2.cokaen.wouldyouin.member.persist.AccountType; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.springframework.http.ResponseEntity; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/dto/LocalLoginRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/LocalLoginRequest.java similarity index 54% rename from src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/dto/LocalLoginRequest.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/LocalLoginRequest.java index 1011fab3..6a18a892 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/dto/LocalLoginRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/LocalLoginRequest.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin.auth.application.dto; +package org.ktc2.cokaen.wouldyouin.auth.api.dto; public record LocalLoginRequest(String email, String password) { } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/LocalSignupRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/LocalSignupRequest.java new file mode 100644 index 00000000..2032ae26 --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/LocalSignupRequest.java @@ -0,0 +1,6 @@ +package org.ktc2.cokaen.wouldyouin.auth.api.dto; + +import org.ktc2.cokaen.wouldyouin.member.api.dto.request.create.HostCreateRequest; + +public class LocalSignupRequest extends HostCreateRequest { +} diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/dto/SocialTokenResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/SocialTokenResponse.java similarity index 66% rename from src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/dto/SocialTokenResponse.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/SocialTokenResponse.java index 4dfce018..bfdb4f43 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/dto/SocialTokenResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/SocialTokenResponse.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin.auth.application.dto; +package org.ktc2.cokaen.wouldyouin.auth.api.dto; import lombok.Builder; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/dto/TokenResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/TokenResponse.java similarity index 79% rename from src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/dto/TokenResponse.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/TokenResponse.java index 37a4b667..0ebae147 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/dto/TokenResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/TokenResponse.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin.auth.application.dto; +package org.ktc2.cokaen.wouldyouin.auth.api.dto; import lombok.Builder; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/AuthService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/AuthService.java index 127a50a1..6a8a1a38 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/AuthService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/AuthService.java @@ -3,18 +3,18 @@ import java.util.Optional; import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; -import org.ktc2.cokaen.wouldyouin.auth.application.dto.LocalLoginRequest; -import org.ktc2.cokaen.wouldyouin.auth.application.dto.LocalSignupRequest; -import org.ktc2.cokaen.wouldyouin.auth.application.dto.SocialTokenResponse; -import org.ktc2.cokaen.wouldyouin.auth.application.dto.TokenResponse; +import org.ktc2.cokaen.wouldyouin.auth.api.dto.LocalLoginRequest; +import org.ktc2.cokaen.wouldyouin.auth.api.dto.LocalSignupRequest; +import org.ktc2.cokaen.wouldyouin.auth.api.dto.SocialTokenResponse; +import org.ktc2.cokaen.wouldyouin.auth.api.dto.TokenResponse; import org.ktc2.cokaen.wouldyouin.auth.application.oauth.OauthRequestServiceFactory; import org.ktc2.cokaen.wouldyouin.auth.application.oauth.dto.OauthResourcesResponse; import org.ktc2.cokaen.wouldyouin.member.application.BaseMemberService; import org.ktc2.cokaen.wouldyouin.member.application.HostService; import org.ktc2.cokaen.wouldyouin.member.application.MemberService; -import org.ktc2.cokaen.wouldyouin.member.application.dto.MemberResponse; -import org.ktc2.cokaen.wouldyouin.member.application.dto.request.MemberAdditionalInfoRequest; -import org.ktc2.cokaen.wouldyouin.member.application.dto.request.create.MemberCreateRequest; +import org.ktc2.cokaen.wouldyouin.member.api.dto.MemberResponse; +import org.ktc2.cokaen.wouldyouin.member.api.dto.request.MemberAdditionalInfoRequest; +import org.ktc2.cokaen.wouldyouin.member.api.dto.request.create.MemberCreateRequest; import org.ktc2.cokaen.wouldyouin.member.persist.AccountType; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.springframework.stereotype.Service; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/dto/LocalSignupRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/dto/LocalSignupRequest.java deleted file mode 100644 index 748ff493..00000000 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/dto/LocalSignupRequest.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.ktc2.cokaen.wouldyouin.auth.application.dto; - -import org.ktc2.cokaen.wouldyouin.member.application.dto.request.create.HostCreateRequest; - -public class LocalSignupRequest extends HostCreateRequest { -} diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/CurationController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/CurationController.java index f411d948..d4857d2d 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/CurationController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/CurationController.java @@ -4,7 +4,7 @@ import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponse; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponseBody; -import org.ktc2.cokaen.wouldyouin._common.config.ParamDefaults; +import org.ktc2.cokaen.wouldyouin._common.api.ParamDefaults; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin.auth.Authorize; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java index 65489c61..7bd2e697 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java @@ -7,7 +7,7 @@ import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.CurationEventResponse; -import org.ktc2.cokaen.wouldyouin.member.application.dto.relationResponse.CurationCuratorResponse; +import org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse.CurationCuratorResponse; @Builder @Getter diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/EventController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/EventController.java index 9230416a..5f411434 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/EventController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/EventController.java @@ -4,14 +4,13 @@ import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponse; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponseBody; -import org.ktc2.cokaen.wouldyouin._common.config.ParamDefaults; +import org.ktc2.cokaen.wouldyouin._common.api.ParamDefaults; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; -import org.ktc2.cokaen.wouldyouin._common.vo.Location; -import org.ktc2.cokaen.wouldyouin._common.vo.UserLocation; +import org.ktc2.cokaen.wouldyouin.event.api.dto.UserLocation; import org.ktc2.cokaen.wouldyouin.auth.Authorize; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; -import org.ktc2.cokaen.wouldyouin.curation.api.dto.LocationFilter; +import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationFilter; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventResponse; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventResponse.java index 7ff20f85..b45e738e 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventResponse.java @@ -7,7 +7,7 @@ import org.ktc2.cokaen.wouldyouin._common.vo.Category; import org.ktc2.cokaen.wouldyouin._common.vo.Location; import org.ktc2.cokaen.wouldyouin.event.persist.Event; -import org.ktc2.cokaen.wouldyouin.member.application.dto.relation.EventHostResponse; +import org.ktc2.cokaen.wouldyouin.member.api.dto.relation.EventHostResponse; import org.ktc2.cokaen.wouldyouin.member.persist.Host; @Builder diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventSliceResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventSliceResponse.java index 64929632..5221024c 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventSliceResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventSliceResponse.java @@ -5,9 +5,6 @@ import lombok.Getter; import org.ktc2.cokaen.wouldyouin._common.api.SliceInfo; import org.ktc2.cokaen.wouldyouin.event.persist.Event; -import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationResponse; -import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationSliceResponse; -import org.ktc2.cokaen.wouldyouin.reservation.persist.Reservation; import org.springframework.data.domain.Slice; @Getter diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/LocationFilter.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationFilter.java similarity index 87% rename from src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/LocationFilter.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationFilter.java index aec28478..fa1e923b 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/LocationFilter.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationFilter.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin.curation.api.dto; +package org.ktc2.cokaen.wouldyouin.event.api.dto; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/vo/UserLocation.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/UserLocation.java similarity index 94% rename from src/main/java/org/ktc2/cokaen/wouldyouin/_common/vo/UserLocation.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/UserLocation.java index 32dfa4aa..be0efccd 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/vo/UserLocation.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/UserLocation.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin._common.vo; +package org.ktc2.cokaen.wouldyouin.event.api.dto; import jakarta.validation.constraints.Max; import jakarta.validation.constraints.Min; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java index 07ac64aa..2c56bc50 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java @@ -9,8 +9,8 @@ import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; -import org.ktc2.cokaen.wouldyouin._common.vo.UserLocation; -import org.ktc2.cokaen.wouldyouin.curation.api.dto.LocationFilter; +import org.ktc2.cokaen.wouldyouin.event.api.dto.UserLocation; +import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationFilter; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventResponse; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java index 205688ef..d715b313 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java @@ -19,13 +19,13 @@ import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.ktc2.cokaen.wouldyouin.Image.persist.EventImage; -import org.ktc2.cokaen.wouldyouin._common.exception.NoLeftSeatException; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; import org.ktc2.cokaen.wouldyouin._common.vo.Location; @@ -119,9 +119,10 @@ protected Event(String title, String content, Host host, Area area, Location loc this.totalSeat = totalSeat; this.leftSeat = totalSeat; this.category = category; - this.images = images; + Optional.ofNullable(images).ifPresent(this::setImages); } + // Todo: oneToMany 연관관계에서 모든 null 처리 public void updateFrom(EventEditRequest eventEditRequest, List images) { this.title = eventEditRequest.getTitle(); this.content = eventEditRequest.getContent(); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/LikeController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/LikeController.java index 75792e55..0629424c 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/LikeController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/LikeController.java @@ -3,12 +3,12 @@ import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponse; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponseBody; -import org.ktc2.cokaen.wouldyouin._common.config.ParamDefaults; +import org.ktc2.cokaen.wouldyouin._common.api.ParamDefaults; import org.ktc2.cokaen.wouldyouin.auth.Authorize; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.like.application.LikeServiceFactory; -import org.ktc2.cokaen.wouldyouin.like.application.dto.LikeResponse; -import org.ktc2.cokaen.wouldyouin.like.application.dto.LikeToggleResponse; +import org.ktc2.cokaen.wouldyouin.like.api.dto.LikeResponse; +import org.ktc2.cokaen.wouldyouin.like.api.dto.LikeToggleResponse; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Slice; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/dto/LikeResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/dto/LikeResponse.java similarity index 93% rename from src/main/java/org/ktc2/cokaen/wouldyouin/like/application/dto/LikeResponse.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/like/api/dto/LikeResponse.java index cc749208..f21ac18d 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/dto/LikeResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/dto/LikeResponse.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin.like.application.dto; +package org.ktc2.cokaen.wouldyouin.like.api.dto; import java.util.List; import lombok.AccessLevel; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/dto/LikeToggleResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/dto/LikeToggleResponse.java similarity index 77% rename from src/main/java/org/ktc2/cokaen/wouldyouin/like/application/dto/LikeToggleResponse.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/like/api/dto/LikeToggleResponse.java index d5181d72..819e700d 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/dto/LikeToggleResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/dto/LikeToggleResponse.java @@ -1,10 +1,9 @@ -package org.ktc2.cokaen.wouldyouin.like.application.dto; +package org.ktc2.cokaen.wouldyouin.like.api.dto; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.RequiredArgsConstructor; -import org.ktc2.cokaen.wouldyouin.member.persist.LikeableMember; @Getter @RequiredArgsConstructor(access = AccessLevel.PROTECTED) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/LikeService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/LikeService.java index 7b2393ab..8a888bad 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/LikeService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/LikeService.java @@ -1,8 +1,8 @@ package org.ktc2.cokaen.wouldyouin.like.application; import lombok.RequiredArgsConstructor; -import org.ktc2.cokaen.wouldyouin.like.application.dto.LikeResponse; -import org.ktc2.cokaen.wouldyouin.like.application.dto.LikeToggleResponse; +import org.ktc2.cokaen.wouldyouin.like.api.dto.LikeResponse; +import org.ktc2.cokaen.wouldyouin.like.api.dto.LikeToggleResponse; import org.ktc2.cokaen.wouldyouin.like.persist.Like; import org.ktc2.cokaen.wouldyouin.like.persist.LikeRepository; import org.ktc2.cokaen.wouldyouin.member.application.LikeableMemberGetterFactory; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/CuratorController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/CuratorController.java index 2500403c..49aa49b7 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/CuratorController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/CuratorController.java @@ -6,8 +6,8 @@ import org.ktc2.cokaen.wouldyouin.auth.Authorize; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.member.application.CuratorService; -import org.ktc2.cokaen.wouldyouin.member.application.dto.MemberResponse; -import org.ktc2.cokaen.wouldyouin.member.application.dto.request.edit.CuratorEditRequest; +import org.ktc2.cokaen.wouldyouin.member.api.dto.MemberResponse; +import org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit.CuratorEditRequest; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/HostController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/HostController.java index 17cac9d6..9e49a3fc 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/HostController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/HostController.java @@ -6,8 +6,8 @@ import org.ktc2.cokaen.wouldyouin.auth.Authorize; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.member.application.HostService; -import org.ktc2.cokaen.wouldyouin.member.application.dto.request.edit.HostEditRequest; -import org.ktc2.cokaen.wouldyouin.member.application.dto.MemberResponse; +import org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit.HostEditRequest; +import org.ktc2.cokaen.wouldyouin.member.api.dto.MemberResponse; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PutMapping; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/MemberController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/MemberController.java index 07425641..f68765b3 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/MemberController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/MemberController.java @@ -9,10 +9,10 @@ import org.ktc2.cokaen.wouldyouin.member.application.BaseMemberService; import org.ktc2.cokaen.wouldyouin.member.application.HostService; import org.ktc2.cokaen.wouldyouin.member.application.MemberService; -import org.ktc2.cokaen.wouldyouin.member.application.dto.MemberResponse; -import org.ktc2.cokaen.wouldyouin.member.application.dto.request.create.HostCreateRequest; -import org.ktc2.cokaen.wouldyouin.member.application.dto.request.create.MemberCreateRequest; -import org.ktc2.cokaen.wouldyouin.member.application.dto.request.edit.MemberEditRequest; +import org.ktc2.cokaen.wouldyouin.member.api.dto.MemberResponse; +import org.ktc2.cokaen.wouldyouin.member.api.dto.request.create.HostCreateRequest; +import org.ktc2.cokaen.wouldyouin.member.api.dto.request.create.MemberCreateRequest; +import org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit.MemberEditRequest; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/MemberResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/MemberResponse.java similarity index 97% rename from src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/MemberResponse.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/MemberResponse.java index ed56592b..4fe093db 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/MemberResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/MemberResponse.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin.member.application.dto; +package org.ktc2.cokaen.wouldyouin.member.api.dto; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/relation/EventHostResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relation/EventHostResponse.java similarity index 92% rename from src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/relation/EventHostResponse.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relation/EventHostResponse.java index 2430622f..fb2d26a8 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/relation/EventHostResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relation/EventHostResponse.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin.member.application.dto.relation; +package org.ktc2.cokaen.wouldyouin.member.api.dto.relation; import java.util.List; import lombok.Builder; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/relation/ReservationMemberResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relation/ReservationMemberResponse.java similarity index 77% rename from src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/relation/ReservationMemberResponse.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relation/ReservationMemberResponse.java index 0ebfe7f9..98b10bbc 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/relation/ReservationMemberResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relation/ReservationMemberResponse.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin.member.application.dto.relation; +package org.ktc2.cokaen.wouldyouin.member.api.dto.relation; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/relationResponse/CurationCuratorResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/CurationCuratorResponse.java similarity index 92% rename from src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/relationResponse/CurationCuratorResponse.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/CurationCuratorResponse.java index 2516823c..ed5e85de 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/relationResponse/CurationCuratorResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/CurationCuratorResponse.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin.member.application.dto.relationResponse; +package org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse; import java.util.List; import lombok.Builder; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/relationResponse/ReviewMemberResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/ReviewMemberResponse.java similarity index 66% rename from src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/relationResponse/ReviewMemberResponse.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/ReviewMemberResponse.java index 21a57579..afbdc6a2 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/relationResponse/ReviewMemberResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/ReviewMemberResponse.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin.member.application.dto.relationResponse; +package org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/request/MemberAdditionalInfoRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/MemberAdditionalInfoRequest.java similarity index 81% rename from src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/request/MemberAdditionalInfoRequest.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/MemberAdditionalInfoRequest.java index 64bfff22..2f3ea13a 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/request/MemberAdditionalInfoRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/MemberAdditionalInfoRequest.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin.member.application.dto.request; +package org.ktc2.cokaen.wouldyouin.member.api.dto.request; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/request/create/HostCreateRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/HostCreateRequest.java similarity index 90% rename from src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/request/create/HostCreateRequest.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/HostCreateRequest.java index 5233ddc3..6a2ceafe 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/request/create/HostCreateRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/HostCreateRequest.java @@ -1,6 +1,5 @@ -package org.ktc2.cokaen.wouldyouin.member.application.dto.request.create; +package org.ktc2.cokaen.wouldyouin.member.api.dto.request.create; -import java.util.List; import lombok.Getter; import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/request/create/MemberCreateRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/MemberCreateRequest.java similarity index 94% rename from src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/request/create/MemberCreateRequest.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/MemberCreateRequest.java index f021e163..6bc10cbf 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/request/create/MemberCreateRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/MemberCreateRequest.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin.member.application.dto.request.create; +package org.ktc2.cokaen.wouldyouin.member.api.dto.request.create; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/request/create/MemberCreateRequestBase.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/MemberCreateRequestBase.java similarity index 82% rename from src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/request/create/MemberCreateRequestBase.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/MemberCreateRequestBase.java index 428664a7..1e4ecc5c 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/request/create/MemberCreateRequestBase.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/MemberCreateRequestBase.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin.member.application.dto.request.create; +package org.ktc2.cokaen.wouldyouin.member.api.dto.request.create; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/request/edit/CuratorEditRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/CuratorEditRequest.java similarity index 88% rename from src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/request/edit/CuratorEditRequest.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/CuratorEditRequest.java index bef7ce24..63ee5b53 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/request/edit/CuratorEditRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/CuratorEditRequest.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin.member.application.dto.request.edit; +package org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit; import io.micrometer.common.lang.Nullable; import lombok.Builder; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/request/edit/HostEditRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/HostEditRequest.java similarity index 88% rename from src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/request/edit/HostEditRequest.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/HostEditRequest.java index 618fe72c..2e816e36 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/request/edit/HostEditRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/HostEditRequest.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin.member.application.dto.request.edit; +package org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit; import jakarta.annotation.Nullable; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/request/edit/MemberEditRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/MemberEditRequest.java similarity index 87% rename from src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/request/edit/MemberEditRequest.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/MemberEditRequest.java index 46e591a8..6afed790 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/request/edit/MemberEditRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/MemberEditRequest.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin.member.application.dto.request.edit; +package org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit; import jakarta.annotation.Nullable; import lombok.Builder; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/request/edit/MemberEditRequestBase.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/MemberEditRequestBase.java similarity index 81% rename from src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/request/edit/MemberEditRequestBase.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/MemberEditRequestBase.java index 45e8da30..f353746b 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/dto/request/edit/MemberEditRequestBase.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/MemberEditRequestBase.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin.member.application.dto.request.edit; +package org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit; import jakarta.annotation.Nullable; import lombok.Getter; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberService.java index 3f11940a..154c2d11 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberService.java @@ -1,7 +1,7 @@ package org.ktc2.cokaen.wouldyouin.member.application; import lombok.RequiredArgsConstructor; -import org.ktc2.cokaen.wouldyouin.member.application.dto.MemberResponse; +import org.ktc2.cokaen.wouldyouin.member.api.dto.MemberResponse; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMember; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMemberRepository; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java index c98a6f34..da78d2c7 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java @@ -3,8 +3,8 @@ import java.util.Optional; import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin.Image.application.MemberImageService; -import org.ktc2.cokaen.wouldyouin.member.application.dto.request.edit.CuratorEditRequest; -import org.ktc2.cokaen.wouldyouin.member.application.dto.MemberResponse; +import org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit.CuratorEditRequest; +import org.ktc2.cokaen.wouldyouin.member.api.dto.MemberResponse; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMemberRepository; import org.ktc2.cokaen.wouldyouin.member.persist.Curator; import org.ktc2.cokaen.wouldyouin.member.persist.CuratorRepository; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java index f2cceed8..abc8c8f8 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java @@ -4,10 +4,10 @@ import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin.Image.application.MemberImageService; import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; -import org.ktc2.cokaen.wouldyouin.auth.application.dto.LocalLoginRequest; -import org.ktc2.cokaen.wouldyouin.member.application.dto.MemberResponse; -import org.ktc2.cokaen.wouldyouin.member.application.dto.request.create.HostCreateRequest; -import org.ktc2.cokaen.wouldyouin.member.application.dto.request.edit.HostEditRequest; +import org.ktc2.cokaen.wouldyouin.auth.api.dto.LocalLoginRequest; +import org.ktc2.cokaen.wouldyouin.member.api.dto.MemberResponse; +import org.ktc2.cokaen.wouldyouin.member.api.dto.request.create.HostCreateRequest; +import org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit.HostEditRequest; import org.ktc2.cokaen.wouldyouin.member.persist.Host; import org.ktc2.cokaen.wouldyouin.member.persist.HostRepository; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/MemberService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/MemberService.java index ea657969..3e7ccc88 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/MemberService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/MemberService.java @@ -5,10 +5,10 @@ import org.ktc2.cokaen.wouldyouin.Image.application.MemberImageService; import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; -import org.ktc2.cokaen.wouldyouin.member.application.dto.MemberResponse; -import org.ktc2.cokaen.wouldyouin.member.application.dto.request.MemberAdditionalInfoRequest; -import org.ktc2.cokaen.wouldyouin.member.application.dto.request.create.MemberCreateRequest; -import org.ktc2.cokaen.wouldyouin.member.application.dto.request.edit.MemberEditRequest; +import org.ktc2.cokaen.wouldyouin.member.api.dto.MemberResponse; +import org.ktc2.cokaen.wouldyouin.member.api.dto.request.MemberAdditionalInfoRequest; +import org.ktc2.cokaen.wouldyouin.member.api.dto.request.create.MemberCreateRequest; +import org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit.MemberEditRequest; import org.ktc2.cokaen.wouldyouin.member.persist.Member; import org.ktc2.cokaen.wouldyouin.member.persist.MemberRepository; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceCommonBehavior.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceCommonBehavior.java index 2dabecef..ed70871e 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceCommonBehavior.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceCommonBehavior.java @@ -1,6 +1,6 @@ package org.ktc2.cokaen.wouldyouin.member.application; -import org.ktc2.cokaen.wouldyouin.member.application.dto.MemberResponse; +import org.ktc2.cokaen.wouldyouin.member.api.dto.MemberResponse; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.springframework.transaction.annotation.Transactional; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java index d5b4fe5c..b5f4d46a 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java @@ -15,7 +15,7 @@ import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin.like.persist.CuratorLike; import org.ktc2.cokaen.wouldyouin.like.persist.HostLike; -import org.ktc2.cokaen.wouldyouin.member.application.dto.request.MemberAdditionalInfoRequest; +import org.ktc2.cokaen.wouldyouin.member.api.dto.request.MemberAdditionalInfoRequest; import org.ktc2.cokaen.wouldyouin.reservation.persist.Reservation; import org.ktc2.cokaen.wouldyouin.review.persist.Review; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/payment/application/PaymentService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/payment/application/PaymentService.java index 0506aab3..c8a48c45 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/payment/application/PaymentService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/payment/application/PaymentService.java @@ -1,75 +1,46 @@ package org.ktc2.cokaen.wouldyouin.payment.application; -import java.net.URI; -import java.util.HashMap; -import java.util.Map; +import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin._common.exception.FailedToPayException; +import org.ktc2.cokaen.wouldyouin._common.util.KakaoPayUtil; +import org.ktc2.cokaen.wouldyouin._common.util.RestClientUtil; import org.ktc2.cokaen.wouldyouin.payment.dto.KakaoPayRequest; import org.ktc2.cokaen.wouldyouin.payment.dto.KakaoPayResponse; import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; -import org.springframework.web.client.RestClient; @Service +@RequiredArgsConstructor public class PaymentService { - // Todo: pay 취소 기능 추가 - // Todo: RestClient 관련 로직 유틸로 분리 - private final RestClient client = RestClient.builder().build(); + private final RestClientUtil client; - @Value("${oauth.payment.kakao_pay_request_host}") + @Value("${oauth.payment.kakao-pay-request-host}") private String kakaoPayRequestHost; - @Value("${oauth.payment.kakao_pay_single_payment_url}") private String kakaoPaySinglePaymentUrl; - @Value("${oauth.payment.approval_url}") private String approvalUrl; - @Value("${oauth.payment.cancel_url}") private String cancelUrl; - @Value("${oauth.payment.fail_url}") private String failUrl; - @Value("${oauth.payment.secret_key}") private String secretKey; public KakaoPayResponse createPayment(KakaoPayRequest kakaoPayRequest) { - try { - return client.post() - .uri(URI.create("https://" + kakaoPayRequestHost + kakaoPaySinglePaymentUrl)) - .headers(httpHeaders -> httpHeaders.addAll(createKakaoPayRequestHeaders())) - .body(createKakaoPayRequestBody(kakaoPayRequest)) - .retrieve() - .body(KakaoPayResponse.class); - } catch (Exception ex) { - throw new FailedToPayException("결제에 실패했습니다."); + ResponseEntity response = client.post( + kakaoPayRequestHost + "/" + kakaoPaySinglePaymentUrl, + KakaoPayUtil.createKakaoPayRequestHeaders(kakaoPayRequestHost, secretKey), + KakaoPayUtil.createKakaoPayRequestBody(kakaoPayRequest, approvalUrl, cancelUrl, failUrl), + KakaoPayResponse.class + ); + if (!response.getStatusCode().is2xxSuccessful()) { + throw new FailedToPayException("카카오페이 API 요청을 실패하였습니다."); } + return response.getBody(); } - private HttpHeaders createKakaoPayRequestHeaders() { - HttpHeaders headers = new HttpHeaders(); - headers.add("Host", kakaoPayRequestHost); - headers.add("Authorization", "SECRET_KEY " + secretKey); - headers.setContentType(MediaType.APPLICATION_JSON); - return headers; - } - - private Map createKakaoPayRequestBody(KakaoPayRequest kakaoPayRequest) { - Map body = new HashMap<>(); - body.put("cid", "TC0ONETIME"); - body.put("partner_order_id", kakaoPayRequest.getReservationId()); - body.put("partner_user_id", kakaoPayRequest.getHostId()); - body.put("item_name", kakaoPayRequest.getEventName()); - body.put("quantity", kakaoPayRequest.getQuantity()); - body.put("total_amount", kakaoPayRequest.getTotalAmount()); - body.put("tax_free_amount", kakaoPayRequest.getTaxFreeAmount()); - body.put("approval_url", approvalUrl); - body.put("cancel_url", cancelUrl); - body.put("fail_url", failUrl); - return body; - } + // Todo: pay 취소 기능 추가 } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/ReservationController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/ReservationController.java index 4199bfea..7d265e66 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/ReservationController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/ReservationController.java @@ -4,7 +4,7 @@ import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponse; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponseBody; -import org.ktc2.cokaen.wouldyouin._common.config.ParamDefaults; +import org.ktc2.cokaen.wouldyouin._common.api.ParamDefaults; import org.ktc2.cokaen.wouldyouin.auth.Authorize; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/ReservationResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/ReservationResponse.java index ba63a297..5249b6ee 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/ReservationResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/ReservationResponse.java @@ -4,7 +4,7 @@ import lombok.Builder; import lombok.Getter; import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.ReservationEventResponse; -import org.ktc2.cokaen.wouldyouin.member.application.dto.relation.ReservationMemberResponse; +import org.ktc2.cokaen.wouldyouin.member.api.dto.relation.ReservationMemberResponse; import org.ktc2.cokaen.wouldyouin.reservation.persist.Reservation; @Builder diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java index 73d26a72..17e1efb5 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java @@ -1,6 +1,5 @@ package org.ktc2.cokaen.wouldyouin.reservation.application; -import java.util.List; import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/ReviewController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/ReviewController.java index ea036dc1..f9637cf4 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/ReviewController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/ReviewController.java @@ -4,9 +4,9 @@ import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponseBody; import org.ktc2.cokaen.wouldyouin.review.application.ReviewService; -import org.ktc2.cokaen.wouldyouin.review.application.dto.ReviewCreateRequest; -import org.ktc2.cokaen.wouldyouin.review.application.dto.ReviewEditRequest; -import org.ktc2.cokaen.wouldyouin.review.application.dto.ReviewResponse; +import org.ktc2.cokaen.wouldyouin.review.api.dto.ReviewCreateRequest; +import org.ktc2.cokaen.wouldyouin.review.api.dto.ReviewEditRequest; +import org.ktc2.cokaen.wouldyouin.review.api.dto.ReviewResponse; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/review/application/dto/ReviewCreateRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewCreateRequest.java similarity index 87% rename from src/main/java/org/ktc2/cokaen/wouldyouin/review/application/dto/ReviewCreateRequest.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewCreateRequest.java index b90571ce..406ee397 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/review/application/dto/ReviewCreateRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewCreateRequest.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin.review.application.dto; +package org.ktc2.cokaen.wouldyouin.review.api.dto; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/review/application/dto/ReviewEditRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewEditRequest.java similarity index 74% rename from src/main/java/org/ktc2/cokaen/wouldyouin/review/application/dto/ReviewEditRequest.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewEditRequest.java index f850e0b2..7b070079 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/review/application/dto/ReviewEditRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewEditRequest.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin.review.application.dto; +package org.ktc2.cokaen.wouldyouin.review.api.dto; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/review/application/dto/ReviewResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewResponse.java similarity index 88% rename from src/main/java/org/ktc2/cokaen/wouldyouin/review/application/dto/ReviewResponse.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewResponse.java index 08a2e764..daf8e8b3 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/review/application/dto/ReviewResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewResponse.java @@ -1,10 +1,10 @@ -package org.ktc2.cokaen.wouldyouin.review.application.dto; +package org.ktc2.cokaen.wouldyouin.review.api.dto; import lombok.Builder; import lombok.Getter; import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.ReviewEventResponse; import org.ktc2.cokaen.wouldyouin.event.persist.Event; -import org.ktc2.cokaen.wouldyouin.member.application.dto.relationResponse.ReviewMemberResponse; +import org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse.ReviewMemberResponse; import org.ktc2.cokaen.wouldyouin.member.persist.Member; import org.ktc2.cokaen.wouldyouin.review.persist.Review; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/review/application/ReviewService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/review/application/ReviewService.java index adb7b604..e0875dd8 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/review/application/ReviewService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/review/application/ReviewService.java @@ -5,9 +5,9 @@ import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin.event.application.EventService; import org.ktc2.cokaen.wouldyouin.member.application.MemberService; -import org.ktc2.cokaen.wouldyouin.review.application.dto.ReviewCreateRequest; -import org.ktc2.cokaen.wouldyouin.review.application.dto.ReviewEditRequest; -import org.ktc2.cokaen.wouldyouin.review.application.dto.ReviewResponse; +import org.ktc2.cokaen.wouldyouin.review.api.dto.ReviewCreateRequest; +import org.ktc2.cokaen.wouldyouin.review.api.dto.ReviewEditRequest; +import org.ktc2.cokaen.wouldyouin.review.api.dto.ReviewResponse; import org.ktc2.cokaen.wouldyouin.review.persist.Review; import org.ktc2.cokaen.wouldyouin.review.persist.ReviewRepository; import org.springframework.stereotype.Service; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/review/persist/Review.java b/src/main/java/org/ktc2/cokaen/wouldyouin/review/persist/Review.java index bc0a7d6e..2316be65 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/review/persist/Review.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/review/persist/Review.java @@ -18,7 +18,7 @@ import lombok.Setter; import org.ktc2.cokaen.wouldyouin.event.persist.Event; import org.ktc2.cokaen.wouldyouin.member.persist.Member; -import org.ktc2.cokaen.wouldyouin.review.application.dto.ReviewEditRequest; +import org.ktc2.cokaen.wouldyouin.review.api.dto.ReviewEditRequest; @Getter @Setter diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 446aa5a9..d3030496 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -46,15 +46,15 @@ logging.level.org.ktc2.cokaen.wouldyouin: debug # for image storage path image: upload: - common-path: src/main/resources/static + parent-path: src/main/resources/static/images curation: - sub-path: images/curation + child-path: curation member: - sub-path: images/member + child-path: member event: - sub-path: images/event + child-path: event ad: - sub-path: images/ad + child-path: advertisement # for jwt jwt: @@ -96,5 +96,5 @@ oauth: "cancel_url": "http://localhost:8080/api/events" "fail_url": "http://localhost:8080/api/events" "secret_key": ${KAKAOPAY_SECRET_KEY} - "kakao_pay_single_payment_url": "/online/v1/payment/ready" - "kakao_pay_request_host": "open-api.kakaopay.com" \ No newline at end of file + "kakao_pay_single_payment_url": "online/v1/payment/ready" + "kakao-pay-request-host": "https://open-api.kakaopay.com" \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/WouldYouInApplicationTests.java b/src/test/java/org/ktc2/cokaen/wouldyouin/WouldYouInApplicationTests.java index b4ff92e9..188f65e8 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/WouldYouInApplicationTests.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/WouldYouInApplicationTests.java @@ -6,8 +6,7 @@ @SpringBootTest class WouldYouInApplicationTests { - @Test - void contextLoads() { - } - +// @Test +// void contextLoads() { +// } } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java index a021fb23..82a4165b 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java @@ -21,8 +21,8 @@ import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.CurationEventResponse; import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.ReservationEventResponse; import org.ktc2.cokaen.wouldyouin.event.persist.Event; -import org.ktc2.cokaen.wouldyouin.member.application.dto.relation.ReservationMemberResponse; -import org.ktc2.cokaen.wouldyouin.member.application.dto.relationResponse.CurationCuratorResponse; +import org.ktc2.cokaen.wouldyouin.member.api.dto.relation.ReservationMemberResponse; +import org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse.CurationCuratorResponse; import org.ktc2.cokaen.wouldyouin.member.persist.AccountType; import org.ktc2.cokaen.wouldyouin.member.persist.Curator; import org.ktc2.cokaen.wouldyouin.member.persist.Host; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java index 716f14a9..8a1be112 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java @@ -16,7 +16,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import java.util.List; import java.util.Random; import org.junit.jupiter.api.BeforeEach; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java index d930cbf0..590cdbfb 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java @@ -25,15 +25,14 @@ import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; -import org.ktc2.cokaen.wouldyouin._common.vo.Location; -import org.ktc2.cokaen.wouldyouin._common.vo.UserLocation; import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; import org.ktc2.cokaen.wouldyouin.auth.application.JwtService; -import org.ktc2.cokaen.wouldyouin.curation.api.dto.LocationFilter; +import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationFilter; import org.ktc2.cokaen.wouldyouin.event.api.EventController; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventSliceResponse; +import org.ktc2.cokaen.wouldyouin.event.api.dto.UserLocation; import org.ktc2.cokaen.wouldyouin.event.application.EventService; import org.ktc2.cokaen.wouldyouin._global.TestData.EventDomain; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java index e38a6596..f36ac5a3 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java @@ -11,7 +11,6 @@ import java.util.List; import java.util.Optional; -import org.h2.engine.User; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -19,12 +18,11 @@ import org.ktc2.cokaen.wouldyouin.Image.application.EventImageService; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; -import org.ktc2.cokaen.wouldyouin._common.vo.Location; -import org.ktc2.cokaen.wouldyouin._common.vo.UserLocation; import org.ktc2.cokaen.wouldyouin._global.TestData.EventDomain; -import org.ktc2.cokaen.wouldyouin.curation.api.dto.LocationFilter; +import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationFilter; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; +import org.ktc2.cokaen.wouldyouin.event.api.dto.UserLocation; import org.ktc2.cokaen.wouldyouin.event.application.EventService; import org.ktc2.cokaen.wouldyouin.event.persist.Event; import org.ktc2.cokaen.wouldyouin.event.persist.EventRepository; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberServiceUnitTest.java index 8a3d0abc..23f7fd54 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberServiceUnitTest.java @@ -25,7 +25,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import org.ktc2.cokaen.wouldyouin.member.application.dto.MemberResponse; +import org.ktc2.cokaen.wouldyouin.member.api.dto.MemberResponse; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMember; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMemberRepository; import org.ktc2.cokaen.wouldyouin.member.persist.Curator; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java index 735d8c4a..5e372806 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java @@ -18,7 +18,7 @@ import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._global.TestUtil; -import org.ktc2.cokaen.wouldyouin.member.application.dto.request.edit.CuratorEditRequest; +import org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit.CuratorEditRequest; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMemberRepository; import org.ktc2.cokaen.wouldyouin.member.persist.Curator; import org.ktc2.cokaen.wouldyouin.member.persist.CuratorRepository; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java index a4052dd2..5097250a 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java @@ -14,10 +14,10 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.ktc2.cokaen.wouldyouin.Image.application.MemberImageService; import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; -import org.ktc2.cokaen.wouldyouin.auth.application.dto.LocalLoginRequest; +import org.ktc2.cokaen.wouldyouin.auth.api.dto.LocalLoginRequest; import org.ktc2.cokaen.wouldyouin._global.TestUtil; -import org.ktc2.cokaen.wouldyouin.member.application.dto.request.create.HostCreateRequest; -import org.ktc2.cokaen.wouldyouin.member.application.dto.request.edit.HostEditRequest; +import org.ktc2.cokaen.wouldyouin.member.api.dto.request.create.HostCreateRequest; +import org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit.HostEditRequest; import org.ktc2.cokaen.wouldyouin.member.persist.Host; import org.ktc2.cokaen.wouldyouin.member.persist.HostRepository; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java index 038ec16b..0c789df4 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java @@ -18,9 +18,9 @@ import org.ktc2.cokaen.wouldyouin.Image.application.MemberImageService; import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin._global.TestUtil; -import org.ktc2.cokaen.wouldyouin.member.application.dto.request.MemberAdditionalInfoRequest; -import org.ktc2.cokaen.wouldyouin.member.application.dto.request.create.MemberCreateRequest; -import org.ktc2.cokaen.wouldyouin.member.application.dto.request.edit.MemberEditRequest; +import org.ktc2.cokaen.wouldyouin.member.api.dto.request.MemberAdditionalInfoRequest; +import org.ktc2.cokaen.wouldyouin.member.api.dto.request.create.MemberCreateRequest; +import org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit.MemberEditRequest; import org.ktc2.cokaen.wouldyouin.member.persist.Member; import org.ktc2.cokaen.wouldyouin.member.persist.MemberRepository; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; From d5b29f36750682ececdbcae1b3c5b8bf8046728b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=99=8D=EC=8B=9D?= <90020593+Daolove0323@users.noreply.github.com> Date: Sun, 10 Nov 2024 23:31:38 +0900 Subject: [PATCH 11/53] [Weekly/11] Image/test (#107) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: image controller unit test * feat: 불필요한 import문 제거 --- build.gradle | 2 + .../wouldyouin/Image/api/ImageController.java | 3 +- .../Image/api/dto/ImageResponse.java | 9 +- .../Image/application/ImageService.java | 4 +- .../application/ImageStorageService.java | 7 +- .../application/AdvertisementService.java | 4 +- .../application/CurationCardService.java | 2 +- .../event/application/EventService.java | 2 +- src/main/resources/application.yml | 2 +- .../cokaen/wouldyouin/_global/TestData.java | 55 +++++++- .../curation/CurationControllerUnitTest.java | 17 ++- .../wouldyouin/image/ImageControllerTest.java | 124 ++++++++++++++++++ .../application/CuratorServiceUnitTest.java | 2 +- .../application/HostServiceUnitTest.java | 2 +- .../application/MemberServiceUnitTest.java | 2 +- 15 files changed, 204 insertions(+), 33 deletions(-) create mode 100644 src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java diff --git a/build.gradle b/build.gradle index 000c37a2..3595fa08 100644 --- a/build.gradle +++ b/build.gradle @@ -50,6 +50,8 @@ dependencies { //for test implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' + testCompileOnly 'org.projectlombok:lombok' + testAnnotationProcessor 'org.projectlombok:lombok' //for Swagger implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0' diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java index 951dc481..fd6fffc6 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java @@ -42,11 +42,12 @@ public ResponseEntity>> uploadImages( } // Todo: authorize + // Todo: 삭제로직 수정필요 @DeleteMapping("/{id}") public ResponseEntity> deleteImage( @PathVariable Long id, @RequestParam(value = "type") ImageDomain imageDomain) { - imageServiceFactory.getImageService(imageDomain).deleteAndDelete(id); + imageServiceFactory.getImageService(imageDomain).deleteImage(id); return ApiResponse.noContent(); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageResponse.java index fa9856b6..70e789e8 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageResponse.java @@ -11,14 +11,17 @@ public class ImageResponse { private Long id; private String url; - private LocalDateTime createdDate; private Long size; + private String extension; + private LocalDateTime createdDate; + - public static ImageResponse from(Image image, String domainName) { + public static ImageResponse from(Image image, String apiUrlHeader) { return ImageResponse.builder() .id(image.getId()) - .url(domainName + image.getUrl()) + .url(apiUrlHeader + "/" + image.getUrl()) .size(image.getSize()) + .extension(image.getExtension()) .createdDate(image.getCreatedDate()) .build(); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java index b4f1506e..b7afb8ff 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java @@ -21,7 +21,7 @@ public abstract class ImageService { @Autowired protected ImageStorageService imageStorageService; - @Value("${spring.wouldyouin-domain-name}") + @Value("${image.api-url}") private String domainName; protected abstract ImageRepository getImageRepository(); @@ -54,7 +54,7 @@ public List saveImages(List images) { } @Transactional - public void deleteAndDelete(Long id) { + public void deleteImage(Long id) { T image = getById(id); delete(id); imageStorageService.delete(image.getUrl()); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorageService.java index 5b68d448..8ec82554 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorageService.java @@ -27,9 +27,10 @@ public byte[] readFromDirectory(Path path) { public ImageRequest saveToDirectory(MultipartFile image, String subPath) { String extension = FileUtil.getExtension(image); String fileName = FileUtil.generateUuidName() + "." + extension; - Path path = Paths.get(parentPath, subPath, fileName); - FileUtil.saveFile(image, path); - return ImageRequest.of(path.toString(), image.getSize(), FileUtil.getExtension(image)); + String relativeFilePath = Paths.get(subPath, fileName).toString(); + Path absoluteFilePath = Paths.get(parentPath, relativeFilePath); + FileUtil.saveFile(image, absoluteFilePath); + return ImageRequest.of(relativeFilePath, image.getSize(), FileUtil.getExtension(image)); } public ImageRequest saveToDirectory(String imageUrl, String subPath) { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java index 2bf7a1f4..4f7c8bd4 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java @@ -55,7 +55,7 @@ public AdvertisementResponse update(Long adId, AdvertisementRequest adRequest, M Advertisement ad = getByIdOrThrow(adId); Optional.ofNullable(multipartFile).ifPresentOrElse( image -> { - adImageService.deleteAndDelete(ad.getAdvertisementImage().getId()); + adImageService.deleteImage(ad.getAdvertisementImage().getId()); AdvertisementImage adImage = adImageService.saveImage(image); ad.updateFrom(adRequest, adImage); adImage.setAdvertisement(ad); @@ -71,7 +71,7 @@ public AdvertisementResponse update(Long adId, AdvertisementRequest adRequest, M @Transactional public void delete(Long adId) { Advertisement ad = getByIdOrThrow(adId); - adImageService.deleteAndDelete(ad.getAdvertisementImage().getId()); + adImageService.deleteImage(ad.getAdvertisementImage().getId()); adRepository.deleteById(adId); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java index 55f9b835..4214b741 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java @@ -48,7 +48,7 @@ public CurationCard create(CurationCardRequest request) { @Transactional public void delete(Long id) { CurationCard target = getByIdOrThrow(id); - target.getCurationImages().forEach(image -> curationImageService.deleteAndDelete(image.getId())); + target.getCurationImages().forEach(image -> curationImageService.deleteImage(image.getId())); curationCardRepository.deleteById(id); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java index 2c56bc50..eeea3bb2 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java @@ -75,7 +75,7 @@ public EventResponse create(Long hostId, EventCreateRequest eventCreateRequest) public EventResponse update(Long hostId, Long eventId, EventEditRequest eventEditRequest) { Event event = getByIdOrThrow(eventId); validateHostId(hostId, event); - event.getImages().forEach(image -> eventImageService.deleteAndDelete(image.getId())); + event.getImages().forEach(image -> eventImageService.deleteImage(image.getId())); List images = eventEditRequest.getImageIds().stream() .map(eventImageService::getById).toList(); event.updateFrom(eventEditRequest, images); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index d3030496..9ff4c855 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -10,7 +10,6 @@ spring: max-request-size: 10MB # 임시 프로젝트 url - wouldyouin-domain-name: http://52.78.71.136/ profiles: default: dev @@ -45,6 +44,7 @@ logging.level.org.ktc2.cokaen.wouldyouin: debug # for image storage path image: + api-url: http://52.78.71.136/api/images upload: parent-path: src/main/resources/static/images curation: diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java index 82a4165b..fc50424b 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java @@ -2,6 +2,8 @@ import java.time.LocalDateTime; import java.util.List; +import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageRequest; +import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageResponse; import org.ktc2.cokaen.wouldyouin.Image.persist.CurationImage; import org.ktc2.cokaen.wouldyouin.Image.persist.EventImage; import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; @@ -32,6 +34,8 @@ import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationResponse; import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationSliceResponse; import org.ktc2.cokaen.wouldyouin.reservation.persist.Reservation; +import org.springframework.http.MediaType; +import org.springframework.mock.web.MockMultipartFile; import org.springframework.test.util.ReflectionTestUtils; public class TestData { @@ -43,7 +47,8 @@ public static SliceInfo createSliceInfo() { .build(); } - public static class ImageDomain { + // Todo: 클래스이름 Domain말고 Data는 어떤지..?, ImageDomain이 중복이라 사용할 수 없음 ㅜ + public static class ImageData { public static MemberImage createValidMemberImage(Long id) { MemberImage ret = MemberImage.builder() @@ -67,13 +72,49 @@ public static EventImage createValidEventImage(Long id) { public static CurationImage createValidCurationImage(Long id) { CurationImage ret = CurationImage.builder() - .url("curationImageUrl") + .url("curationImageUrl.jpg") .size(10L) - .extension(".jpg") + .extension("jpg") .build(); ReflectionTestUtils.setField(ret, "id", id); return ret; } + + public static ImageRequest createValidImageRequest() { + return ImageRequest.builder() + .url("memberImage.png") + .size(20L) + .extension("png") + .build(); + } + + public static ImageResponse createValidImageResponse1() { + return ImageResponse.builder() + .id(1L) + .url("curationImageUrl.jpg") + .size(10L) + .extension(".jpg") + .createdDate(LocalDateTime.of(2024, 3, 23, 0, 0)) + .build(); + } + + public static ImageResponse createValidImageResponse2() { + return ImageResponse.builder() + .id(2L) + .url("memberImage.png") + .size(20L) + .extension(".png") + .createdDate(LocalDateTime.of(2024, 3, 23, 0, 0)) + .build(); + } + + public static MockMultipartFile createValidMultipartFile1() { + return new MockMultipartFile("image1", "image1.jpg", MediaType.IMAGE_JPEG_VALUE, "imageData1".getBytes()); + } + + public static MockMultipartFile createValidMultipartFile2() { + return new MockMultipartFile("image2", "image2.png", MediaType.IMAGE_JPEG_VALUE, "imageData2".getBytes()); + } } public static class MemberDomain { @@ -84,7 +125,7 @@ public static class MemberDomain { public static final long validWelcomeMemberId = 4L; public static Member createValidMember() { - MemberImage memberImage = ImageDomain.createValidMemberImage(validMemberId); + MemberImage memberImage = ImageData.createValidMemberImage(validMemberId); Member ret = Member.builder() .accountType(AccountType.kakao) .email("member1@example.com") @@ -102,7 +143,7 @@ public static Member createValidMember() { } public static Curator createValidCurator() { - MemberImage memberImage = ImageDomain.createValidMemberImage(validCuratorId); + MemberImage memberImage = ImageData.createValidMemberImage(validCuratorId); Curator ret = Curator.curatorBuilder() .accountType(AccountType.google) .email("curator1@example.com") @@ -121,7 +162,7 @@ public static Curator createValidCurator() { } public static Host createValidHost() { - MemberImage memberImage = ImageDomain.createValidMemberImage(validHostId); + MemberImage memberImage = ImageData.createValidMemberImage(validHostId); Host ret = Host.builder() .email("curator1@example.com") .nickname("nick_curator_12") @@ -137,7 +178,7 @@ public static Host createValidHost() { } public static Member createValidWelcomeMember() { - MemberImage memberImage = ImageDomain.createValidMemberImage(validWelcomeMemberId); + MemberImage memberImage = ImageData.createValidMemberImage(validWelcomeMemberId); Member ret = Member.builder() .accountType(AccountType.kakao) .email("member2@example.com") diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java index 8a1be112..fad5703e 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java @@ -45,22 +45,23 @@ @WebMvcTest(CurationController.class) class CurationControllerUnitTest { + @Autowired + private MockMvc mockMvc; + @Autowired private ObjectMapper objectMapper; + @Autowired + private WebApplicationContext context; + + private static final long randomId = abs(new Random().nextLong()); + @MockBean private CurationService curationService; @MockBean private JwtAuthFilter jwtAuthFilter; - @Autowired - private MockMvc mockMvc; - - @Autowired - private WebApplicationContext context; - private static final long randomId = abs(new Random().nextLong()); - @BeforeEach public void setup() throws Exception { mockMvc = MockMvcBuilders @@ -608,7 +609,6 @@ void deleteCuration2() throws Exception { .andExpect(status().isUnauthorized()) .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); - // then then(curationService).shouldHaveNoInteractions(); } @@ -624,7 +624,6 @@ void deleteCuration3() throws Exception { .andExpect(status().isUnauthorized()) .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); - // then then(curationService).shouldHaveNoInteractions(); } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java new file mode 100644 index 00000000..7ef5f13b --- /dev/null +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java @@ -0,0 +1,124 @@ +package org.ktc2.cokaen.wouldyouin.image; + +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.BDDMockito.then; +import static org.mockito.Mockito.times; +import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.nio.file.Paths; +import java.util.UUID; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.ktc2.cokaen.wouldyouin.Image.api.ImageController; +import org.ktc2.cokaen.wouldyouin.Image.application.CurationImageService; +import org.ktc2.cokaen.wouldyouin.Image.application.ImageServiceFactory; +import org.ktc2.cokaen.wouldyouin.Image.application.ImageStorageService; +import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember; +import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +@WebMvcTest(ImageController.class) +class ImageControllerTest { + + @Autowired + private MockMvc mockMvc; + + @Autowired + private WebApplicationContext context; + + @MockBean + private ImageServiceFactory imageServiceFactory; + + @MockBean + private CurationImageService curationImageService; + + @MockBean + private ImageStorageService imageStorageService; + + @MockBean + private JwtAuthFilter jwtAuthFilter; + + @BeforeEach + public void setup() throws Exception { + + mockMvc = MockMvcBuilders + .webAppContextSetup(context) + .apply(springSecurity()) + .build(); + } + + @Test + @DisplayName("이미지 경로를 통해 이미지를 조회한다.") + @WithMockMember + void getImage() throws Exception { + // given + String directory = "member"; + String file = UUID.randomUUID().toString() + ".png"; + + // when + mockMvc.perform(get("/api/images/" + directory + "/" + file)) + .andDo(print()) + .andExpect(status().isOk()); + +// then + then(imageStorageService).should(times(1)).readFromDirectory(eq(Paths.get(directory, file))); + } + +// @PostMapping +// public ResponseEntity>> uploadImages( +// @RequestParam List images, +// @RequestParam(value = "type") ImageDomain imageDomain) { +// return ApiResponse.ok(imageServiceFactory.getImageService(imageDomain).saveImages(images)); +// } + + @Test + @WithMockMember + void uploadImages() throws Exception { +// // given +// MockMultipartFile image1 = ImageData.createValidMultipartFile1(); +// MockMultipartFile image2 = ImageData.createValidMultipartFile2(); +// given((CurationImageService) imageServiceFactory.getImageService(ImageDomain.CURATION)).willReturn(curationImageService); +// given(curationImageService.saveImages(List.of(image1, image2))) +// .willReturn(List.of(ImageData.createValidImageResponse1(), ImageData.createValidImageResponse2())); +// +//// // when +// mockMvc.perform(multipart("/api/images") +// .file(ImageData.createValidMultipartFile1()) +// .file(ImageData.createValidMultipartFile2()) +// .contentType(MediaType.MULTIPART_FORM_DATA) +// .param("type", ImageDomain.CURATION.name()) +// .with(csrf())) +// .andDo(print()) +// .andExpect(status().isOk()); +// .andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON)) // 응답 콘텐츠 타입 확인 +// .andExpect(MockMvcResultMatchers.jsonPath("$.data[0].imageName").value("image1.png")) // 첫 번째 이미지 이름 확인 +// .andExpect(MockMvcResultMatchers.jsonPath("$.data[1].imageName").value("image2.jpg")); // 두 번째 이미지 이름 확인 +// ArgumentCaptor captor = ArgumentCaptor.forClass(CurationCreateRequest.class); +// CurationCreateRequest request = CurationDomain.createValidCurationCreateRequest(); +// +// // when +// mockMvc.perform(post("/api/curations") +// .with(csrf()) +// .contentType(MediaType.APPLICATION_JSON) +// .content(objectMapper.writeValueAsString(request))) +// .andDo(print()) +// .andExpect(status().isCreated()); +// +// // then +// then(curationService).should(times(1)).create(eq(MemberDomain.validCuratorId), captor.capture()); +// assertThat(captor.getValue()).isEqualTo(request); + } + + @Test + void deleteImage() { + } +} \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java index 5e372806..c5482afc 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java @@ -1,7 +1,7 @@ package org.ktc2.cokaen.wouldyouin.member.application; import static org.assertj.core.api.Assertions.assertThat; -import static org.ktc2.cokaen.wouldyouin._global.TestData.ImageDomain.createValidMemberImage; +import static org.ktc2.cokaen.wouldyouin._global.TestData.ImageData.createValidMemberImage; import static org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain.createValidCurator; import static org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain.createValidMember; import static org.mockito.ArgumentMatchers.any; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java index 5097250a..3d3c7921 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java @@ -2,7 +2,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain.createValidHost; -import static org.ktc2.cokaen.wouldyouin._global.TestData.ImageDomain.createValidMemberImage; +import static org.ktc2.cokaen.wouldyouin._global.TestData.ImageData.createValidMemberImage; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.times; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java index 0c789df4..1fbcb3eb 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java @@ -2,7 +2,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.ktc2.cokaen.wouldyouin._global.TestData.ImageDomain.createValidMemberImage; +import static org.ktc2.cokaen.wouldyouin._global.TestData.ImageData.createValidMemberImage; import static org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain.createValidMember; import static org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain.createValidWelcomeMember; import static org.mockito.BDDMockito.given; From eec61544f3a3304164537db98883a844cc8282bb Mon Sep 17 00:00:00 2001 From: Jangan Lee Date: Mon, 11 Nov 2024 01:44:07 +0900 Subject: [PATCH 12/53] =?UTF-8?q?[Weekly/11/Refactor/ExtractRestClient]=20?= =?UTF-8?q?RestClientUtil=20=EC=9D=B4=EC=9A=A9,=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=B6=94=EC=B6=9C=20(#108)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Image/api/dto/ImageResponse.java | 4 +- .../Image/application/ImageService.java | 4 +- .../application/ImageStorageService.java | 23 +++--- .../_common/util/RestClientUtil.java | 24 ++++-- .../oauth/GoogleRequestService.java | 72 ++++++++++------- .../oauth/KakaoRequestService.java | 78 +++++++++++-------- .../wouldyouin/member/persist/BaseMember.java | 2 +- .../payment/application/PaymentService.java | 16 ++-- 8 files changed, 132 insertions(+), 91 deletions(-) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageResponse.java index 70e789e8..3ecdd1dc 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageResponse.java @@ -1,5 +1,6 @@ package org.ktc2.cokaen.wouldyouin.Image.api.dto; +import java.nio.file.Paths; import java.time.LocalDateTime; import lombok.Builder; import lombok.Getter; @@ -15,11 +16,10 @@ public class ImageResponse { private String extension; private LocalDateTime createdDate; - public static ImageResponse from(Image image, String apiUrlHeader) { return ImageResponse.builder() .id(image.getId()) - .url(apiUrlHeader + "/" + image.getUrl()) + .url(Paths.get(apiUrlHeader, image.getUrl()).toString()) .size(image.getSize()) .extension(image.getExtension()) .createdDate(image.getCreatedDate()) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java index b7afb8ff..435d156c 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java @@ -22,7 +22,7 @@ public abstract class ImageService { protected ImageStorageService imageStorageService; @Value("${image.api-url}") - private String domainName; + private String apiUrl; protected abstract ImageRepository getImageRepository(); @@ -38,7 +38,7 @@ public T getById(Long id) { } protected ImageResponse create(ImageRequest imageRequest) { - return ImageResponse.from(getImageRepository().save(toEntity(imageRequest)), domainName); + return ImageResponse.from(getImageRepository().save(toEntity(imageRequest)), apiUrl); } protected void delete(Long id) { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorageService.java index 8ec82554..80b59bbb 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorageService.java @@ -2,13 +2,14 @@ import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Optional; import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageRequest; import org.ktc2.cokaen.wouldyouin._common.exception.FailedToUploadImageException; import org.ktc2.cokaen.wouldyouin._common.util.FileUtil; import org.ktc2.cokaen.wouldyouin._common.util.RestClientUtil; import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.ResponseEntity; +import org.springframework.http.HttpHeaders; import org.springframework.stereotype.Component; import org.springframework.web.multipart.MultipartFile; @@ -34,19 +35,17 @@ public ImageRequest saveToDirectory(MultipartFile image, String subPath) { } public ImageRequest saveToDirectory(String imageUrl, String subPath) { - ResponseEntity response = client.get(imageUrl, byte[].class); - if (response.getBody() == null) { - throw new FailedToUploadImageException("응답 본문이 비어있어 이미지를 가져올 수 없습니다."); - } - if (!response.getStatusCode().is2xxSuccessful()) { - throw new FailedToUploadImageException("이미지 URL에 대한 요청을 실패하였습니다."); - } + byte[] response = client.get(byte[].class, imageUrl, new HttpHeaders(), + (req, rsp) -> { throw new FailedToUploadImageException("이미지 URL에 대한 요청을 실패하였습니다."); } + ); + Optional.ofNullable(response).orElseThrow( + () -> new FailedToUploadImageException("응답 본문이 비어있어 이미지를 가져올 수 없습니다.")); String extension = FileUtil.getExtension(imageUrl); String fileName = FileUtil.generateUuidName() + "." + extension; - Path path = Paths.get(parentPath, subPath, fileName); - FileUtil.saveFile(response.getBody(), path); - long size = response.getBody().length; - return ImageRequest.of(path.toString(), size, extension); + String relativeFilePath = Paths.get(subPath, fileName).toString(); + Path absoluteFilePath = Paths.get(parentPath, relativeFilePath); + FileUtil.saveFile(response, absoluteFilePath); + return ImageRequest.of(relativeFilePath, (long) response.length, extension); } public void delete(String imagePath) { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/RestClientUtil.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/RestClientUtil.java index 464d4200..a1a1e533 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/RestClientUtil.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/RestClientUtil.java @@ -1,10 +1,12 @@ package org.ktc2.cokaen.wouldyouin._common.util; +import java.util.function.Predicate; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpHeaders; -import org.springframework.http.ResponseEntity; +import org.springframework.http.HttpStatusCode; import org.springframework.stereotype.Component; import org.springframework.web.client.RestClient; +import org.springframework.web.client.RestClient.ResponseSpec.ErrorHandler; @Component @RequiredArgsConstructor @@ -12,19 +14,31 @@ public class RestClientUtil { private final RestClient client; - public ResponseEntity get(String url, Class classType) { + public T get(Class classType, String url, HttpHeaders headers, ErrorHandler errorHandler) { return client.get() .uri(url) + .headers(httpHeaders -> httpHeaders.putAll(headers)) .retrieve() - .toEntity(classType); + .onStatus(Predicate.not(HttpStatusCode::is2xxSuccessful), errorHandler) + .body(classType); } - public ResponseEntity post(String url, HttpHeaders headers, B body, Class classType) { + public T post( Class classType, String url, HttpHeaders headers, ErrorHandler errorHandler) { + return client.post() + .uri(url) + .headers(httpHeaders -> httpHeaders.addAll(headers)) + .retrieve() + .onStatus(Predicate.not(HttpStatusCode::is2xxSuccessful), errorHandler) + .body(classType); + } + + public T post(Class classType, String url, HttpHeaders headers, B body, ErrorHandler errorHandler) { return client.post() .uri(url) .headers(httpHeaders -> httpHeaders.addAll(headers)) .body(body) .retrieve() - .toEntity(classType); + .onStatus(Predicate.not(HttpStatusCode::is2xxSuccessful), errorHandler) + .body(classType); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/GoogleRequestService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/GoogleRequestService.java index c15e9e8b..f70095d2 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/GoogleRequestService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/GoogleRequestService.java @@ -3,16 +3,16 @@ import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; import com.fasterxml.jackson.databind.annotation.JsonNaming; import java.util.Objects; +import org.ktc2.cokaen.wouldyouin._common.util.RestClientUtil; import org.ktc2.cokaen.wouldyouin.auth.application.oauth.dto.AccessTokenResponse; import org.ktc2.cokaen.wouldyouin.auth.application.oauth.dto.OauthRequest; import org.ktc2.cokaen.wouldyouin.auth.application.oauth.dto.OauthResourcesResponse; import org.ktc2.cokaen.wouldyouin.member.persist.AccountType; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatusCode; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; -import org.springframework.web.client.RestClient; +import org.springframework.web.util.UriComponentsBuilder; @Service public class GoogleRequestService extends OauthRequestService { @@ -38,11 +38,46 @@ public class GoogleRequestService extends OauthRequestService { @Value("${oauth.google.redirect_uri}") private String redirectUri; + private final RestClientUtil client; + private final String loginRequestUri; + private final String accessRequestUri; + private final HttpHeaders loginRequestHeaders; + + public GoogleRequestService(RestClientUtil restClientUtil) { + + this.client = restClientUtil; + + loginRequestUri = UriComponentsBuilder.newInstance() + .scheme("https") + .host(loginRequestHost) + .path(loginRequestPath) + .build(true) + .toString(); + + accessRequestUri = UriComponentsBuilder.newInstance() + .scheme("https") + .host(accessRequestHost) + .path(accessRequestPath) + .build(true) + .toString(); + + loginRequestHeaders = new HttpHeaders(); + loginRequestHeaders.add(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE); + } + + protected HttpHeaders getAccessRequestHeaders(AccessTokenResponse authenticationResponse) { + HttpHeaders accessRequestHeaders = new HttpHeaders(); + accessRequestHeaders.add(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE); + accessRequestHeaders.add(HttpHeaders.AUTHORIZATION, "Bearer " + authenticationResponse.getAccessToken()); + return accessRequestHeaders; + } + @Override protected AccountType getAccountType() { return AccountType.google; } + @Override protected OauthRequest getOauthRequestBase() { return OauthRequest.builder() .grantType("authorization_code") @@ -54,36 +89,17 @@ protected OauthRequest getOauthRequestBase() { @Override protected OauthResourcesResponse requestLoginAndAccessResources(OauthRequest request) { - AccessTokenResponse authenticationResponse = RestClient.create() - .post() - .uri(uriBuilder -> uriBuilder - .scheme("https") - .host(loginRequestHost) - .path(loginRequestPath) - .build(true)) - .header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE) - .body(request) - .retrieve() + + AccessTokenResponse authenticationResponse = client.post( + AccessTokenResponse.class, loginRequestUri, loginRequestHeaders, request, // TODO: 커스텀 예외 추가 - .onStatus(HttpStatusCode::is4xxClientError, (httpRequest, clientHttpResponse) -> { throw new RuntimeException("에러"); }) - .onStatus(HttpStatusCode::is5xxServerError, (httpRequest, clientHttpResponse) -> { throw new RuntimeException("에러"); }) - .body(AccessTokenResponse.class); + (req, response) -> { throw new RuntimeException("에러"); }); Objects.requireNonNull(authenticationResponse); - GoogleAccessRequestResponse result = RestClient.create() - .get() - .uri(uriBuilder -> uriBuilder - .scheme("https") - .host(accessRequestHost) - .path(accessRequestPath) - .build(true)) - .header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE) - .header(HttpHeaders.AUTHORIZATION, "Bearer " + authenticationResponse.getAccessToken()) - .retrieve() + GoogleAccessRequestResponse result = client.get( + GoogleAccessRequestResponse.class, accessRequestUri, getAccessRequestHeaders(authenticationResponse), // TODO: 커스텀 예외 추가 - .onStatus(HttpStatusCode::is4xxClientError, (httpRequest, clientHttpResponse) -> { throw new RuntimeException("에러"); }) - .onStatus(HttpStatusCode::is5xxServerError, (httpRequest, clientHttpResponse) -> { throw new RuntimeException("에러"); }) - .body(GoogleAccessRequestResponse.class); + (req, rsp) -> { throw new RuntimeException("에러"); }); Objects.requireNonNull(result); return OauthResourcesResponse.builder() diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/KakaoRequestService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/KakaoRequestService.java index 1a8cb838..57ae9585 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/KakaoRequestService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/KakaoRequestService.java @@ -5,16 +5,16 @@ import java.util.Objects; import lombok.Getter; import lombok.RequiredArgsConstructor; +import org.ktc2.cokaen.wouldyouin._common.util.RestClientUtil; import org.ktc2.cokaen.wouldyouin.auth.application.oauth.dto.AccessTokenResponse; import org.ktc2.cokaen.wouldyouin.auth.application.oauth.dto.OauthRequest; import org.ktc2.cokaen.wouldyouin.auth.application.oauth.dto.OauthResourcesResponse; import org.ktc2.cokaen.wouldyouin.member.persist.AccountType; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatusCode; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; -import org.springframework.web.client.RestClient; +import org.springframework.web.util.UriComponentsBuilder; @Service public class KakaoRequestService extends OauthRequestService { @@ -45,6 +45,45 @@ protected AccountType getAccountType() { return AccountType.kakao; } + private final RestClientUtil client; + private final String loginRequestUri; + private final String accessRequestUri; + private final HttpHeaders loginRequestHeaders; + + public KakaoRequestService(RestClientUtil restClientUtil) { + this.client = restClientUtil; + + OauthRequest request = getOauthRequestBase(); + loginRequestUri = UriComponentsBuilder.newInstance() + .scheme("https") + .host(loginRequestHost) + .path(loginRequestPath) + .queryParam("grant_type", request.getGrantType()) + .queryParam("client_id", request.getClientId()) + .queryParam("client_secret", request.getClientSecret()) + .queryParam("code", request.getCode()) + .build(true) + .toString(); + + accessRequestUri = UriComponentsBuilder.newInstance() + .scheme("https") + .host(accessRequestHost) + .path(accessRequestPath) + .build(true) + .toString(); + + loginRequestHeaders = new HttpHeaders(); + loginRequestHeaders.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE); + } + + protected HttpHeaders getAccessRequestHeaders(AccessTokenResponse authenticationResponse) { + HttpHeaders accessRequestHeaders = new HttpHeaders(); + accessRequestHeaders.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE); + accessRequestHeaders.add(HttpHeaders.AUTHORIZATION, "Bearer " + authenticationResponse.getAccessToken()); + return accessRequestHeaders; + } + + @Override protected OauthRequest getOauthRequestBase() { return OauthRequest.builder() .grantType("authorization_code") @@ -56,39 +95,16 @@ protected OauthRequest getOauthRequestBase() { @Override protected OauthResourcesResponse requestLoginAndAccessResources(OauthRequest request) { - AccessTokenResponse authenticationResponse = RestClient.create() - .post() - .uri(uriBuilder -> uriBuilder - .scheme("https") - .host(loginRequestHost) - .path(loginRequestPath) - .queryParam("grant_type", request.getGrantType()) - .queryParam("client_id", request.getClientId()) - .queryParam("client_secret", request.getClientSecret()) - .queryParam("code", request.getCode()) - .build(true)) - .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE) - .retrieve() + AccessTokenResponse authenticationResponse = client.post( + AccessTokenResponse.class, loginRequestUri, loginRequestHeaders, // TODO: 커스텀 예외 추가 - .onStatus(HttpStatusCode::is4xxClientError, (httpRequest, clientHttpResponse) -> { throw new RuntimeException("에러"); }) - .onStatus(HttpStatusCode::is5xxServerError, (httpRequest, clientHttpResponse) -> { throw new RuntimeException("에러"); }) - .body(AccessTokenResponse.class); + (req, rsp) -> { throw new RuntimeException("에러"); }); Objects.requireNonNull(authenticationResponse); - KakaoAccessRequestResponse result = RestClient.create() - .get() - .uri(uriBuilder -> uriBuilder - .scheme("https") - .host(accessRequestHost) - .path(accessRequestPath) - .build(true)) - .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE) - .header(HttpHeaders.AUTHORIZATION, "Bearer " + authenticationResponse.getAccessToken()) - .retrieve() + KakaoAccessRequestResponse result = client.get( + KakaoAccessRequestResponse.class, accessRequestUri, getAccessRequestHeaders(authenticationResponse), // TODO: 커스텀 예외 추가 - .onStatus(HttpStatusCode::is4xxClientError, (httpRequest, clientHttpResponse) -> { throw new RuntimeException("에러"); }) - .onStatus(HttpStatusCode::is5xxServerError, (httpRequest, clientHttpResponse) -> { throw new RuntimeException("에러"); }) - .body(KakaoAccessRequestResponse.class); + (req, rsp) -> { throw new RuntimeException("에러"); }); Objects.requireNonNull(result); return OauthResourcesResponse.builder() diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java index 2d7afb34..e2a80e47 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java @@ -5,7 +5,6 @@ import jakarta.persistence.Entity; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; -import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; @@ -30,6 +29,7 @@ public abstract class BaseMember { @Id @Setter(AccessLevel.NONE) @GeneratedValue(strategy = GenerationType.IDENTITY) + // TODO: 네이밍 소문자로 바꾸기 private Long Id; @Column(nullable = false) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/payment/application/PaymentService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/payment/application/PaymentService.java index c8a48c45..3476c52e 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/payment/application/PaymentService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/payment/application/PaymentService.java @@ -1,5 +1,6 @@ package org.ktc2.cokaen.wouldyouin.payment.application; +import java.nio.file.Paths; import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin._common.exception.FailedToPayException; import org.ktc2.cokaen.wouldyouin._common.util.KakaoPayUtil; @@ -7,7 +8,6 @@ import org.ktc2.cokaen.wouldyouin.payment.dto.KakaoPayRequest; import org.ktc2.cokaen.wouldyouin.payment.dto.KakaoPayResponse; import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; @Service @@ -30,17 +30,13 @@ public class PaymentService { private String secretKey; public KakaoPayResponse createPayment(KakaoPayRequest kakaoPayRequest) { - ResponseEntity response = client.post( - kakaoPayRequestHost + "/" + kakaoPaySinglePaymentUrl, + return client.post( + KakaoPayResponse.class, + Paths.get(kakaoPayRequestHost, kakaoPaySinglePaymentUrl).toString(), KakaoPayUtil.createKakaoPayRequestHeaders(kakaoPayRequestHost, secretKey), KakaoPayUtil.createKakaoPayRequestBody(kakaoPayRequest, approvalUrl, cancelUrl, failUrl), - KakaoPayResponse.class + (req, rsp) -> { throw new FailedToPayException("카카오페이 API 요청을 실패하였습니다."); } ); - if (!response.getStatusCode().is2xxSuccessful()) { - throw new FailedToPayException("카카오페이 API 요청을 실패하였습니다."); - } - return response.getBody(); } - // Todo: pay 취소 기능 추가 -} +} \ No newline at end of file From d399e955efb3f88246172744faea41e470cfaab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=99=8D=EC=8B=9D?= <90020593+Daolove0323@users.noreply.github.com> Date: Mon, 11 Nov 2024 14:03:35 +0900 Subject: [PATCH 13/53] [Weekly/11] refactor: ImageService delete (#109) --- .gitignore | 2 +- .../Image/api/dto/ImageResponse.java | 6 ++-- .../AdvertisementImageService.java | 1 + .../application/CurationImageService.java | 1 + .../Image/application/EventImageService.java | 1 + .../Image/application/ImageService.java | 31 +++++++++-------- .../application/ImageStorageService.java | 32 ++++++++--------- .../Image/application/MemberImageService.java | 1 + .../wouldyouin/Image/persist/Image.java | 8 ++--- .../wouldyouin/_common/util/FileUtil.java | 4 +-- .../wouldyouin/_common/util/UriUtil.java | 34 +++++++++++++++++++ .../api/dto/AdvertisementResponse.java | 2 +- .../oauth/GoogleRequestService.java | 18 ++-------- .../oauth/KakaoRequestService.java | 34 ++++++++----------- .../api/dto/CurationCardResponse.java | 2 +- .../member/api/dto/MemberResponse.java | 2 +- .../api/dto/relation/EventHostResponse.java | 2 +- .../wouldyouin/member/persist/BaseMember.java | 2 +- 18 files changed, 102 insertions(+), 81 deletions(-) create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/UriUtil.java diff --git a/.gitignore b/.gitignore index f4f1f4ac..c7e998cd 100644 --- a/.gitignore +++ b/.gitignore @@ -37,7 +37,7 @@ out/ .vscode/ ### static images -/src/main/resources/staticimages/ +/src/main/resources/static/images/ ### env file .env \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageResponse.java index 3ecdd1dc..347af557 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageResponse.java @@ -1,10 +1,10 @@ package org.ktc2.cokaen.wouldyouin.Image.api.dto; -import java.nio.file.Paths; import java.time.LocalDateTime; import lombok.Builder; import lombok.Getter; import org.ktc2.cokaen.wouldyouin.Image.persist.Image; +import org.ktc2.cokaen.wouldyouin._common.util.UriUtil; @Getter @Builder @@ -16,10 +16,10 @@ public class ImageResponse { private String extension; private LocalDateTime createdDate; - public static ImageResponse from(Image image, String apiUrlHeader) { + public static ImageResponse from(Image image, String path) { return ImageResponse.builder() .id(image.getId()) - .url(Paths.get(apiUrlHeader, image.getUrl()).toString()) + .url(UriUtil.assembleFullUrl(path, image.getName())) .size(image.getSize()) .extension(image.getExtension()) .createdDate(image.getCreatedDate()) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java index 413d75e4..ad8308a1 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java @@ -41,6 +41,7 @@ protected AdvertisementImage toEntity(ImageRequest imageRequest) { return AdvertisementImage.builder() .name(imageRequest.getUrl()) .size(imageRequest.getSize()) + .extension(imageRequest.getExtension()) .build(); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/CurationImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/CurationImageService.java index 2af86340..5493073d 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/CurationImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/CurationImageService.java @@ -39,6 +39,7 @@ protected CurationImage toEntity(ImageRequest imageRequest) { return CurationImage.builder() .url(imageRequest.getUrl()) .size(imageRequest.getSize()) + .extension(imageRequest.getExtension()) .build(); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/EventImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/EventImageService.java index 821c433e..a2a020a4 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/EventImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/EventImageService.java @@ -39,6 +39,7 @@ protected EventImage toEntity(ImageRequest imageRequest) { return EventImage.builder() .url(imageRequest.getUrl()) .size(imageRequest.getSize()) + .extension(imageRequest.getExtension()) .build(); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java index 435d156c..a056d22d 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java @@ -8,6 +8,7 @@ import org.ktc2.cokaen.wouldyouin.Image.persist.Image; import org.ktc2.cokaen.wouldyouin.Image.persist.ImageRepository; import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; +import org.ktc2.cokaen.wouldyouin._common.util.UriUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -32,20 +33,6 @@ public abstract class ImageService { protected abstract T toEntity(ImageRequest imageRequest); - public T getById(Long id) { - return getImageRepository().findById(id) - .orElseThrow(() -> new EntityNotFoundException(getImageDomain().name() + " 이미지를 찾을 수 없습니다.")); - } - - protected ImageResponse create(ImageRequest imageRequest) { - return ImageResponse.from(getImageRepository().save(toEntity(imageRequest)), apiUrl); - } - - protected void delete(Long id) { - getById(id); - getImageRepository().deleteById(id); - } - @Transactional public List saveImages(List images) { return images.stream() @@ -57,6 +44,20 @@ public List saveImages(List images) { public void deleteImage(Long id) { T image = getById(id); delete(id); - imageStorageService.delete(image.getUrl()); + imageStorageService.delete(getChildPath(), image.getName()); + } + + public T getById(Long id) { + return getImageRepository().findById(id) + .orElseThrow(() -> new EntityNotFoundException(getImageDomain().name() + " 이미지를 찾을 수 없습니다.")); + } + + protected ImageResponse create(ImageRequest imageRequest) { + return ImageResponse.from(getImageRepository().save(toEntity(imageRequest)), UriUtil.assembleFullUrl(apiUrl, getChildPath())); + } + + protected void delete(Long id) { + getById(id); + getImageRepository().deleteById(id); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorageService.java index 80b59bbb..0e685398 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorageService.java @@ -21,34 +21,32 @@ public class ImageStorageService { private String parentPath; private final RestClientUtil client; - public byte[] readFromDirectory(Path path) { - return FileUtil.readFile(Paths.get(parentPath).resolve(path)); + public byte[] readFromDirectory(Path childPath) { + return FileUtil.readFile(Paths.get(parentPath).resolve(childPath)); } - public ImageRequest saveToDirectory(MultipartFile image, String subPath) { + public ImageRequest saveToDirectory(MultipartFile image, String childPath) { String extension = FileUtil.getExtension(image); - String fileName = FileUtil.generateUuidName() + "." + extension; - String relativeFilePath = Paths.get(subPath, fileName).toString(); - Path absoluteFilePath = Paths.get(parentPath, relativeFilePath); - FileUtil.saveFile(image, absoluteFilePath); - return ImageRequest.of(relativeFilePath, image.getSize(), FileUtil.getExtension(image)); + String fileName = FileUtil.createRandomFileName(extension); + FileUtil.saveFile(image, Path.of(parentPath, childPath, fileName)); + return ImageRequest.of(fileName, image.getSize(), extension); } - public ImageRequest saveToDirectory(String imageUrl, String subPath) { + public ImageRequest saveToDirectory(String imageUrl, String childPath) { byte[] response = client.get(byte[].class, imageUrl, new HttpHeaders(), (req, rsp) -> { throw new FailedToUploadImageException("이미지 URL에 대한 요청을 실패하였습니다."); } ); Optional.ofNullable(response).orElseThrow( - () -> new FailedToUploadImageException("응답 본문이 비어있어 이미지를 가져올 수 없습니다.")); + () -> new FailedToUploadImageException("응답 본문이 비어있어 이미지를 가져올 수 없습니다.") + ); String extension = FileUtil.getExtension(imageUrl); - String fileName = FileUtil.generateUuidName() + "." + extension; - String relativeFilePath = Paths.get(subPath, fileName).toString(); - Path absoluteFilePath = Paths.get(parentPath, relativeFilePath); - FileUtil.saveFile(response, absoluteFilePath); - return ImageRequest.of(relativeFilePath, (long) response.length, extension); + String fileName = FileUtil.createRandomFileName(extension); + Path path = Path.of(parentPath, childPath, fileName); + FileUtil.saveFile(response, path); + return ImageRequest.of(fileName, (long) response.length, extension); } - public void delete(String imagePath) { - FileUtil.deleteFile(Paths.get(imagePath)); + public void delete(String childPath, String fileName) { + FileUtil.deleteFile(Path.of(parentPath, childPath, fileName)); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java index c791b08e..ddc40e53 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java @@ -39,6 +39,7 @@ protected MemberImage toEntity(ImageRequest imageRequest) { return MemberImage.builder() .url(imageRequest.getUrl()) .size(imageRequest.getSize()) + .extension(imageRequest.getExtension()) .build(); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/Image.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/Image.java index 436c436d..ccdcbe2e 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/Image.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/Image.java @@ -29,8 +29,8 @@ public abstract class Image { protected Long id; @NotNull - @Column(name = "url") - protected String url; + @Column(name = "name") + protected String name; @Column(name = "size") private Long size; @@ -42,8 +42,8 @@ public abstract class Image { @Column(name = "created_date") private LocalDateTime createdDate; - protected Image(String url, Long size, String extension) { - this.url = url; + protected Image(String name, Long size, String extension) { + this.name = name; this.size = size; this.extension = extension; } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/FileUtil.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/FileUtil.java index d4ff27db..3e14780e 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/FileUtil.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/FileUtil.java @@ -45,8 +45,8 @@ public static void deleteFile(Path path) { } } - public static String generateUuidName() { - return UUID.randomUUID().toString().replace("-", ""); + public static String createRandomFileName(String extension) { + return UUID.randomUUID().toString().replace("-", "") + "." + extension; } public static String getExtension(MultipartFile file) { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/UriUtil.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/UriUtil.java new file mode 100644 index 00000000..75fbd2ab --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/UriUtil.java @@ -0,0 +1,34 @@ +package org.ktc2.cokaen.wouldyouin._common.util; + +import org.springframework.util.MultiValueMap; +import org.springframework.web.util.UriComponentsBuilder; + +public class UriUtil { + + public static String buildUrl(String scheme, String host, String path, MultiValueMap params) { + return UriComponentsBuilder.newInstance() + .scheme(scheme) + .host(host) + .path(path) + .queryParams(params) + .build() + .toString(); + } + + public static String buildUrl(String scheme, String host, String path) { + return UriComponentsBuilder.newInstance() + .scheme(scheme) + .host(host) + .path(path) + .build() + .toString(); + } + + public static String assembleFullUrl(String baseUrl, String... paths) { + String joinedPath = String.join("/", paths); + return UriComponentsBuilder.fromHttpUrl(baseUrl) + .path("/" + joinedPath) + .build() + .toString(); + } +} \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/dto/AdvertisementResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/dto/AdvertisementResponse.java index daf6a21c..4920d9f1 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/dto/AdvertisementResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/dto/AdvertisementResponse.java @@ -17,7 +17,7 @@ public static AdvertisementResponse from(Advertisement advertisement) { return AdvertisementResponse.builder() .id(advertisement.getId()) .title(advertisement.getTitle()) - .imageUrl(advertisement.getAdvertisementImage().getUrl()) + .imageUrl(advertisement.getAdvertisementImage().getName()) .startTime(advertisement.getStartTime()) .endTime(advertisement.getEndTime()) .build(); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/GoogleRequestService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/GoogleRequestService.java index f70095d2..1b378ab2 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/GoogleRequestService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/GoogleRequestService.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.annotation.JsonNaming; import java.util.Objects; import org.ktc2.cokaen.wouldyouin._common.util.RestClientUtil; +import org.ktc2.cokaen.wouldyouin._common.util.UriUtil; import org.ktc2.cokaen.wouldyouin.auth.application.oauth.dto.AccessTokenResponse; import org.ktc2.cokaen.wouldyouin.auth.application.oauth.dto.OauthRequest; import org.ktc2.cokaen.wouldyouin.auth.application.oauth.dto.OauthResourcesResponse; @@ -12,7 +13,6 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; -import org.springframework.web.util.UriComponentsBuilder; @Service public class GoogleRequestService extends OauthRequestService { @@ -44,22 +44,10 @@ public class GoogleRequestService extends OauthRequestService { private final HttpHeaders loginRequestHeaders; public GoogleRequestService(RestClientUtil restClientUtil) { - this.client = restClientUtil; - loginRequestUri = UriComponentsBuilder.newInstance() - .scheme("https") - .host(loginRequestHost) - .path(loginRequestPath) - .build(true) - .toString(); - - accessRequestUri = UriComponentsBuilder.newInstance() - .scheme("https") - .host(accessRequestHost) - .path(accessRequestPath) - .build(true) - .toString(); + loginRequestUri = UriUtil.buildUrl("https", loginRequestHost, loginRequestPath); + accessRequestUri = UriUtil.buildUrl("https", accessRequestHost, accessRequestPath); loginRequestHeaders = new HttpHeaders(); loginRequestHeaders.add(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/KakaoRequestService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/KakaoRequestService.java index 57ae9585..22defe71 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/KakaoRequestService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/KakaoRequestService.java @@ -6,6 +6,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin._common.util.RestClientUtil; +import org.ktc2.cokaen.wouldyouin._common.util.UriUtil; import org.ktc2.cokaen.wouldyouin.auth.application.oauth.dto.AccessTokenResponse; import org.ktc2.cokaen.wouldyouin.auth.application.oauth.dto.OauthRequest; import org.ktc2.cokaen.wouldyouin.auth.application.oauth.dto.OauthResourcesResponse; @@ -14,7 +15,8 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; -import org.springframework.web.util.UriComponentsBuilder; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; @Service public class KakaoRequestService extends OauthRequestService { @@ -53,29 +55,23 @@ protected AccountType getAccountType() { public KakaoRequestService(RestClientUtil restClientUtil) { this.client = restClientUtil; - OauthRequest request = getOauthRequestBase(); - loginRequestUri = UriComponentsBuilder.newInstance() - .scheme("https") - .host(loginRequestHost) - .path(loginRequestPath) - .queryParam("grant_type", request.getGrantType()) - .queryParam("client_id", request.getClientId()) - .queryParam("client_secret", request.getClientSecret()) - .queryParam("code", request.getCode()) - .build(true) - .toString(); - - accessRequestUri = UriComponentsBuilder.newInstance() - .scheme("https") - .host(accessRequestHost) - .path(accessRequestPath) - .build(true) - .toString(); + loginRequestUri = UriUtil.buildUrl("https", loginRequestHost, loginRequestPath, getLoginRequestQueryParams()); + accessRequestUri = UriUtil.buildUrl("https", accessRequestHost, accessRequestPath); loginRequestHeaders = new HttpHeaders(); loginRequestHeaders.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE); } + protected MultiValueMap getLoginRequestQueryParams() { + OauthRequest request = getOauthRequestBase(); + var queries = new LinkedMultiValueMap(); + queries.add("grant_type", request.getGrantType()); + queries.add("client_id", request.getClientId()); + queries.add("client_secret", request.getClientSecret()); + queries.add("code", request.getCode()); + return queries; + } + protected HttpHeaders getAccessRequestHeaders(AccessTokenResponse authenticationResponse) { HttpHeaders accessRequestHeaders = new HttpHeaders(); accessRequestHeaders.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCardResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCardResponse.java index 5dc27bb8..60048c89 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCardResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCardResponse.java @@ -18,7 +18,7 @@ public static CurationCardResponse from(CurationCard curationCard) { .content(curationCard.getContent()) .imageUrls( curationCard.getCurationImages().stream() - .map(CurationImage::getUrl) + .map(CurationImage::getName) .toList() ) .build(); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/MemberResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/MemberResponse.java index 4fe093db..201653e2 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/MemberResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/MemberResponse.java @@ -34,7 +34,7 @@ private static MemberResponseBuilder responseBase(BaseMember baseMember) { .memberId(baseMember.getId()) .nickname(baseMember.getNickname()) .phoneNumber(baseMember.getPhone()) - .profileUrl(baseMember.getProfileImage().getUrl()); + .profileUrl(baseMember.getProfileImage().getName()); } // TODO: normal member임에도 불구, curator 형식이 호출되는 현상 수정필요 diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relation/EventHostResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relation/EventHostResponse.java index fb2d26a8..f3e9d42b 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relation/EventHostResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relation/EventHostResponse.java @@ -22,7 +22,7 @@ public static EventHostResponse from(Host host) { .nickname(host.getNickname()) .email(host.getEmail()) .phone(host.getPhone()) - .profileImageUrl(host.getProfileImage().getUrl()) + .profileImageUrl(host.getProfileImage().getName()) .intro(host.getIntro()) .likes(host.getLikes()) .hashtags(host.getHashTagList()) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java index e2a80e47..9f6d513f 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java @@ -64,6 +64,6 @@ protected BaseMember(AccountType accountType, MemberType memberType, String emai } public String getProfileImageUrl() { - return profileImage.getUrl(); + return profileImage.getName(); } } From 82f31ff3eaa86e60c6983087faea5beac3c16343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=99=8D=EC=8B=9D?= <90020593+Daolove0323@users.noreply.github.com> Date: Mon, 11 Nov 2024 23:04:02 +0900 Subject: [PATCH 14/53] [Weekly/11] Image/delete (#110) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: ImageService delete * refactor: 해시태그 컨버터 사용 --- .../wouldyouin/_common/error/ErrorCode.java | 2 + .../wouldyouin/_common/vo/Location.java | 1 + .../api/dto/CurationCreateRequest.java | 4 +- .../curation/api/dto/CurationEditRequest.java | 2 +- .../curation/api/dto/CurationResponse.java | 2 +- .../wouldyouin/curation/persist/Curation.java | 12 ++-- .../curation/persist/CurationCard.java | 3 +- .../wouldyouin/event/api/EventController.java | 6 +- .../event/api/dto/EventCreateRequest.java | 4 +- .../event/api/dto/LocationFilter.java | 26 +++++++- ...UserLocation.java => LocationRequest.java} | 4 +- .../event/application/EventService.java | 4 +- .../wouldyouin/event/persist/Event.java | 20 +++--- .../wouldyouin/like/api/dto/LikeResponse.java | 2 +- .../member/api/dto/MemberResponse.java | 2 +- .../api/dto/relation/EventHostResponse.java | 2 +- .../CurationCuratorResponse.java | 2 +- .../api/dto/request/edit/HostEditRequest.java | 7 +- .../member/application/CuratorService.java | 66 +++++++++---------- .../member/application/HostService.java | 2 +- .../wouldyouin/member/persist/BaseMember.java | 2 - .../wouldyouin/member/persist/Curator.java | 21 +++++- .../wouldyouin/member/persist/Host.java | 12 +++- .../member/persist/LikeableMember.java | 6 +- .../wouldyouin/member/persist/Member.java | 9 +-- .../reservation/persist/Reservation.java | 10 +-- .../cokaen/wouldyouin/_global/TestData.java | 24 +++---- .../event/EventControllerUnitTest.java | 6 +- .../event/EventServiceUnitTest.java | 4 +- .../wouldyouin/image/ImageControllerTest.java | 46 +++++++------ .../application/HostServiceUnitTest.java | 3 +- 31 files changed, 183 insertions(+), 133 deletions(-) rename src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/{UserLocation.java => LocationRequest.java} (96%) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/ErrorCode.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/ErrorCode.java index 9140ed01..6e5f7737 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/ErrorCode.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/ErrorCode.java @@ -6,6 +6,8 @@ @Getter public enum ErrorCode { + // TODO: status,code, message 수정 + UNEXPECTED(HttpStatus.BAD_REQUEST.value(), "-1", "예상치 못한 오류가 발생했습니다."), ENTITY_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "-10404", "엔티티를 찾을 수 없습니다."), diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/vo/Location.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/vo/Location.java index 240d31d5..459f2f7b 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/vo/Location.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/vo/Location.java @@ -14,4 +14,5 @@ public class Location { Double longitude; Double latitude; + String detailAddress; } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCreateRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCreateRequest.java index 4e584fa6..5000fcec 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCreateRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCreateRequest.java @@ -30,7 +30,7 @@ public class CurationCreateRequest { @NotNull(message = "지역은 필수입니다.") private Area area; - private List hashTag; + private List hashTags; private List eventIds; @@ -49,7 +49,7 @@ public Curation toEntity(Curator curator, List curationCards, List .content(this.content) .curationCards(curationCards) .area(this.area) - .hashTag(this.hashTag) + .hashTags(this.hashTags) .events(events) .build(); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationEditRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationEditRequest.java index 2a691007..1d4051d5 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationEditRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationEditRequest.java @@ -26,7 +26,7 @@ public class CurationEditRequest { @NotNull(message = "지역은 필수입니다.") private Area area; - private List hashTag; + private List hashTags; private List eventIds; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java index 7bd2e697..98675d27 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java @@ -33,7 +33,7 @@ public static CurationResponse from(Curation curation) { .curationCards(curation.getCurationCards().stream() .map(CurationCardResponse::from).toList()) .area(curation.getArea()) - .hashTag(curation.getHashTag()) + .hashTag(curation.getHashTags()) .eventsInfo(curation.getEvents().stream() .map(CurationEventResponse::from).toList()) .createdTime(curation.getCreatedDate()) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java index 3eb150e1..216ca700 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java @@ -69,7 +69,7 @@ public class Curation { @Column(name = "hashtag") @Convert(converter = HashtagConverter.class) - private List hashTag = new ArrayList<>(); + private List hashTags = new ArrayList<>(); @ManyToMany(fetch = FetchType.LAZY) @JoinTable( @@ -88,22 +88,22 @@ public class Curation { private LocalDateTime modifiedDate; @Builder - public Curation(Curator curator, String title, String content, List curationCards, Area area, List hashTag, + public Curation(Curator curator, String title, String content, List curationCards, Area area, List hashTags, List events) { this.curator = curator; this.title = title; this.content = content; - this.curationCards = curationCards; + Optional.ofNullable(curationCards).ifPresent(this::setCurationCards); this.area = area; - this.hashTag = hashTag; - this.events = events; + Optional.ofNullable(hashTags).ifPresent(this::setHashTags); + Optional.ofNullable(events).ifPresent(this::setEvents); } public void updateFrom(CurationEditRequest curationEditRequest, List curationCards, List events) { Optional.ofNullable(curationEditRequest.getTitle()).ifPresent(this::setTitle); Optional.ofNullable(curationEditRequest.getContent()).ifPresent(this::setContent); Optional.ofNullable(curationEditRequest.getArea()).ifPresent(this::setArea); - Optional.ofNullable(curationEditRequest.getHashTag()).ifPresent(this::setHashTag); + Optional.ofNullable(curationEditRequest.getHashTags()).ifPresent(this::setHashTags); Optional.ofNullable(curationCards).ifPresent(this::setCurationCards); Optional.ofNullable(events).ifPresent(this::setEvents); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCard.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCard.java index 56403eee..127bfad5 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCard.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCard.java @@ -11,6 +11,7 @@ import jakarta.persistence.OneToMany; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -48,6 +49,6 @@ public CurationCard(String subtitle, String content, Curation curation, List> getEventsByFilterOrderByDistanceAsc( - @ModelAttribute LocationFilter locationFilter, - @Valid @ModelAttribute UserLocation currentLocation, + @Valid @ModelAttribute LocationFilter locationFilter, + @Valid @ModelAttribute LocationRequest currentLocation, @RequestParam(defaultValue = ParamDefaults.TITLE) String title, @RequestParam(defaultValue = ParamDefaults.CATEGORY) Category category, @RequestParam(defaultValue = ParamDefaults.AREA) Area area, diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java index e276a6e2..aec20b45 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java @@ -8,6 +8,7 @@ import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; import lombok.Builder; import lombok.Getter; @@ -53,6 +54,7 @@ public class EventCreateRequest { @NotNull(message = "카테고리는 필수입니다.") private Category category; + // TODO : 이미지 not null 고민, 큐레이션도! private List imageIds; @AssertTrue(message = "종료 시간은 시작 시간 이후여야 합니다.") @@ -65,7 +67,7 @@ public boolean isEndTimeAfterStartTime() { @AssertTrue(message = "이미지는 최대 5개까지 등록할 수 있습니다.") public boolean isImageSizeValid() { - return imageIds == null || imageIds.size() <= 5; + return imageIds.size() <= 5; } public Event toEntity(Host host, List images) { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationFilter.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationFilter.java index fa1e923b..4f97fbc5 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationFilter.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationFilter.java @@ -1,5 +1,8 @@ package org.ktc2.cokaen.wouldyouin.event.api.dto; +import jakarta.validation.constraints.AssertTrue; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; @@ -11,8 +14,29 @@ @AllArgsConstructor public class LocationFilter { + @Min(value = -90, message = "시작 위도는 -90 이상이어야 합니다.") + @Max(value = 90, message = "시작 위도는 90 이하여야 합니다.") private Double startLatitude = -90.0; + + @Min(value = -180, message = "시작 경도는 -180 이상이어야 합니다.") + @Max(value = 180, message = "시작 경도는 180 이하여야 합니다.") private Double startLongitude = -180.0; + + @Min(value = -90, message = "끝 위도는 -90 이상이어야 합니다.") + @Max(value = 90, message = "끝 위도는 90 이하여야 합니다.") private Double endLatitude = 90.0; + + @Min(value = -180, message = "끝 경도는 -180 이상이어야 합니다.") + @Max(value = 180, message = "끝 경도는 180 이하여야 합니다.") private Double endLongitude = 180.0; -} + + @AssertTrue(message = "시작 위도는 끝 위도보다 작아야 합니다.") + public boolean isStartLatitudeLessThanEndLatitude() { + return startLatitude <= endLatitude; + } + + @AssertTrue(message = "시작 경도는 끝 경도보다 작아야 합니다.") + public boolean isStartLongitudeLessThanEndLongitude() { + return startLongitude <= endLongitude; + } +} \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/UserLocation.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationRequest.java similarity index 96% rename from src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/UserLocation.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationRequest.java index be0efccd..c6605b2e 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/UserLocation.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationRequest.java @@ -12,7 +12,7 @@ @Setter @AllArgsConstructor @NoArgsConstructor -public class UserLocation { +public class LocationRequest { @NotNull(message = "위도 값은 필수입니다.") @Min(value = -90, message = "위도는 -90 이상이어야 합니다.") @@ -23,4 +23,4 @@ public class UserLocation { @Min(value = -180, message = "경도는 -180 이상이어야 합니다.") @Max(value = 180, message = "경도는 180 이하여야 합니다.") private Double longitude; -} +} \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java index eeea3bb2..a5c6c976 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java @@ -9,7 +9,7 @@ import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; -import org.ktc2.cokaen.wouldyouin.event.api.dto.UserLocation; +import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationFilter; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; @@ -43,7 +43,7 @@ public EventResponse getById(Long id) { } @Transactional(readOnly = true) - public EventSliceResponse getAllByFilterOrderByDistanceAsc(LocationFilter location, UserLocation currentLocation, String title, + public EventSliceResponse getAllByFilterOrderByDistanceAsc(LocationFilter location, LocationRequest currentLocation, String title, Category category, Area area, Pageable pageable, Long beforeLastId) { Slice events = eventRepository.findAllByFilterOrderByDistance( location.getStartLatitude(), location.getStartLongitude(), location.getEndLatitude(), diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java index d715b313..309e37c5 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java @@ -124,16 +124,16 @@ protected Event(String title, String content, Host host, Area area, Location loc // Todo: oneToMany 연관관계에서 모든 null 처리 public void updateFrom(EventEditRequest eventEditRequest, List images) { - this.title = eventEditRequest.getTitle(); - this.content = eventEditRequest.getContent(); - this.area = eventEditRequest.getArea(); - this.location = eventEditRequest.getLocation(); - this.startTime = eventEditRequest.getStartTime(); - this.endTime = eventEditRequest.getEndTime(); - this.price = eventEditRequest.getPrice(); - this.totalSeat = eventEditRequest.getTotalSeat(); - this.category = eventEditRequest.getCategory(); - this.images = images; + Optional.ofNullable(eventEditRequest.getTitle()).ifPresent(this::setTitle); + Optional.ofNullable(eventEditRequest.getContent()).ifPresent(this::setContent); + Optional.ofNullable(eventEditRequest.getArea()).ifPresent(this::setArea); + Optional.ofNullable(eventEditRequest.getLocation()).ifPresent(this::setLocation); + Optional.ofNullable(eventEditRequest.getStartTime()).ifPresent(this::setStartTime); + Optional.ofNullable(eventEditRequest.getEndTime()).ifPresent(this::setEndTime); + Optional.ofNullable(eventEditRequest.getPrice()).ifPresent(this::setPrice); + Optional.ofNullable(eventEditRequest.getTotalSeat()).ifPresent(this::setTotalSeat); + Optional.ofNullable(eventEditRequest.getCategory()).ifPresent(this::setCategory); + Optional.ofNullable(images).ifPresent(this::setImages); } public void decreaseLeftSeat(Integer count) { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/dto/LikeResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/dto/LikeResponse.java index f21ac18d..5530179d 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/dto/LikeResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/dto/LikeResponse.java @@ -23,7 +23,7 @@ public static LikeResponse from(LikeableMember member) { .memberId(member.getId()) .nickname(member.getNickname()) .intro(member.getIntro()) - .hashtags(member.getHashTagList()) + .hashtags(member.getHashtags()) .profileImageUrl(member.getProfileImageUrl()) .build(); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/MemberResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/MemberResponse.java index 201653e2..5ba6a985 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/MemberResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/MemberResponse.java @@ -51,7 +51,7 @@ public static MemberResponse from(final Host host) { .memberType(host.getMemberType()) .intro(host.getIntro()) .likes(host.getLikes()) - .hashtag(host.getHashTagList()) + .hashtag(host.getHashtags()) .build(); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relation/EventHostResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relation/EventHostResponse.java index f3e9d42b..8d5ffb3f 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relation/EventHostResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relation/EventHostResponse.java @@ -25,7 +25,7 @@ public static EventHostResponse from(Host host) { .profileImageUrl(host.getProfileImage().getName()) .intro(host.getIntro()) .likes(host.getLikes()) - .hashtags(host.getHashTagList()) + .hashtags(host.getHashtags()) .build(); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/CurationCuratorResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/CurationCuratorResponse.java index ed5e85de..123d0eee 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/CurationCuratorResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/CurationCuratorResponse.java @@ -26,7 +26,7 @@ public static CurationCuratorResponse from(Curator curator) { .profileImageUrl(curator.getProfileImageUrl()) .intro(curator.getIntro()) .likes(curator.getLikes()) - .hashtags(curator.getHashTagList()) + .hashtags(curator.getHashtags()) .build(); } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/HostEditRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/HostEditRequest.java index 2e816e36..f9228913 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/HostEditRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/HostEditRequest.java @@ -2,6 +2,7 @@ import jakarta.annotation.Nullable; +import java.util.List; import lombok.Builder; import lombok.Getter; @@ -9,13 +10,13 @@ public class HostEditRequest extends MemberEditRequestBase { @Nullable private final String intro; - @Nullable private final String hashtag; + @Nullable private final List hashtags; @Builder public HostEditRequest(@Nullable String nickname, @Nullable String phoneNumber, @Nullable Long profileImageId, - @Nullable String intro, @Nullable String hashtag) { + @Nullable String intro, @Nullable List hashtags) { super(nickname, phoneNumber, profileImageId); this.intro = intro; - this.hashtag = hashtag; + this.hashtags = hashtags; } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java index da78d2c7..0332e871 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java @@ -1,10 +1,11 @@ package org.ktc2.cokaen.wouldyouin.member.application; -import java.util.Optional; import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin.Image.application.MemberImageService; -import org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit.CuratorEditRequest; +import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; +import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; import org.ktc2.cokaen.wouldyouin.member.api.dto.MemberResponse; +import org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit.CuratorEditRequest; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMemberRepository; import org.ktc2.cokaen.wouldyouin.member.persist.Curator; import org.ktc2.cokaen.wouldyouin.member.persist.CuratorRepository; @@ -23,10 +24,32 @@ public class CuratorService implements MemberServiceCommonBehavior, LikeableMemb private final BaseMemberRepository baseMemberRepository; private final MemberImageService memberImageService; + @Override + public LikeableMemberService getLikeableMemberService() { + return this; + } + + @Override + @Transactional(readOnly = true) + public MemberResponse getMemberResponseById(Long id) { + return MemberResponse.from(getByIdOrThrow(id)); + } + + @Override + public MemberType getTargetMemberType() { + return MemberType.curator; + } + + @Transactional(readOnly = true) + public Curator getByIdOrThrow(Long id) { + return curatorRepository.findById(id). + orElseThrow(() -> new EntityNotFoundException("해당하는 큐레이터 정보를 찾을 수 없습니다.")); + } + @Transactional public MemberResponse createCurator(Long normalMemberId) { - //TODO: 커스텀 예외 필요 - Member member = memberRepository.findById(normalMemberId).orElseThrow(RuntimeException::new); + Member member = memberRepository.findById(normalMemberId) + .orElseThrow(() -> new EntityNotFoundException("해당하는 멤버 정보를 찾을 수 없습니다.")); // 일반 멤버 정보로 큐레이터 생성 후, 기존 일반멤버 및 BaseMember 정보는 데이터베이스에서 제거 Curator curator = Curator.curatorBuilder() @@ -52,18 +75,13 @@ public MemberResponse createCurator(Long normalMemberId) { return MemberResponse.from(curator); } + // TODO : 반대방향 연관관계 설정 setter? @Transactional public MemberResponse updateCurator(Long curatorId, CuratorEditRequest request) { Curator curator = getByIdOrThrow(curatorId); - - Optional.ofNullable(request.getPhoneNumber()).ifPresent(curator::setPhone); - Optional.ofNullable(request.getNickname()).ifPresent(curator::setNickname); - Optional.ofNullable(request.getArea()).ifPresent(curator::setArea); - Optional.ofNullable(request.getIntro()).ifPresent(curator::setIntro); - Optional.ofNullable(request.getProfileImageId()) - .map(memberImageService::getById) - .ifPresent(curator::setProfileImage); - + MemberImage image = memberImageService.getById(request.getProfileImageId()); + curator.updateFrom(request, image); + image.setBaseMember(curator); return MemberResponse.from(curator); } @@ -72,26 +90,4 @@ public MemberResponse updateCurator(Long curatorId, CuratorEditRequest request) public void deleteById(Long id) { curatorRepository.delete(getByIdOrThrow(id)); } - - @Override - @Transactional(readOnly = true) - public MemberResponse getMemberResponseById(Long id) { - return MemberResponse.from(getByIdOrThrow(id)); - } - - @Transactional(readOnly = true) - public Curator getByIdOrThrow(Long id) { - //TODO: 커스텀 예외 필요 - return curatorRepository.findById(id).orElseThrow(RuntimeException::new); - } - - @Override - public MemberType getTargetMemberType() { - return MemberType.curator; - } - - @Override - public LikeableMemberService getLikeableMemberService() { - return this; - } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java index abc8c8f8..1182a9ff 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java @@ -39,7 +39,7 @@ public MemberResponse updateHost(Long hostId, HostEditRequest request) { Optional.ofNullable(request.getPhoneNumber()).ifPresent(host::setPhone); Optional.ofNullable(request.getProfileImageId()).map(memberImageService::getById).ifPresent(host::setProfileImage); Optional.ofNullable(request.getIntro()).ifPresent(host::setIntro); - Optional.ofNullable(request.getHashtag()).ifPresent(host::setHashtag); + Optional.ofNullable(request.getHashtags()).ifPresent(host::setHashtags); return MemberResponse.from(host); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java index 9f6d513f..e45dc1c8 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java @@ -11,7 +11,6 @@ import jakarta.persistence.Inheritance; import jakarta.persistence.InheritanceType; import jakarta.persistence.OneToOne; -import jakarta.persistence.PrimaryKeyJoinColumn; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -49,7 +48,6 @@ public abstract class BaseMember { @Column(nullable = false) private String phone; - @PrimaryKeyJoinColumn @OneToOne(mappedBy = "baseMember") private MemberImage profileImage; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java index 25431476..2c74d6bf 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java @@ -1,19 +1,25 @@ package org.ktc2.cokaen.wouldyouin.member.persist; import jakarta.persistence.Column; +import jakarta.persistence.Convert; import jakarta.persistence.DiscriminatorValue; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; import jakarta.persistence.OneToMany; +import java.util.ArrayList; import java.util.List; +import java.util.Optional; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.experimental.SuperBuilder; import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; +import org.ktc2.cokaen.wouldyouin._common.converter.HashtagConverter; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; +import org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit.CuratorEditRequest; @Getter @Setter @@ -29,10 +35,11 @@ public class Curator extends Member implements LikeableMember { private Integer likes; @Column(nullable = false) - private String hashtag; + @Convert(converter = HashtagConverter.class) + private List hashtags; @OneToMany(mappedBy = "curator", fetch = FetchType.LAZY) - private List curations; + private List curations = new ArrayList<>(); @Builder(builderMethodName = "curatorBuilder") public Curator(AccountType accountType, String email, String nickname, String phone, MemberImage profileImage, Area area, String gender, @@ -40,6 +47,14 @@ public Curator(AccountType accountType, String email, String nickname, String ph super(accountType, MemberType.curator, email, nickname, phone, profileImage, area, gender, socialId); this.intro = ""; this.likes = 0; - this.hashtag = ""; + hashtags = new ArrayList<>(); + } + + public void updateFrom(CuratorEditRequest request, MemberImage image) { + Optional.ofNullable(request.getPhoneNumber()).ifPresent(this::setPhone); + Optional.ofNullable(request.getNickname()).ifPresent(this::setNickname); + Optional.ofNullable(request.getArea()).ifPresent(this::setArea); + Optional.ofNullable(request.getIntro()).ifPresent(this::setIntro); + Optional.ofNullable(image).ifPresent(this::setProfileImage); } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java index 1ef6efee..14d9c80b 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java @@ -1,17 +1,22 @@ package org.ktc2.cokaen.wouldyouin.member.persist; import jakarta.persistence.Column; +import jakarta.persistence.Convert; import jakarta.persistence.DiscriminatorValue; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; import jakarta.persistence.OneToMany; +import java.util.ArrayList; import java.util.List; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.experimental.Helper; +import lombok.experimental.SuperBuilder; import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; +import org.ktc2.cokaen.wouldyouin._common.converter.HashtagConverter; import org.ktc2.cokaen.wouldyouin.event.persist.Event; @Getter @@ -31,10 +36,11 @@ public class Host extends BaseMember implements LikeableMember { private Integer likes; @Column(nullable = false) - private String hashtag; + @Convert(converter = HashtagConverter.class) + private List hashtags; @OneToMany(mappedBy = "host", fetch = FetchType.LAZY) - private List events; + private List events = new ArrayList<>(); @Builder protected Host(String email, String nickname, String phone, String hashedPassword, MemberImage profileImage) { @@ -42,6 +48,6 @@ protected Host(String email, String nickname, String phone, String hashedPasswor this.hashedPassword = hashedPassword; this.intro = ""; this.likes = 0; - this.hashtag = ""; + this.hashtags = new ArrayList<>(); } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/LikeableMember.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/LikeableMember.java index 5fdc4608..9b94d3df 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/LikeableMember.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/LikeableMember.java @@ -17,7 +17,7 @@ public interface LikeableMember { void setLikes(Integer likes); - String getHashtag(); + List getHashtags(); default void increaseLikes() { setLikes(getLikes() + 1); @@ -27,10 +27,6 @@ default void decreaseLikes() { setLikes(getLikes() - 1); } - default List getHashTagList() { - return Arrays.stream(getHashtag().split("#")).toList(); - } - static List getLikeableMemberTypes() { return List.of(MemberType.host, MemberType.curator); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java index b5f4d46a..5607afcc 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java @@ -5,6 +5,7 @@ import jakarta.persistence.Entity; import jakarta.persistence.FetchType; import jakarta.persistence.OneToMany; +import java.util.ArrayList; import java.util.List; import lombok.AccessLevel; import lombok.Builder; @@ -40,16 +41,16 @@ public class Member extends BaseMember { private String refreshToken; @OneToMany(mappedBy = "member", fetch = FetchType.LAZY) - private List curatorLikes; + private List curatorLikes = new ArrayList<>(); @OneToMany(mappedBy = "member", fetch = FetchType.LAZY) - private List hostLikes; + private List hostLikes = new ArrayList<>(); @OneToMany(mappedBy = "member", fetch = FetchType.LAZY) - private List reservations; + private List reservations = new ArrayList<>(); @OneToMany(mappedBy = "member", fetch = FetchType.LAZY) - private List reviews; + private List reviews = new ArrayList<>(); // for Curator protected Member(AccountType accountType, MemberType memberType, String email, String nickname, String phone, MemberImage profileImage, Area area, String gender, String socialId) { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/Reservation.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/Reservation.java index 14d3bbf6..e72ea3d6 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/Reservation.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/Reservation.java @@ -1,6 +1,5 @@ package org.ktc2.cokaen.wouldyouin.reservation.persist; -import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.EntityListeners; @@ -13,6 +12,7 @@ import jakarta.persistence.OneToOne; import jakarta.validation.constraints.NotNull; import java.time.LocalDateTime; +import java.util.Optional; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -58,9 +58,9 @@ public class Reservation { @Builder protected Reservation(Member member, Event event, Integer price, Integer quantity) { - this.member = member; - this.event = event; - this.price = price; - this.quantity = quantity; + Optional.ofNullable(member).ifPresent(this::setMember); + Optional.ofNullable(event).ifPresent(this::setEvent); + Optional.ofNullable(price).ifPresent(this::setPrice); + Optional.ofNullable(quantity).ifPresent(this::setQuantity); } } \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java index fc50424b..15e07439 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java @@ -109,11 +109,11 @@ public static ImageResponse createValidImageResponse2() { } public static MockMultipartFile createValidMultipartFile1() { - return new MockMultipartFile("image1", "image1.jpg", MediaType.IMAGE_JPEG_VALUE, "imageData1".getBytes()); + return new MockMultipartFile("images", "image1.jpg", MediaType.IMAGE_JPEG_VALUE, "imageData1".getBytes()); } public static MockMultipartFile createValidMultipartFile2() { - return new MockMultipartFile("image2", "image2.png", MediaType.IMAGE_JPEG_VALUE, "imageData2".getBytes()); + return new MockMultipartFile("images", "image2.png", MediaType.IMAGE_JPEG_VALUE, "imageData2".getBytes()); } } @@ -156,7 +156,7 @@ public static Curator createValidCurator() { .build(); ReflectionTestUtils.setField(ret, "Id", validCuratorId); ReflectionTestUtils.setField(ret, "intro", "큐레이터 자기소개입니다."); - ReflectionTestUtils.setField(ret, "hashtag", "#큐레이터#해시태그#입니다"); + ReflectionTestUtils.setField(ret, "hashtags", List.of("#큐레이터", "#해시태그", "#입니다")); ReflectionTestUtils.setField(memberImage, "baseMember", ret); return ret; } @@ -172,7 +172,7 @@ public static Host createValidHost() { .build(); ReflectionTestUtils.setField(ret, "Id", validHostId); ReflectionTestUtils.setField(ret, "intro", "주최자 자기소개입니다."); - ReflectionTestUtils.setField(ret, "hashtag", "#주최자#해시태그#입니다"); + ReflectionTestUtils.setField(ret, "hashtags", List.of("#주최자", "#해시태그", "#입니다")); ReflectionTestUtils.setField(memberImage, "baseMember", ret); return ret; } @@ -212,7 +212,7 @@ public static Event createValidEvent() { .title("title") .content("content") .area(Area.전체) - .location(new Location(132.0, 43.0)) + .location(new Location(132.0, 43.0, "광주 북구 용봉로77")) .startTime(LocalDateTime.now()) .endTime(LocalDateTime.now()) .price(10000) @@ -228,7 +228,7 @@ public static EventCreateRequest createValidEventCreateRequest() { .title("title") .content("content 조홍식씨 최소글자 20자라고 해놓고 안 지켰어요.") .area(Area.전체) - .location(new Location(132.0, 43.0)) + .location(new Location(132.0, 43.0, "광주 북구 용봉로 77")) .startTime(LocalDateTime.of(2025, 10, 1, 9, 0)) .endTime(LocalDateTime.of(2025, 10, 1, 10, 0)) .price(10000) @@ -243,7 +243,7 @@ public static EventEditRequest createValidEventEditRequest() { .title("modifiedTitle") .content("modifiedContent 조홍식씨 최소글자 20자라고 해놓고 안 지켰어요. ") .area(Area.광주) - .location(new Location(232.0, 143.0)) + .location(new Location(232.0, 143.0, "광주 북구 용봉로 77")) .startTime(LocalDateTime.of(2024, 10, 2, 17, 0)) .endTime(LocalDateTime.of(2024, 10, 2, 18, 0)) .price(20000) @@ -257,7 +257,7 @@ public static CurationEventResponse createValidCurationEventResponse() { return CurationEventResponse.builder() .id(1L) .title("title") - .location(new Location(132.0, 43.0)) + .location(new Location(132.0, 43.0, "광주 북구 용봉로 77")) .thumbnailImageUrl("thumbnailImageUrl") .hostProfileImageUrl("hostProfileImageUrl") .hostNickname("nick_curator_12") @@ -321,7 +321,7 @@ public static Curation createValidCuration() { .content("content") .curationCards(List.of()) .area(Area.전체) - .hashTag(List.of("#해시태그1", "#해시태그2")) + .hashTags(List.of("#해시태그1", "#해시태그2")) .events(List.of(EventDomain.createValidEvent())) .build(); } @@ -364,7 +364,7 @@ public static CurationCreateRequest createValidCurationCreateRequest() { .content("큐레이션 카드 내용1 입니다. 큐레이션 카드의 내용은 최소 20자 최대 1000자 입니다.") .curationCards(List.of(createValidCurationCardRequest1())) .area(Area.광주) - .hashTag(List.of("#광주밴드", "#전남대")) + .hashTags(List.of("#광주밴드", "#전남대")) .eventIds(List.of(1L, 2L)) .build(); } @@ -375,7 +375,7 @@ public static CurationEditRequest createValidCurationEditRequest() { .content("큐레이션 내용2 입니다.") .curationCards(List.of(createValidCurationCardRequest2())) .area(Area.서울) - .hashTag(List.of("#서울밴드", "#서울대")) + .hashTags(List.of("#서울밴드", "#서울대")) .eventIds(List.of(3L, 4L)) .build(); } @@ -389,7 +389,7 @@ public static CurationCuratorResponse createCurationCuratorResponse() { .profileImageUrl(curator.getProfileImageUrl()) .intro(curator.getIntro()) .likes(curator.getLikes()) - .hashtags(curator.getHashTagList()) + .hashtags(curator.getHashtags()) .build(); } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java index 590cdbfb..b19b6299 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java @@ -32,7 +32,7 @@ import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventSliceResponse; -import org.ktc2.cokaen.wouldyouin.event.api.dto.UserLocation; +import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationRequest; import org.ktc2.cokaen.wouldyouin.event.application.EventService; import org.ktc2.cokaen.wouldyouin._global.TestData.EventDomain; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost; @@ -90,7 +90,7 @@ public void setup() throws Exception { void getEventsByFilterOrderByDistanceAsc() throws Exception { // given LocationFilter locationFilter = new LocationFilter(0.0, 0.0, 10.0, 10.0); - UserLocation currentLocation = new UserLocation(3.0, 2.0); + LocationRequest currentLocation = new LocationRequest(3.0, 2.0); String title = "testTitle"; Category category = Category.공예; Area area = Area.광주; @@ -129,7 +129,7 @@ void getEventsByFilterOrderByDistanceAsc() throws Exception { // then then(eventService).should(times(1)).getAllByFilterOrderByDistanceAsc( any(LocationFilter.class), - any(UserLocation.class), + any(LocationRequest.class), eq(title), eq(category), eq(area), diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java index f36ac5a3..1590e5ec 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java @@ -22,7 +22,7 @@ import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationFilter; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; -import org.ktc2.cokaen.wouldyouin.event.api.dto.UserLocation; +import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationRequest; import org.ktc2.cokaen.wouldyouin.event.application.EventService; import org.ktc2.cokaen.wouldyouin.event.persist.Event; import org.ktc2.cokaen.wouldyouin.event.persist.EventRepository; @@ -60,7 +60,7 @@ void setUp() { void getAllByFilterOrderByDistanceAsc() { // given LocationFilter location = new LocationFilter(); - UserLocation currentLocation = new UserLocation(3.0, 2.0); + LocationRequest currentLocation = new LocationRequest(3.0, 2.0); String title = "testTitle"; Category category = Category.공예; Area area = Area.광주; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java index 7ef5f13b..c41c2a58 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java @@ -1,27 +1,35 @@ package org.ktc2.cokaen.wouldyouin.image; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.times; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import java.nio.file.Paths; +import java.util.List; import java.util.UUID; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.ktc2.cokaen.wouldyouin.Image.api.ImageController; +import org.ktc2.cokaen.wouldyouin.Image.api.ImageDomain; import org.ktc2.cokaen.wouldyouin.Image.application.CurationImageService; import org.ktc2.cokaen.wouldyouin.Image.application.ImageServiceFactory; import org.ktc2.cokaen.wouldyouin.Image.application.ImageStorageService; +import org.ktc2.cokaen.wouldyouin._global.TestData.ImageData; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember; import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.mock.web.MockMultipartFile; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; @@ -84,28 +92,26 @@ void getImage() throws Exception { @WithMockMember void uploadImages() throws Exception { // // given -// MockMultipartFile image1 = ImageData.createValidMultipartFile1(); -// MockMultipartFile image2 = ImageData.createValidMultipartFile2(); -// given((CurationImageService) imageServiceFactory.getImageService(ImageDomain.CURATION)).willReturn(curationImageService); -// given(curationImageService.saveImages(List.of(image1, image2))) -// .willReturn(List.of(ImageData.createValidImageResponse1(), ImageData.createValidImageResponse2())); -// -//// // when -// mockMvc.perform(multipart("/api/images") -// .file(ImageData.createValidMultipartFile1()) -// .file(ImageData.createValidMultipartFile2()) -// .contentType(MediaType.MULTIPART_FORM_DATA) -// .param("type", ImageDomain.CURATION.name()) -// .with(csrf())) -// .andDo(print()) -// .andExpect(status().isOk()); -// .andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON)) // 응답 콘텐츠 타입 확인 -// .andExpect(MockMvcResultMatchers.jsonPath("$.data[0].imageName").value("image1.png")) // 첫 번째 이미지 이름 확인 -// .andExpect(MockMvcResultMatchers.jsonPath("$.data[1].imageName").value("image2.jpg")); // 두 번째 이미지 이름 확인 + MockMultipartFile image1 = ImageData.createValidMultipartFile1(); + MockMultipartFile image2 = ImageData.createValidMultipartFile2(); + given((CurationImageService) imageServiceFactory.getImageService(ImageDomain.CURATION)).willReturn(curationImageService); + given(curationImageService.saveImages(List.of(image1, image2))) + .willReturn(List.of(ImageData.createValidImageResponse1(), ImageData.createValidImageResponse2())); + +// // when + mockMvc.perform(multipart("/api/images?type=CURATION") + .file(ImageData.createValidMultipartFile1()) + .file(ImageData.createValidMultipartFile2()) + .contentType(MediaType.MULTIPART_FORM_DATA) + .param("type", ImageDomain.CURATION.name()) + .with(csrf())) + .andDo(print()) + .andExpect(status().isOk()); + // ArgumentCaptor captor = ArgumentCaptor.forClass(CurationCreateRequest.class); // CurationCreateRequest request = CurationDomain.createValidCurationCreateRequest(); -// -// // when + + // when // mockMvc.perform(post("/api/curations") // .with(csrf()) // .contentType(MediaType.APPLICATION_JSON) diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java index 3d3c7921..25c13d4c 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java @@ -7,6 +7,7 @@ import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.times; +import java.util.List; import java.util.Optional; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -94,7 +95,7 @@ void updateHost() { .phoneNumber(TestUtil.getOrNull("010-1010-8888")) .profileImageId(TestUtil.getOrNull(newProfileImageId)) .intro(TestUtil.getOrNull("new intro")) - .hashtag(TestUtil.getOrNull("#new#hashtag")) + .hashtags(TestUtil.getOrNull(List.of("#new", "#hashtag"))) .build(); given(hostRepository.findById(validHost.getId())).willReturn(Optional.of(validHost)); From 7795e24a68ecac9b5b254436b37316f08c150841 Mon Sep 17 00:00:00 2001 From: Jangan Lee Date: Tue, 12 Nov 2024 13:26:19 +0900 Subject: [PATCH 15/53] =?UTF-8?q?[Weekly/11/Feature/MySQL]=20MySQL=20?= =?UTF-8?q?=EC=97=B0=EB=8F=99,=20=EB=8F=84=EC=BB=A4=20=EB=B3=BC=EB=A5=A8?= =?UTF-8?q?=20=EB=B0=8F=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=A0=80=EC=9E=A5?= =?UTF-8?q?=20=EC=97=B0=EB=8F=99=20(#111)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Weekly/10/Test/CurationController] curationControllerUnitTest 2 (#90) * feat: MySQL 도입 및 배포 관련 설정 * feat: 서버 도메인 이름 변수화, 이미지 저장소와 도커 볼륨 연동 --- .github/workflows/gradle.yml | 20 ++++--- build.gradle | 2 - src/main/resources/application-create.yml | 1 - src/main/resources/application-deploy.yml | 6 +- src/main/resources/application-dev.yml | 3 +- src/main/resources/application.yml | 33 +++++------ .../application/CuratorServiceUnitTest.java | 56 +++++++++---------- 7 files changed, 57 insertions(+), 64 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index c4dddfa0..158c6808 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -3,21 +3,22 @@ name: CI/CD Github Action on: push: branches: [ "Master", "Weekly/*" ] - pull_request_target: - branches: [ "Master", "Weekly/*" ] permissions: contents: read env: + DATASOURCE_URL : ${{ secrets.ENV_DATASOURCE_URL }} + DATASOURCE_USERNAME : ${{ secrets.ENV_DATASOURCE_USERNAME }} + DATASOURCE_PASSWORD : ${{ secrets.ENV_DATASOURCE_PASSWORD }} GOOGLE_CLIENT_ID : ${{ secrets.ENV_GOOGLE_CLIENT_ID }} GOOGLE_CLIENT_SECRET: ${{ secrets.ENV_GOOGLE_CLIENT_SECRET }} - GOOGLE_REDIRECT_URI : ${{ secrets.ENV_GOOGLE_REDIRECT_URI }} + IMAGE_UPLOAD_PATH : ${{ secrets.ENV_IMAGE_UPLOAD_PATH }} JWT_SECRET : ${{ secrets.ENV_JWT_SECRET }} KAKAO_CLIENT_ID : ${{ secrets.ENV_KAKAO_CLIENT_ID }} KAKAO_CLIENT_SECRET : ${{ secrets.ENV_KAKAO_CLIENT_SECRET }} - KAKAO_REDIRECT_URI : ${{ secrets.ENV_KAKAO_REDIRECT_URI }} KAKAOPAY_SECRET_KEY : ${{ secrets.ENV_KAKAOPAY_SECRET_KEY }} + SERVER_DOMAIN_NAME : ${{ secrets.ENV_SERVER_DOMAIN_NAME }} jobs: ## 1단계: 프로젝트 빌드 @@ -137,14 +138,17 @@ jobs: key: ${{ secrets.SSH_PRIVATE_KEY }} port: ${{ secrets.SSH_PORT }} script: | - echo "GOOGLE_CLIENT_ID=${{ secrets.ENV_GOOGLE_CLIENT_ID }}" > ~/.env + echo "DATASOURCE_URL=${{ secrets.ENV_DATASOURCE_URL }}" > ~/.env + echo "DATASOURCE_USERNAME=${{ secrets.ENV_DATASOURCE_USERNAME }}" >> ~/.env + echo "DATASOURCE_PASSWORD=${{ secrets.ENV_DATASOURCE_PASSWORD }}" >> ~/.env + echo "GOOGLE_CLIENT_ID=${{ secrets.ENV_GOOGLE_CLIENT_ID }}" >> ~/.env echo "GOOGLE_CLIENT_SECRET=${{ secrets.ENV_GOOGLE_CLIENT_SECRET }}" >> ~/.env - echo "GOOGLE_REDIRECT_URI=${{ secrets.ENV_GOOGLE_REDIRECT_URI }}" >> ~/.env echo "JWT_SECRET=${{ secrets.ENV_JWT_SECRET }}" >> ~/.env + echo "IMAGE_UPLOAD_PATH=${{ secrets.ENV_IMAGE_UPLOAD_PATH }}" >> ~/.env echo "KAKAO_CLIENT_ID=${{ secrets.ENV_KAKAO_CLIENT_ID }}" >> ~/.env echo "KAKAO_CLIENT_SECRET=${{ secrets.ENV_KAKAO_CLIENT_SECRET }}" >> ~/.env - echo "KAKAO_REDIRECT_URI=${{ secrets.ENV_KAKAO_REDIRECT_URI }}" >> ~/.env echo "KAKAOPAY_SECRET_KEY=${{ secrets.ENV_KAKAOPAY_SECRET_KEY }}" >> ~/.env + echo "SERVER_DOMAIN_NAME=${{ secrets.ENV_SERVER_DOMAIN_NAME }}" >> ~/.env echo "Environment setup has been completed." - name: Pull New Docker Image @@ -175,7 +179,7 @@ jobs: key: ${{ secrets.SSH_PRIVATE_KEY }} port: ${{ secrets.SSH_PORT }} envs: GITHUB_SHA - script: sudo docker run --rm -d -p 80:8080 --env-file ~/.env --name would-you-in ${{ secrets.DOCKER_REPO_FULLNAME }} + script: sudo docker run --rm -d -p 80:8080 --env-file ~/.env --name would-you-in -v would-you-in-image-volume:${{ secrets.ENV_IMAGE_UPLOAD_PATH }} ${{ secrets.DOCKER_REPO_FULLNAME }} - name: Clean-Up Docker Image uses: appleboy/ssh-action@master diff --git a/build.gradle b/build.gradle index 3595fa08..316b8018 100644 --- a/build.gradle +++ b/build.gradle @@ -29,13 +29,11 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' - implementation 'com.h2database:h2' implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310' implementation 'com.fasterxml.jackson.core:jackson-databind' compileOnly 'org.projectlombok:lombok' developmentOnly 'org.springframework.boot:spring-boot-devtools' runtimeOnly 'com.mysql:mysql-connector-j' - runtimeOnly 'com.h2database:h2' annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.security:spring-security-test' diff --git a/src/main/resources/application-create.yml b/src/main/resources/application-create.yml index 019b5eda..477bcadd 100644 --- a/src/main/resources/application-create.yml +++ b/src/main/resources/application-create.yml @@ -7,6 +7,5 @@ spring: activate: on-profile: create jpa: - show-sql: true hibernate: ddl-auto: create diff --git a/src/main/resources/application-deploy.yml b/src/main/resources/application-deploy.yml index d7b6971f..a23c61e7 100644 --- a/src/main/resources/application-deploy.yml +++ b/src/main/resources/application-deploy.yml @@ -7,9 +7,5 @@ spring: activate: on-profile: deploy jpa: - show-sql: false hibernate: - ddl-auto: create - -# log4j log level setting -logging.level.org.ktc2.cokaen.wouldyouin: info \ No newline at end of file + ddl-auto: update \ No newline at end of file diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index d0202301..36fa911f 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -7,6 +7,5 @@ spring: activate: on-profile: dev jpa: - show-sql: true hibernate: - ddl-auto: update + ddl-auto: create-drop \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 9ff4c855..aa633fa1 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -9,7 +9,6 @@ spring: max-file-size: 10MB max-request-size: 10MB - # 임시 프로젝트 url profiles: default: dev @@ -22,31 +21,29 @@ spring: restart: enabled: false - # h2 database settings - h2: - console: - enabled: true - datasource: - url: jdbc:h2:mem:test - driver-class-name: org.h2.Driver + driver-class-name: com.mysql.cj.jdbc.Driver + url: ${DATASOURCE_URL}?useSSL=false&useUnicode=true&serverTimezone=Asia/Seoul + username: ${DATASOURCE_USERNAME} + password: ${DATASOURCE_PASSWORD} jpa: + database: mysql + database-platform: org.hibernate.dialect.MySQLDialect properties: hibernate: format_sql: true default_batch_fetch_size: 100 show-sql: true - hibernate.ddl-auto: create # log4j log level setting logging.level.org.ktc2.cokaen.wouldyouin: debug # for image storage path image: - api-url: http://52.78.71.136/api/images + api-url: ${SERVER_DOMAIN_NAME}/api/images upload: - parent-path: src/main/resources/static/images + parent-path: ${IMAGE_UPLOAD_PATH} curation: child-path: curation member: @@ -75,7 +72,7 @@ oauth: client: id: ${KAKAO_CLIENT_ID} secret: ${KAKAO_CLIENT_SECRET} - redirect_uri: ${KAKAO_REDIRECT_URI} + redirect_uri: ${SERVER_DOMAIN_NAME}/api/auth/social/redirect/kakao google: uri: login: @@ -87,14 +84,14 @@ oauth: client: id: ${GOOGLE_CLIENT_ID} secret: ${GOOGLE_CLIENT_SECRET} - redirect_uri: ${GOOGLE_REDIRECT_URI} + redirect_uri: ${SERVER_DOMAIN_NAME}/api/auth/social/redirect/google scope: - email - profile payment: - "approval_url": "http://localhost:8080/api/events" - "cancel_url": "http://localhost:8080/api/events" - "fail_url": "http://localhost:8080/api/events" + "approval_url": ${SERVER_DOMAIN_NAME}/api/events + "cancel_url": ${SERVER_DOMAIN_NAME}/api/events + "fail_url": ${SERVER_DOMAIN_NAME}/api/events "secret_key": ${KAKAOPAY_SECRET_KEY} - "kakao_pay_single_payment_url": "online/v1/payment/ready" - "kakao-pay-request-host": "https://open-api.kakaopay.com" \ No newline at end of file + "kakao_pay_single_payment_url": online/v1/payment/ready + "kakao-pay-request-host": https://open-api.kakaopay.com \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java index c5482afc..e0fe3e54 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java @@ -72,34 +72,34 @@ void createCurator() { then(curatorRepository).should(times(1)).save(any(Curator.class)); } - @Test - @DisplayName("") - void updateCurator() { - // given - Long newProfileImageId = 5L; - MemberImage newProfileImage = createValidMemberImage(newProfileImageId); - CuratorEditRequest editRequest = CuratorEditRequest.curatorEditRequestBuilder() - .nickname(TestUtil.getOrNull("newNickname")) - .phoneNumber(TestUtil.getOrNull("010-1010-8888")) - .profileImageId(TestUtil.getOrNull(newProfileImageId)) - .area(Area.광주) - .intro(TestUtil.getOrNull("new intro")) - .build(); - - given(curatorRepository.findById(validCurator.getId())).willReturn(Optional.of(validCurator)); - given(memberImageService.getById(newProfileImageId)).willReturn(newProfileImage); - - // when - curatorService.updateCurator(validCurator.getId(), editRequest); - - // then - then(curatorRepository).should(times(1)).findById(validCurator.getId()); - int times = 1; - if (editRequest.getProfileImageId() == null) { - times = 0; - } - then(memberImageService).should(times(times)).getById(newProfileImageId); - } +// @Test +// @DisplayName("") +// void updateCurator() { +// // given +// Long newProfileImageId = 5L; +// MemberImage newProfileImage = createValidMemberImage(newProfileImageId); +// CuratorEditRequest editRequest = CuratorEditRequest.curatorEditRequestBuilder() +// .nickname(TestUtil.getOrNull("newNickname")) +// .phoneNumber(TestUtil.getOrNull("010-1010-8888")) +// .profileImageId(TestUtil.getOrNull(newProfileImageId)) +// .area(Area.광주) +// .intro(TestUtil.getOrNull("new intro")) +// .build(); +// +// given(curatorRepository.findById(validCurator.getId())).willReturn(Optional.of(validCurator)); +// given(memberImageService.getById(newProfileImageId)).willReturn(newProfileImage); +// +// // when +// curatorService.updateCurator(validCurator.getId(), editRequest); +// +// // then +// then(curatorRepository).should(times(1)).findById(validCurator.getId()); +// int times = 1; +// if (editRequest.getProfileImageId() == null) { +// times = 0; +// } +// then(memberImageService).should(times(times)).getById(newProfileImageId); +// } @Test @DisplayName("큐레이터 삭제 테스트") From 7ff6f8ea14c556128b98e10917927f8e3f315545 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=99=8D=EC=8B=9D?= <90020593+Daolove0323@users.noreply.github.com> Date: Tue, 12 Nov 2024 18:29:49 +0900 Subject: [PATCH 16/53] [Weekly/11] Image/delete (#114) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 해시태그 네이밍 통일 * feat: 이벤트 응답 수정 * feat: testData 수정 --- .../AdvertisementImageService.java | 2 +- .../Image/application/ImageService.java | 7 +- .../Image/persist/AdvertisementImage.java | 4 +- .../wouldyouin/_common/error/ErrorCode.java | 2 + .../_common/error/GlobalExceptionHandler.java | 10 + .../wouldyouin/_common/vo/Location.java | 18 +- .../api/dto/CurationCreateRequest.java | 4 +- .../curation/api/dto/CurationEditRequest.java | 2 +- .../curation/api/dto/CurationResponse.java | 4 +- .../wouldyouin/curation/persist/Curation.java | 12 +- .../event/api/dto/EventCreateRequest.java | 2 + .../event/api/dto/EventEditRequest.java | 2 + .../event/api/dto/EventResponse.java | 6 +- .../event/api/dto/EventSliceResponse.java | 6 +- .../event/application/EventService.java | 24 +- .../cokaen/wouldyouin/_global/TestData.java | 295 +----------------- .../cokaen/wouldyouin/_global/TestUtil.java | 1 - .../_global/mockMember/WithMockCurator.java | 4 +- .../_global/mockMember/WithMockHost.java | 4 +- .../_global/mockMember/WithMockMember.java | 4 +- .../mockMember/WithMockWelcomeMember.java | 4 +- .../_global/testdata/CurationData.java | 108 +++++++ .../_global/testdata/ImageData.java | 135 ++++++++ .../_global/testdata/MemberData.java | 101 ++++++ .../curation/CurationControllerUnitTest.java | 77 ++--- .../curation/CurationServiceTest.java | 111 +++++++ .../event/EventControllerUnitTest.java | 17 +- .../wouldyouin/image/ImageControllerTest.java | 122 +++++--- .../BaseMemberServiceUnitTest.java | 16 +- .../application/CuratorServiceUnitTest.java | 9 +- .../application/HostServiceUnitTest.java | 6 +- .../application/MemberServiceUnitTest.java | 8 +- .../ReservationControllerUnitTest.java | 22 +- 33 files changed, 716 insertions(+), 433 deletions(-) create mode 100644 src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java create mode 100644 src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ImageData.java create mode 100644 src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java create mode 100644 src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java index ad8308a1..ae49285c 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java @@ -39,7 +39,7 @@ protected String getChildPath() { @Override protected AdvertisementImage toEntity(ImageRequest imageRequest) { return AdvertisementImage.builder() - .name(imageRequest.getUrl()) + .url(imageRequest.getUrl()) .size(imageRequest.getSize()) .extension(imageRequest.getExtension()) .build(); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java index a056d22d..be55e1a5 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java @@ -53,7 +53,12 @@ public T getById(Long id) { } protected ImageResponse create(ImageRequest imageRequest) { - return ImageResponse.from(getImageRepository().save(toEntity(imageRequest)), UriUtil.assembleFullUrl(apiUrl, getChildPath())); + T image = toEntity(imageRequest); + return ImageResponse.from(getImageRepository().save(image), getImageUrl(image)); + } + + public String getImageUrl(T image) { + return UriUtil.assembleFullUrl(apiUrl, getChildPath(), image.getName()); } protected void delete(Long id) { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/AdvertisementImage.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/AdvertisementImage.java index 2fd5c836..5c01ffd3 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/AdvertisementImage.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/AdvertisementImage.java @@ -19,8 +19,8 @@ public class AdvertisementImage extends Image { private Advertisement advertisement; @Builder - public AdvertisementImage(String name, Long size, String extension, Advertisement advertisement) { - super(name, size, extension); + public AdvertisementImage(String url, Long size, String extension, Advertisement advertisement) { + super(url, size, extension); this.advertisement = advertisement; } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/ErrorCode.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/ErrorCode.java index 6e5f7737..47e4e115 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/ErrorCode.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/ErrorCode.java @@ -28,6 +28,8 @@ public enum ErrorCode { URL_PARSING_FAILED(HttpStatus.BAD_REQUEST.value(), "-20400", "URL 파싱에 실패했습니다."), + INVALID_IMAGE_DOMAIN(HttpStatus.BAD_REQUEST.value(), "-20400", "해당 이미지 도메인에 대한 서비스가 존재하지 않습니다."), + CURRENT_LOCATION_EMPTY(HttpStatus.BAD_REQUEST.value(), "-20400", "현재 위치 정보를 찾을 수 없습니다."); private final Integer status; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/GlobalExceptionHandler.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/GlobalExceptionHandler.java index 4c62df26..185ba406 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/GlobalExceptionHandler.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/GlobalExceptionHandler.java @@ -2,6 +2,7 @@ import java.util.stream.Collectors; +import org.ktc2.cokaen.wouldyouin.Image.api.ImageDomain; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponse; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponseBody; import org.ktc2.cokaen.wouldyouin._common.exception.BusinessException; @@ -10,6 +11,7 @@ import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; @ControllerAdvice public class GlobalExceptionHandler { @@ -19,6 +21,14 @@ public ResponseEntity> handleBusinessException(BusinessExc return ApiResponse.error(e.getErrorCode(), e.getMessage()); } + @ExceptionHandler(MethodArgumentTypeMismatchException.class) + public ResponseEntity> handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException ex) { + if (ex.getRequiredType() == ImageDomain.class) { + return ApiResponse.error(ErrorCode.INVALID_IMAGE_DOMAIN, "해당 이미지 도메인에 대한 서비스가 존재하지 않습니다."); + } + return ApiResponse.error(ErrorCode.INVALID_INPUT_VALUE, "잘못된 요청 값입니다."); + } + @ExceptionHandler(MethodArgumentNotValidException.class) public ResponseEntity> handleMethodArgumentNotValidException(MethodArgumentNotValidException e) { return ApiResponse.error(ErrorCode.INVALID_INPUT_VALUE, e.getBindingResult().getFieldErrors().stream() diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/vo/Location.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/vo/Location.java index 459f2f7b..ad551893 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/vo/Location.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/vo/Location.java @@ -1,6 +1,10 @@ package org.ktc2.cokaen.wouldyouin._common.vo; import jakarta.persistence.Embeddable; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; @@ -12,7 +16,17 @@ @AllArgsConstructor @Embeddable public class Location { - Double longitude; - Double latitude; + + @NotNull(message = "위도 값은 필수입니다.") + @Min(value = -90, message = "위도는 -90 이상이어야 합니다.") + @Max(value = 90, message = "위도는 90 이하여야 합니다.") + private Double latitude; + + @NotNull(message = "경도 값은 필수입니다.") + @Min(value = -180, message = "경도는 -180 이상이어야 합니다.") + @Max(value = 180, message = "경도는 180 이하여야 합니다.") + private Double longitude; + + @NotEmpty(message = "상세 주소는 필수입니다.") String detailAddress; } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCreateRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCreateRequest.java index 5000fcec..f4f21f45 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCreateRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCreateRequest.java @@ -30,7 +30,7 @@ public class CurationCreateRequest { @NotNull(message = "지역은 필수입니다.") private Area area; - private List hashTags; + private List hashtags; private List eventIds; @@ -49,7 +49,7 @@ public Curation toEntity(Curator curator, List curationCards, List .content(this.content) .curationCards(curationCards) .area(this.area) - .hashTags(this.hashTags) + .hashtags(this.hashtags) .events(events) .build(); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationEditRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationEditRequest.java index 1d4051d5..a113f851 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationEditRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationEditRequest.java @@ -26,7 +26,7 @@ public class CurationEditRequest { @NotNull(message = "지역은 필수입니다.") private Area area; - private List hashTags; + private List hashtags; private List eventIds; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java index 98675d27..7277ed77 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java @@ -21,8 +21,8 @@ public class CurationResponse { private final Area area; private final List hashTag; private final List eventsInfo; - private LocalDateTime modifiedDate; private final LocalDateTime createdTime; + private final LocalDateTime modifiedDate; public static CurationResponse from(Curation curation) { return CurationResponse.builder() @@ -33,7 +33,7 @@ public static CurationResponse from(Curation curation) { .curationCards(curation.getCurationCards().stream() .map(CurationCardResponse::from).toList()) .area(curation.getArea()) - .hashTag(curation.getHashTags()) + .hashTag(curation.getHashtags()) .eventsInfo(curation.getEvents().stream() .map(CurationEventResponse::from).toList()) .createdTime(curation.getCreatedDate()) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java index 216ca700..e8d86244 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java @@ -60,7 +60,7 @@ public class Curation { private String content; @OneToMany(mappedBy = "curation", fetch = FetchType.LAZY) - private List curationCards = new ArrayList<>(); + private List curationCards; @NotNull @Enumerated(EnumType.STRING) @@ -69,7 +69,7 @@ public class Curation { @Column(name = "hashtag") @Convert(converter = HashtagConverter.class) - private List hashTags = new ArrayList<>(); + private List hashtags; @ManyToMany(fetch = FetchType.LAZY) @JoinTable( @@ -77,7 +77,7 @@ public class Curation { joinColumns = @JoinColumn(name = "curation_id"), inverseJoinColumns = @JoinColumn(name = "event_id") ) - private List events = new ArrayList<>(); + private List events; @CreatedDate @Column(name = "created_date") @@ -88,14 +88,14 @@ public class Curation { private LocalDateTime modifiedDate; @Builder - public Curation(Curator curator, String title, String content, List curationCards, Area area, List hashTags, + public Curation(Curator curator, String title, String content, List curationCards, Area area, List hashtags, List events) { this.curator = curator; this.title = title; this.content = content; Optional.ofNullable(curationCards).ifPresent(this::setCurationCards); this.area = area; - Optional.ofNullable(hashTags).ifPresent(this::setHashTags); + Optional.ofNullable(hashtags).ifPresent(this::setHashtags); Optional.ofNullable(events).ifPresent(this::setEvents); } @@ -103,7 +103,7 @@ public void updateFrom(CurationEditRequest curationEditRequest, List images; private EventHostResponse host; private Area area; private Location location; @@ -28,12 +31,13 @@ public class EventResponse { private Category category; private Boolean expired; - public static EventResponse from(Event event) { + public static EventResponse from(Event event, List imageUrls) { Host host = event.getHost(); return EventResponse.builder() .id(event.getId()) .title(event.getTitle()) .content(event.getContent()) + .images(imageUrls) .host(EventHostResponse.from(host)) .area(event.getArea()) .location(event.getLocation()) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventSliceResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventSliceResponse.java index 5221024c..b9870f98 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventSliceResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventSliceResponse.java @@ -3,6 +3,7 @@ import java.util.List; import lombok.Builder; import lombok.Getter; +import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageResponse; import org.ktc2.cokaen.wouldyouin._common.api.SliceInfo; import org.ktc2.cokaen.wouldyouin.event.persist.Event; import org.springframework.data.domain.Slice; @@ -14,10 +15,9 @@ public class EventSliceResponse { private List events; private SliceInfo sliceInfo; - public static EventSliceResponse from(Slice reservations, int size, Long lastId) { + public static EventSliceResponse from(List events, int size, Long lastId) { return EventSliceResponse.builder() - .events(reservations.stream() - .map(EventResponse::from).toList()) + .events(events) .sliceInfo(SliceInfo.builder() .sliceSize(size) .lastId(lastId) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java index a5c6c976..706d6472 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java @@ -2,6 +2,7 @@ import java.util.List; import lombok.RequiredArgsConstructor; +import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageResponse; import org.ktc2.cokaen.wouldyouin.Image.application.EventImageService; import org.ktc2.cokaen.wouldyouin.Image.persist.EventImage; import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; @@ -39,7 +40,8 @@ public Event getByIdOrThrow(Long id) throws EntityNotFoundException { @Transactional(readOnly = true) public EventResponse getById(Long id) { - return EventResponse.from(getByIdOrThrow(id)); + Event event = getByIdOrThrow(id); + return EventResponse.from(event, getImageUrl(event)); } @Transactional(readOnly = true) @@ -51,14 +53,16 @@ public EventSliceResponse getAllByFilterOrderByDistanceAsc(LocationFilter locati title, category, area, pageable ); Long newLastId = getLastId(events, beforeLastId); - return EventSliceResponse.from(events, events.getSize(), newLastId); + List responses = events.stream().map(this::getEventResponse).toList(); + return EventSliceResponse.from(responses, events.getSize(), newLastId); } @Transactional(readOnly = true) public EventSliceResponse getAllByHostIdOrderByCreatedDateDesc(Long hostId, Pageable pageable, Long beforeLastId) { Slice events = eventRepository.findAllByHostIdOrderByEventIdDesc(hostId, beforeLastId, pageable); Long newLastId = getLastId(events, beforeLastId); - return EventSliceResponse.from(events, events.getSize(), newLastId); + List responses = events.stream().map(this::getEventResponse).toList(); + return EventSliceResponse.from(responses, events.getSize(), newLastId); } @Transactional @@ -68,7 +72,7 @@ public EventResponse create(Long hostId, EventCreateRequest eventCreateRequest) .map(eventImageService::getById).toList(); Event event = eventRepository.save(eventCreateRequest.toEntity(host, images)); images.forEach(image -> eventImageService.setEvent(image, event)); - return EventResponse.from(event); + return getEventResponse(event); } @Transactional @@ -80,7 +84,7 @@ public EventResponse update(Long hostId, Long eventId, EventEditRequest eventEdi .map(eventImageService::getById).toList(); event.updateFrom(eventEditRequest, images); images.forEach(image -> eventImageService.setEvent(image, event)); - return EventResponse.from(event); + return getEventResponse(event); } @Transactional @@ -110,4 +114,14 @@ public void validateHostId(Long hostId, Event event) { throw new UnauthorizedException("호스트 ID가 행사의 호스트 ID와 일치하지 않습니다."); } } + + private EventResponse getEventResponse(Event event) { + return EventResponse.from(event, getImageUrl(event)); + } + + private List getImageUrl(Event event) { + return event.getImages().stream() + .map(eventImageService::getImageUrl) + .toList(); + } } \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java index 15e07439..38f06c9f 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java @@ -1,41 +1,24 @@ package org.ktc2.cokaen.wouldyouin._global; +import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidHost; +import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidMember; +import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidReservationMemberResponse; + import java.time.LocalDateTime; import java.util.List; -import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageRequest; -import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageResponse; -import org.ktc2.cokaen.wouldyouin.Image.persist.CurationImage; -import org.ktc2.cokaen.wouldyouin.Image.persist.EventImage; -import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin._common.api.SliceInfo; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; import org.ktc2.cokaen.wouldyouin._common.vo.Location; -import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCardRequest; -import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCardResponse; -import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCreateRequest; -import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationEditRequest; -import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationResponse; -import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationSliceResponse; -import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.CurationEventResponse; import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.ReservationEventResponse; import org.ktc2.cokaen.wouldyouin.event.persist.Event; -import org.ktc2.cokaen.wouldyouin.member.api.dto.relation.ReservationMemberResponse; -import org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse.CurationCuratorResponse; -import org.ktc2.cokaen.wouldyouin.member.persist.AccountType; -import org.ktc2.cokaen.wouldyouin.member.persist.Curator; -import org.ktc2.cokaen.wouldyouin.member.persist.Host; -import org.ktc2.cokaen.wouldyouin.member.persist.Member; -import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationRequest; import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationResponse; import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationSliceResponse; import org.ktc2.cokaen.wouldyouin.reservation.persist.Reservation; -import org.springframework.http.MediaType; -import org.springframework.mock.web.MockMultipartFile; import org.springframework.test.util.ReflectionTestUtils; public class TestData { @@ -47,164 +30,6 @@ public static SliceInfo createSliceInfo() { .build(); } - // Todo: 클래스이름 Domain말고 Data는 어떤지..?, ImageDomain이 중복이라 사용할 수 없음 ㅜ - public static class ImageData { - - public static MemberImage createValidMemberImage(Long id) { - MemberImage ret = MemberImage.builder() - .url("memberImageUrl") - .size(10L) - .extension(".jpg") - .build(); - ReflectionTestUtils.setField(ret, "id", id); - return ret; - } - - public static EventImage createValidEventImage(Long id) { - EventImage ret = EventImage.builder() - .url("eventImageUrl") - .size(10L) - .extension(".jpg") - .build(); - ReflectionTestUtils.setField(ret, "id", id); - return ret; - } - - public static CurationImage createValidCurationImage(Long id) { - CurationImage ret = CurationImage.builder() - .url("curationImageUrl.jpg") - .size(10L) - .extension("jpg") - .build(); - ReflectionTestUtils.setField(ret, "id", id); - return ret; - } - - public static ImageRequest createValidImageRequest() { - return ImageRequest.builder() - .url("memberImage.png") - .size(20L) - .extension("png") - .build(); - } - - public static ImageResponse createValidImageResponse1() { - return ImageResponse.builder() - .id(1L) - .url("curationImageUrl.jpg") - .size(10L) - .extension(".jpg") - .createdDate(LocalDateTime.of(2024, 3, 23, 0, 0)) - .build(); - } - - public static ImageResponse createValidImageResponse2() { - return ImageResponse.builder() - .id(2L) - .url("memberImage.png") - .size(20L) - .extension(".png") - .createdDate(LocalDateTime.of(2024, 3, 23, 0, 0)) - .build(); - } - - public static MockMultipartFile createValidMultipartFile1() { - return new MockMultipartFile("images", "image1.jpg", MediaType.IMAGE_JPEG_VALUE, "imageData1".getBytes()); - } - - public static MockMultipartFile createValidMultipartFile2() { - return new MockMultipartFile("images", "image2.png", MediaType.IMAGE_JPEG_VALUE, "imageData2".getBytes()); - } - } - - public static class MemberDomain { - - public static final long validMemberId = 1L; - public static final long validCuratorId = 2L; - public static final long validHostId = 3L; - public static final long validWelcomeMemberId = 4L; - - public static Member createValidMember() { - MemberImage memberImage = ImageData.createValidMemberImage(validMemberId); - Member ret = Member.builder() - .accountType(AccountType.kakao) - .email("member1@example.com") - .nickname("nick_normal_123") - .phone("010-1112-2233") - .profileImage(memberImage) - .area(Area.광주) - .gender("Men") - .socialId("100100100100100") - .build(); - ReflectionTestUtils.setField(ret, "Id", validMemberId); - ReflectionTestUtils.setField(ret, "memberType", MemberType.normal); - ReflectionTestUtils.setField(memberImage, "baseMember", ret); - return ret; - } - - public static Curator createValidCurator() { - MemberImage memberImage = ImageData.createValidMemberImage(validCuratorId); - Curator ret = Curator.curatorBuilder() - .accountType(AccountType.google) - .email("curator1@example.com") - .nickname("nick_curator_12") - .phone("010-4545-6767") - .profileImage(memberImage) - .area(Area.광주) - .gender("Women") - .socialId("200200200200200") - .build(); - ReflectionTestUtils.setField(ret, "Id", validCuratorId); - ReflectionTestUtils.setField(ret, "intro", "큐레이터 자기소개입니다."); - ReflectionTestUtils.setField(ret, "hashtags", List.of("#큐레이터", "#해시태그", "#입니다")); - ReflectionTestUtils.setField(memberImage, "baseMember", ret); - return ret; - } - - public static Host createValidHost() { - MemberImage memberImage = ImageData.createValidMemberImage(validHostId); - Host ret = Host.builder() - .email("curator1@example.com") - .nickname("nick_curator_12") - .phone("010-4545-6767") - .hashedPassword("hashed_password") - .profileImage(memberImage) - .build(); - ReflectionTestUtils.setField(ret, "Id", validHostId); - ReflectionTestUtils.setField(ret, "intro", "주최자 자기소개입니다."); - ReflectionTestUtils.setField(ret, "hashtags", List.of("#주최자", "#해시태그", "#입니다")); - ReflectionTestUtils.setField(memberImage, "baseMember", ret); - return ret; - } - - public static Member createValidWelcomeMember() { - MemberImage memberImage = ImageData.createValidMemberImage(validWelcomeMemberId); - Member ret = Member.builder() - .accountType(AccountType.kakao) - .email("member2@example.com") - .nickname("nick_normal_333") - .phone("010-4414-1144") - .profileImage(memberImage) - .area(Area.서울) - .gender("Men") - .socialId("456456456456") - .build(); - ReflectionTestUtils.setField(ret, "Id", validWelcomeMemberId); - ReflectionTestUtils.setField(memberImage, "baseMember", ret); - return ret; - } - - public static ReservationMemberResponse createValidReservationMemberResponse() { - return ReservationMemberResponse.builder() - .id(validMemberId) - .email("member1@example.com") - .nickname("nick_normal_123") - .phone("010-1112-2233") - .gender("Men") - .build(); - } - } - public static class EventDomain { public static Event createValidEvent() { @@ -219,7 +44,8 @@ public static Event createValidEvent() { .totalSeat(100) .category(Category.밴드) .build(); - validEvent.setHost(MemberDomain.createValidHost()); + validEvent.setHost(createValidHost()); + ReflectionTestUtils.setField(validEvent, "id", 201L); return validEvent; } @@ -228,7 +54,7 @@ public static EventCreateRequest createValidEventCreateRequest() { .title("title") .content("content 조홍식씨 최소글자 20자라고 해놓고 안 지켰어요.") .area(Area.전체) - .location(new Location(132.0, 43.0, "광주 북구 용봉로 77")) + .location(new Location(55.0, 43.0, "광주 북구 용봉로 77")) .startTime(LocalDateTime.of(2025, 10, 1, 9, 0)) .endTime(LocalDateTime.of(2025, 10, 1, 10, 0)) .price(10000) @@ -284,7 +110,7 @@ public static ReservationRequest createValidReservationRequest() { public static Reservation createValidReservation() { Reservation reservation = Reservation.builder() - .member(MemberDomain.createValidMember()) + .member(createValidMember()) .event(EventDomain.createValidEvent()) .price(15000) .quantity(2) @@ -296,7 +122,7 @@ public static Reservation createValidReservation() { public static ReservationResponse createValidReservationResponse() { return ReservationResponse.builder() .id(1L) - .member(MemberDomain.createValidReservationMemberResponse()) + .member(createValidReservationMemberResponse()) .event(EventDomain.createValidReservationEventResponse()) .price(15000) .quantity(2) @@ -311,105 +137,4 @@ public static ReservationSliceResponse createValidReservationSliceResponse() { .build(); } } - - public static class CurationDomain { - - public static Curation createValidCuration() { - return Curation.builder() - .curator(MemberDomain.createValidCurator()) - .title("title") - .content("content") - .curationCards(List.of()) - .area(Area.전체) - .hashTags(List.of("#해시태그1", "#해시태그2")) - .events(List.of(EventDomain.createValidEvent())) - .build(); - } - - public static CurationCardRequest createValidCurationCardRequest1() { - return CurationCardRequest.builder() - .subtitle("부제목1") - .content("큐레이션 카드 내용1 입니다. 큐레이션 카드의 내용은 최소 20자 최대 1000자 입니다.") - .imageIds(List.of(1L, 2L)) - .build(); - } - - public static CurationCardRequest createValidCurationCardRequest2() { - return CurationCardRequest.builder() - .subtitle("부제목2") - .content("큐레이션 카드 내용2 입니다. 큐레이션 카드의 내용은 최소 20자 최대 1000자 입니다.") - .imageIds(List.of(3L, 4L)) - .build(); - } - - public static CurationCardResponse createCurationCardResponse1() { - return CurationCardResponse.builder() - .subtitle("부제목1") - .content("큐레이션 카드 내용1 입니다. 큐레이션 카드의 내용은 최소 20자 최대 1000자 입니다.") - .imageUrls(List.of("image1.com", "image2.com")) - .build(); - } - - public static CurationCardResponse createCurationCardResponse2() { - return CurationCardResponse.builder() - .subtitle("부제목2") - .content("큐레이션 카드 내용2 입니다. 큐레이션 카드의 내용은 최소 20자 최대 1000자 입니다.") - .imageUrls(List.of("image3.com", "image4.com")) - .build(); - } - - public static CurationCreateRequest createValidCurationCreateRequest() { - return CurationCreateRequest.builder() - .title("큐레이션 제목1") - .content("큐레이션 카드 내용1 입니다. 큐레이션 카드의 내용은 최소 20자 최대 1000자 입니다.") - .curationCards(List.of(createValidCurationCardRequest1())) - .area(Area.광주) - .hashTags(List.of("#광주밴드", "#전남대")) - .eventIds(List.of(1L, 2L)) - .build(); - } - - public static CurationEditRequest createValidCurationEditRequest() { - return CurationEditRequest.builder() - .title("큐레이션 제목2") - .content("큐레이션 내용2 입니다.") - .curationCards(List.of(createValidCurationCardRequest2())) - .area(Area.서울) - .hashTags(List.of("#서울밴드", "#서울대")) - .eventIds(List.of(3L, 4L)) - .build(); - } - - public static CurationCuratorResponse createCurationCuratorResponse() { - Curator curator = MemberDomain.createValidCurator(); - return CurationCuratorResponse.builder() - .nickname(curator.getNickname()) - .email(curator.getEmail()) - .phone(curator.getPhone()) - .profileImageUrl(curator.getProfileImageUrl()) - .intro(curator.getIntro()) - .likes(curator.getLikes()) - .hashtags(curator.getHashtags()) - .build(); - } - - public static CurationResponse createValidCurationResponse() { - return CurationResponse.builder() - .curator(createCurationCuratorResponse()) - .title("title") - .content("content") - .curationCards(List.of(createCurationCardResponse1())) - .area(Area.전체) - .hashTag(List.of("#해시태그1", "#해시태그2")) - .eventsInfo(List.of(EventDomain.createValidCurationEventResponse())) - .build(); - } - - public static CurationSliceResponse createValidCurationSliceResponse() { - return CurationSliceResponse.builder() - .curations(List.of(createValidCurationResponse())) - .sliceInfo(TestData.createSliceInfo()) - .build(); - } - } -} +} \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestUtil.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestUtil.java index 50cbb345..f6f35839 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestUtil.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestUtil.java @@ -9,5 +9,4 @@ public static T getLeftOrRight(T left, T right) { public static T getOrNull(T object) { return getLeftOrRight(object, null); } - } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockCurator.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockCurator.java index 58488b23..e07aa771 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockCurator.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockCurator.java @@ -2,11 +2,11 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @Retention(RetentionPolicy.RUNTIME) -@WithMockCustomUser(memberId = MemberDomain.validCuratorId, memberType = MemberType.curator) +@WithMockCustomUser(memberId = MemberData.validCuratorId, memberType = MemberType.curator) public @interface WithMockCurator { } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockHost.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockHost.java index 1805cbf8..2a84fd47 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockHost.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockHost.java @@ -2,11 +2,11 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @Retention(RetentionPolicy.RUNTIME) -@WithMockCustomUser(memberId = MemberDomain.validHostId, memberType = MemberType.host) +@WithMockCustomUser(memberId = MemberData.validHostId, memberType = MemberType.host) public @interface WithMockHost { } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockMember.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockMember.java index 0bbaf38c..6b71ff00 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockMember.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockMember.java @@ -2,11 +2,11 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @Retention(RetentionPolicy.RUNTIME) -@WithMockCustomUser(memberId = MemberDomain.validMemberId, memberType = MemberType.normal) +@WithMockCustomUser(memberId = MemberData.validMemberId, memberType = MemberType.normal) public @interface WithMockMember { } \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockWelcomeMember.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockWelcomeMember.java index 1f8e877b..4dc60ff8 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockWelcomeMember.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockWelcomeMember.java @@ -2,11 +2,11 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @Retention(RetentionPolicy.RUNTIME) -@WithMockCustomUser(memberId = MemberDomain.validWelcomeMemberId, memberType = MemberType.welcome) +@WithMockCustomUser(memberId = MemberData.validWelcomeMemberId, memberType = MemberType.welcome) public @interface WithMockWelcomeMember { } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java new file mode 100644 index 00000000..a32b9cb7 --- /dev/null +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java @@ -0,0 +1,108 @@ +package org.ktc2.cokaen.wouldyouin._global.testdata; + +import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidCurator; + +import java.time.LocalDateTime; +import java.util.List; +import org.ktc2.cokaen.wouldyouin._common.vo.Area; +import org.ktc2.cokaen.wouldyouin._global.TestData; +import org.ktc2.cokaen.wouldyouin._global.TestData.EventDomain; +import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCardRequest; +import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCardResponse; +import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCreateRequest; +import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationEditRequest; +import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationResponse; +import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationSliceResponse; +import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; +import org.ktc2.cokaen.wouldyouin.curation.persist.CurationCard; +import org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse.CurationCuratorResponse; +import org.springframework.test.util.ReflectionTestUtils; + +public class CurationData { + + public static CurationCardRequest createValidCurationCardRequest1() { + return CurationCardRequest.builder() + .subtitle("큐레이션 카드 부제목1") + .content("큐레이션 카드 내용1 입니다. 큐레이션 카드의 내용은 최소 20자 최대 1000자 입니다.") + .imageIds(List.of(1301L)) + .build(); + } + + public static CurationCardRequest createValidCurationCardRequest2() { + return CurationCardRequest.builder() + .subtitle("큐레이션 카드 부제목2") + .content("큐레이션 카드 내용2 입니다. 큐레이션 카드의 내용은 최소 20자 최대 1000자 입니다.") + .imageIds(List.of(1302L)) + .build(); + } + + public static CurationCard createValidCurationCard1() { + CurationCard validCurationCard1 = + createValidCurationCardRequest1().toEntity(List.of(ImageData.createValidCurationImage1())); + ReflectionTestUtils.setField(validCurationCard1, "id", 351L); +// ReflectionTestUtils.setField(validCurationCard1, "curation", createValidCuration()); + return validCurationCard1; + } + + public static CurationCard createValidCurationCard2() { + CurationCard validCurationCard2 = + createValidCurationCardRequest2().toEntity(List.of(ImageData.createValidCurationImage2())); + ReflectionTestUtils.setField(validCurationCard2, "id", 352L); +// ReflectionTestUtils.setField(validCurationCard1, "curation", createValidCuration()); + return validCurationCard2; + } + + public static CurationCardResponse createValidCurationCardResponse1() { + return CurationCardResponse.from(createValidCurationCard1()); + } + + public static CurationCardResponse createValidCurationCardResponse2() { + return CurationCardResponse.from(createValidCurationCard2()); + } + + public static CurationCreateRequest createValidCurationCreateRequest() { + return CurationCreateRequest.builder() + .title("큐레이션 제목") + .content("큐레이션 본문") + .curationCards(List.of(createValidCurationCardRequest1())) + .area(Area.전체) + .hashtags(List.of("#큐레이션", "#해시태그")) + .eventIds(List.of(201L)) + .build(); + } + + public static CurationEditRequest createValidCurationEditRequest() { + return CurationEditRequest.builder() + .title("큐레이션 제목 수정") + .content("큐레이션 본문 수정") + .curationCards(List.of(createValidCurationCardRequest2())) + .area(Area.광주) + .hashtags(List.of("수정 해시태그")) + .eventIds(List.of(202L)) + .build(); + } + + public static Curation createValidCuration() { + Curation validCuration = createValidCurationCreateRequest().toEntity( + createValidCurator(), List.of(createValidCurationCard1()), List.of(EventDomain.createValidEvent())); + ReflectionTestUtils.setField(validCuration, "id", 301L); + ReflectionTestUtils.setField(validCuration, "createdDate", LocalDateTime.of(2023, 3, 23, 0, 0)); + ReflectionTestUtils.setField(validCuration, "modifiedDate", LocalDateTime.of(2024, 3, 23, 0, 0)); + return validCuration; + } + + public static CurationCuratorResponse createValidCurationCuratorResponse() { + return CurationCuratorResponse.from(createValidCurator()); + } + + public static CurationResponse createValidCurationResponse() { + return CurationResponse.from(createValidCuration()); + } + + public static CurationSliceResponse createValidCurationSliceResponse() { + return CurationSliceResponse.builder() + .curations(List.of(createValidCurationResponse())) + .sliceInfo(TestData.createSliceInfo()) + .build(); + } +} \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ImageData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ImageData.java new file mode 100644 index 00000000..11e047d6 --- /dev/null +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ImageData.java @@ -0,0 +1,135 @@ +package org.ktc2.cokaen.wouldyouin._global.testdata; + +import java.time.LocalDateTime; +import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageRequest; +import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageResponse; +import org.ktc2.cokaen.wouldyouin.Image.persist.AdvertisementImage; +import org.ktc2.cokaen.wouldyouin.Image.persist.CurationImage; +import org.ktc2.cokaen.wouldyouin.Image.persist.EventImage; +import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; +import org.springframework.http.MediaType; +import org.springframework.mock.web.MockMultipartFile; +import org.springframework.test.util.ReflectionTestUtils; + +public class ImageData { + + public static final long validMemberImageId = 1101L; + public static final long validEventImageId = 1201L; + public static final long validCurationImageId = 1301L; + public static final long validAdImageId = 1401L; + + public static MemberImage createValidMemberImage() { + MemberImage validMemberImage = MemberImage.builder() + .url("member/memberImage.jpg") + .size(10L) + .extension(".jpg") + .build(); + ReflectionTestUtils.setField(validMemberImage, "id", 1101L); +// ReflectionTestUtils.setField(validMemberImage, "baseMember", MemberDomain.createValidMember()); + return validMemberImage; + } + + public static EventImage createValidEventImage() { + EventImage validEventImage = EventImage.builder() + .url("event/eventImage.jpg") + .size(20L) + .extension(".jpg") + .build(); + ReflectionTestUtils.setField(validEventImage, "id", 1201L); +// ReflectionTestUtils.setField(validMemberImage, "baseMember", MemberDomain.createValidMember()); + return validEventImage; + } + + public static CurationImage createValidCurationImage1() { + CurationImage validCurationImage = CurationImage.builder() + .url("curation/curationImage1.jpg") + .size(30L) + .extension(".jpg") + .build(); + ReflectionTestUtils.setField(validCurationImage, "id", 1301L); +// ReflectionTestUtils.setField(validMemberImage, "baseMember", MemberDomain.createValidMember()); + return validCurationImage; + } + + public static CurationImage createValidCurationImage2() { + CurationImage validCurationImage = CurationImage.builder() + .url("curation/curationImage2.jpg") + .size(30L) + .extension(".jpg") + .build(); + ReflectionTestUtils.setField(validCurationImage, "id", 1302L); +// ReflectionTestUtils.setField(validMemberImage, "baseMember", MemberDomain.createValidMember()); + return validCurationImage; + } + + public static AdvertisementImage createValidAdImage() { + AdvertisementImage validAdImage = AdvertisementImage.builder() + .url("curation/curationImage.jpg") + .size(40L) + .extension(".jpg") + .build(); + ReflectionTestUtils.setField(validAdImage, "id", 1401L); +// ReflectionTestUtils.setField(validMemberImage, "baseMember", MemberDomain.createValidMember()); + return validAdImage; + } + + public static ImageRequest createValidMemberImageRequest() { + return ImageRequest.builder() + .url("member/memberImage.jpg") + .size(10L) + .extension(".jpg") + .build(); + } + + public static ImageRequest createValidEventImageRequest() { + return ImageRequest.builder() + .url("event/eventImage.jpg") + .size(20L) + .extension(".jpg") + .build(); + } + + public static ImageRequest createValidCurationImageRequest() { + return ImageRequest.builder() + .url("curation/curationImage.jpg") + .size(30L) + .extension(".jpg") + .build(); + } + + public static ImageRequest createValidAdImageRequest() { + return ImageRequest.builder() + .url("ad/adImage.jpg") + .size(40L) + .extension(".jpg") + .build(); + } + + public static ImageResponse createValidImageResponse1() { + return ImageResponse.builder() + .id(1L) + .url("curationImageUrl.jpg") + .size(10L) + .extension(".jpg") + .createdDate(LocalDateTime.of(2024, 3, 23, 0, 0)) + .build(); + } + + public static ImageResponse createValidImageResponse2() { + return ImageResponse.builder() + .id(2L) + .url("memberImage.png") + .size(20L) + .extension(".png") + .createdDate(LocalDateTime.of(2024, 3, 23, 0, 0)) + .build(); + } + + public static MockMultipartFile createValidMultipartFile1() { + return new MockMultipartFile("images", "image1.jpg", MediaType.IMAGE_JPEG_VALUE, "imageData1".getBytes()); + } + + public static MockMultipartFile createValidMultipartFile2() { + return new MockMultipartFile("images", "image2.png", MediaType.IMAGE_JPEG_VALUE, "imageData2".getBytes()); + } +} diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java new file mode 100644 index 00000000..1633ce5c --- /dev/null +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java @@ -0,0 +1,101 @@ +package org.ktc2.cokaen.wouldyouin._global.testdata; + +import java.util.List; +import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; +import org.ktc2.cokaen.wouldyouin._common.vo.Area; +import org.ktc2.cokaen.wouldyouin.member.api.dto.relation.ReservationMemberResponse; +import org.ktc2.cokaen.wouldyouin.member.persist.AccountType; +import org.ktc2.cokaen.wouldyouin.member.persist.Curator; +import org.ktc2.cokaen.wouldyouin.member.persist.Host; +import org.ktc2.cokaen.wouldyouin.member.persist.Member; +import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; +import org.springframework.test.util.ReflectionTestUtils; + +public class MemberData { + + public static final long validMemberId = 101L; + public static final long validCuratorId = 102L; + public static final long validHostId = 103L; + public static final long validWelcomeMemberId = 104L; + public static final long validAdminId = 105L; + + public static Member createValidMember() { + MemberImage memberImage = ImageData.createValidMemberImage(); + Member ret = Member.builder() + .accountType(AccountType.kakao) + .email("member1@example.com") + .nickname("nick_normal_123") + .phone("010-1112-2233") + .profileImage(memberImage) + .area(Area.광주) + .gender("Men") + .socialId("100100100100100") + .build(); + ReflectionTestUtils.setField(ret, "Id", validMemberId); + ReflectionTestUtils.setField(ret, "memberType", MemberType.normal); + ReflectionTestUtils.setField(memberImage, "baseMember", ret); + return ret; + } + + public static Curator createValidCurator() { + MemberImage memberImage = ImageData.createValidMemberImage(); + Curator ret = Curator.curatorBuilder() + .accountType(AccountType.google) + .email("curator1@example.com") + .nickname("nick_curator_12") + .phone("010-4545-6767") + .profileImage(memberImage) + .area(Area.광주) + .gender("Women") + .socialId("200200200200200") + .build(); + ReflectionTestUtils.setField(ret, "Id", validCuratorId); + ReflectionTestUtils.setField(ret, "intro", "큐레이터 자기소개입니다."); + ReflectionTestUtils.setField(ret, "hashtags", List.of("#큐레이터", "#해시태그", "#입니다")); + ReflectionTestUtils.setField(memberImage, "baseMember", ret); + return ret; + } + + public static Host createValidHost() { + MemberImage memberImage = ImageData.createValidMemberImage(); + Host ret = Host.builder() + .email("curator1@example.com") + .nickname("nick_curator_12") + .phone("010-4545-6767") + .hashedPassword("hashed_password") + .profileImage(memberImage) + .build(); + ReflectionTestUtils.setField(ret, "Id", validHostId); + ReflectionTestUtils.setField(ret, "intro", "주최자 자기소개입니다."); + ReflectionTestUtils.setField(ret, "hashtags", List.of("#주최자", "#해시태그", "#입니다")); + ReflectionTestUtils.setField(memberImage, "baseMember", ret); + return ret; + } + + public static Member createValidWelcomeMember() { + MemberImage memberImage = ImageData.createValidMemberImage(); + Member ret = Member.builder() + .accountType(AccountType.kakao) + .email("member2@example.com") + .nickname("nick_normal_333") + .phone("010-4414-1144") + .profileImage(memberImage) + .area(Area.서울) + .gender("Men") + .socialId("456456456456") + .build(); + ReflectionTestUtils.setField(ret, "Id", validWelcomeMemberId); + ReflectionTestUtils.setField(memberImage, "baseMember", ret); + return ret; + } + + public static ReservationMemberResponse createValidReservationMemberResponse() { + return ReservationMemberResponse.builder() + .id(validMemberId) + .email("member1@example.com") + .nickname("nick_normal_123") + .phone("010-1112-2233") + .gender("Men") + .build(); + } +} \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java index fad5703e..fd437c1b 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java @@ -2,6 +2,10 @@ import static java.lang.Math.abs; import static org.assertj.core.api.Assertions.assertThat; +import static org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.createValidCurationCardRequest1; +import static org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.createValidCurationCreateRequest; +import static org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.createValidCurationEditRequest; +import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.validCuratorId; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.times; @@ -22,11 +26,10 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.ktc2.cokaen.wouldyouin._common.vo.Area; -import org.ktc2.cokaen.wouldyouin._global.TestData.CurationDomain; -import org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockCurator; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; import org.ktc2.cokaen.wouldyouin.curation.api.CurationController; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCreateRequest; @@ -54,14 +57,14 @@ class CurationControllerUnitTest { @Autowired private WebApplicationContext context; - private static final long randomId = abs(new Random().nextLong()); - @MockBean private CurationService curationService; @MockBean private JwtAuthFilter jwtAuthFilter; + private final long randomId = abs(new Random().nextLong()); + @BeforeEach public void setup() throws Exception { mockMvc = MockMvcBuilders @@ -147,7 +150,7 @@ void getCurationByCurationId() throws Exception { void createCuration1() throws Exception { // given ArgumentCaptor captor = ArgumentCaptor.forClass(CurationCreateRequest.class); - CurationCreateRequest request = CurationDomain.createValidCurationCreateRequest(); + CurationCreateRequest request = createValidCurationCreateRequest(); // when mockMvc.perform(post("/api/curations") @@ -158,7 +161,7 @@ void createCuration1() throws Exception { .andExpect(status().isCreated()); // then - then(curationService).should(times(1)).create(eq(MemberDomain.validCuratorId), captor.capture()); + then(curationService).should(times(1)).create(eq(validCuratorId), captor.capture()); assertThat(captor.getValue()).isEqualTo(request); } @@ -170,7 +173,7 @@ void createCuration2() throws Exception { mockMvc.perform(post("/api/curations") .with(csrf()) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(CurationDomain.createValidCurationCreateRequest()))) + .content(objectMapper.writeValueAsString(createValidCurationCreateRequest()))) .andDo(print()) .andExpect(status().isUnauthorized()) .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); @@ -188,7 +191,7 @@ void createCuration3() throws Exception { mockMvc.perform(post("/api/curations") .with(csrf()) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(CurationDomain.createValidCurationCreateRequest()))) + .content(objectMapper.writeValueAsString(createValidCurationCreateRequest()))) .andDo(print()) .andExpect(status().isUnauthorized()) .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); @@ -203,7 +206,7 @@ void createCuration3() throws Exception { @WithMockCurator void createCuration4() throws Exception { // given - CurationCreateRequest request = CurationDomain.createValidCurationCreateRequest().toBuilder() + CurationCreateRequest request = createValidCurationCreateRequest().toBuilder() .title("").build(); // when @@ -224,8 +227,8 @@ void createCuration4() throws Exception { @WithMockCurator void createCuration5() throws Exception { // given - CurationCreateRequest request = CurationDomain.createValidCurationCreateRequest().toBuilder() - .curationCards(List.of(CurationDomain.createValidCurationCardRequest1().toBuilder().subtitle("").build())) + CurationCreateRequest request = createValidCurationCreateRequest().toBuilder() + .curationCards(List.of(createValidCurationCardRequest1().toBuilder().subtitle("").build())) .build(); // when @@ -246,8 +249,8 @@ void createCuration5() throws Exception { @WithMockCurator void createCuration6() throws Exception { // given - CurationCreateRequest request = CurationDomain.createValidCurationCreateRequest().toBuilder() - .curationCards(List.of(CurationDomain.createValidCurationCardRequest1().toBuilder().content(null).build())) + CurationCreateRequest request = createValidCurationCreateRequest().toBuilder() + .curationCards(List.of(createValidCurationCardRequest1().toBuilder().content(null).build())) .build(); // when @@ -268,8 +271,8 @@ void createCuration6() throws Exception { @WithMockCurator void createCuration7() throws Exception { // given - CurationCreateRequest request = CurationDomain.createValidCurationCreateRequest().toBuilder() - .curationCards(List.of(CurationDomain.createValidCurationCardRequest1().toBuilder().content(null).build())) + CurationCreateRequest request = createValidCurationCreateRequest().toBuilder() + .curationCards(List.of(createValidCurationCardRequest1().toBuilder().content(null).build())) .build(); // when @@ -290,8 +293,8 @@ void createCuration7() throws Exception { @WithMockCurator void createCuration8() throws Exception { // given - CurationCreateRequest request = CurationDomain.createValidCurationCreateRequest().toBuilder() - .curationCards(List.of(CurationDomain.createValidCurationCardRequest1().toBuilder().content("짧은 내용").build())) + CurationCreateRequest request = createValidCurationCreateRequest().toBuilder() + .curationCards(List.of(createValidCurationCardRequest1().toBuilder().content("짧은 내용").build())) .build(); // when @@ -312,8 +315,8 @@ void createCuration8() throws Exception { @WithMockCurator void createCuration9() throws Exception { // given - CurationCreateRequest request = CurationDomain.createValidCurationCreateRequest().toBuilder() - .curationCards(List.of(CurationDomain.createValidCurationCardRequest1().toBuilder() + CurationCreateRequest request = createValidCurationCreateRequest().toBuilder() + .curationCards(List.of(createValidCurationCardRequest1().toBuilder() .imageIds(List.of(1L, 2L, 3L, 4L, 5L, 6L)).build())) .build(); @@ -335,7 +338,7 @@ void createCuration9() throws Exception { @WithMockCurator void createCuration10() throws Exception { // given - CurationCreateRequest request = CurationDomain.createValidCurationCreateRequest().toBuilder() + CurationCreateRequest request = createValidCurationCreateRequest().toBuilder() .area(null).build(); // when @@ -356,7 +359,7 @@ void createCuration10() throws Exception { @WithMockCurator void createCuration11() throws Exception { // given - CurationCreateRequest request = CurationDomain.createValidCurationCreateRequest().toBuilder(). + CurationCreateRequest request = createValidCurationCreateRequest().toBuilder(). curationCards(List.of()).build(); // when @@ -378,7 +381,7 @@ void createCuration11() throws Exception { void updateCuration1() throws Exception { // given ArgumentCaptor captor = ArgumentCaptor.forClass(CurationEditRequest.class); - CurationEditRequest request = CurationDomain.createValidCurationEditRequest(); + CurationEditRequest request = createValidCurationEditRequest(); // when mockMvc.perform(put("/api/curations/" + randomId) @@ -389,7 +392,7 @@ void updateCuration1() throws Exception { .andExpect(status().isOk()); // then - then(curationService).should(times(1)).update(eq(MemberDomain.validCuratorId), eq(randomId), captor.capture()); + then(curationService).should(times(1)).update(eq(validCuratorId), eq(randomId), captor.capture()); assertThat(captor.getValue()).isEqualTo(request); } @@ -401,7 +404,7 @@ void updateCuration2() throws Exception { mockMvc.perform(put("/api/curations/" + randomId) .with(csrf()) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(CurationDomain.createValidCurationEditRequest()))) + .content(objectMapper.writeValueAsString(createValidCurationEditRequest()))) .andDo(print()) .andExpect(status().isUnauthorized()) .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); @@ -419,7 +422,7 @@ void updateCuration3() throws Exception { mockMvc.perform(put("/api/curations/" + randomId) .with(csrf()) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(CurationDomain.createValidCurationEditRequest()))) + .content(objectMapper.writeValueAsString(createValidCurationEditRequest()))) .andDo(print()) .andExpect(status().isUnauthorized()) .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); @@ -434,7 +437,7 @@ void updateCuration3() throws Exception { @WithMockCurator void updateCuration4() throws Exception { // given - CurationEditRequest request = CurationDomain.createValidCurationEditRequest().toBuilder() + CurationEditRequest request = createValidCurationEditRequest().toBuilder() .title(null).build(); // when @@ -455,8 +458,8 @@ void updateCuration4() throws Exception { @WithMockCurator void updateCuration5() throws Exception { // given - CurationEditRequest request = CurationDomain.createValidCurationEditRequest().toBuilder() - .curationCards(List.of(CurationDomain.createValidCurationCardRequest1().toBuilder() + CurationEditRequest request = createValidCurationEditRequest().toBuilder() + .curationCards(List.of(createValidCurationCardRequest1().toBuilder() .subtitle("").build())) .build(); @@ -478,8 +481,8 @@ void updateCuration5() throws Exception { @WithMockCurator void updateCuration6() throws Exception { // given - CurationEditRequest request = CurationDomain.createValidCurationEditRequest().toBuilder() - .curationCards(List.of(CurationDomain.createValidCurationCardRequest1().toBuilder() + CurationEditRequest request = createValidCurationEditRequest().toBuilder() + .curationCards(List.of(createValidCurationCardRequest1().toBuilder() .content(null).build())) .build(); @@ -501,8 +504,8 @@ void updateCuration6() throws Exception { @WithMockCurator void updateCuration7() throws Exception { // given - CurationEditRequest request = CurationDomain.createValidCurationEditRequest().toBuilder() - .curationCards(List.of(CurationDomain.createValidCurationCardRequest1().toBuilder() + CurationEditRequest request = createValidCurationEditRequest().toBuilder() + .curationCards(List.of(createValidCurationCardRequest1().toBuilder() .content("짧은 내용").build())) .build(); @@ -524,8 +527,8 @@ void updateCuration7() throws Exception { @WithMockCurator void updateCuration8() throws Exception { // given - CurationEditRequest request = CurationDomain.createValidCurationEditRequest().toBuilder() - .curationCards(List.of(CurationDomain.createValidCurationCardRequest1().toBuilder() + CurationEditRequest request = createValidCurationEditRequest().toBuilder() + .curationCards(List.of(createValidCurationCardRequest1().toBuilder() .imageIds(List.of(1L, 2L, 3L, 4L, 5L, 6L)).build())) .build(); @@ -547,7 +550,7 @@ void updateCuration8() throws Exception { @WithMockCurator void updateCuration9() throws Exception { // given - CurationEditRequest request = CurationDomain.createValidCurationEditRequest().toBuilder() + CurationEditRequest request = createValidCurationEditRequest().toBuilder() .area(null).build(); // when @@ -568,7 +571,7 @@ void updateCuration9() throws Exception { @WithMockCurator void updateCuration10() throws Exception { // given - CurationEditRequest request = CurationDomain.createValidCurationEditRequest().toBuilder() + CurationEditRequest request = createValidCurationEditRequest().toBuilder() .curationCards(List.of()).build(); // when @@ -595,7 +598,7 @@ void deleteCuration1() throws Exception { .andExpect(status().isNoContent()); // then - then(curationService).should(times(1)).delete(eq(MemberDomain.validCuratorId), eq(randomId)); + then(curationService).should(times(1)).delete(eq(validCuratorId), eq(randomId)); } @Test diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java new file mode 100644 index 00000000..d14d31bd --- /dev/null +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java @@ -0,0 +1,111 @@ +package org.ktc2.cokaen.wouldyouin.curation; + +import static java.lang.Math.abs; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.createValidCuration; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; +import static org.mockito.Mockito.times; + +import java.util.Optional; +import java.util.Random; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; +import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; +import org.ktc2.cokaen.wouldyouin.curation.application.CurationCardService; +import org.ktc2.cokaen.wouldyouin.curation.application.CurationService; +import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; +import org.ktc2.cokaen.wouldyouin.curation.persist.CurationRepository; +import org.ktc2.cokaen.wouldyouin.event.application.EventService; +import org.ktc2.cokaen.wouldyouin.member.application.CuratorService; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class CurationServiceTest { + + private CurationService curationService; + + @Mock + private CurationRepository curationRepository; + + @Mock + private CuratorService curatorService; + + @Mock + private EventService eventService; + + @Mock + private CurationCardService curationCardService; + + @Mock + private MemberImage memberImage; + + private Curation validCuration; + + private final long randomId = abs(new Random().nextLong()); + + @BeforeEach + void setUp() { + curationService = new CurationService(curationRepository, curatorService, eventService, curationCardService); + validCuration = createValidCuration(); + } + + @Test + @DisplayName("큐레이션 ID를 통해 큐레이션 조회한다.") + void getByIdOrThrow1() { + // given + given(curationRepository.findById(randomId)).willReturn(Optional.of(validCuration)); + + // when + curationService.getByIdOrThrow(randomId); + + // then + then(curationRepository).should(times(1)).findById(randomId); + assertThat(curationService.getByIdOrThrow(randomId)).isEqualTo(validCuration); + } + + @Test + @DisplayName("큐레이션 ID를 통해 큐레이션을 찾지 못한 경우, 예외를 던진다.") + void getByIdOrThrow2() { + // given + given(curationRepository.findById(randomId)).willReturn(Optional.empty()); + + // when, then + EntityNotFoundException thrown = assertThrows( + EntityNotFoundException.class, () -> curationService.getByIdOrThrow(randomId)); + assertThat(thrown.getMessage()).isEqualTo("해당하는 큐레이션을 찾을 수 없습니다."); + } + + @Test + void getById() { + } + + @Test + void getAllByAreaOrderByCreatedDateDesc() { + } + + @Test + void getAllByCuratorIdOrderByCreatedDateDesc() { + } + + @Test + void create() { + } + + @Test + void update() { + } + + @Test + void delete() { + } + + @Test + void validateCuratorId() { + } +} \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java index b19b6299..a840608b 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java @@ -1,7 +1,7 @@ package org.ktc2.cokaen.wouldyouin.event; - -import static org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain.createValidHost; +import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidHost; +import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.validHostId; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; @@ -22,20 +22,19 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; - import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; +import org.ktc2.cokaen.wouldyouin._global.TestData.EventDomain; +import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost; import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; import org.ktc2.cokaen.wouldyouin.auth.application.JwtService; -import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationFilter; import org.ktc2.cokaen.wouldyouin.event.api.EventController; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventSliceResponse; +import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationFilter; import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationRequest; import org.ktc2.cokaen.wouldyouin.event.application.EventService; -import org.ktc2.cokaen.wouldyouin._global.TestData.EventDomain; -import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost; import org.ktc2.cokaen.wouldyouin.member.application.MemberService; import org.ktc2.cokaen.wouldyouin.member.persist.Host; import org.springframework.beans.factory.annotation.Autowired; @@ -192,7 +191,7 @@ void createEvent() throws Exception { .andExpect(status().isCreated()); //then - then(eventService).should(times(1)).create(eq(id), any(EventCreateRequest.class)); + then(eventService).should(times(1)).create(eq(validHostId), any(EventCreateRequest.class)); } @Test @@ -208,7 +207,7 @@ void updateEvent() throws Exception { .andExpect(status().isOk()); //then - then(eventService).should(times(1)).update(eq(id), eq(id), any(EventEditRequest.class)); + then(eventService).should(times(1)).update(eq(validHostId), eq(id), any(EventEditRequest.class)); } @Test @@ -222,6 +221,6 @@ void deleteEvent() throws Exception { ).andExpect(status().isNoContent()); //then - then(eventService).should(times(1)).delete(eq(id), eq(id)); + then(eventService).should(times(1)).delete(eq(validHostId), eq(id)); } } \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java index c41c2a58..52e6f2ff 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java @@ -1,19 +1,26 @@ package org.ktc2.cokaen.wouldyouin.image; +import static java.lang.Math.abs; +import static org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.createValidImageResponse1; +import static org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.createValidImageResponse2; +import static org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.createValidMultipartFile1; +import static org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.createValidMultipartFile2; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.times; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import java.nio.file.Paths; import java.util.List; -import java.util.UUID; +import java.util.Random; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -22,8 +29,9 @@ import org.ktc2.cokaen.wouldyouin.Image.application.CurationImageService; import org.ktc2.cokaen.wouldyouin.Image.application.ImageServiceFactory; import org.ktc2.cokaen.wouldyouin.Image.application.ImageStorageService; -import org.ktc2.cokaen.wouldyouin._global.TestData.ImageData; +import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockCurator; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember; +import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData; import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; @@ -55,6 +63,8 @@ class ImageControllerTest { @MockBean private JwtAuthFilter jwtAuthFilter; + private final long randomId = abs(new Random().nextLong()); + @BeforeEach public void setup() throws Exception { @@ -70,61 +80,103 @@ public void setup() throws Exception { void getImage() throws Exception { // given String directory = "member"; - String file = UUID.randomUUID().toString() + ".png"; + String file = "image.jpg"; // when - mockMvc.perform(get("/api/images/" + directory + "/" + file)) + mockMvc.perform(get("/api/images/{directory}/{file}", directory, file)) .andDo(print()) .andExpect(status().isOk()); -// then + // then then(imageStorageService).should(times(1)).readFromDirectory(eq(Paths.get(directory, file))); } -// @PostMapping -// public ResponseEntity>> uploadImages( -// @RequestParam List images, -// @RequestParam(value = "type") ImageDomain imageDomain) { -// return ApiResponse.ok(imageServiceFactory.getImageService(imageDomain).saveImages(images)); -// } - @Test - @WithMockMember - void uploadImages() throws Exception { -// // given - MockMultipartFile image1 = ImageData.createValidMultipartFile1(); - MockMultipartFile image2 = ImageData.createValidMultipartFile2(); + @DisplayName("RequestParam으로 이미지 도메인을 받아 첨부된 이미지를 업로드한다.") + @WithMockCurator + void uploadImages1() throws Exception { + // given + MockMultipartFile image1 = createValidMultipartFile1(); + MockMultipartFile image2 = createValidMultipartFile2(); given((CurationImageService) imageServiceFactory.getImageService(ImageDomain.CURATION)).willReturn(curationImageService); given(curationImageService.saveImages(List.of(image1, image2))) - .willReturn(List.of(ImageData.createValidImageResponse1(), ImageData.createValidImageResponse2())); + .willReturn(List.of(createValidImageResponse1(), createValidImageResponse2())); -// // when - mockMvc.perform(multipart("/api/images?type=CURATION") - .file(ImageData.createValidMultipartFile1()) - .file(ImageData.createValidMultipartFile2()) + // when + mockMvc.perform(multipart("/api/images") + .file(image1) + .file(image2) .contentType(MediaType.MULTIPART_FORM_DATA) .param("type", ImageDomain.CURATION.name()) .with(csrf())) .andDo(print()) .andExpect(status().isOk()); -// ArgumentCaptor captor = ArgumentCaptor.forClass(CurationCreateRequest.class); -// CurationCreateRequest request = CurationDomain.createValidCurationCreateRequest(); + // then + then(imageServiceFactory).should(times(1)).getImageService(eq(ImageDomain.CURATION)); + then(curationImageService).should(times(1)).saveImages(List.of(image1, image2)); + } + + @Test + @DisplayName("RequestParam의 이미지 도메인의 값으로는 MEMBER, CURATION, ADVERTISEMENT, EVENT만 사용할 수 있다.") + @WithMockCurator + void uploadImages2() throws Exception { + // given + MockMultipartFile image1 = createValidMultipartFile1(); + MockMultipartFile image2 = createValidMultipartFile2(); // when -// mockMvc.perform(post("/api/curations") -// .with(csrf()) -// .contentType(MediaType.APPLICATION_JSON) -// .content(objectMapper.writeValueAsString(request))) -// .andDo(print()) -// .andExpect(status().isCreated()); -// -// // then -// then(curationService).should(times(1)).create(eq(MemberDomain.validCuratorId), captor.capture()); -// assertThat(captor.getValue()).isEqualTo(request); + mockMvc.perform(multipart("/api/images") + .file(image1) + .file(image2) + .contentType(MediaType.MULTIPART_FORM_DATA) + .param("type", "INVALID") + .with(csrf())) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("해당 이미지 도메인에 대한 서비스가 존재하지 않습니다.")); + + // then + then(imageServiceFactory).shouldHaveNoInteractions(); + then(curationImageService).shouldHaveNoInteractions(); } @Test - void deleteImage() { + @DisplayName("PathVariable로 이미지의 ID를 받아 이미지를 삭제한다.") + @WithMockCurator + void deleteImage1() throws Exception { + // given + given((CurationImageService) imageServiceFactory.getImageService(ImageDomain.CURATION)).willReturn(curationImageService); + + // when + mockMvc.perform(delete("/api/images/" + randomId) + .param("type", ImageDomain.CURATION.name()) + .with(csrf())) + .andDo(print()) + .andExpect(status().isNoContent()); + + // then + then(imageServiceFactory).should(times(1)).getImageService(eq(ImageDomain.CURATION)); + then(curationImageService).should(times(1)).deleteImage(randomId); + } + + @Test + @DisplayName("RequestParam의 이미지 도메인의 값으로는 MEMBER, CURATION, ADVERTISEMENT, EVENT만 사용할 수 있다.") + @WithMockCurator + void deleteImage2() throws Exception { + // given + given((CurationImageService) imageServiceFactory.getImageService(ImageDomain.CURATION)).willReturn(curationImageService); + + // when + mockMvc.perform(delete("/api/images/" + randomId) + .param("type", "INVALID") + .with(csrf())) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("해당 이미지 도메인에 대한 서비스가 존재하지 않습니다.")); + + // then + then(imageServiceFactory).shouldHaveNoInteractions(); + then(curationImageService).shouldHaveNoInteractions(); } } \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberServiceUnitTest.java index 23f7fd54..28968e9e 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberServiceUnitTest.java @@ -2,14 +2,14 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain.createValidCurator; -import static org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain.createValidHost; -import static org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain.createValidMember; -import static org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain.createValidWelcomeMember; -import static org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain.validCuratorId; -import static org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain.validHostId; -import static org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain.validMemberId; -import static org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain.validWelcomeMemberId; +import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidCurator; +import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidHost; +import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidMember; +import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidWelcomeMember; +import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.validCuratorId; +import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.validHostId; +import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.validMemberId; +import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.validWelcomeMemberId; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java index e0fe3e54..31a5b87f 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java @@ -1,9 +1,8 @@ package org.ktc2.cokaen.wouldyouin.member.application; import static org.assertj.core.api.Assertions.assertThat; -import static org.ktc2.cokaen.wouldyouin._global.TestData.ImageData.createValidMemberImage; -import static org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain.createValidCurator; -import static org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain.createValidMember; +import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidCurator; +import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidMember; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; @@ -15,10 +14,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.ktc2.cokaen.wouldyouin.Image.application.MemberImageService; -import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; -import org.ktc2.cokaen.wouldyouin._common.vo.Area; -import org.ktc2.cokaen.wouldyouin._global.TestUtil; -import org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit.CuratorEditRequest; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMemberRepository; import org.ktc2.cokaen.wouldyouin.member.persist.Curator; import org.ktc2.cokaen.wouldyouin.member.persist.CuratorRepository; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java index 25c13d4c..0c518e8e 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java @@ -1,8 +1,8 @@ package org.ktc2.cokaen.wouldyouin.member.application; import static org.assertj.core.api.Assertions.assertThat; -import static org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain.createValidHost; -import static org.ktc2.cokaen.wouldyouin._global.TestData.ImageData.createValidMemberImage; +import static org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.createValidMemberImage; +import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidHost; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.times; @@ -88,7 +88,7 @@ void createHost() { void updateHost() { // given Long newProfileImageId = 5L; - MemberImage newProfileImage = createValidMemberImage(newProfileImageId); + MemberImage newProfileImage = createValidMemberImage(); newProfileImage.setBaseMember(validHost); HostEditRequest editRequest = HostEditRequest.builder() .nickname(TestUtil.getOrNull("newNickname")) diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java index 1fbcb3eb..e26283f6 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java @@ -2,9 +2,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.ktc2.cokaen.wouldyouin._global.TestData.ImageData.createValidMemberImage; -import static org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain.createValidMember; -import static org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain.createValidWelcomeMember; +import static org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.createValidMemberImage; +import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidMember; +import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidWelcomeMember; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.never; @@ -76,7 +76,7 @@ void createMember() { @DisplayName("사용자 업데이트 테스트") void updateMember() { // given - MemberImage validMemberImage = createValidMemberImage(5L); + MemberImage validMemberImage = createValidMemberImage(); Long givenMemberId = validMember.getId(); given(memberRepository.findById(givenMemberId)).willReturn(Optional.of(validMember)); given(memberImageService.getById(validMember.getProfileImage().getId())).willReturn(validMemberImage); diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java index 8c9711ee..1e9c2195 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java @@ -2,6 +2,9 @@ import static java.lang.Math.abs; import static org.assertj.core.api.Assertions.assertThat; +import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.validCuratorId; +import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.validHostId; +import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.validMemberId; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.times; @@ -19,7 +22,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain; import org.ktc2.cokaen.wouldyouin._global.TestData.ReservationDomain; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockCurator; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost; @@ -78,7 +80,7 @@ void getReservationsByMemberId1() throws Exception { // then then(reservationService).should(times(1)).getAllByMemberId( - eq(MemberDomain.validMemberId), eq(PageRequest.of(5, 20)), eq(100L)); + eq(validMemberId), eq(PageRequest.of(5, 20)), eq(100L)); } @Test @@ -91,7 +93,7 @@ void getReservationsByMemberId2() throws Exception { // then then(reservationService).should(times(1)).getAllByMemberId( - eq(MemberDomain.validMemberId), eq(PageRequest.of(0, 10)), eq(Long.MAX_VALUE)); + eq(validMemberId), eq(PageRequest.of(0, 10)), eq(Long.MAX_VALUE)); } @Test @@ -107,7 +109,7 @@ void getReservationsByMemberId3() throws Exception { // then then(reservationService).should(times(1)).getAllByMemberId( - eq(MemberDomain.validCuratorId), eq(PageRequest.of(5, 20)), eq(100L)); + eq(validCuratorId), eq(PageRequest.of(5, 20)), eq(100L)); } @Test @@ -139,7 +141,7 @@ void getReservationByEventId1() throws Exception { // then then(reservationService).should(times(1)).getAllByEventId( - eq(MemberDomain.validHostId), eq(randomId), eq(PageRequest.of(5, 20)), eq(100L)); + eq(validHostId), eq(randomId), eq(PageRequest.of(5, 20)), eq(100L)); } @Test @@ -153,7 +155,7 @@ void getReservationByEventId2() throws Exception { // then then(reservationService).should(times(1)).getAllByEventId( - eq(MemberDomain.validHostId), eq(randomId), eq(PageRequest.of(0, 10)), eq(Long.MAX_VALUE)); + eq(validHostId), eq(randomId), eq(PageRequest.of(0, 10)), eq(Long.MAX_VALUE)); } @Test @@ -214,7 +216,7 @@ void createReservation1() throws Exception { .andExpect(status().isCreated()); // then - then(reservationService).should(times(1)).create(eq(MemberDomain.validMemberId), captor.capture()); + then(reservationService).should(times(1)).create(eq(validMemberId), captor.capture()); assertThat(captor.getValue()).isEqualTo(request); } @@ -235,7 +237,7 @@ void createReservation2() throws Exception { .andExpect(status().isCreated()); // then - then(reservationService).should(times(1)).create(eq(MemberDomain.validCuratorId), captor.capture()); + then(reservationService).should(times(1)).create(eq(validCuratorId), captor.capture()); assertThat(captor.getValue()).isEqualTo(request); } @@ -330,7 +332,7 @@ void deleteReservation1() throws Exception { .andExpect(status().isNoContent()); // then - then(reservationService).should(times(1)).delete(MemberDomain.validMemberId, randomId); + then(reservationService).should(times(1)).delete(validMemberId, randomId); } @Test @@ -344,7 +346,7 @@ void deleteReservation2() throws Exception { .andExpect(status().isNoContent()); // then - then(reservationService).should(times(1)).delete(MemberDomain.validCuratorId, randomId); + then(reservationService).should(times(1)).delete(validCuratorId, randomId); } @Test From 1624888ad3d3769d66dd5c1a96efa96720912603 Mon Sep 17 00:00:00 2001 From: ariimo Date: Wed, 13 Nov 2024 00:57:19 +0900 Subject: [PATCH 17/53] =?UTF-8?q?[Weekly/11/Refactor/Review]=20Review=20?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=A7=80=EB=84=A4=EC=9D=B4=EC=85=98=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9,=20Review=20validation=20=EC=A0=81=EC=9A=A9?= =?UTF-8?q?=20(#116)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: ReservationNotFoundForReviewException 생성 * refactor: FetchType.LAZY 적용 * feat: Event 코드 컨벤션 적용 * feat(Reservation): memberId, eventId에 해당하는 예약 여부 확인 메서드 작성 * feat: Review Validatoin 추가 * feat: ReviewSliceResponse 생성 * feat(review): Review 페이지네이션 적용 --- .../wouldyouin/_common/error/ErrorCode.java | 2 + ...ReservationNotFoundForReviewException.java | 9 +++ .../wouldyouin/event/api/EventController.java | 7 +- .../event/api/dto/EventCreateRequest.java | 1 - .../event/api/dto/EventEditRequest.java | 15 ---- .../event/api/dto/EventResponse.java | 1 - .../event/api/dto/EventSliceResponse.java | 3 - .../event/application/EventService.java | 34 ++++++---- .../wouldyouin/event/persist/Event.java | 5 +- .../event/persist/EventRepository.java | 3 +- .../cokaen/wouldyouin/like/persist/Like.java | 5 +- .../application/ReservationService.java | 8 +++ .../persist/ReservationRepository.java | 2 + .../review/api/ReviewController.java | 68 +++++++++++-------- .../review/api/dto/ReviewCreateRequest.java | 19 +++++- .../review/api/dto/ReviewEditRequest.java | 12 ++++ .../review/api/dto/ReviewSliceResponse.java | 27 ++++++++ .../review/application/ReviewService.java | 68 ++++++++++++++----- .../wouldyouin/review/persist/Review.java | 6 +- .../review/persist/ReviewRepository.java | 14 +++- 20 files changed, 211 insertions(+), 98 deletions(-) create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/ReservationNotFoundForReviewException.java create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewSliceResponse.java diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/ErrorCode.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/ErrorCode.java index 47e4e115..1eedf58d 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/ErrorCode.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/ErrorCode.java @@ -14,6 +14,8 @@ public enum ErrorCode { NO_LEFT_SEAT(HttpStatus.BAD_REQUEST.value(), "-10400", "남은 좌석이 부족합니다."), + RESERVATION_NOT_FOUND_FOR_REVIEW(HttpStatus.NOT_FOUND.value(), "14044", "리뷰를 작성할 자격이 없습니다."), + INVALID_INPUT_VALUE(HttpStatus.BAD_REQUEST.value(), "-20400", "Invalid Input Value"), FAIL_TO_READ_IMAGE(HttpStatus.CONFLICT.value(), "-20400", "Fail to read image"), diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/ReservationNotFoundForReviewException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/ReservationNotFoundForReviewException.java new file mode 100644 index 00000000..af17d83d --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/ReservationNotFoundForReviewException.java @@ -0,0 +1,9 @@ +package org.ktc2.cokaen.wouldyouin._common.exception; + +import org.ktc2.cokaen.wouldyouin._common.error.ErrorCode; + +public class ReservationNotFoundForReviewException extends BusinessException { + public ReservationNotFoundForReviewException(String message) { + super(message, ErrorCode.RESERVATION_NOT_FOUND_FOR_REVIEW); + } +} diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/EventController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/EventController.java index 74fc6d9d..57075ee8 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/EventController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/EventController.java @@ -7,14 +7,14 @@ import org.ktc2.cokaen.wouldyouin._common.api.ParamDefaults; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; -import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationRequest; import org.ktc2.cokaen.wouldyouin.auth.Authorize; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; -import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationFilter; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventResponse; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventSliceResponse; +import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationFilter; +import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationRequest; import org.ktc2.cokaen.wouldyouin.event.application.EventService; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.springframework.data.domain.PageRequest; @@ -49,7 +49,8 @@ public ResponseEntity> getEventsByFilterOrde @RequestParam(defaultValue = ParamDefaults.LAST_ID) Long lastId ) { return ApiResponse.ok(eventService.getAllByFilterOrderByDistanceAsc( - locationFilter, currentLocation, title, category, area, PageRequest.of(page, size), lastId)); + locationFilter, currentLocation, title, category, area, PageRequest.of(page, size), + lastId)); } @GetMapping("/hosts/{hostId}") diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java index 104648c4..43b8f01f 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java @@ -9,7 +9,6 @@ import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; import java.time.LocalDateTime; -import java.util.ArrayList; import java.util.List; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventEditRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventEditRequest.java index ae28f0bc..aff0cd41 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventEditRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventEditRequest.java @@ -15,7 +15,6 @@ import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; import org.ktc2.cokaen.wouldyouin._common.vo.Location; -import org.ktc2.cokaen.wouldyouin.event.persist.Event; @Getter @Builder(toBuilder = true) @@ -67,18 +66,4 @@ public boolean isEndTimeAfterStartTime() { public boolean isImageSizeValid() { return imageIds.size() <= 5; } - - public Event toEntity() { - return Event.builder() - .title(title) - .content(content) - .area(area) - .location(location) - .startTime(startTime) - .endTime(endTime) - .price(price) - .totalSeat(totalSeat) - .category(category) - .build(); - } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventResponse.java index 4c932c2c..4e019415 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventResponse.java @@ -4,7 +4,6 @@ import java.util.List; import lombok.Builder; import lombok.Getter; -import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageResponse; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; import org.ktc2.cokaen.wouldyouin._common.vo.Location; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventSliceResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventSliceResponse.java index b9870f98..d974a17f 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventSliceResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventSliceResponse.java @@ -3,10 +3,7 @@ import java.util.List; import lombok.Builder; import lombok.Getter; -import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageResponse; import org.ktc2.cokaen.wouldyouin._common.api.SliceInfo; -import org.ktc2.cokaen.wouldyouin.event.persist.Event; -import org.springframework.data.domain.Slice; @Getter @Builder diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java index 706d6472..911af259 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java @@ -2,7 +2,6 @@ import java.util.List; import lombok.RequiredArgsConstructor; -import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageResponse; import org.ktc2.cokaen.wouldyouin.Image.application.EventImageService; import org.ktc2.cokaen.wouldyouin.Image.persist.EventImage; import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; @@ -10,12 +9,12 @@ import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; -import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationRequest; -import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationFilter; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventResponse; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventSliceResponse; +import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationFilter; +import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationRequest; import org.ktc2.cokaen.wouldyouin.event.persist.Event; import org.ktc2.cokaen.wouldyouin.event.persist.EventRepository; import org.ktc2.cokaen.wouldyouin.member.application.HostService; @@ -33,9 +32,17 @@ public class EventService { private final HostService hostService; private final EventImageService eventImageService; + private static Long getLastId(Slice events, Long oldLastId) { + if (events.hasContent()) { + return events.getContent().getLast().getId(); + } + return oldLastId; + } + @Transactional public Event getByIdOrThrow(Long id) throws EntityNotFoundException { - return eventRepository.findById(id).orElseThrow(() -> new EntityNotFoundException("해당하는 이벤트를 찾을 수 없습니다.")); + return eventRepository.findById(id) + .orElseThrow(() -> new EntityNotFoundException("해당하는 이벤트를 찾을 수 없습니다.")); } @Transactional(readOnly = true) @@ -45,11 +52,13 @@ public EventResponse getById(Long id) { } @Transactional(readOnly = true) - public EventSliceResponse getAllByFilterOrderByDistanceAsc(LocationFilter location, LocationRequest currentLocation, String title, + public EventSliceResponse getAllByFilterOrderByDistanceAsc(LocationFilter location, + LocationRequest currentLocation, String title, Category category, Area area, Pageable pageable, Long beforeLastId) { Slice events = eventRepository.findAllByFilterOrderByDistance( location.getStartLatitude(), location.getStartLongitude(), location.getEndLatitude(), - location.getEndLongitude(), currentLocation.getLatitude(), currentLocation.getLongitude(), + location.getEndLongitude(), currentLocation.getLatitude(), + currentLocation.getLongitude(), title, category, area, pageable ); Long newLastId = getLastId(events, beforeLastId); @@ -58,8 +67,10 @@ public EventSliceResponse getAllByFilterOrderByDistanceAsc(LocationFilter locati } @Transactional(readOnly = true) - public EventSliceResponse getAllByHostIdOrderByCreatedDateDesc(Long hostId, Pageable pageable, Long beforeLastId) { - Slice events = eventRepository.findAllByHostIdOrderByEventIdDesc(hostId, beforeLastId, pageable); + public EventSliceResponse getAllByHostIdOrderByCreatedDateDesc(Long hostId, Pageable pageable, + Long beforeLastId) { + Slice events = eventRepository.findAllByHostIdOrderByEventIdDesc(hostId, + beforeLastId, pageable); Long newLastId = getLastId(events, beforeLastId); List responses = events.stream().map(this::getEventResponse).toList(); return EventSliceResponse.from(responses, events.getSize(), newLastId); @@ -102,13 +113,6 @@ public void decreaseLeftSeat(Long eventId, Integer count) { event.decreaseLeftSeat(count); } - private static Long getLastId(Slice events, Long oldLastId) { - if (events.hasContent()) { - return events.getContent().getLast().getId(); - } - return oldLastId; - } - public void validateHostId(Long hostId, Event event) { if (!hostId.equals(event.getHost().getId())) { throw new UnauthorizedException("호스트 ID가 행사의 호스트 ID와 일치하지 않습니다."); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java index 309e37c5..5aa0724a 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java @@ -56,7 +56,7 @@ public class Event { private String content; @NotNull - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "host_id") private Host host; @@ -107,7 +107,8 @@ public class Event { @Builder protected Event(String title, String content, Host host, Area area, Location location, - LocalDateTime startTime, LocalDateTime endTime, Integer price, Integer totalSeat, Category category, List images) { + LocalDateTime startTime, LocalDateTime endTime, Integer price, Integer totalSeat, + Category category, List images) { this.title = title; this.content = content; this.host = host; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/EventRepository.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/EventRepository.java index 837f5463..efa63ff6 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/EventRepository.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/EventRepository.java @@ -27,5 +27,6 @@ public interface EventRepository extends JpaRepository { + "(:currentLongitude - E.location.longitude) * (:currentLongitude - E.location.longitude) ASC") Slice findAllByFilterOrderByDistance( Double startLatitude, Double startLongitude, Double endLatitude, Double endLongitude, - Double currentLatitude, Double currentLongitude, String title, Category category, Area area, Pageable pageable); + Double currentLatitude, Double currentLongitude, String title, Category category, Area area, + Pageable pageable); } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/Like.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/Like.java index 0bc22682..5f7bf605 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/Like.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/Like.java @@ -1,6 +1,7 @@ package org.ktc2.cokaen.wouldyouin.like.persist; import jakarta.persistence.Column; +import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; @@ -28,7 +29,7 @@ public abstract class Like { private Long id; @NotNull - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn private T likeableMember; @@ -37,7 +38,7 @@ public abstract class Like { private MemberType likeableMemberType; @NotNull - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn private Member member; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java index 17e1efb5..27af730e 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java @@ -2,6 +2,7 @@ import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; +import org.ktc2.cokaen.wouldyouin._common.exception.ReservationNotFoundForReviewException; import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; import org.ktc2.cokaen.wouldyouin.event.application.EventService; import org.ktc2.cokaen.wouldyouin.member.application.MemberService; @@ -38,6 +39,13 @@ public ReservationResponse getById(Long id) { return ReservationResponse.from(getByIdOrThrow(id)); } + @Transactional + public void validateByMemberIdAndEventId(Long memberId, Long eventId) { + if (reservationRepository.findByMemberIdAndEventId(memberId, eventId) == null) { + throw new ReservationNotFoundForReviewException("해당 이벤트에 대한 리뷰를 작성할 자격이 없습니다."); + } + } + @Transactional(readOnly = true) public ReservationSliceResponse getAllByMemberId(Long memberId, Pageable pageable, Long oldLastId) { Slice reservations = reservationRepository.findByMemberIdOrderByReservationIdDesc(memberId, oldLastId, pageable); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/ReservationRepository.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/ReservationRepository.java index bddac660..cc3bcbc2 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/ReservationRepository.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/ReservationRepository.java @@ -18,4 +18,6 @@ public interface ReservationRepository extends JpaRepository + "WHERE R.event.id = :eventId AND R.id > :lastId " + "ORDER BY R.id DESC") Slice findByEventIdOrderByReservationIdDesc(Long eventId, Long lastId, Pageable pageable); + + Reservation findByMemberIdAndEventId(Long memberId, Long eventId); } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/ReviewController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/ReviewController.java index f9637cf4..af5f422a 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/ReviewController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/ReviewController.java @@ -1,13 +1,19 @@ package org.ktc2.cokaen.wouldyouin.review.api; -import java.util.List; +import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; +import org.ktc2.cokaen.wouldyouin._common.api.ApiResponse; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponseBody; -import org.ktc2.cokaen.wouldyouin.review.application.ReviewService; +import org.ktc2.cokaen.wouldyouin._common.api.ParamDefaults; +import org.ktc2.cokaen.wouldyouin.auth.Authorize; +import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; +import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.ktc2.cokaen.wouldyouin.review.api.dto.ReviewCreateRequest; import org.ktc2.cokaen.wouldyouin.review.api.dto.ReviewEditRequest; import org.ktc2.cokaen.wouldyouin.review.api.dto.ReviewResponse; -import org.springframework.http.HttpStatus; +import org.ktc2.cokaen.wouldyouin.review.api.dto.ReviewSliceResponse; +import org.ktc2.cokaen.wouldyouin.review.application.ReviewService; +import org.springframework.data.domain.PageRequest; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; @@ -16,6 +22,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.RequestParam; import org.springframework.web.bind.annotation.RestController; @RestController @@ -25,51 +32,52 @@ public class ReviewController { private final ReviewService reviewService; - // ToDo: ApiResponse 정적메서드 활용 - - @GetMapping("/{memberId}") - public ResponseEntity>> getReviewsByMemberId( - @PathVariable("memberId") Long memberId) { - return ResponseEntity.status(HttpStatus.OK) - .body(new ApiResponseBody<>(true, reviewService.getAllByMemberId(memberId))); + @GetMapping + public ResponseEntity> getReviewsByMemberId( + @Authorize({MemberType.normal}) MemberIdentifier member, + @RequestParam(defaultValue = ParamDefaults.PAGE) Integer page, + @RequestParam(defaultValue = ParamDefaults.PAGE_SIZE) Integer size, + @RequestParam(defaultValue = ParamDefaults.LAST_ID) Long lastId) { + return ApiResponse.ok( + reviewService.getAllByMemberId(member.id(), lastId, PageRequest.of(page, size))); } - @GetMapping("/{eventId}") - public ResponseEntity>> getReviewsByEventId( - @PathVariable("eventId") Long eventId) { - return ResponseEntity.status(HttpStatus.OK) - .body(new ApiResponseBody<>(true, reviewService.getAllByEventId(eventId))); + @GetMapping("/events/{eventId}") + public ResponseEntity> getReviewsByEventId( + @PathVariable("eventId") Long eventId, + @RequestParam(defaultValue = ParamDefaults.PAGE) Integer page, + @RequestParam(defaultValue = ParamDefaults.PAGE_SIZE) Integer size, + @RequestParam(defaultValue = ParamDefaults.LAST_ID) Long lastId) { + return ApiResponse.ok( + reviewService.getAllByEventId(eventId, lastId, PageRequest.of(page, size))); } @GetMapping("/{reviewId}") public ResponseEntity> getReviewByReviewId( @PathVariable("reviewId") Long reviewId) { - return ResponseEntity.status(HttpStatus.OK) - .body(new ApiResponseBody<>(true, reviewService.getById(reviewId))); + return ApiResponse.ok(reviewService.getById(reviewId)); } - @PostMapping("/{eventId}") + @PostMapping public ResponseEntity> createReview( - @PathVariable("eventId") Long eventId, - @RequestBody ReviewCreateRequest reviewCreateRequest) { - return ResponseEntity.status(HttpStatus.OK) - .body(new ApiResponseBody<>(true, reviewService.create(eventId, reviewCreateRequest))); + @Authorize(MemberType.normal) MemberIdentifier member, + @Valid @RequestBody ReviewCreateRequest reviewCreateRequest) { + return ApiResponse.created(reviewService.create(member.id(), reviewCreateRequest)); } @PutMapping("/{reviewId}") public ResponseEntity> updateReview( @PathVariable("reviewId") Long reviewId, - @RequestBody ReviewEditRequest reviewEditRequest) { - return ResponseEntity.status(HttpStatus.OK) - .body(new ApiResponseBody<>(true, reviewService.update(reviewId, reviewEditRequest))); + @Authorize(MemberType.normal) MemberIdentifier member, + @Valid @RequestBody ReviewEditRequest reviewEditRequest) { + return ApiResponse.ok(reviewService.update(member.id(), reviewId, reviewEditRequest)); } @DeleteMapping("/{reviewId}") public ResponseEntity> deleteReview( - @PathVariable("reviewId") Long reviewId) { - reviewService.delete(reviewId); - return ResponseEntity.status(HttpStatus.NO_CONTENT) - .body(new ApiResponseBody<>(true, null)); + @PathVariable("reviewId") Long reviewId, + @Authorize(MemberType.normal) MemberIdentifier member) { + reviewService.delete(member.id(), reviewId); + return ApiResponse.noContent(); } - } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewCreateRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewCreateRequest.java index 406ee397..9a1b4bd6 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewCreateRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewCreateRequest.java @@ -1,18 +1,33 @@ package org.ktc2.cokaen.wouldyouin.review.api.dto; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import lombok.Builder; import lombok.Getter; +import org.ktc2.cokaen.wouldyouin.event.persist.Event; +import org.ktc2.cokaen.wouldyouin.member.persist.Member; import org.ktc2.cokaen.wouldyouin.review.persist.Review; @Getter @Builder public class ReviewCreateRequest { - private Long memberId; + @NotNull(message = "이벤트 ID는 필수입니다.") + private Long eventId; + + @NotBlank(message = "별점은 필수입니다.") + @Min(value = 0, message = "별점은 0점 이상입니다. ") + @Max(value = 5, message = "별점은 5점 이하입니다. ") private int score; + + @NotBlank(message = "내용은 필수입니다. ") + @Size(min = 5, max = 50, message = "내용은 5자 이상 50자 이하입니다.") private String content; - public Review toEntity() { + public Review toEntity(Member member, Event event) { return Review.builder() .score(this.score) .content(this.content) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewEditRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewEditRequest.java index 7b070079..03a03676 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewEditRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewEditRequest.java @@ -1,5 +1,11 @@ package org.ktc2.cokaen.wouldyouin.review.api.dto; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Positive; +import jakarta.validation.constraints.PositiveOrZero; +import jakarta.validation.constraints.Size; import lombok.Builder; import lombok.Getter; @@ -7,6 +13,12 @@ @Builder(toBuilder = true) public class ReviewEditRequest { + @NotBlank(message = "별점은 필수입니다.") + @Min(value = 0, message = "별점은 0점 이상입니다. ") + @Max(value = 5, message = "별점은 5점 이하입니다. ") private Integer score; + + @NotBlank(message = "내용은 필수입니다. ") + @Size(min = 5, max = 50, message = "내용은 5자 이상 50자 이하입니다.") private String content; } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewSliceResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewSliceResponse.java new file mode 100644 index 00000000..39397ca7 --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewSliceResponse.java @@ -0,0 +1,27 @@ +package org.ktc2.cokaen.wouldyouin.review.api.dto; + +import java.util.List; +import lombok.Builder; +import lombok.Getter; +import org.ktc2.cokaen.wouldyouin._common.api.SliceInfo; +import org.ktc2.cokaen.wouldyouin.review.persist.Review; +import org.springframework.data.domain.Slice; + +@Getter +@Builder +public class ReviewSliceResponse { + + private List reviews; + private SliceInfo sliceInfo; + + public static ReviewSliceResponse from(Slice reviews, int size, Long lastId) { + return ReviewSliceResponse.builder() + .reviews(reviews.stream() + .map(ReviewResponse::from).toList()) + .sliceInfo(SliceInfo.builder() + .sliceSize(size) + .lastId(lastId) + .build()) + .build(); + } +} diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/review/application/ReviewService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/review/application/ReviewService.java index e0875dd8..77b7c570 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/review/application/ReviewService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/review/application/ReviewService.java @@ -1,15 +1,22 @@ package org.ktc2.cokaen.wouldyouin.review.application; -import java.util.List; import lombok.AccessLevel; import lombok.RequiredArgsConstructor; +import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; +import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; import org.ktc2.cokaen.wouldyouin.event.application.EventService; +import org.ktc2.cokaen.wouldyouin.event.persist.Event; import org.ktc2.cokaen.wouldyouin.member.application.MemberService; +import org.ktc2.cokaen.wouldyouin.member.persist.Member; +import org.ktc2.cokaen.wouldyouin.reservation.application.ReservationService; import org.ktc2.cokaen.wouldyouin.review.api.dto.ReviewCreateRequest; import org.ktc2.cokaen.wouldyouin.review.api.dto.ReviewEditRequest; import org.ktc2.cokaen.wouldyouin.review.api.dto.ReviewResponse; +import org.ktc2.cokaen.wouldyouin.review.api.dto.ReviewSliceResponse; import org.ktc2.cokaen.wouldyouin.review.persist.Review; import org.ktc2.cokaen.wouldyouin.review.persist.ReviewRepository; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -20,43 +27,70 @@ public class ReviewService { private final ReviewRepository reviewRepository; private final EventService eventService; private final MemberService memberService; + private final ReservationService reservationService; @Transactional(readOnly = true) public ReviewResponse getById(Long reviewId) { - Review target = reviewRepository.findById(reviewId).orElseThrow(RuntimeException::new); - return ReviewResponse.from(target); + return ReviewResponse.from(getByIdOrThrow(reviewId)); } @Transactional(readOnly = true) - public List getAllByMemberId(Long memberId) { - return reviewRepository.findByMemberId(memberId).stream().map(ReviewResponse::from) - .toList(); + public ReviewSliceResponse getAllByMemberId(Long memberId, Long oldLastId, Pageable pageable) { + Slice reviews = reviewRepository.findByMemberIdOrderByReviewIdDesc(memberId, + oldLastId, pageable); + Long newLastId = getLastId(reviews, oldLastId); + return ReviewSliceResponse.from(reviews, reviews.getSize(), newLastId); } @Transactional(readOnly = true) - public List getAllByEventId(Long eventId) { - return reviewRepository.findByEventId(eventId).stream().map(ReviewResponse::from) - .toList(); + public ReviewSliceResponse getAllByEventId(Long eventId, Long oldLastId, Pageable pageable) { + Slice reviews = reviewRepository.findByEventIdOrderByReviewIdDesc(eventId, + oldLastId, pageable); + Long newLastId = getLastId(reviews, oldLastId); + return ReviewSliceResponse.from(reviews, reviews.getSize(), newLastId); + } + + private Long getLastId(Slice reviews, Long oldLastId) { + if (reviews.hasContent()) { + return reviews.getContent().getLast().getId(); + } + return oldLastId; } @Transactional - public ReviewResponse create(Long eventId, ReviewCreateRequest reviewCreateRequest) { - Review review = reviewRepository.save(reviewCreateRequest.toEntity()); - review.setMember(memberService.getByIdOrThrow(reviewCreateRequest.getMemberId())); - review.setEvent(eventService.getByIdOrThrow(eventId)); + public ReviewResponse create(Long memberId, ReviewCreateRequest reviewCreateRequest) { + reservationService.validateByMemberIdAndEventId(memberId, reviewCreateRequest.getEventId()); + Review review = reviewRepository.save( + reviewCreateRequest.toEntity( + memberService.getByIdOrThrow(memberId), + eventService.getByIdOrThrow(reviewCreateRequest.getEventId()))); return ReviewResponse.from(review); } @Transactional - public ReviewResponse update(Long reviewId, ReviewEditRequest reviewEditRequest) { - Review target = reviewRepository.findById(reviewId).orElseThrow(RuntimeException::new); + public ReviewResponse update(Long memberId, Long reviewId, + ReviewEditRequest reviewEditRequest) { + Review target = getByIdOrThrow(reviewId); + validateMemberId(memberId, target); target.updateFrom(reviewEditRequest); return ReviewResponse.from(target); } @Transactional - public void delete(Long reviewId) { - reviewRepository.findById(reviewId).orElseThrow(RuntimeException::new); + public void delete(Long memberId, Long reviewId) { + validateMemberId(memberId, getByIdOrThrow(reviewId)); reviewRepository.deleteById(reviewId); } + + @Transactional + public Review getByIdOrThrow(Long id) { + return reviewRepository.findById(id) + .orElseThrow(() -> new EntityNotFoundException("해당하는 리뷰를 찾을 수 없습니다.")); + } + + private void validateMemberId(Long memberId, Review review) { + if (!memberId.equals(review.getMember().getId())) { + throw new UnauthorizedException("member ID가 리뷰의 member ID와 일치하지 않습니다."); + } + } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/review/persist/Review.java b/src/main/java/org/ktc2/cokaen/wouldyouin/review/persist/Review.java index 2316be65..a48a46b9 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/review/persist/Review.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/review/persist/Review.java @@ -1,8 +1,8 @@ package org.ktc2.cokaen.wouldyouin.review.persist; -import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; @@ -32,11 +32,11 @@ public class Review { @Column(name = "review_id") private Long id; - @ManyToOne(cascade = CascadeType.ALL) + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "member_id") private Member member; - @ManyToOne(cascade = CascadeType.ALL) + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "event_id") private Event event; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/review/persist/ReviewRepository.java b/src/main/java/org/ktc2/cokaen/wouldyouin/review/persist/ReviewRepository.java index bd430639..d06dcc58 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/review/persist/ReviewRepository.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/review/persist/ReviewRepository.java @@ -1,13 +1,21 @@ package org.ktc2.cokaen.wouldyouin.review.persist; -import java.util.List; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; @Repository public interface ReviewRepository extends JpaRepository { - List findByMemberId(Long memberId); + @Query("SELECT R FROM Review R JOIN FETCH R.member JOIN FETCH R.event " + + "WHERE R.member.id = :memberId AND R.id > :lastId " + + "ORDER BY R.id DESC") + Slice findByMemberIdOrderByReviewIdDesc(Long memberId, Long lastId, Pageable pageable); - List findByEventId(Long eventId); + @Query("SELECT R FROM Review R JOIN FETCH R.member JOIN FETCH R.event " + + "WHERE R.event.id = :eventId AND R.id > :lastId " + + "ORDER BY R.id DESC") + Slice findByEventIdOrderByReviewIdDesc(Long eventId, Long lastId, Pageable pageable); } From fd0147359454fc6ea0ce81cd2f4606aedc1e141a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=99=8D=EC=8B=9D?= <90020593+Daolove0323@users.noreply.github.com> Date: Wed, 13 Nov 2024 01:12:29 +0900 Subject: [PATCH 18/53] [Weekly/11] Feature/image/delete (#117) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 해시태그 네이밍 통일 * feat: 이벤트 응답 수정 * feat: validate member * feat: import 추가 --- .../wouldyouin/Image/api/ImageController.java | 17 ++++--- .../Image/api/dto/ImageResponse.java | 4 +- .../AdvertisementImageService.java | 13 ++++- .../application/CurationImageService.java | 13 ++++- .../Image/application/EventImageService.java | 12 ++++- .../Image/application/ImageService.java | 15 ++++-- .../Image/application/MemberImageService.java | 12 ++++- .../Image/persist/AdvertisementImage.java | 6 ++- .../Image/persist/CurationImage.java | 6 ++- .../wouldyouin/Image/persist/EventImage.java | 6 ++- .../wouldyouin/Image/persist/MemberImage.java | 6 ++- .../api/AdvertisementController.java | 8 ++-- .../application/AdvertisementService.java | 9 ++-- .../curation/api/CurationController.java | 12 ++--- .../curation/api/dto/CurationResponse.java | 6 ++- .../application/CurationCardService.java | 5 +- .../curation/application/CurationService.java | 24 +++++----- .../wouldyouin/curation/persist/Curation.java | 1 - .../wouldyouin/event/api/EventController.java | 12 ++--- .../event/api/dto/EventResponse.java | 1 + .../event/api/dto/EventSliceResponse.java | 1 + .../event/application/EventService.java | 48 +++++++++---------- .../wouldyouin/member/persist/MemberType.java | 1 - .../api/ReservationController.java | 4 +- .../application/ReservationService.java | 5 +- 25 files changed, 155 insertions(+), 92 deletions(-) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java index fd6fffc6..a0ab2c96 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java @@ -8,6 +8,9 @@ import org.ktc2.cokaen.wouldyouin.Image.application.ImageStorageService; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponse; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponseBody; +import org.ktc2.cokaen.wouldyouin.auth.Authorize; +import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; +import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -33,21 +36,21 @@ public ResponseEntity getImage(@PathVariable String directory, @PathVari return ResponseEntity.status(HttpStatus.OK).body(imageStorageService.readFromDirectory(Paths.get(directory, file))); } - // Todo: authorize @PostMapping public ResponseEntity>> uploadImages( @RequestParam List images, - @RequestParam(value = "type") ImageDomain imageDomain) { + @RequestParam(value = "type") ImageDomain imageDomain, + @Authorize({MemberType.normal, MemberType.curator, MemberType.host}) MemberIdentifier identifier) { return ApiResponse.ok(imageServiceFactory.getImageService(imageDomain).saveImages(images)); } - // Todo: authorize // Todo: 삭제로직 수정필요 - @DeleteMapping("/{id}") + @DeleteMapping("/{imageId}") public ResponseEntity> deleteImage( - @PathVariable Long id, - @RequestParam(value = "type") ImageDomain imageDomain) { - imageServiceFactory.getImageService(imageDomain).deleteImage(id); + @PathVariable Long imageId, + @RequestParam(value = "type") ImageDomain imageDomain, + @Authorize({MemberType.normal, MemberType.curator, MemberType.host}) MemberIdentifier identifier) { + imageServiceFactory.getImageService(imageDomain).deleteImage(identifier, imageId); return ApiResponse.noContent(); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageResponse.java index 347af557..32498c58 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageResponse.java @@ -16,10 +16,10 @@ public class ImageResponse { private String extension; private LocalDateTime createdDate; - public static ImageResponse from(Image image, String path) { + public static ImageResponse from(Image image, String url) { return ImageResponse.builder() .id(image.getId()) - .url(UriUtil.assembleFullUrl(path, image.getName())) + .url(url) .size(image.getSize()) .extension(image.getExtension()) .createdDate(image.getCreatedDate()) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java index ae49285c..a1fa43ef 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java @@ -6,7 +6,10 @@ import org.ktc2.cokaen.wouldyouin.Image.persist.AdvertisementImage; import org.ktc2.cokaen.wouldyouin.Image.persist.AdvertisementImageRepository; import org.ktc2.cokaen.wouldyouin.Image.persist.ImageRepository; +import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; import org.ktc2.cokaen.wouldyouin.advertisement.persist.Advertisement; +import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; +import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -39,12 +42,20 @@ protected String getChildPath() { @Override protected AdvertisementImage toEntity(ImageRequest imageRequest) { return AdvertisementImage.builder() - .url(imageRequest.getUrl()) + .name(imageRequest.getUrl()) .size(imageRequest.getSize()) .extension(imageRequest.getExtension()) .build(); } + // TODO : ad image 삭제 인가 + @Override + protected void validateMemberId(MemberIdentifier identifier, AdvertisementImage image) { + if (!identifier.type().equals(MemberType.admin)) { + throw new UnauthorizedException("광고 이미지에 접근할 권한이 없습니다."); + } + } + @Transactional public AdvertisementImage saveImage(MultipartFile image) { return adImageRepository.save(toEntity(imageStorageService.saveToDirectory(image, getChildPath()))); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/CurationImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/CurationImageService.java index 5493073d..ab1d9a81 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/CurationImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/CurationImageService.java @@ -6,7 +6,10 @@ import org.ktc2.cokaen.wouldyouin.Image.persist.CurationImage; import org.ktc2.cokaen.wouldyouin.Image.persist.CurationImageRepository; import org.ktc2.cokaen.wouldyouin.Image.persist.ImageRepository; +import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; +import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.curation.persist.CurationCard; +import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -37,12 +40,20 @@ protected String getChildPath() { @Override protected CurationImage toEntity(ImageRequest imageRequest) { return CurationImage.builder() - .url(imageRequest.getUrl()) + .name(imageRequest.getUrl()) .size(imageRequest.getSize()) .extension(imageRequest.getExtension()) .build(); } + @Override + protected void validateMemberId(MemberIdentifier identifier, CurationImage image) { + if (!identifier.type().equals(MemberType.admin) && + !identifier.id().equals(image.getCurationCard().getCuration().getCurator().getId())) { + throw new UnauthorizedException("해당 큐레이션 이미지에 접근할 권한이 없습니다."); + } + } + @Transactional public void setCuration(CurationImage image, CurationCard curationCard) { image.setCurationCard(curationCard); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/EventImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/EventImageService.java index a2a020a4..db64e62a 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/EventImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/EventImageService.java @@ -6,7 +6,10 @@ import org.ktc2.cokaen.wouldyouin.Image.persist.EventImage; import org.ktc2.cokaen.wouldyouin.Image.persist.EventImageRepository; import org.ktc2.cokaen.wouldyouin.Image.persist.ImageRepository; +import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; +import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.event.persist.Event; +import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -37,12 +40,19 @@ protected String getChildPath() { @Override protected EventImage toEntity(ImageRequest imageRequest) { return EventImage.builder() - .url(imageRequest.getUrl()) + .name(imageRequest.getUrl()) .size(imageRequest.getSize()) .extension(imageRequest.getExtension()) .build(); } + @Override + protected void validateMemberId(MemberIdentifier identifier, EventImage image) { + if (!identifier.type().equals(MemberType.admin) && !identifier.id().equals(image.getEvent().getHost().getId())) { + throw new UnauthorizedException("해당 이벤트 이미지에 접근할 권한이 없습니다."); + } + } + @Transactional public void setEvent(EventImage image, Event event) { image.setEvent(event); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java index be55e1a5..63898a52 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java @@ -9,6 +9,7 @@ import org.ktc2.cokaen.wouldyouin.Image.persist.ImageRepository; import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; import org.ktc2.cokaen.wouldyouin._common.util.UriUtil; +import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -23,7 +24,7 @@ public abstract class ImageService { protected ImageStorageService imageStorageService; @Value("${image.api-url}") - private String apiUrl; + private String parentPath; protected abstract ImageRepository getImageRepository(); @@ -33,6 +34,8 @@ public abstract class ImageService { protected abstract T toEntity(ImageRequest imageRequest); + protected abstract void validateMemberId(MemberIdentifier identifier, T image); + @Transactional public List saveImages(List images) { return images.stream() @@ -40,10 +43,12 @@ public List saveImages(List images) { .toList(); } + // TODO: delete 이미지 바꿔야함 @Transactional - public void deleteImage(Long id) { - T image = getById(id); - delete(id); + public void deleteImage(MemberIdentifier identifier, Long imageId) { + T image = getById(imageId); + validateMemberId(identifier, image); + delete(imageId); imageStorageService.delete(getChildPath(), image.getName()); } @@ -58,7 +63,7 @@ protected ImageResponse create(ImageRequest imageRequest) { } public String getImageUrl(T image) { - return UriUtil.assembleFullUrl(apiUrl, getChildPath(), image.getName()); + return UriUtil.assembleFullUrl(parentPath, getChildPath(), image.getName()); } protected void delete(Long id) { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java index ddc40e53..7ada23a5 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java @@ -6,7 +6,10 @@ import org.ktc2.cokaen.wouldyouin.Image.persist.ImageRepository; import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImageRepository; +import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; +import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMember; +import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -37,12 +40,19 @@ protected String getChildPath() { @Override protected MemberImage toEntity(ImageRequest imageRequest) { return MemberImage.builder() - .url(imageRequest.getUrl()) + .name(imageRequest.getUrl()) .size(imageRequest.getSize()) .extension(imageRequest.getExtension()) .build(); } + @Override + protected void validateMemberId(MemberIdentifier identifier, MemberImage image) { + if (!identifier.type().equals(MemberType.admin) && !identifier.id().equals(image.getBaseMember().getId())) { + throw new UnauthorizedException("해당 프로필 이미지에 접근할 권한이 없습니다."); + } + } + @Transactional public void setBaseMember(MemberImage image, BaseMember member) { image.setBaseMember(member); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/AdvertisementImage.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/AdvertisementImage.java index 5c01ffd3..13049fe6 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/AdvertisementImage.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/AdvertisementImage.java @@ -5,11 +5,13 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.OneToOne; import lombok.Builder; +import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.ktc2.cokaen.wouldyouin.advertisement.persist.Advertisement; @Entity +@Getter @Setter @NoArgsConstructor public class AdvertisementImage extends Image { @@ -19,8 +21,8 @@ public class AdvertisementImage extends Image { private Advertisement advertisement; @Builder - public AdvertisementImage(String url, Long size, String extension, Advertisement advertisement) { - super(url, size, extension); + public AdvertisementImage(String name, Long size, String extension, Advertisement advertisement) { + super(name, size, extension); this.advertisement = advertisement; } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/CurationImage.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/CurationImage.java index aee7d07d..5f2e9c9d 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/CurationImage.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/CurationImage.java @@ -5,11 +5,13 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import lombok.Builder; +import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.ktc2.cokaen.wouldyouin.curation.persist.CurationCard; @Entity +@Getter @Setter @NoArgsConstructor public class CurationImage extends Image { @@ -19,7 +21,7 @@ public class CurationImage extends Image { private CurationCard curationCard; @Builder - public CurationImage(String url, Long size, String extension) { - super(url, size, extension); + public CurationImage(String name, Long size, String extension) { + super(name, size, extension); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/EventImage.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/EventImage.java index ce8d1265..4e9a520c 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/EventImage.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/EventImage.java @@ -5,11 +5,13 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import lombok.Builder; +import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.ktc2.cokaen.wouldyouin.event.persist.Event; @Entity +@Getter @Setter @NoArgsConstructor public class EventImage extends Image { @@ -19,7 +21,7 @@ public class EventImage extends Image { private Event event; @Builder - public EventImage(String url, Long size, String extension) { - super(url, size, extension); + public EventImage(String name, Long size, String extension) { + super(name, size, extension); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/MemberImage.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/MemberImage.java index 30158439..a7a7d52f 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/MemberImage.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/MemberImage.java @@ -5,12 +5,14 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.OneToOne; import lombok.Builder; +import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMember; @Entity @Setter +@Getter @NoArgsConstructor public class MemberImage extends Image { @@ -19,7 +21,7 @@ public class MemberImage extends Image { private BaseMember baseMember; @Builder - public MemberImage(String url, Long size, String extension) { - super(url, size, extension); + public MemberImage(String name, Long size, String extension) { + super(name, size, extension); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/AdvertisementController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/AdvertisementController.java index 89c66f07..ce043087 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/AdvertisementController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/AdvertisementController.java @@ -54,15 +54,15 @@ public ResponseEntity> updateAdvertisemen @PathVariable Long adId, @Valid @RequestPart AdvertisementRequest advertisementRequest, @RequestPart(required = false) MultipartFile image, - @Authorize(MemberType.admin) MemberIdentifier admin) { - return ApiResponse.ok(advertisementService.update(adId, advertisementRequest, image)); + @Authorize(MemberType.admin) MemberIdentifier identifier) { + return ApiResponse.ok(advertisementService.update(identifier, adId, advertisementRequest, image)); } @DeleteMapping("/{adId}") public ResponseEntity> deleteAdvertisement( @PathVariable Long adId, - @Authorize(MemberType.admin) MemberIdentifier admin) { - advertisementService.delete(adId); + @Authorize(MemberType.admin) MemberIdentifier identifier) { + advertisementService.delete(identifier, adId); return ApiResponse.noContent(); } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java index 4f7c8bd4..4dfd7f5e 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java @@ -11,6 +11,7 @@ import org.ktc2.cokaen.wouldyouin.advertisement.api.dto.AdvertisementResponse; import org.ktc2.cokaen.wouldyouin.advertisement.persist.Advertisement; import org.ktc2.cokaen.wouldyouin.advertisement.persist.AdvertisementRepository; +import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; @@ -51,11 +52,11 @@ public AdvertisementResponse create(AdvertisementRequest adRequest, MultipartFil // Todo: 수정될 때 이미지가 null인 경우 기존 이미지로 대체하는 로직 프론트와 협의 // Todo: 롤백될 경우, 저장한 이미지 삭제 @Transactional - public AdvertisementResponse update(Long adId, AdvertisementRequest adRequest, MultipartFile multipartFile) { + public AdvertisementResponse update(MemberIdentifier identifier, Long adId, AdvertisementRequest adRequest, MultipartFile multipartFile) { Advertisement ad = getByIdOrThrow(adId); Optional.ofNullable(multipartFile).ifPresentOrElse( image -> { - adImageService.deleteImage(ad.getAdvertisementImage().getId()); + adImageService.deleteImage(identifier, ad.getAdvertisementImage().getId()); AdvertisementImage adImage = adImageService.saveImage(image); ad.updateFrom(adRequest, adImage); adImage.setAdvertisement(ad); @@ -69,9 +70,9 @@ public AdvertisementResponse update(Long adId, AdvertisementRequest adRequest, M } @Transactional - public void delete(Long adId) { + public void delete(MemberIdentifier identifier, Long adId) { Advertisement ad = getByIdOrThrow(adId); - adImageService.deleteImage(ad.getAdvertisementImage().getId()); + adImageService.deleteImage(identifier, ad.getAdvertisementImage().getId()); adRepository.deleteById(adId); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/CurationController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/CurationController.java index d4857d2d..b31035fa 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/CurationController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/CurationController.java @@ -64,23 +64,23 @@ public ResponseEntity> getCurationByCurationId @PostMapping public ResponseEntity> createCuration( @Valid @RequestBody CurationCreateRequest curationCreateRequest, - @Authorize(MemberType.curator) MemberIdentifier curator) { - return ApiResponse.created(curationService.create(curator.id(), curationCreateRequest)); + @Authorize(MemberType.curator) MemberIdentifier identifier) { + return ApiResponse.created(curationService.create(identifier, curationCreateRequest)); } @PutMapping("/{curationId}") public ResponseEntity> updateCuration( @PathVariable Long curationId, @Valid @RequestBody CurationEditRequest curationEditRequest, - @Authorize(MemberType.curator) MemberIdentifier curator) { - return ApiResponse.ok(curationService.update(curator.id(), curationId, curationEditRequest)); + @Authorize(MemberType.curator) MemberIdentifier identifier) { + return ApiResponse.ok(curationService.update(identifier, curationId, curationEditRequest)); } @DeleteMapping("/{curationId}") public ResponseEntity> deleteCuration( @PathVariable Long curationId, - @Authorize(MemberType.curator) MemberIdentifier curator) { - curationService.delete(curator.id(), curationId); + @Authorize(MemberType.curator) MemberIdentifier identifier) { + curationService.delete(identifier, curationId); return ApiResponse.noContent(); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java index 7277ed77..eba9cd09 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java @@ -3,6 +3,7 @@ import java.time.LocalDateTime; import java.util.List; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; @@ -11,6 +12,7 @@ @Builder @Getter +@EqualsAndHashCode public class CurationResponse { private final Long id; @@ -19,7 +21,7 @@ public class CurationResponse { private final String content; private final List curationCards; private final Area area; - private final List hashTag; + private final List hashtags; private final List eventsInfo; private final LocalDateTime createdTime; private final LocalDateTime modifiedDate; @@ -33,7 +35,7 @@ public static CurationResponse from(Curation curation) { .curationCards(curation.getCurationCards().stream() .map(CurationCardResponse::from).toList()) .area(curation.getArea()) - .hashTag(curation.getHashtags()) + .hashtags(curation.getHashtags()) .eventsInfo(curation.getEvents().stream() .map(CurationEventResponse::from).toList()) .createdTime(curation.getCreatedDate()) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java index 4214b741..aa8076fd 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java @@ -5,6 +5,7 @@ import org.ktc2.cokaen.wouldyouin.Image.application.CurationImageService; import org.ktc2.cokaen.wouldyouin.Image.persist.CurationImage; import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; +import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCardRequest; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCardResponse; import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; @@ -46,9 +47,9 @@ public CurationCard create(CurationCardRequest request) { } @Transactional - public void delete(Long id) { + public void delete(MemberIdentifier identifier, Long id) { CurationCard target = getByIdOrThrow(id); - target.getCurationImages().forEach(image -> curationImageService.deleteImage(image.getId())); + target.getCurationImages().forEach(image -> curationImageService.deleteImage(identifier, image.getId())); curationCardRepository.deleteById(id); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationService.java index c1988cc2..dc935c55 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationService.java @@ -5,6 +5,7 @@ import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; import org.ktc2.cokaen.wouldyouin._common.vo.Area; +import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCreateRequest; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationEditRequest; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationResponse; @@ -16,6 +17,7 @@ import org.ktc2.cokaen.wouldyouin.event.persist.Event; import org.ktc2.cokaen.wouldyouin.member.application.CuratorService; import org.ktc2.cokaen.wouldyouin.member.persist.Curator; +import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; import org.springframework.stereotype.Service; @@ -56,8 +58,8 @@ public CurationSliceResponse getAllByCuratorIdOrderByCreatedDateDesc(Long curato } @Transactional - public CurationResponse create(Long curatorId, CurationCreateRequest curationCreateRequest) { - Curator curator = curatorService.getByIdOrThrow(curatorId); + public CurationResponse create(MemberIdentifier identifier, CurationCreateRequest curationCreateRequest) { + Curator curator = curatorService.getByIdOrThrow(identifier.id()); List curationCards = curationCreateRequest.getCurationCards().stream() .map(curationCardService::create) .toList(); @@ -70,27 +72,27 @@ public CurationResponse create(Long curatorId, CurationCreateRequest curationCre } @Transactional - public CurationResponse update(Long curatorId, Long curationId, CurationEditRequest curationEditRequest) { + public CurationResponse update(MemberIdentifier identifier, Long curationId, CurationEditRequest curationEditRequest) { Curation curation = getByIdOrThrow(curationId); - validateCuratorId(curatorId, curation); + validateCuratorId(identifier, curation); List curationCards = curationEditRequest.getCurationCards().stream() .map(curationCardService::create) .toList(); List events = curationEditRequest.getEventIds().stream() .map(eventService::getByIdOrThrow) .toList(); - curation.getCurationCards().forEach(card -> curationCardService.delete(card.getId())); + curation.getCurationCards().forEach(card -> curationCardService.delete(identifier, card.getId())); curation.updateFrom(curationEditRequest, curationCards, events); curationCards.forEach(curationCard -> curationCardService.setCuration(curationCard, curation)); return CurationResponse.from(curation); } @Transactional - public void delete(Long curatorId, Long curationId) { + public void delete(MemberIdentifier identifier, Long curationId) { Curation curation = getByIdOrThrow(curationId); - validateCuratorId(curatorId, curation); + validateCuratorId(identifier, curation); curation.getCurationCards() - .forEach(curationCard -> curationCardService.delete(curationCard.getId())); + .forEach(curationCard -> curationCardService.delete(identifier, curationCard.getId())); curationRepository.deleteById(curationId); } @@ -101,9 +103,9 @@ private Long getLastId(Slice curations, Long oldLastId) { return oldLastId; } - public void validateCuratorId(Long curatorId, Curation curation) { - if (!curatorId.equals(curation.getCurator().getId())) { - throw new UnauthorizedException("큐레이터 ID가 큐레이션의 큐레이터 ID와 일치하지 않습니다."); + private void validateCuratorId(MemberIdentifier identifier, Curation curation) { + if (!identifier.type().equals(MemberType.admin) && !identifier.id().equals(curation.getCurator().getId())) { + throw new UnauthorizedException("큐레이션에 접근할 권한이 없습니다."); } } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java index e8d86244..fb142fab 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java @@ -17,7 +17,6 @@ import jakarta.persistence.OneToMany; import jakarta.validation.constraints.NotNull; import java.time.LocalDateTime; -import java.util.ArrayList; import java.util.List; import java.util.Optional; import lombok.AccessLevel; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/EventController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/EventController.java index 57075ee8..d5c312d1 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/EventController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/EventController.java @@ -73,22 +73,22 @@ public ResponseEntity> getEventByEventId( @PostMapping public ResponseEntity> createEvent( @Valid @RequestBody EventCreateRequest eventCreateRequest, - @Authorize(MemberType.host) MemberIdentifier host) { - return ApiResponse.created(eventService.create(host.id(), eventCreateRequest)); + @Authorize(MemberType.host) MemberIdentifier identifier) { + return ApiResponse.created(eventService.create(identifier, eventCreateRequest)); } @PutMapping("/{eventId}") public ResponseEntity> updateEvent(@PathVariable Long eventId, @Valid @RequestBody EventEditRequest eventEditRequest, - @Authorize(MemberType.host) MemberIdentifier host) { - return ApiResponse.ok(eventService.update(host.id(), eventId, eventEditRequest)); + @Authorize(MemberType.host) MemberIdentifier identifier) { + return ApiResponse.ok(eventService.update(identifier, eventId, eventEditRequest)); } @DeleteMapping("/{eventId}") public ResponseEntity> deleteEvent( @PathVariable("eventId") Long eventId, - @Authorize(MemberType.host) MemberIdentifier host) { - eventService.delete(host.id(), eventId); + @Authorize(MemberType.host) MemberIdentifier identifier) { + eventService.delete(identifier, eventId); return ApiResponse.noContent(); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventResponse.java index 4e019415..4c932c2c 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventResponse.java @@ -4,6 +4,7 @@ import java.util.List; import lombok.Builder; import lombok.Getter; +import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageResponse; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; import org.ktc2.cokaen.wouldyouin._common.vo.Location; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventSliceResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventSliceResponse.java index d974a17f..4326e2b1 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventSliceResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventSliceResponse.java @@ -3,6 +3,7 @@ import java.util.List; import lombok.Builder; import lombok.Getter; +import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageResponse; import org.ktc2.cokaen.wouldyouin._common.api.SliceInfo; @Getter diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java index 911af259..1bf247e3 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java @@ -9,6 +9,7 @@ import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; +import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventResponse; @@ -19,6 +20,7 @@ import org.ktc2.cokaen.wouldyouin.event.persist.EventRepository; import org.ktc2.cokaen.wouldyouin.member.application.HostService; import org.ktc2.cokaen.wouldyouin.member.persist.Host; +import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; import org.springframework.stereotype.Service; @@ -32,13 +34,6 @@ public class EventService { private final HostService hostService; private final EventImageService eventImageService; - private static Long getLastId(Slice events, Long oldLastId) { - if (events.hasContent()) { - return events.getContent().getLast().getId(); - } - return oldLastId; - } - @Transactional public Event getByIdOrThrow(Long id) throws EntityNotFoundException { return eventRepository.findById(id) @@ -52,13 +47,11 @@ public EventResponse getById(Long id) { } @Transactional(readOnly = true) - public EventSliceResponse getAllByFilterOrderByDistanceAsc(LocationFilter location, - LocationRequest currentLocation, String title, + public EventSliceResponse getAllByFilterOrderByDistanceAsc(LocationFilter location, LocationRequest currentLocation, String title, Category category, Area area, Pageable pageable, Long beforeLastId) { Slice events = eventRepository.findAllByFilterOrderByDistance( location.getStartLatitude(), location.getStartLongitude(), location.getEndLatitude(), - location.getEndLongitude(), currentLocation.getLatitude(), - currentLocation.getLongitude(), + location.getEndLongitude(), currentLocation.getLatitude(), currentLocation.getLongitude(), title, category, area, pageable ); Long newLastId = getLastId(events, beforeLastId); @@ -67,18 +60,16 @@ public EventSliceResponse getAllByFilterOrderByDistanceAsc(LocationFilter locati } @Transactional(readOnly = true) - public EventSliceResponse getAllByHostIdOrderByCreatedDateDesc(Long hostId, Pageable pageable, - Long beforeLastId) { - Slice events = eventRepository.findAllByHostIdOrderByEventIdDesc(hostId, - beforeLastId, pageable); + public EventSliceResponse getAllByHostIdOrderByCreatedDateDesc(Long hostId, Pageable pageable, Long beforeLastId) { + Slice events = eventRepository.findAllByHostIdOrderByEventIdDesc(hostId, beforeLastId, pageable); Long newLastId = getLastId(events, beforeLastId); List responses = events.stream().map(this::getEventResponse).toList(); return EventSliceResponse.from(responses, events.getSize(), newLastId); } @Transactional - public EventResponse create(Long hostId, EventCreateRequest eventCreateRequest) { - Host host = hostService.getByIdOrThrow(hostId); + public EventResponse create(MemberIdentifier identifier, EventCreateRequest eventCreateRequest) { + Host host = hostService.getByIdOrThrow(identifier.id()); List images = eventCreateRequest.getImageIds().stream() .map(eventImageService::getById).toList(); Event event = eventRepository.save(eventCreateRequest.toEntity(host, images)); @@ -87,10 +78,10 @@ public EventResponse create(Long hostId, EventCreateRequest eventCreateRequest) } @Transactional - public EventResponse update(Long hostId, Long eventId, EventEditRequest eventEditRequest) { + public EventResponse update(MemberIdentifier identifier, Long eventId, EventEditRequest eventEditRequest) { Event event = getByIdOrThrow(eventId); - validateHostId(hostId, event); - event.getImages().forEach(image -> eventImageService.deleteImage(image.getId())); + validateHostId(identifier, event); + event.getImages().forEach(image -> eventImageService.deleteImage(identifier, image.getId())); List images = eventEditRequest.getImageIds().stream() .map(eventImageService::getById).toList(); event.updateFrom(eventEditRequest, images); @@ -99,8 +90,8 @@ public EventResponse update(Long hostId, Long eventId, EventEditRequest eventEdi } @Transactional - public void delete(Long hostId, Long eventId) { - validateHostId(hostId, getByIdOrThrow(eventId)); + public void delete(MemberIdentifier identifier, Long eventId) { + validateHostId(identifier, getByIdOrThrow(eventId)); eventRepository.deleteById(eventId); } @@ -113,9 +104,16 @@ public void decreaseLeftSeat(Long eventId, Integer count) { event.decreaseLeftSeat(count); } - public void validateHostId(Long hostId, Event event) { - if (!hostId.equals(event.getHost().getId())) { - throw new UnauthorizedException("호스트 ID가 행사의 호스트 ID와 일치하지 않습니다."); + private static Long getLastId(Slice events, Long oldLastId) { + if (events.hasContent()) { + return events.getContent().getLast().getId(); + } + return oldLastId; + } + + public void validateHostId(MemberIdentifier identifier, Event event) { + if (!identifier.type().equals(MemberType.admin) && !identifier.id().equals(event.getHost().getId())) { + throw new UnauthorizedException("해당 이벤트에 접근할 권한이 없습니다."); } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/MemberType.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/MemberType.java index e77abba5..8e60abbd 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/MemberType.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/MemberType.java @@ -9,5 +9,4 @@ public enum MemberType { curator, host, admin; - } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/ReservationController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/ReservationController.java index 7d265e66..710ad4ae 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/ReservationController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/ReservationController.java @@ -42,12 +42,12 @@ public ResponseEntity> getReservations @GetMapping("/events/{eventId}") public ResponseEntity> getReservationsByEventId( - @Authorize(MemberType.host) MemberIdentifier host, + @Authorize(MemberType.host) MemberIdentifier identifier, @PathVariable Long eventId, @RequestParam(defaultValue = ParamDefaults.PAGE) Integer page, @RequestParam(defaultValue = ParamDefaults.PAGE_SIZE) Integer size, @RequestParam(defaultValue = ParamDefaults.LAST_ID) Long lastId) { - return ApiResponse.ok(reservationService.getAllByEventId(host.id(), eventId, PageRequest.of(page, size), lastId)); + return ApiResponse.ok(reservationService.getAllByEventId(identifier, eventId, PageRequest.of(page, size), lastId)); } @GetMapping("/{reservationId}") diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java index 27af730e..1c96a501 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java @@ -4,6 +4,7 @@ import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; import org.ktc2.cokaen.wouldyouin._common.exception.ReservationNotFoundForReviewException; import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; +import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.event.application.EventService; import org.ktc2.cokaen.wouldyouin.member.application.MemberService; import org.ktc2.cokaen.wouldyouin.payment.application.PaymentService; @@ -54,8 +55,8 @@ public ReservationSliceResponse getAllByMemberId(Long memberId, Pageable pageabl } @Transactional(readOnly = true) - public ReservationSliceResponse getAllByEventId(Long hostId, Long eventId, Pageable pageable, Long oldLastId) { - eventService.validateHostId(hostId, eventService.getByIdOrThrow(eventId)); + public ReservationSliceResponse getAllByEventId(MemberIdentifier identifier, Long eventId, Pageable pageable, Long oldLastId) { + eventService.validateHostId(identifier, eventService.getByIdOrThrow(eventId)); Slice reservations = reservationRepository.findByEventIdOrderByReservationIdDesc(eventId, oldLastId, pageable); Long newLastId = getLastId(reservations, oldLastId); return ReservationSliceResponse.from(reservations, reservations.getSize(), newLastId); From 48610a46f0b7364c47e7900153988ab9db179e19 Mon Sep 17 00:00:00 2001 From: ariimo Date: Wed, 13 Nov 2024 02:47:02 +0900 Subject: [PATCH 19/53] =?UTF-8?q?[Weekly/11/Refactor/Validation]=20from=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EB=B0=8F=20=EB=A6=AC=ED=8C=A9=ED=84=B0?= =?UTF-8?q?=EB=A7=81=20(#118)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/AdvertisementController.java | 3 ++- .../advertisement/persist/Advertisement.java | 3 ++- .../api/dto/CurationCreateRequest.java | 7 ++++- .../curation/api/dto/CurationEditRequest.java | 4 +++ .../wouldyouin/curation/persist/Curation.java | 6 +++-- .../persist/CurationCardRepository.java | 2 +- .../curation/persist/CurationRepository.java | 3 ++- .../event/api/dto/EventResponse.java | 2 +- .../CurationEventResponse.java | 4 +-- .../ReservationEventResponse.java | 16 +++++++++++- .../relationResonse/ReviewEventResponse.java | 16 ++++++++++-- .../relation/ReservationMemberResponse.java | 15 ----------- .../EventHostResponse.java | 4 ++- .../ReservationMemberResponse.java | 26 +++++++++++++++++++ .../ReviewMemberResponse.java | 12 ++++++++- .../api/dto/ReservationResponse.java | 20 +++----------- .../review/api/dto/ReviewEditRequest.java | 2 -- .../review/api/dto/ReviewResponse.java | 13 +++------- .../_global/testdata/MemberData.java | 2 +- 19 files changed, 100 insertions(+), 60 deletions(-) delete mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relation/ReservationMemberResponse.java rename src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/{relation => relationResponse}/EventHostResponse.java (86%) create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/ReservationMemberResponse.java diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/AdvertisementController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/AdvertisementController.java index ce043087..1fde187e 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/AdvertisementController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/AdvertisementController.java @@ -49,7 +49,8 @@ public ResponseEntity> createAdvertisemen return ApiResponse.created(advertisementService.create(advertisementRequest, image)); } - @PutMapping(path = "/{adId}", consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE}) + @PutMapping(path = "/{adId}", consumes = {MediaType.APPLICATION_JSON_VALUE, + MediaType.MULTIPART_FORM_DATA_VALUE}) public ResponseEntity> updateAdvertisement( @PathVariable Long adId, @Valid @RequestPart AdvertisementRequest advertisementRequest, diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/persist/Advertisement.java b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/persist/Advertisement.java index f6fef66f..8c708a1a 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/persist/Advertisement.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/persist/Advertisement.java @@ -47,7 +47,8 @@ public class Advertisement { private LocalDateTime endTime; @Builder - public Advertisement(String title, AdvertisementImage advertisementImage, LocalDateTime startTime, + public Advertisement(String title, AdvertisementImage advertisementImage, + LocalDateTime startTime, LocalDateTime endTime) { this.title = title; this.advertisementImage = advertisementImage; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCreateRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCreateRequest.java index f4f21f45..f46db9da 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCreateRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCreateRequest.java @@ -2,8 +2,10 @@ import jakarta.validation.Valid; import jakarta.validation.constraints.AssertTrue; +import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import java.util.List; import lombok.Builder; import lombok.EqualsAndHashCode; @@ -22,6 +24,8 @@ public class CurationCreateRequest { @NotEmpty(message = "제목은 필수입니다.") private String title; + @NotBlank(message = "내용은 필수입니다.") + @Size(min = 20, max = 1000, message = "내용은 20자 이상 1000자 이하입니다.") private String content; @Valid @@ -42,7 +46,8 @@ public boolean isCurationCardsSizeValid() { return 1 <= this.curationCards.size() && this.curationCards.size() <= 10; } - public Curation toEntity(Curator curator, List curationCards, List events) { + public Curation toEntity(Curator curator, List curationCards, + List events) { return Curation.builder() .curator(curator) .title(this.title) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationEditRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationEditRequest.java index a113f851..f7451859 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationEditRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationEditRequest.java @@ -2,8 +2,10 @@ import jakarta.validation.Valid; import jakarta.validation.constraints.AssertTrue; +import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import java.util.List; import lombok.Builder; import lombok.EqualsAndHashCode; @@ -18,6 +20,8 @@ public class CurationEditRequest { @NotEmpty(message = "제목은 필수입니다.") private String title; + @NotBlank(message = "내용은 필수입니다.") + @Size(min = 20, max = 1000, message = "내용은 20자 이상 1000자 이하입니다.") private String content; @Valid diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java index fb142fab..a55a69e6 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java @@ -87,7 +87,8 @@ public class Curation { private LocalDateTime modifiedDate; @Builder - public Curation(Curator curator, String title, String content, List curationCards, Area area, List hashtags, + public Curation(Curator curator, String title, String content, List curationCards, + Area area, List hashtags, List events) { this.curator = curator; this.title = title; @@ -98,7 +99,8 @@ public Curation(Curator curator, String title, String content, List curationCards, List events) { + public void updateFrom(CurationEditRequest curationEditRequest, + List curationCards, List events) { Optional.ofNullable(curationEditRequest.getTitle()).ifPresent(this::setTitle); Optional.ofNullable(curationEditRequest.getContent()).ifPresent(this::setContent); Optional.ofNullable(curationEditRequest.getArea()).ifPresent(this::setArea); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCardRepository.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCardRepository.java index d312e320..80f1b01d 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCardRepository.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCardRepository.java @@ -7,7 +7,7 @@ @Repository public interface CurationCardRepository extends JpaRepository { - + @Query("SELECT CC FROM CurationCard CC JOIN FETCH CC.curation WHERE CC.curation = :curation ORDER BY CC.id ASC") List findAllByCurationOrderByIdAsc(Curation curation); } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationRepository.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationRepository.java index 95ce7854..b3190237 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationRepository.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationRepository.java @@ -19,5 +19,6 @@ public interface CurationRepository extends JpaRepository { @Query("SELECT C FROM Curation C JOIN FETCH C.curator " + "WHERE C.curator = :curator AND C.id > :lastId " + "ORDER BY C.id DESC") - Slice findAllByCuratorOrderByCreatedDateDesc(Curator curator, Long lastId, Pageable pageable); + Slice findAllByCuratorOrderByCreatedDateDesc(Curator curator, Long lastId, + Pageable pageable); } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventResponse.java index 4c932c2c..0958a23b 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventResponse.java @@ -9,7 +9,7 @@ import org.ktc2.cokaen.wouldyouin._common.vo.Category; import org.ktc2.cokaen.wouldyouin._common.vo.Location; import org.ktc2.cokaen.wouldyouin.event.persist.Event; -import org.ktc2.cokaen.wouldyouin.member.api.dto.relation.EventHostResponse; +import org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse.EventHostResponse; import org.ktc2.cokaen.wouldyouin.member.persist.Host; @Builder diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/CurationEventResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/CurationEventResponse.java index 6073a499..ec9ebe7c 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/CurationEventResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/CurationEventResponse.java @@ -10,7 +10,7 @@ @Builder public class CurationEventResponse { - private Long id; + private Long eventId; private String title; private Location location; private LocalDateTime startTime; @@ -20,7 +20,7 @@ public class CurationEventResponse { public static CurationEventResponse from(Event event) { return CurationEventResponse.builder() - .id(event.getId()) + .eventId(event.getId()) .title(event.getTitle()) .location(event.getLocation()) .startTime(event.getStartTime()) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/ReservationEventResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/ReservationEventResponse.java index 801b0cb3..98e76401 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/ReservationEventResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/ReservationEventResponse.java @@ -2,12 +2,26 @@ import lombok.Builder; import lombok.Getter; +import org.ktc2.cokaen.wouldyouin._common.vo.Location; +import org.ktc2.cokaen.wouldyouin.event.persist.Event; @Getter @Builder public class ReservationEventResponse { - private Long id; + private Long eventId; private String title; private Integer price; + private Location location; + private String thumbnailUrl; + + public static ReservationEventResponse from(Event event) { + return ReservationEventResponse.builder() + .eventId(event.getId()) + .title(event.getTitle()) + .price(event.getPrice()) + .location(event.getLocation()) + .thumbnailUrl(event.getThumbnailUrl()) + .build(); + } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/ReviewEventResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/ReviewEventResponse.java index 9db9e214..560c930c 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/ReviewEventResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/ReviewEventResponse.java @@ -1,13 +1,25 @@ package org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse; +import java.time.LocalDateTime; import lombok.Builder; import lombok.Getter; +import org.ktc2.cokaen.wouldyouin.event.persist.Event; @Getter @Builder public class ReviewEventResponse { - private Long id; + private Long eventId; private String title; - private String mainImage; + private LocalDateTime startTime; + private String thumbnailUrl; + + public static ReviewEventResponse from(Event event){ + return builder() + .eventId(event.getId()) + .title(event.getTitle()) + .startTime(event.getStartTime()) + .thumbnailUrl(event.getThumbnailUrl()) + .build(); + } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relation/ReservationMemberResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relation/ReservationMemberResponse.java deleted file mode 100644 index 98b10bbc..00000000 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relation/ReservationMemberResponse.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.ktc2.cokaen.wouldyouin.member.api.dto.relation; - -import lombok.Builder; -import lombok.Getter; - -@Getter -@Builder -public class ReservationMemberResponse { - - private Long id; - private String email; - private String nickname; - private String phone; - private String gender; -} diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relation/EventHostResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/EventHostResponse.java similarity index 86% rename from src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relation/EventHostResponse.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/EventHostResponse.java index 8d5ffb3f..3cc7ed35 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relation/EventHostResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/EventHostResponse.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin.member.api.dto.relation; +package org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse; import java.util.List; import lombok.Builder; @@ -9,6 +9,7 @@ @Getter public class EventHostResponse { + private Long hostId; private String nickname; private String email; private String phone; @@ -19,6 +20,7 @@ public class EventHostResponse { public static EventHostResponse from(Host host) { return EventHostResponse.builder() + .hostId(host.getId()) .nickname(host.getNickname()) .email(host.getEmail()) .phone(host.getPhone()) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/ReservationMemberResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/ReservationMemberResponse.java new file mode 100644 index 00000000..70514dda --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/ReservationMemberResponse.java @@ -0,0 +1,26 @@ +package org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse; + +import lombok.Builder; +import lombok.Getter; +import org.ktc2.cokaen.wouldyouin.member.persist.Member; + +@Getter +@Builder +public class ReservationMemberResponse { + + private Long memberId; + private String email; + private String nickname; + private String phone; + private String gender; + + public static ReservationMemberResponse from(Member member) { + return ReservationMemberResponse.builder() + .memberId(member.getId()) + .email(member.getEmail()) + .nickname(member.getNickname()) + .phone(member.getPhone()) + .gender(member.getGender()) + .build(); + } +} diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/ReviewMemberResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/ReviewMemberResponse.java index afbdc6a2..d9967e83 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/ReviewMemberResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/ReviewMemberResponse.java @@ -1,12 +1,22 @@ package org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse; +import java.awt.MenuBar; import lombok.Builder; import lombok.Getter; +import org.ktc2.cokaen.wouldyouin.member.persist.Member; +import org.ktc2.cokaen.wouldyouin.review.persist.Review; @Getter @Builder public class ReviewMemberResponse { - private Long id; + private Long memberId; private String nickname; + + public static ReviewMemberResponse from(Member member){ + return builder() + .memberId(member.getId()) + .nickname(member.getNickname()) + .build(); + } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/ReservationResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/ReservationResponse.java index 5249b6ee..27db4266 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/ReservationResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/ReservationResponse.java @@ -4,7 +4,7 @@ import lombok.Builder; import lombok.Getter; import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.ReservationEventResponse; -import org.ktc2.cokaen.wouldyouin.member.api.dto.relation.ReservationMemberResponse; +import org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse.ReservationMemberResponse; import org.ktc2.cokaen.wouldyouin.reservation.persist.Reservation; @Builder @@ -21,22 +21,8 @@ public class ReservationResponse { public static ReservationResponse from(Reservation reservation) { return ReservationResponse.builder() .id(reservation.getId()) - .member( - ReservationMemberResponse.builder() - .id(reservation.getMember().getId()) - .email(reservation.getMember().getEmail()) - .nickname(reservation.getMember().getNickname()) - .phone(reservation.getMember().getPhone()) - .gender(reservation.getMember().getGender()) - .build() - ) - .event( - ReservationEventResponse.builder() - .id(reservation.getEvent().getId()) - .title(reservation.getEvent().getTitle()) - .price(reservation.getEvent().getPrice()) - .build() - ) + .member(ReservationMemberResponse.from(reservation.getMember())) + .event(ReservationEventResponse.from(reservation.getEvent())) .price(reservation.getPrice()) .quantity(reservation.getQuantity()) .reservationDate(reservation.getReservationDate()) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewEditRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewEditRequest.java index 03a03676..d1d2653f 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewEditRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewEditRequest.java @@ -3,8 +3,6 @@ import jakarta.validation.constraints.Max; import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.Positive; -import jakarta.validation.constraints.PositiveOrZero; import jakarta.validation.constraints.Size; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewResponse.java index daf8e8b3..50eb6f00 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewResponse.java @@ -20,18 +20,11 @@ public class ReviewResponse { public static ReviewResponse from(final Review review) { Member member = review.getMember(); - Event eventInReview = review.getEvent(); + Event event = review.getEvent(); return ReviewResponse.builder() .id(review.getId()) - .member(ReviewMemberResponse.builder() - .id(member.getId()) - .nickname(member.getNickname()) - .build()) - .event(ReviewEventResponse.builder() - .id(eventInReview.getId()) - .title(eventInReview.getTitle()) -// .mainImage(eventInCuration.getMainImage()) - .build()) + .member(ReviewMemberResponse.from(member)) + .event(ReviewEventResponse.from(event)) .score(review.getScore()) .content(review.getContent()) .build(); diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java index 1633ce5c..d4581c38 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java @@ -3,7 +3,7 @@ import java.util.List; import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin._common.vo.Area; -import org.ktc2.cokaen.wouldyouin.member.api.dto.relation.ReservationMemberResponse; +import org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse.ReservationMemberResponse; import org.ktc2.cokaen.wouldyouin.member.persist.AccountType; import org.ktc2.cokaen.wouldyouin.member.persist.Curator; import org.ktc2.cokaen.wouldyouin.member.persist.Host; From 852a69fbdbaa45f48c5a2465124a1824e5f9a750 Mon Sep 17 00:00:00 2001 From: ariimo Date: Wed, 13 Nov 2024 03:30:26 +0900 Subject: [PATCH 20/53] =?UTF-8?q?[Weekly/11/Refactor/Validation]=20thumbna?= =?UTF-8?q?il=20=EC=B6=94=EA=B0=80=20(#119)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wouldyouin/curation/api/dto/CurationResponse.java | 3 +++ .../ktc2/cokaen/wouldyouin/curation/persist/Curation.java | 3 +++ .../ktc2/cokaen/wouldyouin/event/api/dto/EventResponse.java | 6 ++++-- .../api/dto/relationResponse/ReviewMemberResponse.java | 4 +--- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java index eba9cd09..cc6ca2ba 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java @@ -1,5 +1,6 @@ package org.ktc2.cokaen.wouldyouin.curation.api.dto; +import jakarta.persistence.Column; import java.time.LocalDateTime; import java.util.List; import lombok.Builder; @@ -23,6 +24,7 @@ public class CurationResponse { private final Area area; private final List hashtags; private final List eventsInfo; + private final String thumbnailUrl; private final LocalDateTime createdTime; private final LocalDateTime modifiedDate; @@ -38,6 +40,7 @@ public static CurationResponse from(Curation curation) { .hashtags(curation.getHashtags()) .eventsInfo(curation.getEvents().stream() .map(CurationEventResponse::from).toList()) + .thumbnailUrl(curation.getThumbnailUrl()) .createdTime(curation.getCreatedDate()) .modifiedDate(curation.getModifiedDate()) .build(); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java index a55a69e6..7c1db6e1 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java @@ -78,6 +78,9 @@ public class Curation { ) private List events; + @Column(name = "thumbnail_url") + private String thumbnailUrl; + @CreatedDate @Column(name = "created_date") private LocalDateTime createdDate; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventResponse.java index 0958a23b..385d44b3 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventResponse.java @@ -19,7 +19,6 @@ public class EventResponse { private Long id; private String title; private String content; - private List images; private EventHostResponse host; private Area area; private Location location; @@ -29,6 +28,8 @@ public class EventResponse { private Integer totalSeat; private Integer leftSeat; private Category category; + private String thumbnailUrl; + private List images; private Boolean expired; public static EventResponse from(Event event, List imageUrls) { @@ -37,7 +38,6 @@ public static EventResponse from(Event event, List imageUrls) { .id(event.getId()) .title(event.getTitle()) .content(event.getContent()) - .images(imageUrls) .host(EventHostResponse.from(host)) .area(event.getArea()) .location(event.getLocation()) @@ -47,6 +47,8 @@ public static EventResponse from(Event event, List imageUrls) { .totalSeat(event.getTotalSeat()) .leftSeat(event.getLeftSeat()) .category(event.getCategory()) + .thumbnailUrl(event.getThumbnailUrl()) + .images(imageUrls) .expired(event.getStartTime().isAfter(LocalDateTime.now())) .build(); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/ReviewMemberResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/ReviewMemberResponse.java index d9967e83..aca47786 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/ReviewMemberResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/ReviewMemberResponse.java @@ -1,10 +1,8 @@ package org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse; -import java.awt.MenuBar; import lombok.Builder; import lombok.Getter; import org.ktc2.cokaen.wouldyouin.member.persist.Member; -import org.ktc2.cokaen.wouldyouin.review.persist.Review; @Getter @Builder @@ -13,7 +11,7 @@ public class ReviewMemberResponse { private Long memberId; private String nickname; - public static ReviewMemberResponse from(Member member){ + public static ReviewMemberResponse from(Member member) { return builder() .memberId(member.getId()) .nickname(member.getNickname()) From d8bfb07c906773ca5489da68588d504eceabe37e Mon Sep 17 00:00:00 2001 From: Jangan Lee Date: Wed, 13 Nov 2024 06:12:46 +0900 Subject: [PATCH 21/53] =?UTF-8?q?[Weekly/11/Refactor/Test-TeatData]=20test?= =?UTF-8?q?data=20=EB=A6=AC=ED=8C=A9=ED=84=B0=EB=A7=81=20(#120)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Image/api/dto/ImageRequest.java | 6 +- .../AdvertisementImageService.java | 2 +- .../application/CurationImageService.java | 2 +- .../Image/application/EventImageService.java | 2 +- .../Image/application/MemberImageService.java | 2 +- .../_common/error/GlobalExceptionHandler.java | 1 + .../cokaen/wouldyouin/_global/TestData.java | 140 ------- .../_global/mockMember/WithMockCurator.java | 4 +- .../_global/mockMember/WithMockHost.java | 4 +- .../_global/mockMember/WithMockMember.java | 4 +- .../mockMember/WithMockWelcomeMember.java | 4 +- .../_global/testdata/CommonData.java | 17 + .../_global/testdata/CurationData.java | 266 ++++++++---- .../_global/testdata/EventData.java | 130 ++++++ .../_global/testdata/ImageData.java | 395 +++++++++++++----- .../_global/testdata/MemberData.java | 274 ++++++++---- .../_global/testdata/ReservationData.java | 77 ++++ .../curation/CurationControllerUnitTest.java | 73 ++-- .../curation/CurationServiceTest.java | 26 +- .../event/EventControllerUnitTest.java | 19 +- .../event/EventServiceUnitTest.java | 26 +- .../wouldyouin/image/ImageControllerTest.java | 19 +- .../BaseMemberServiceUnitTest.java | 31 +- .../application/CuratorServiceUnitTest.java | 7 +- .../application/HostServiceUnitTest.java | 8 +- .../application/MemberServiceUnitTest.java | 11 +- .../ReservationControllerUnitTest.java | 38 +- 27 files changed, 1050 insertions(+), 538 deletions(-) delete mode 100644 src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java create mode 100644 src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java create mode 100644 src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/EventData.java create mode 100644 src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ReservationData.java diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageRequest.java index 2825c2dd..15dda0cd 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageRequest.java @@ -7,13 +7,13 @@ @Builder public class ImageRequest { - private String url; + private String name; private Long size; private String extension; - public static ImageRequest of(String url, Long size, String extension) { + public static ImageRequest of(String name, Long size, String extension) { return ImageRequest.builder() - .url(url) + .name(name) .size(size) .extension(extension) .build(); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java index a1fa43ef..40403f31 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java @@ -42,7 +42,7 @@ protected String getChildPath() { @Override protected AdvertisementImage toEntity(ImageRequest imageRequest) { return AdvertisementImage.builder() - .name(imageRequest.getUrl()) + .name(imageRequest.getName()) .size(imageRequest.getSize()) .extension(imageRequest.getExtension()) .build(); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/CurationImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/CurationImageService.java index ab1d9a81..f9051050 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/CurationImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/CurationImageService.java @@ -40,7 +40,7 @@ protected String getChildPath() { @Override protected CurationImage toEntity(ImageRequest imageRequest) { return CurationImage.builder() - .name(imageRequest.getUrl()) + .name(imageRequest.getName()) .size(imageRequest.getSize()) .extension(imageRequest.getExtension()) .build(); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/EventImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/EventImageService.java index db64e62a..72b982b8 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/EventImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/EventImageService.java @@ -40,7 +40,7 @@ protected String getChildPath() { @Override protected EventImage toEntity(ImageRequest imageRequest) { return EventImage.builder() - .name(imageRequest.getUrl()) + .name(imageRequest.getName()) .size(imageRequest.getSize()) .extension(imageRequest.getExtension()) .build(); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java index 7ada23a5..2e8ed906 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java @@ -40,7 +40,7 @@ protected String getChildPath() { @Override protected MemberImage toEntity(ImageRequest imageRequest) { return MemberImage.builder() - .name(imageRequest.getUrl()) + .name(imageRequest.getName()) .size(imageRequest.getSize()) .extension(imageRequest.getExtension()) .build(); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/GlobalExceptionHandler.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/GlobalExceptionHandler.java index 185ba406..ebe4de5e 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/GlobalExceptionHandler.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/GlobalExceptionHandler.java @@ -33,6 +33,7 @@ public ResponseEntity> handleMethodArgumentTypeMismatchExc public ResponseEntity> handleMethodArgumentNotValidException(MethodArgumentNotValidException e) { return ApiResponse.error(ErrorCode.INVALID_INPUT_VALUE, e.getBindingResult().getFieldErrors().stream() .map(DefaultMessageSourceResolvable::getDefaultMessage) +// .map((reslover) -> "필드명: " + reslover.getField() + reslover.getDefaultMessage()) .collect(Collectors.joining(", "))); } } \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java deleted file mode 100644 index 38f06c9f..00000000 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java +++ /dev/null @@ -1,140 +0,0 @@ -package org.ktc2.cokaen.wouldyouin._global; - -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidHost; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidMember; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidReservationMemberResponse; - -import java.time.LocalDateTime; -import java.util.List; -import org.ktc2.cokaen.wouldyouin._common.api.SliceInfo; -import org.ktc2.cokaen.wouldyouin._common.vo.Area; -import org.ktc2.cokaen.wouldyouin._common.vo.Category; -import org.ktc2.cokaen.wouldyouin._common.vo.Location; -import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; -import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; -import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.CurationEventResponse; -import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.ReservationEventResponse; -import org.ktc2.cokaen.wouldyouin.event.persist.Event; -import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationRequest; -import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationResponse; -import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationSliceResponse; -import org.ktc2.cokaen.wouldyouin.reservation.persist.Reservation; -import org.springframework.test.util.ReflectionTestUtils; - -public class TestData { - - public static SliceInfo createSliceInfo() { - return SliceInfo.builder() - .sliceSize(10) - .lastId(100L) - .build(); - } - - public static class EventDomain { - - public static Event createValidEvent() { - Event validEvent = Event.builder() - .title("title") - .content("content") - .area(Area.전체) - .location(new Location(132.0, 43.0, "광주 북구 용봉로77")) - .startTime(LocalDateTime.now()) - .endTime(LocalDateTime.now()) - .price(10000) - .totalSeat(100) - .category(Category.밴드) - .build(); - validEvent.setHost(createValidHost()); - ReflectionTestUtils.setField(validEvent, "id", 201L); - return validEvent; - } - - public static EventCreateRequest createValidEventCreateRequest() { - return EventCreateRequest.builder() - .title("title") - .content("content 조홍식씨 최소글자 20자라고 해놓고 안 지켰어요.") - .area(Area.전체) - .location(new Location(55.0, 43.0, "광주 북구 용봉로 77")) - .startTime(LocalDateTime.of(2025, 10, 1, 9, 0)) - .endTime(LocalDateTime.of(2025, 10, 1, 10, 0)) - .price(10000) - .totalSeat(100) - .category(Category.밴드) - .imageIds(List.of()) - .build(); - } - - public static EventEditRequest createValidEventEditRequest() { - return EventEditRequest.builder() - .title("modifiedTitle") - .content("modifiedContent 조홍식씨 최소글자 20자라고 해놓고 안 지켰어요. ") - .area(Area.광주) - .location(new Location(232.0, 143.0, "광주 북구 용봉로 77")) - .startTime(LocalDateTime.of(2024, 10, 2, 17, 0)) - .endTime(LocalDateTime.of(2024, 10, 2, 18, 0)) - .price(20000) - .totalSeat(200) - .category(Category.뮤지컬) - .imageIds(List.of()) - .build(); - } - - public static CurationEventResponse createValidCurationEventResponse() { - return CurationEventResponse.builder() - .id(1L) - .title("title") - .location(new Location(132.0, 43.0, "광주 북구 용봉로 77")) - .thumbnailImageUrl("thumbnailImageUrl") - .hostProfileImageUrl("hostProfileImageUrl") - .hostNickname("nick_curator_12") - .build(); - } - - public static ReservationEventResponse createValidReservationEventResponse() { - return ReservationEventResponse.builder() - .id(1L) - .title("title") - .price(15000) - .build(); - } - } - - public static class ReservationDomain { - - public static ReservationRequest createValidReservationRequest() { - return ReservationRequest.builder() - .eventId(1L) - .quantity(2) - .build(); - } - - public static Reservation createValidReservation() { - Reservation reservation = Reservation.builder() - .member(createValidMember()) - .event(EventDomain.createValidEvent()) - .price(15000) - .quantity(2) - .build(); - ReflectionTestUtils.setField(reservation, "id", 1L); - return reservation; - } - - public static ReservationResponse createValidReservationResponse() { - return ReservationResponse.builder() - .id(1L) - .member(createValidReservationMemberResponse()) - .event(EventDomain.createValidReservationEventResponse()) - .price(15000) - .quantity(2) - .reservationDate(LocalDateTime.of(2024, 3, 23, 0, 0)) - .build(); - } - - public static ReservationSliceResponse createValidReservationSliceResponse() { - return ReservationSliceResponse.builder() - .reservations(List.of(createValidReservationResponse())) - .sliceInfo(TestData.createSliceInfo()) - .build(); - } - } -} \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockCurator.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockCurator.java index e07aa771..a44df782 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockCurator.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockCurator.java @@ -2,11 +2,11 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @Retention(RetentionPolicy.RUNTIME) -@WithMockCustomUser(memberId = MemberData.validCuratorId, memberType = MemberType.curator) +@WithMockCustomUser(memberId = curator.id, memberType = MemberType.curator) public @interface WithMockCurator { } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockHost.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockHost.java index 2a84fd47..a92d6950 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockHost.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockHost.java @@ -2,11 +2,11 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @Retention(RetentionPolicy.RUNTIME) -@WithMockCustomUser(memberId = MemberData.validHostId, memberType = MemberType.host) +@WithMockCustomUser(memberId = host.id, memberType = MemberType.host) public @interface WithMockHost { } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockMember.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockMember.java index 6b71ff00..4e5cbe8d 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockMember.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockMember.java @@ -2,11 +2,11 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.normal; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @Retention(RetentionPolicy.RUNTIME) -@WithMockCustomUser(memberId = MemberData.validMemberId, memberType = MemberType.normal) +@WithMockCustomUser(memberId = normal.id, memberType = MemberType.normal) public @interface WithMockMember { } \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockWelcomeMember.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockWelcomeMember.java index 4dc60ff8..951a6cf2 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockWelcomeMember.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockWelcomeMember.java @@ -2,11 +2,11 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.welcome; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @Retention(RetentionPolicy.RUNTIME) -@WithMockCustomUser(memberId = MemberData.validWelcomeMemberId, memberType = MemberType.welcome) +@WithMockCustomUser(memberId = welcome.id, memberType = MemberType.welcome) public @interface WithMockWelcomeMember { } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java new file mode 100644 index 00000000..8fa8fcc7 --- /dev/null +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java @@ -0,0 +1,17 @@ +package org.ktc2.cokaen.wouldyouin._global.testdata; + +import org.ktc2.cokaen.wouldyouin._common.api.SliceInfo; + +public class CommonData { + + public static class sliceInfo { + + public static SliceInfo get() { + return SliceInfo.builder() + .sliceSize(10) + .lastId(100L) + .build(); + } + } + +} \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java index a32b9cb7..dfcd2107 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java @@ -1,12 +1,11 @@ package org.ktc2.cokaen.wouldyouin._global.testdata; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidCurator; - import java.time.LocalDateTime; import java.util.List; +import org.ktc2.cokaen.wouldyouin.Image.persist.CurationImage; import org.ktc2.cokaen.wouldyouin._common.vo.Area; -import org.ktc2.cokaen.wouldyouin._global.TestData; -import org.ktc2.cokaen.wouldyouin._global.TestData.EventDomain; +import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.R.curationCard1; +import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.R.curationEditRequest; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCardRequest; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCardResponse; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCreateRequest; @@ -15,94 +14,195 @@ import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationSliceResponse; import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; import org.ktc2.cokaen.wouldyouin.curation.persist.CurationCard; -import org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse.CurationCuratorResponse; +import org.ktc2.cokaen.wouldyouin.event.persist.Event; import org.springframework.test.util.ReflectionTestUtils; public class CurationData { - public static CurationCardRequest createValidCurationCardRequest1() { - return CurationCardRequest.builder() - .subtitle("큐레이션 카드 부제목1") - .content("큐레이션 카드 내용1 입니다. 큐레이션 카드의 내용은 최소 20자 최대 1000자 입니다.") - .imageIds(List.of(1301L)) - .build(); - } - - public static CurationCardRequest createValidCurationCardRequest2() { - return CurationCardRequest.builder() - .subtitle("큐레이션 카드 부제목2") - .content("큐레이션 카드 내용2 입니다. 큐레이션 카드의 내용은 최소 20자 최대 1000자 입니다.") - .imageIds(List.of(1302L)) - .build(); - } - - public static CurationCard createValidCurationCard1() { - CurationCard validCurationCard1 = - createValidCurationCardRequest1().toEntity(List.of(ImageData.createValidCurationImage1())); - ReflectionTestUtils.setField(validCurationCard1, "id", 351L); -// ReflectionTestUtils.setField(validCurationCard1, "curation", createValidCuration()); - return validCurationCard1; - } - - public static CurationCard createValidCurationCard2() { - CurationCard validCurationCard2 = - createValidCurationCardRequest2().toEntity(List.of(ImageData.createValidCurationImage2())); - ReflectionTestUtils.setField(validCurationCard2, "id", 352L); -// ReflectionTestUtils.setField(validCurationCard1, "curation", createValidCuration()); - return validCurationCard2; - } - - public static CurationCardResponse createValidCurationCardResponse1() { - return CurationCardResponse.from(createValidCurationCard1()); - } - - public static CurationCardResponse createValidCurationCardResponse2() { - return CurationCardResponse.from(createValidCurationCard2()); - } - - public static CurationCreateRequest createValidCurationCreateRequest() { - return CurationCreateRequest.builder() - .title("큐레이션 제목") - .content("큐레이션 본문") - .curationCards(List.of(createValidCurationCardRequest1())) - .area(Area.전체) - .hashtags(List.of("#큐레이션", "#해시태그")) - .eventIds(List.of(201L)) - .build(); - } - - public static CurationEditRequest createValidCurationEditRequest() { - return CurationEditRequest.builder() - .title("큐레이션 제목 수정") - .content("큐레이션 본문 수정") - .curationCards(List.of(createValidCurationCardRequest2())) - .area(Area.광주) - .hashtags(List.of("수정 해시태그")) - .eventIds(List.of(202L)) - .build(); - } - - public static Curation createValidCuration() { - Curation validCuration = createValidCurationCreateRequest().toEntity( - createValidCurator(), List.of(createValidCurationCard1()), List.of(EventDomain.createValidEvent())); - ReflectionTestUtils.setField(validCuration, "id", 301L); - ReflectionTestUtils.setField(validCuration, "createdDate", LocalDateTime.of(2023, 3, 23, 0, 0)); - ReflectionTestUtils.setField(validCuration, "modifiedDate", LocalDateTime.of(2024, 3, 23, 0, 0)); - return validCuration; + public static class R { + public static class curationCard1 { + public static final Long id = 351L; + public static final String subtitle = "큐레이션 카드 부제목1"; + public static final String content = "큐레이션 카드 내용1 입니다. 큐레이션 카드의 내용은 최소 20자 최대 1000자 입니다."; + public static final List images = List.of(ImageData.curation1.entity.get()); + public static final List imageIds = List.of(1301L); + public static final List imageUrls = List.of("wouldyouin.com/curationImage1.jpg"); + } + public static class curationCard2 { + public static final Long id = 352L; + public static final String subtitle = "큐레이션 카드 부제목2"; + public static final String content = "큐레이션 카드 내용2 입니다. 큐레이션 카드의 내용은 최소 20자 최대 1000자 입니다."; + public static final List imageIds = List.of(1302L); + public static final List imageUrls = List.of("wouldyouin.com/curationImage2.jpg"); + } + public static class curation { + public static final Long id = 301L; + public static final String title = "큐레이션 제목"; + public static final String content = "큐레이션 본문 입니다. 큐레이션의 본문은 최소 20자 최대 1000자 입니다."; + public static final List curationCards = List.of( + CurationData.curationCard1.entity.get(), + CurationData.curationCard2.entity.get() + ); + public static final List curationCardRequests = List.of( + CurationData.curationCard1.request.get(), + CurationData.curationCard2.request.get() + ); + public static final List curationCardResponses = List.of( + CurationData.curationCard1.response.get(), + CurationData.curationCard2.response.get() + ); + public static final Area area = Area.전체; + public static final List hashtags = List.of("#큐레이션", "#해시태그"); + public static final List eventIds = List.of(201L); + public static final List events = List.of(EventData.event.entity.get()); + public static final LocalDateTime createdDate = LocalDateTime.of(2023, 3, 23, 0, 0); + public static final LocalDateTime modifiedDate = LocalDateTime.of(2024, 3, 23, 0, 0); + } + public static class curationEditRequest { + public static final String title = "큐레이션 제목 수정"; + public static final String content = "수정된 큐레이션 본문 입니다. 큐레이션의 본문은 최소 20자 최대 1000자 입니다."; + public static final List curationCardRequests = List.of( + CurationData.curationCard2.request.get() + ); + public static final Area area = Area.광주; + public static final List hashtags = List.of("수정 해시태그"); + public static final List eventIds = List.of(202L); + } } - public static CurationCuratorResponse createValidCurationCuratorResponse() { - return CurationCuratorResponse.from(createValidCurator()); + public static class curationCard1 { + public static class entity { + public static CurationCard get() { + CurationCard validCurationCard1 = CurationCard.builder() + .subtitle(R.curationCard1.subtitle) + .content(R.curationCard2.content) + // .curation(createValidCuration()) + .images(R.curationCard1.images) + .build(); + ReflectionTestUtils.setField(validCurationCard1, "id", R.curationCard1.id); + return validCurationCard1; + } + } + public static class request { + public static CurationCardRequest get() { + return CurationCardRequest.builder() + .subtitle(R.curationCard1.subtitle) + .content(R.curationCard1.content) + .imageIds(R.curationCard1.imageIds) + .build(); + } + } + public static class response { + public static CurationCardResponse get() { + return CurationCardResponse.builder() + .subtitle(R.curationCard1.subtitle) + .content(R.curationCard1.content) + .imageUrls(R.curationCard1.imageUrls) + .build(); + } + } } - public static CurationResponse createValidCurationResponse() { - return CurationResponse.from(createValidCuration()); + public static class curationCard2 { + public static class entity { + public static CurationCard get() { + CurationCard validCurationCard2 = CurationCard.builder() + .subtitle(R.curationCard2.subtitle) + .content(R.curationCard2.content) + // .curation(createValidCuration()) + .images(List.of(ImageData.curation2.entity.get())) + .build(); + ReflectionTestUtils.setField(validCurationCard2, "id", R.curationCard2.id); + return validCurationCard2; + } + } + public static class request { + public static CurationCardRequest get() { + return CurationCardRequest.builder() + .subtitle(R.curationCard2.subtitle) + .content(R.curationCard2.content) + .imageIds(R.curationCard2.imageIds) + .build(); + } + } + public static class response { + public static CurationCardResponse get() { + return CurationCardResponse.builder() + .subtitle(R.curationCard2.subtitle) + .content(R.curationCard2.content) + .imageUrls(R.curationCard2.imageUrls) + .build(); + } + } } - public static CurationSliceResponse createValidCurationSliceResponse() { - return CurationSliceResponse.builder() - .curations(List.of(createValidCurationResponse())) - .sliceInfo(TestData.createSliceInfo()) - .build(); + public static class curation { + public static class entity { + public static Curation get() { + Curation validCuration = Curation.builder() + .curator(MemberData.curator.entity.get()) + .title(R.curation.title) + .content(R.curation.content) + .curationCards(R.curation.curationCards) + .area(R.curation.area) + .hashtags(R.curation.hashtags) + .events(R.curation.events) + .build(); + ReflectionTestUtils.setField(validCuration, "id", R.curation.id); + ReflectionTestUtils.setField(validCuration, "createdDate", R.curation.createdDate); + ReflectionTestUtils.setField(validCuration, "modifiedDate", R.curation.modifiedDate); + return validCuration; + } + } + public static class request { + public static class create { + public static CurationCreateRequest get() { + return CurationCreateRequest.builder() + .title(R.curation.title) + .content(R.curation.content) + .curationCards(R.curation.curationCardRequests) + .area(R.curation.area) + .hashtags(R.curation.hashtags) + .eventIds(R.curation.eventIds) + .build(); + } + } + public static class edit { + public static CurationEditRequest get() { + return CurationEditRequest.builder() + .title(curationEditRequest.title) + .content(curationEditRequest.content) + .curationCards(curationEditRequest.curationCardRequests) + .area(curationEditRequest.area) + .hashtags(curationEditRequest.hashtags) + .eventIds(curationEditRequest.eventIds) + .build(); + } + } + } + public static class response { + public static CurationResponse get() { + return CurationResponse.builder() + .id(R.curation.id) + //.curator(MemberData.dto.response.curationCurator.get()) + .title(R.curation.title) + .content(R.curation.content) + .curationCards(R.curation.curationCardResponses) + .area(R.curation.area) + .hashtags(R.curation.hashtags) + //.eventsInfo(List.of(EventDomain.createValidCurationEventResponse())) + .createdTime(R.curation.createdDate) + .modifiedDate(R.curation.modifiedDate) + .build(); + } + public static class slice { + public static CurationSliceResponse get() { + return CurationSliceResponse.builder() + .curations(List.of(response.get())) + .sliceInfo(CommonData.sliceInfo.get()) + .build(); + } + } + } } } \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/EventData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/EventData.java new file mode 100644 index 00000000..5babf5d3 --- /dev/null +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/EventData.java @@ -0,0 +1,130 @@ +package org.ktc2.cokaen.wouldyouin._global.testdata; + +import java.time.LocalDateTime; +import java.util.List; +import org.ktc2.cokaen.wouldyouin._common.vo.Area; +import org.ktc2.cokaen.wouldyouin._common.vo.Category; +import org.ktc2.cokaen.wouldyouin._common.vo.Location; +import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; +import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; +import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.CurationEventResponse; +import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.ReservationEventResponse; +import org.ktc2.cokaen.wouldyouin.event.persist.Event; +import org.springframework.test.util.ReflectionTestUtils; + +public class EventData { + + public static class R { + + public static class event { + public static final long id = 201L; + public static final String title = "행사 제목"; + public static final String content = "행사 내용입니다. 행사의 내용은 최소 20자 최대 1000자 입니다."; + public static final Area area = Area.전체; + public static final Location location = new Location(55.0, 43.0, "광주 북구 용봉로 77"); + public static final LocalDateTime startTime = LocalDateTime.now().plusDays(3).plusHours(11).plusMinutes(47); + public static final LocalDateTime endTime = startTime.plusWeeks(2); + public static final int price = 15000; + public static final int totalSeat = 100; + public static final Category category = Category.밴드; + + public static final String hostNickname = MemberData.R.host.nickname; + public static final String hostProfileImageUrl = ImageData.R.member.host.url; + public static final String thumbnailImageUrl = "ImageData.R.event.thumbnail.url"; + } + public static class eventEditRequest { + public static final String title = "modifiedTitle"; + public static final String content = "modifiedContent 조홍식씨 최소글자 20자라고 해놓고 안 지켰어요. "; + public static final Area area = Area.광주; + public static final Location location = new Location(45.0, 143.0, "광주 북구 용봉로 77"); + public static final LocalDateTime startTime = event.startTime.plusDays(2); + public static final LocalDateTime endTime = startTime.plusWeeks(3); + public static final int price = 20000; + public static final int totalSeat = 200; + public static final Category category = Category.뮤지컬; + } + } + + public static class event { + public static class entity { + public static Event get() { + Event ret = Event.builder() + .title(R.event.title) + .content(R.event.content) + .area(R.event.area) + .location(R.event.location) + .startTime(R.event.startTime) + .endTime(R.event.endTime) + .price(R.event.price) + .totalSeat(R.event.totalSeat) + .category(R.event.category) + .build(); + ret.setHost(MemberData.host.entity.get()); + ReflectionTestUtils.setField(ret, "id", R.event.id); + return ret; + } + } + public static class request { + public static class create { + public static EventCreateRequest get() { + return EventCreateRequest.builder() + .title(R.event.title) + .content(R.event.content) + .area(R.event.area) + .location(R.event.location) + .startTime(R.event.startTime) + .endTime(R.event.endTime) + .price(R.event.price) + .totalSeat(R.event.totalSeat) + .category(R.event.category) + .imageIds(List.of()) + .build(); + } + } + public static class edit { + public static EventEditRequest get() { + return EventEditRequest.builder() + .title(R.eventEditRequest.title) + .content(R.eventEditRequest.content) + .area(R.eventEditRequest.area) + .location(R.eventEditRequest.location) + .startTime(R.eventEditRequest.startTime) + .endTime(R.eventEditRequest.endTime) + .price(R.eventEditRequest.price) + .totalSeat(R.eventEditRequest.totalSeat) + .category(R.eventEditRequest.category) + .imageIds(List.of()) + .build(); + } + } + } + public static class response { + + } + } + + public static class response { + public static class reservationEvent { + public static ReservationEventResponse createValidReservationEventResponse() { + return ReservationEventResponse.builder() + .eventId(R.event.id) + .title(R.event.title) + .price(R.event.price) + .build(); + } + } + public static class curationEvent { + public static CurationEventResponse createValidCurationEventResponse() { + return CurationEventResponse.builder() + .eventId(R.event.id) + .title(R.event.title) + .location(R.event.location) + .thumbnailImageUrl(R.event.thumbnailImageUrl) + .hostProfileImageUrl(R.event.hostProfileImageUrl) + .hostNickname(R.event.hostNickname) + .build(); + } + } + } + +} diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ImageData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ImageData.java index 11e047d6..a35eaff2 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ImageData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ImageData.java @@ -6,6 +6,7 @@ import org.ktc2.cokaen.wouldyouin.Image.persist.AdvertisementImage; import org.ktc2.cokaen.wouldyouin.Image.persist.CurationImage; import org.ktc2.cokaen.wouldyouin.Image.persist.EventImage; +import org.ktc2.cokaen.wouldyouin.Image.persist.Image; import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; import org.springframework.http.MediaType; import org.springframework.mock.web.MockMultipartFile; @@ -13,123 +14,319 @@ public class ImageData { - public static final long validMemberImageId = 1101L; - public static final long validEventImageId = 1201L; - public static final long validCurationImageId = 1301L; - public static final long validAdImageId = 1401L; - - public static MemberImage createValidMemberImage() { - MemberImage validMemberImage = MemberImage.builder() - .url("member/memberImage.jpg") - .size(10L) - .extension(".jpg") - .build(); - ReflectionTestUtils.setField(validMemberImage, "id", 1101L); -// ReflectionTestUtils.setField(validMemberImage, "baseMember", MemberDomain.createValidMember()); - return validMemberImage; - } + // name: 파일 이름만 있어야 함 => entity, request + // 예: memberImage1.png + // url: 도메인 그거 => response + // 예: https://localhost:8080/images/member/Image1.png - public static EventImage createValidEventImage() { - EventImage validEventImage = EventImage.builder() - .url("event/eventImage.jpg") - .size(20L) - .extension(".jpg") - .build(); - ReflectionTestUtils.setField(validEventImage, "id", 1201L); -// ReflectionTestUtils.setField(validMemberImage, "baseMember", MemberDomain.createValidMember()); - return validEventImage; + public static class R { + public static class member { + public static class normal { + public static final Long id = 1101L; + public static final String name = "memberImage1.jpg"; + public static final String url = "https://wouldyouin.store/api/images/" + name; + public static final Long size = 11000L; + public static final String extension = ".jpg"; + public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); + } + public static class curator { + public static final Long id = 1102L; + public static final String name = "curatorImage1.jpg"; + public static final String url = "https://wouldyouin.store/api/images/" + name; + public static final Long size = 12000L; + public static final String extension = ".jpg"; + public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); + } + public static class host { + public static final Long id = 1103L; + public static final String name = "hostImage1.jpg"; + public static final String url = "https://wouldyouin.store/api/images/" + name; + public static final Long size = 13000L; + public static final String extension = ".jpg"; + public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); + } + public static class welcome { + public static final Long id = 1104L; + public static final String name = "welcomeImage1.jpg"; + public static final String url = "https://wouldyouin.store/api/images/" + name; + public static final Long size = 14000L; + public static final String extension = ".jpg"; + public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); + } + } + public static class event { + public static final Long id = 1201L; + public static final String name = "eventImage1.jpg"; + public static final String url = "https://wouldyouin.store/api/images/" + name; + public static final Long size = 22000L; + public static final String extension = ".jpg"; + public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); + } + public static class curation1 { + public static final Long id = 1301L; + public static final String name = "curationImage1.jpg"; + public static final String url = "https://wouldyouin.store/api/images/" + name; + public static final Long size = 31000L; + public static final String extension = ".jpg"; + public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); + } + public static class curation2 { + public static final Long id = 1302L; + public static final String name = "curationImage2.jpg"; + public static final String url = "https://wouldyouin.store/api/images/" + name; + public static final Long size = 32000L; + public static final String extension = ".jpg"; + public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); + } + public static class advertisement { + public static final Long id = 1401L; + public static final String name = "adImage1.jpg"; + public static final String url = "https://wouldyouin.store/api/images/" + name; + public static final Long size = 40000L; + public static final String extension = ".jpg"; + public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); + } + public static class mockMultipartFile1 { + public static final String name = "images"; + public static final String originalFileName = "image1.jpg"; + public static final String contentType = MediaType.IMAGE_JPEG_VALUE; + public static final byte[] content = "imageData1".getBytes(); + } + public static class mockMultipartFile2 { + public static final String name = "images"; + public static final String originalFileName = "image2.png"; + public static final String contentType = MediaType.IMAGE_JPEG_VALUE; + public static final byte[] content = "imageData2".getBytes(); + } } - public static CurationImage createValidCurationImage1() { - CurationImage validCurationImage = CurationImage.builder() - .url("curation/curationImage1.jpg") - .size(30L) - .extension(".jpg") - .build(); - ReflectionTestUtils.setField(validCurationImage, "id", 1301L); -// ReflectionTestUtils.setField(validMemberImage, "baseMember", MemberDomain.createValidMember()); - return validCurationImage; + private static void setImageFields(Image image, Long id, LocalDateTime createdDate) { + ReflectionTestUtils.setField(image, "id", id); + ReflectionTestUtils.setField(image, "createdDate", createdDate); } - public static CurationImage createValidCurationImage2() { - CurationImage validCurationImage = CurationImage.builder() - .url("curation/curationImage2.jpg") - .size(30L) - .extension(".jpg") - .build(); - ReflectionTestUtils.setField(validCurationImage, "id", 1302L); -// ReflectionTestUtils.setField(validMemberImage, "baseMember", MemberDomain.createValidMember()); - return validCurationImage; - } + public static class member { + public static class normal { + public static class entity { + public static MemberImage get() { + MemberImage ret = MemberImage.builder() + .name(R.member.normal.name) + .size(R.member.normal.size) + .extension(R.member.normal.extension) + .build(); + setImageFields(ret, R.member.normal.id, R.member.normal.createdDate); + // ReflectionTestUtils.setField(ret, "baseMember", createValidMember()); + return ret; + } + } + public static class request { + public static ImageRequest get() { + return ImageRequest.builder() + .name(R.member.normal.url) + .size(R.member.normal.size) + .extension(R.member.normal.extension) + .build(); + } + } + public static class response { - public static AdvertisementImage createValidAdImage() { - AdvertisementImage validAdImage = AdvertisementImage.builder() - .url("curation/curationImage.jpg") - .size(40L) - .extension(".jpg") - .build(); - ReflectionTestUtils.setField(validAdImage, "id", 1401L); -// ReflectionTestUtils.setField(validMemberImage, "baseMember", MemberDomain.createValidMember()); - return validAdImage; - } + } + } + public static class curator { + public static class entity { + public static MemberImage get() { + MemberImage ret = MemberImage.builder() + .name(R.member.curator.name) + .size(R.member.curator.size) + .extension(R.member.curator.extension) + .build(); + setImageFields(ret, R.member.curator.id, R.member.curator.createdDate); + // ReflectionTestUtils.setField(ret, "baseMember", createValidCurator()); + return ret; + } + } + public static class request { - public static ImageRequest createValidMemberImageRequest() { - return ImageRequest.builder() - .url("member/memberImage.jpg") - .size(10L) - .extension(".jpg") - .build(); - } + } + public static class response { + + } + } + public static class host { + public static class entity { + public static MemberImage get() { + MemberImage ret = MemberImage.builder() + .name(R.member.host.name) + .size(R.member.host.size) + .extension(R.member.host.extension) + .build(); + setImageFields(ret, R.member.host.id, R.member.host.createdDate); + // ReflectionTestUtils.setField(ret, "baseMember", createValidHost()); + return ret; + } + } + public static class request { + + } + public static class response { - public static ImageRequest createValidEventImageRequest() { - return ImageRequest.builder() - .url("event/eventImage.jpg") - .size(20L) - .extension(".jpg") - .build(); + } + } + public static class welcome { + public static class entity { + public static MemberImage get() { + MemberImage ret = MemberImage.builder() + .name(R.member.welcome.name) + .size(R.member.welcome.size) + .extension(R.member.welcome.extension) + .build(); + setImageFields(ret, R.member.welcome.id, R.member.welcome.createdDate); + // ReflectionTestUtils.setField(validMemberImage, "baseMember", createValidWelcome()); + return ret; + } + } + public static class request { + + } + public static class response { + + } + } } - public static ImageRequest createValidCurationImageRequest() { - return ImageRequest.builder() - .url("curation/curationImage.jpg") - .size(30L) - .extension(".jpg") - .build(); + public static class event { + public static class entity { + public static EventImage get() { + EventImage ret = EventImage.builder() + .name(R.event.name) + .size(R.event.size) + .extension(R.event.extension) + .build(); + setImageFields(ret, R.event.id, R.event.createdDate); +// ReflectionTestUtils.setField(ret, "event", createValidEvent()); + return ret; + } + } + public static class request { + public static ImageRequest get() { + return ImageRequest.builder() + .name(R.event.name) + .size(R.event.size) + .extension(R.event.extension) + .build(); + } + } + public static class response { + + } } - public static ImageRequest createValidAdImageRequest() { - return ImageRequest.builder() - .url("ad/adImage.jpg") - .size(40L) - .extension(".jpg") - .build(); + public static class curation1 { + public static class entity { + public static CurationImage get() { + CurationImage ret = CurationImage.builder() + .name(R.curation1.name) + .size(R.curation1.size) + .extension(R.curation1.extension) + .build(); + setImageFields(ret, R.curation1.id, R.curation1.createdDate); + // ReflectionTestUtils.setField(ret, "curationCard", createValidCurator()); + return ret; + } + } + public static class request { + public static ImageRequest get() { + return ImageRequest.builder() + .name(R.curation1.name) + .size(R.curation1.size) + .extension(R.curation1.extension) + .build(); + } + } + public static class response { + public static ImageResponse get() { + return ImageResponse.builder() + .id(R.curation1.id) + .url(R.curation1.url) + .size(R.curation1.size) + .extension(R.curation1.extension) + .createdDate(R.curation1.createdDate) + .build(); + } + } } - public static ImageResponse createValidImageResponse1() { - return ImageResponse.builder() - .id(1L) - .url("curationImageUrl.jpg") - .size(10L) - .extension(".jpg") - .createdDate(LocalDateTime.of(2024, 3, 23, 0, 0)) - .build(); + public static class curation2 { + public static class entity { + public static CurationImage get() { + CurationImage ret = CurationImage.builder() + .name(R.curation2.name) + .size(R.curation2.size) + .extension(R.curation2.extension) + .build(); + setImageFields(ret, R.curation2.id, R.curation2.createdDate); + // ReflectionTestUtils.setField(ret, "curationCard", createValidCurator()); + return ret; + } + } + public static class request { + + } + public static class response { + public static ImageResponse get() { + return ImageResponse.builder() + .id(R.curation2.id) + .url(R.curation2.url) + .size(R.curation2.size) + .extension(R.curation2.extension) + .createdDate(R.curation2.createdDate) + .build(); + } + } } - public static ImageResponse createValidImageResponse2() { - return ImageResponse.builder() - .id(2L) - .url("memberImage.png") - .size(20L) - .extension(".png") - .createdDate(LocalDateTime.of(2024, 3, 23, 0, 0)) - .build(); + public static class advertisement { + public static class entity { + public static AdvertisementImage get() { + AdvertisementImage ret = AdvertisementImage.builder() + .name(R.advertisement.name) + .size(R.advertisement.size) + .extension(R.advertisement.extension) + .build(); + setImageFields(ret, R.advertisement.id, R.advertisement.createdDate); + // ReflectionTestUtils.setField(ret, "advertisement", createValidMember()); + return ret; + } + } + public static class request { + public static ImageRequest get() { + return ImageRequest.builder() + .name(R.advertisement.name) + .size(R.advertisement.size) + .extension(R.advertisement.extension) + .build(); + } + } } - public static MockMultipartFile createValidMultipartFile1() { - return new MockMultipartFile("images", "image1.jpg", MediaType.IMAGE_JPEG_VALUE, "imageData1".getBytes()); + public static class mockMultipartFile1 { + public static MockMultipartFile get() { + return new MockMultipartFile( + R.mockMultipartFile1.name, + R.mockMultipartFile1.originalFileName, + R.mockMultipartFile1.contentType, + R.mockMultipartFile1.content); + } } - public static MockMultipartFile createValidMultipartFile2() { - return new MockMultipartFile("images", "image2.png", MediaType.IMAGE_JPEG_VALUE, "imageData2".getBytes()); + public static class mockMultipartFile2 { + public static MockMultipartFile get() { + return new MockMultipartFile( + R.mockMultipartFile2.name, + R.mockMultipartFile2.originalFileName, + R.mockMultipartFile2.contentType, + R.mockMultipartFile2.content); + } } -} + +} \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java index d4581c38..22c94d7e 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java @@ -3,7 +3,9 @@ import java.util.List; import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin._common.vo.Area; +import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse.ReservationMemberResponse; +import org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse.CurationCuratorResponse; import org.ktc2.cokaen.wouldyouin.member.persist.AccountType; import org.ktc2.cokaen.wouldyouin.member.persist.Curator; import org.ktc2.cokaen.wouldyouin.member.persist.Host; @@ -13,89 +15,209 @@ public class MemberData { - public static final long validMemberId = 101L; - public static final long validCuratorId = 102L; - public static final long validHostId = 103L; - public static final long validWelcomeMemberId = 104L; - public static final long validAdminId = 105L; - - public static Member createValidMember() { - MemberImage memberImage = ImageData.createValidMemberImage(); - Member ret = Member.builder() - .accountType(AccountType.kakao) - .email("member1@example.com") - .nickname("nick_normal_123") - .phone("010-1112-2233") - .profileImage(memberImage) - .area(Area.광주) - .gender("Men") - .socialId("100100100100100") - .build(); - ReflectionTestUtils.setField(ret, "Id", validMemberId); - ReflectionTestUtils.setField(ret, "memberType", MemberType.normal); - ReflectionTestUtils.setField(memberImage, "baseMember", ret); - return ret; + public static class R { + public static class normal { + public static final long id = 101L; + public static final MemberIdentifier memberIdentifier = new MemberIdentifier(id, MemberType.normal); + public static final AccountType accountType = AccountType.kakao; + public static final String email = "member1@example.com"; + public static final String nickname = "nick_normal_123"; + public static final String phone = "010-1112-2233"; + public static final MemberImage profileImage = ImageData.member.normal.entity.get(); + public static final Area area = Area.광주; + public static final String gender = "Men"; + public static final String socialId = "100100100100100"; + public static final MemberType memberType = MemberType.normal; + } + public static class curator { + public static final long id = 102L; + public static final MemberIdentifier memberIdentifier = new MemberIdentifier(id, MemberType.curator); + public static final AccountType accountType = AccountType.google; + public static final String email = "curator1@example.com"; + public static final String nickname = "nick_curator_12"; + public static final String phone = "010-4545-6767"; + public static final MemberImage profileImage = ImageData.member.curator.entity.get(); + public static final String profileImageUrl = "https://wouldyouin.store/api/images/member/" + profileImage.getName(); + public static final Area area = Area.광주; + public static final String gender = "Women"; + public static final String socialId = "200200200200200"; + public static final String intro = "큐레이터 자기소개입니다."; + public static final List hashtags = List.of("#큐레이터", "#해시태그", "#입니다"); + } + public static class host { + public static final long id = 103L; + public static final MemberIdentifier memberIdentifier = new MemberIdentifier(id, MemberType.host); + public static final String email = "host1@example.com"; + public static final String nickname = "nick_host_12"; + public static final String phone = "010-4545-6767"; + public static final String hashedPassword = "hashed_password"; + public static final MemberImage profileImage = ImageData.member.host.entity.get(); + public static final String intro = "주최자 자기소개입니다."; + public static final List hashtags = List.of("#주최자", "#해시태그", "#입니다"); + + } + public static class welcome { + public static final long id = 104L; + public static final MemberIdentifier memberIdentifier = new MemberIdentifier(id, MemberType.welcome); + public static final AccountType accountType = AccountType.kakao; + public static final String email = "welcome2@example.com"; + public static final String nickname = "nick_normal_333"; + public static final String phone = "010-4414-1144"; + public static final MemberImage profileImage = ImageData.member.welcome.entity.get(); + public static final Area area = Area.서울; + public static final String gender = "Men"; + public static final String socialId = "456456456456"; + + } + public static class admin { + public static final long id = 105L; + public static final MemberIdentifier memberIdentifier = new MemberIdentifier(id, MemberType.admin); + } } - public static Curator createValidCurator() { - MemberImage memberImage = ImageData.createValidMemberImage(); - Curator ret = Curator.curatorBuilder() - .accountType(AccountType.google) - .email("curator1@example.com") - .nickname("nick_curator_12") - .phone("010-4545-6767") - .profileImage(memberImage) - .area(Area.광주) - .gender("Women") - .socialId("200200200200200") - .build(); - ReflectionTestUtils.setField(ret, "Id", validCuratorId); - ReflectionTestUtils.setField(ret, "intro", "큐레이터 자기소개입니다."); - ReflectionTestUtils.setField(ret, "hashtags", List.of("#큐레이터", "#해시태그", "#입니다")); - ReflectionTestUtils.setField(memberImage, "baseMember", ret); - return ret; + public static class normal { + public static class entity { + public static Member get() { + Member ret = Member.builder() + .accountType(R.normal.accountType) + .email(R.normal.email) + .nickname(R.normal.nickname) + .phone(R.normal.phone) + .profileImage(R.normal.profileImage) + .area(R.normal.area) + .gender(R.normal.gender) + .socialId(R.normal.socialId) + .build(); + ReflectionTestUtils.setField(ret, "Id", R.normal.id); + ReflectionTestUtils.setField(ret, "memberType", R.normal.memberType); +// ReflectionTestUtils.setField(ret.getProfileImage(), "baseMember", ret); + return ret; + } + } + public static class request { + + } + public static class response { + + } } - public static Host createValidHost() { - MemberImage memberImage = ImageData.createValidMemberImage(); - Host ret = Host.builder() - .email("curator1@example.com") - .nickname("nick_curator_12") - .phone("010-4545-6767") - .hashedPassword("hashed_password") - .profileImage(memberImage) - .build(); - ReflectionTestUtils.setField(ret, "Id", validHostId); - ReflectionTestUtils.setField(ret, "intro", "주최자 자기소개입니다."); - ReflectionTestUtils.setField(ret, "hashtags", List.of("#주최자", "#해시태그", "#입니다")); - ReflectionTestUtils.setField(memberImage, "baseMember", ret); - return ret; + public static class curator { + public static class entity { + public static Curator get() { + Curator ret = Curator.curatorBuilder() + .accountType(R.curator.accountType) + .email(R.curator.email) + .nickname(R.curator.nickname) + .phone(R.curator.phone) + .profileImage(R.curator.profileImage) + .area(R.curator.area) + .gender(R.curator.gender) + .socialId(R.curator.socialId) + .build(); + ReflectionTestUtils.setField(ret, "Id", R.curator.id); + ReflectionTestUtils.setField(ret, "intro", R.curator.intro); + ReflectionTestUtils.setField(ret, "hashtags", R.curator.hashtags); +// ReflectionTestUtils.setField(ret.getProfileImage(), "baseMember", ret); + return ret; + } + } + public static class request { + + } + public static class response { + + } } - public static Member createValidWelcomeMember() { - MemberImage memberImage = ImageData.createValidMemberImage(); - Member ret = Member.builder() - .accountType(AccountType.kakao) - .email("member2@example.com") - .nickname("nick_normal_333") - .phone("010-4414-1144") - .profileImage(memberImage) - .area(Area.서울) - .gender("Men") - .socialId("456456456456") - .build(); - ReflectionTestUtils.setField(ret, "Id", validWelcomeMemberId); - ReflectionTestUtils.setField(memberImage, "baseMember", ret); - return ret; + public static class host { + public static class entity { + public static Host get() { + Host ret = Host.builder() + .email(R.host.email) + .nickname(R.host.nickname) + .phone(R.host.phone) + .hashedPassword(R.host.hashedPassword) + .profileImage(R.host.profileImage) + .build(); + ReflectionTestUtils.setField(ret, "Id", R.host.id); + ReflectionTestUtils.setField(ret, "intro", R.host.intro); + ReflectionTestUtils.setField(ret, "hashtags", R.host.hashtags); +// ReflectionTestUtils.setField(ret.getProfileImage(), "baseMember", ret); + return ret; + } + } + public static class request { + + } + public static class response { + + } + } + + public static class welcome { + public static class entity { + public static Member get() { + Member ret = Member.builder() + .accountType(R.welcome.accountType) + .email(R.welcome.email) + .nickname(R.welcome.nickname) + .phone(R.welcome.phone) + .profileImage(R.welcome.profileImage) + .area(R.welcome.area) + .gender(R.welcome.gender) + .socialId(R.welcome.socialId) + .build(); + ReflectionTestUtils.setField(ret, "Id", R.welcome.id); +// ReflectionTestUtils.setField(ret.getProfileImage(), "baseMember", ret); + return ret; + } + } + public static class request { + + } + public static class response { + + } + } + + public static class admin { + public static class entity { + + public static final long validAdminId = 105L; + } + public static class request { + + } + public static class response { + + } } - public static ReservationMemberResponse createValidReservationMemberResponse() { - return ReservationMemberResponse.builder() - .id(validMemberId) - .email("member1@example.com") - .nickname("nick_normal_123") - .phone("010-1112-2233") - .gender("Men") - .build(); + public static class response { + public static class reservationMember { + public static ReservationMemberResponse get() { + return ReservationMemberResponse.builder() + .memberId(R.normal.id) + .email(R.normal.email) + .nickname(R.normal.nickname) + .phone(R.normal.phone) + .gender(R.normal.gender) + .build(); + } + } + public static class curationCurator { + public static CurationCuratorResponse get() { + return CurationCuratorResponse.builder() + .nickname(R.curator.nickname) + .email(R.curator.email) + .phone(R.curator.phone) + .profileImageUrl(R.curator.profileImageUrl) + .intro(R.curator.intro) + .likes(0) + .hashtags(R.curator.hashtags) + .build(); + } + } } } \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ReservationData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ReservationData.java new file mode 100644 index 00000000..a6e56405 --- /dev/null +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ReservationData.java @@ -0,0 +1,77 @@ +package org.ktc2.cokaen.wouldyouin._global.testdata; + +import java.time.LocalDateTime; +import java.util.List; +import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.ReservationEventResponse; +import org.ktc2.cokaen.wouldyouin.event.persist.Event; +import org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse.ReservationMemberResponse; +import org.ktc2.cokaen.wouldyouin.member.persist.Member; +import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationRequest; +import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationResponse; +import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationSliceResponse; +import org.ktc2.cokaen.wouldyouin.reservation.persist.Reservation; +import org.springframework.test.util.ReflectionTestUtils; + +public class ReservationData { + + public static class R { + public static class reservation { + public static final Long id = 1L; + public static final Member member = MemberData.normal.entity.get(); + public static final Event event = EventData.event.entity.get(); + public static final Integer price = EventData.R.event.price; + public static final Integer quantity = 2; + public static final LocalDateTime reservationDate = LocalDateTime.of(2024, 3, 23, 0, 0); + + public static final ReservationMemberResponse memberResponse = MemberData.response.reservationMember.get(); + public static final ReservationEventResponse eventResponse = EventData.response.reservationEvent.createValidReservationEventResponse(); + } + } + + public static class reservation { + public static class entity { + public static Reservation get() { + Reservation ret = Reservation.builder() + .member(R.reservation.member) + .event(R.reservation.event) + .price(R.reservation.price) + .quantity(R.reservation.quantity) + .build(); + ReflectionTestUtils.setField(ret, "id", R.reservation.id); + ReflectionTestUtils.setField(ret, "reservationDate", R.reservation.reservationDate); + return ret; + } + } + public static class request { + public static ReservationRequest get() { + return ReservationRequest.builder() + .eventId(R.reservation.event.getId()) + .quantity(R.reservation.quantity) + .build(); + } + } + public static class response { + public static ReservationResponse get() { + return ReservationResponse.builder() + .id(R.reservation.id) + .member(R.reservation.memberResponse) + .event(R.reservation.eventResponse) + .price(R.reservation.price) + .quantity(R.reservation.quantity) + .reservationDate(R.reservation.reservationDate) + .build(); + + } + public static class slice { + public static ReservationSliceResponse get() { + return ReservationSliceResponse.builder() + .reservations(List.of( + ReservationData.reservation.response.get())) + .sliceInfo(CommonData.sliceInfo.get()) + .build(); + } + } + } + } + +} diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java index fd437c1b..f64f4884 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java @@ -2,10 +2,6 @@ import static java.lang.Math.abs; import static org.assertj.core.api.Assertions.assertThat; -import static org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.createValidCurationCardRequest1; -import static org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.createValidCurationCreateRequest; -import static org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.createValidCurationEditRequest; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.validCuratorId; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.times; @@ -29,7 +25,8 @@ import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockCurator; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; +import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator; import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; import org.ktc2.cokaen.wouldyouin.curation.api.CurationController; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCreateRequest; @@ -150,7 +147,7 @@ void getCurationByCurationId() throws Exception { void createCuration1() throws Exception { // given ArgumentCaptor captor = ArgumentCaptor.forClass(CurationCreateRequest.class); - CurationCreateRequest request = createValidCurationCreateRequest(); + CurationCreateRequest request = CurationData.curation.request.create.get(); // when mockMvc.perform(post("/api/curations") @@ -161,7 +158,7 @@ void createCuration1() throws Exception { .andExpect(status().isCreated()); // then - then(curationService).should(times(1)).create(eq(validCuratorId), captor.capture()); + then(curationService).should(times(1)).create(eq(curator.memberIdentifier), captor.capture()); assertThat(captor.getValue()).isEqualTo(request); } @@ -173,7 +170,7 @@ void createCuration2() throws Exception { mockMvc.perform(post("/api/curations") .with(csrf()) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(createValidCurationCreateRequest()))) + .content(objectMapper.writeValueAsString(CurationData.curation.request.create.get()))) .andDo(print()) .andExpect(status().isUnauthorized()) .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); @@ -191,7 +188,7 @@ void createCuration3() throws Exception { mockMvc.perform(post("/api/curations") .with(csrf()) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(createValidCurationCreateRequest()))) + .content(objectMapper.writeValueAsString(CurationData.curation.request.create.get()))) .andDo(print()) .andExpect(status().isUnauthorized()) .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); @@ -206,7 +203,7 @@ void createCuration3() throws Exception { @WithMockCurator void createCuration4() throws Exception { // given - CurationCreateRequest request = createValidCurationCreateRequest().toBuilder() + CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() .title("").build(); // when @@ -227,8 +224,8 @@ void createCuration4() throws Exception { @WithMockCurator void createCuration5() throws Exception { // given - CurationCreateRequest request = createValidCurationCreateRequest().toBuilder() - .curationCards(List.of(createValidCurationCardRequest1().toBuilder().subtitle("").build())) + CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() + .curationCards(List.of(CurationData.curationCard1.request.get().toBuilder().subtitle("").build())) .build(); // when @@ -249,8 +246,8 @@ void createCuration5() throws Exception { @WithMockCurator void createCuration6() throws Exception { // given - CurationCreateRequest request = createValidCurationCreateRequest().toBuilder() - .curationCards(List.of(createValidCurationCardRequest1().toBuilder().content(null).build())) + CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() + .curationCards(List.of(CurationData.curationCard1.request.get().toBuilder().content(null).build())) .build(); // when @@ -271,8 +268,8 @@ void createCuration6() throws Exception { @WithMockCurator void createCuration7() throws Exception { // given - CurationCreateRequest request = createValidCurationCreateRequest().toBuilder() - .curationCards(List.of(createValidCurationCardRequest1().toBuilder().content(null).build())) + CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() + .curationCards(List.of(CurationData.curationCard1.request.get().toBuilder().content(null).build())) .build(); // when @@ -293,8 +290,8 @@ void createCuration7() throws Exception { @WithMockCurator void createCuration8() throws Exception { // given - CurationCreateRequest request = createValidCurationCreateRequest().toBuilder() - .curationCards(List.of(createValidCurationCardRequest1().toBuilder().content("짧은 내용").build())) + CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() + .curationCards(List.of(CurationData.curationCard1.request.get().toBuilder().content("짧은 내용").build())) .build(); // when @@ -315,8 +312,8 @@ void createCuration8() throws Exception { @WithMockCurator void createCuration9() throws Exception { // given - CurationCreateRequest request = createValidCurationCreateRequest().toBuilder() - .curationCards(List.of(createValidCurationCardRequest1().toBuilder() + CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() + .curationCards(List.of(CurationData.curationCard1.request.get().toBuilder() .imageIds(List.of(1L, 2L, 3L, 4L, 5L, 6L)).build())) .build(); @@ -338,7 +335,7 @@ void createCuration9() throws Exception { @WithMockCurator void createCuration10() throws Exception { // given - CurationCreateRequest request = createValidCurationCreateRequest().toBuilder() + CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() .area(null).build(); // when @@ -359,7 +356,7 @@ void createCuration10() throws Exception { @WithMockCurator void createCuration11() throws Exception { // given - CurationCreateRequest request = createValidCurationCreateRequest().toBuilder(). + CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder(). curationCards(List.of()).build(); // when @@ -381,7 +378,7 @@ void createCuration11() throws Exception { void updateCuration1() throws Exception { // given ArgumentCaptor captor = ArgumentCaptor.forClass(CurationEditRequest.class); - CurationEditRequest request = createValidCurationEditRequest(); + CurationEditRequest request = CurationData.curation.request.edit.get(); // when mockMvc.perform(put("/api/curations/" + randomId) @@ -392,7 +389,7 @@ void updateCuration1() throws Exception { .andExpect(status().isOk()); // then - then(curationService).should(times(1)).update(eq(validCuratorId), eq(randomId), captor.capture()); + then(curationService).should(times(1)).update(eq(curator.memberIdentifier), eq(randomId), captor.capture()); assertThat(captor.getValue()).isEqualTo(request); } @@ -404,7 +401,7 @@ void updateCuration2() throws Exception { mockMvc.perform(put("/api/curations/" + randomId) .with(csrf()) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(createValidCurationEditRequest()))) + .content(objectMapper.writeValueAsString(CurationData.curation.request.edit.get()))) .andDo(print()) .andExpect(status().isUnauthorized()) .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); @@ -422,7 +419,7 @@ void updateCuration3() throws Exception { mockMvc.perform(put("/api/curations/" + randomId) .with(csrf()) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(createValidCurationEditRequest()))) + .content(objectMapper.writeValueAsString(CurationData.curation.request.edit.get()))) .andDo(print()) .andExpect(status().isUnauthorized()) .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); @@ -437,7 +434,7 @@ void updateCuration3() throws Exception { @WithMockCurator void updateCuration4() throws Exception { // given - CurationEditRequest request = createValidCurationEditRequest().toBuilder() + CurationEditRequest request = CurationData.curation.request.edit.get().toBuilder() .title(null).build(); // when @@ -458,8 +455,8 @@ void updateCuration4() throws Exception { @WithMockCurator void updateCuration5() throws Exception { // given - CurationEditRequest request = createValidCurationEditRequest().toBuilder() - .curationCards(List.of(createValidCurationCardRequest1().toBuilder() + CurationEditRequest request = CurationData.curation.request.edit.get().toBuilder() + .curationCards(List.of(CurationData.curationCard1.request.get().toBuilder() .subtitle("").build())) .build(); @@ -481,8 +478,8 @@ void updateCuration5() throws Exception { @WithMockCurator void updateCuration6() throws Exception { // given - CurationEditRequest request = createValidCurationEditRequest().toBuilder() - .curationCards(List.of(createValidCurationCardRequest1().toBuilder() + CurationEditRequest request = CurationData.curation.request.edit.get().toBuilder() + .curationCards(List.of(CurationData.curationCard1.request.get().toBuilder() .content(null).build())) .build(); @@ -504,8 +501,8 @@ void updateCuration6() throws Exception { @WithMockCurator void updateCuration7() throws Exception { // given - CurationEditRequest request = createValidCurationEditRequest().toBuilder() - .curationCards(List.of(createValidCurationCardRequest1().toBuilder() + CurationEditRequest request = CurationData.curation.request.edit.get().toBuilder() + .curationCards(List.of(CurationData.curationCard1.request.get().toBuilder() .content("짧은 내용").build())) .build(); @@ -527,8 +524,8 @@ void updateCuration7() throws Exception { @WithMockCurator void updateCuration8() throws Exception { // given - CurationEditRequest request = createValidCurationEditRequest().toBuilder() - .curationCards(List.of(createValidCurationCardRequest1().toBuilder() + CurationEditRequest request = CurationData.curation.request.edit.get().toBuilder() + .curationCards(List.of(CurationData.curationCard1.request.get().toBuilder() .imageIds(List.of(1L, 2L, 3L, 4L, 5L, 6L)).build())) .build(); @@ -550,7 +547,7 @@ void updateCuration8() throws Exception { @WithMockCurator void updateCuration9() throws Exception { // given - CurationEditRequest request = createValidCurationEditRequest().toBuilder() + CurationEditRequest request = CurationData.curation.request.edit.get().toBuilder() .area(null).build(); // when @@ -571,7 +568,7 @@ void updateCuration9() throws Exception { @WithMockCurator void updateCuration10() throws Exception { // given - CurationEditRequest request = createValidCurationEditRequest().toBuilder() + CurationEditRequest request = CurationData.curation.request.edit.get().toBuilder() .curationCards(List.of()).build(); // when @@ -598,7 +595,7 @@ void deleteCuration1() throws Exception { .andExpect(status().isNoContent()); // then - then(curationService).should(times(1)).delete(eq(validCuratorId), eq(randomId)); + then(curationService).should(times(1)).delete(eq(curator.memberIdentifier), eq(randomId)); } @Test diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java index d14d31bd..516f88d9 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java @@ -3,7 +3,6 @@ import static java.lang.Math.abs; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.createValidCuration; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.times; @@ -16,6 +15,8 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; +import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData; +import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationResponse; import org.ktc2.cokaen.wouldyouin.curation.application.CurationCardService; import org.ktc2.cokaen.wouldyouin.curation.application.CurationService; import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; @@ -45,20 +46,18 @@ class CurationServiceTest { @Mock private MemberImage memberImage; - private Curation validCuration; - private final long randomId = abs(new Random().nextLong()); @BeforeEach void setUp() { curationService = new CurationService(curationRepository, curatorService, eventService, curationCardService); - validCuration = createValidCuration(); } @Test @DisplayName("큐레이션 ID를 통해 큐레이션 조회한다.") void getByIdOrThrow1() { // given + Curation validCuration = CurationData.curation.entity.get(); given(curationRepository.findById(randomId)).willReturn(Optional.of(validCuration)); // when @@ -78,12 +77,25 @@ void getByIdOrThrow2() { // when, then EntityNotFoundException thrown = assertThrows( EntityNotFoundException.class, () -> curationService.getByIdOrThrow(randomId)); + then(curationRepository).should(times(1)).findById(randomId); assertThat(thrown.getMessage()).isEqualTo("해당하는 큐레이션을 찾을 수 없습니다."); } - @Test - void getById() { - } + // TODO: 이게 통과하면 데이터 정합성은 완벽한 것일거임 +// @Test +// @DisplayName("큐레이션 ID를 통해 큐레이션을 찾지 못한 경우, 예외를 던진다.") +// void getById() { +// // given +// Curation validCuration = CurationData.curation.entity.get(); +// given(curationRepository.findById(randomId)).willReturn(Optional.of(validCuration)); +// +// // when +// CurationResponse response = curationService.getById(randomId); +// +// // then +// then(curationRepository).should(times(1)).findById(randomId); +// assertThat(response).usingRecursiveComparison().isEqualTo(CurationData.curation.response.get()); +// } @Test void getAllByAreaOrderByCreatedDateDesc() { diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java index a840608b..7207c369 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java @@ -1,7 +1,5 @@ package org.ktc2.cokaen.wouldyouin.event; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidHost; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.validHostId; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; @@ -24,8 +22,10 @@ import org.junit.jupiter.api.Test; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; -import org.ktc2.cokaen.wouldyouin._global.TestData.EventDomain; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost; +import org.ktc2.cokaen.wouldyouin._global.testdata.EventData; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.host.entity; import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; import org.ktc2.cokaen.wouldyouin.auth.application.JwtService; import org.ktc2.cokaen.wouldyouin.event.api.EventController; @@ -70,7 +70,7 @@ class EventControllerUnitTest { @BeforeAll public static void init() { id = 3L; - validHost = createValidHost(); + validHost = entity.get(); objectMapper = new ObjectMapper(); objectMapper.registerModule(new JavaTimeModule()); } @@ -186,12 +186,12 @@ void createEvent() throws Exception { mockMvc.perform(post("/api/events") .with(csrf()) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(EventDomain.createValidEventCreateRequest()))) + .content(objectMapper.writeValueAsString(EventData.event.request.create.get()))) .andDo(print()) .andExpect(status().isCreated()); //then - then(eventService).should(times(1)).create(eq(validHostId), any(EventCreateRequest.class)); + then(eventService).should(times(1)).create(eq(host.memberIdentifier), any(EventCreateRequest.class)); } @Test @@ -203,11 +203,12 @@ void updateEvent() throws Exception { mockMvc.perform(put("/api/events/" + id) .with(csrf()) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(EventDomain.createValidEventCreateRequest()))) + .content(objectMapper.writeValueAsString(EventData.event.request.create.get()))) + .andDo(print()) .andExpect(status().isOk()); //then - then(eventService).should(times(1)).update(eq(validHostId), eq(id), any(EventEditRequest.class)); + then(eventService).should(times(1)).update(eq(host.memberIdentifier), eq(id), any(EventEditRequest.class)); } @Test @@ -221,6 +222,6 @@ void deleteEvent() throws Exception { ).andExpect(status().isNoContent()); //then - then(eventService).should(times(1)).delete(eq(validHostId), eq(id)); + then(eventService).should(times(1)).delete(eq(host.memberIdentifier), eq(id)); } } \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java index 1590e5ec..60414a94 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java @@ -18,7 +18,10 @@ import org.ktc2.cokaen.wouldyouin.Image.application.EventImageService; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; -import org.ktc2.cokaen.wouldyouin._global.TestData.EventDomain; +import org.ktc2.cokaen.wouldyouin._global.testdata.EventData; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host; +import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationFilter; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; @@ -27,6 +30,7 @@ import org.ktc2.cokaen.wouldyouin.event.persist.Event; import org.ktc2.cokaen.wouldyouin.event.persist.EventRepository; import org.ktc2.cokaen.wouldyouin.member.application.HostService; +import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.domain.PageRequest; @@ -52,7 +56,7 @@ class EventServiceUnitTest { @BeforeEach void setUp() { eventService = new EventService(eventRepository, hostService, eventImageService); - validEvent = EventDomain.createValidEvent(); + validEvent = EventData.event.entity.get(); } @Test @@ -135,11 +139,11 @@ void getByInvalidId() { void create() { // given Long hostId = validEvent.getHost().getId(); - EventCreateRequest validEventCreateRequest = EventDomain.createValidEventCreateRequest(); + EventCreateRequest validEventCreateRequest = EventData.event.request.create.get(); given(eventRepository.save(any())).willReturn(validEvent); // when - eventService.create(hostId, validEventCreateRequest); + eventService.create(host.memberIdentifier, validEventCreateRequest); // then then(eventRepository).should(times(1)).save(any(Event.class)); @@ -151,11 +155,11 @@ void update() { // given Long eventId = validEvent.getId(); Long hostId = validEvent.getHost().getId(); - EventEditRequest validEventEditRequest = EventDomain.createValidEventEditRequest(); + EventEditRequest validEventEditRequest = EventData.event.request.edit.get(); given(eventRepository.findById(eventId)).willReturn(Optional.of(validEvent)); // when - eventService.update(hostId, eventId, validEventEditRequest); + eventService.update(host.memberIdentifier, eventId, validEventEditRequest); // then then(eventRepository).should(times(1)).findById(eventId); @@ -176,14 +180,14 @@ void update() { @DisplayName("유효하지 않은 행사 id를 통한 행사 수정 - 실패") void updateByInvalidId() { // given - EventEditRequest request = EventDomain.createValidEventEditRequest(); + EventEditRequest request = EventData.event.request.edit.get(); Long invalidHostId = 999L; given(eventRepository.findById(invalidHostId)).willThrow(RuntimeException.class); // when & then assertThrows(RuntimeException.class, - () -> eventService.update(invalidHostId, validEvent.getId(), - EventDomain.createValidEventEditRequest())); + () -> eventService.update(new MemberIdentifier(invalidHostId, MemberType.host), validEvent.getId(), + EventData.event.request.edit.get())); } @Test @@ -196,7 +200,7 @@ void delete() { // when given(eventRepository.findById(eventId)).willReturn(Optional.of(validEvent)); willDoNothing().given(eventRepository).deleteById(eventId); - eventService.delete(hostId, eventId); + eventService.delete(host.memberIdentifier, eventId); // then then(eventRepository).should(times(1)).findById(eventId); @@ -212,6 +216,6 @@ void deleteByInvalidId() { given(eventRepository.findById(eventId)).willThrow(RuntimeException.class); // when & then - assertThrows(RuntimeException.class, () -> eventService.delete(hostId, eventId)); + assertThrows(RuntimeException.class, () -> eventService.delete(host.memberIdentifier, eventId)); } } \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java index 52e6f2ff..9160fc52 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java @@ -1,10 +1,6 @@ package org.ktc2.cokaen.wouldyouin.image; import static java.lang.Math.abs; -import static org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.createValidImageResponse1; -import static org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.createValidImageResponse2; -import static org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.createValidMultipartFile1; -import static org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.createValidMultipartFile2; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; @@ -32,6 +28,9 @@ import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockCurator; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember; import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData; +import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.mockMultipartFile1; +import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.mockMultipartFile2; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator; import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; @@ -96,11 +95,11 @@ void getImage() throws Exception { @WithMockCurator void uploadImages1() throws Exception { // given - MockMultipartFile image1 = createValidMultipartFile1(); - MockMultipartFile image2 = createValidMultipartFile2(); + MockMultipartFile image1 = mockMultipartFile1.get(); + MockMultipartFile image2 = mockMultipartFile2.get(); given((CurationImageService) imageServiceFactory.getImageService(ImageDomain.CURATION)).willReturn(curationImageService); given(curationImageService.saveImages(List.of(image1, image2))) - .willReturn(List.of(createValidImageResponse1(), createValidImageResponse2())); + .willReturn(List.of(ImageData.curation1.response.get(), ImageData.curation2.response.get())); // when mockMvc.perform(multipart("/api/images") @@ -122,8 +121,8 @@ void uploadImages1() throws Exception { @WithMockCurator void uploadImages2() throws Exception { // given - MockMultipartFile image1 = createValidMultipartFile1(); - MockMultipartFile image2 = createValidMultipartFile2(); + MockMultipartFile image1 = mockMultipartFile1.get(); + MockMultipartFile image2 = mockMultipartFile2.get(); // when mockMvc.perform(multipart("/api/images") @@ -157,7 +156,7 @@ void deleteImage1() throws Exception { // then then(imageServiceFactory).should(times(1)).getImageService(eq(ImageDomain.CURATION)); - then(curationImageService).should(times(1)).deleteImage(randomId); + then(curationImageService).should(times(1)).deleteImage(curator.memberIdentifier, randomId); } @Test diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberServiceUnitTest.java index 28968e9e..3f4497c1 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberServiceUnitTest.java @@ -2,14 +2,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidCurator; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidHost; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidMember; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidWelcomeMember; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.validCuratorId; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.validHostId; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.validMemberId; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.validWelcomeMemberId; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; @@ -25,6 +17,11 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.normal; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.welcome; import org.ktc2.cokaen.wouldyouin.member.api.dto.MemberResponse; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMember; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMemberRepository; @@ -61,10 +58,10 @@ class BaseMemberServiceUnitTest { private BaseMemberService baseMemberService; private static Map members; - private static final Member validMember = createValidMember(); - private static final Member validWelcomeMember = createValidWelcomeMember(); - private static final Host validHost = createValidHost(); - private static final Curator validCurator = createValidCurator(); + private static final Member validMember = MemberData.normal.entity.get(); + private static final Member validWelcomeMember = MemberData.welcome.entity.get(); + private static final Host validHost = MemberData.host.entity.get(); + private static final Curator validCurator = MemberData.curator.entity.get(); @BeforeAll static void beforeAll() { @@ -92,7 +89,7 @@ MemberType welcomeTypeMapping(MemberType memberType) { } @ParameterizedTest - @ValueSource(longs = {validMemberId, validCuratorId, validHostId, validWelcomeMemberId}) + @ValueSource(longs = {normal.id, curator.id, host.id, welcome.id}) @DisplayName("임의의 사용자를 찾는 메서드 테스트") void getByIdOrThrow(long id) { // when @@ -105,7 +102,7 @@ void getByIdOrThrow(long id) { } @ParameterizedTest - @ValueSource(longs = {validMemberId, validCuratorId, validHostId, validWelcomeMemberId}) + @ValueSource(longs = {normal.id, curator.id, host.id, welcome.id}) @DisplayName("임의의 사용자의 타입을 반환하는 메서드 테스트") void getMemberType(long id) { // when @@ -118,7 +115,7 @@ void getMemberType(long id) { } @ParameterizedTest - @ValueSource(longs = {validMemberId, validCuratorId, validHostId, validWelcomeMemberId}) + @ValueSource(longs = {normal.id, curator.id, host.id, welcome.id}) @DisplayName("각 유형의 사용자를 찾고 응답 반환하는 메서드 테스트") void findById(long id) { // given @@ -140,7 +137,7 @@ void findById(long id) { } @ParameterizedTest - @ValueSource(longs = {validMemberId, validCuratorId, validHostId, validWelcomeMemberId}) + @ValueSource(longs = {normal.id, curator.id, host.id, welcome.id}) @DisplayName("중복 있는 이메일 있는 경우 테스트") void checkUniqueEmailOrThrow(long id) { // given @@ -169,7 +166,7 @@ void checkUniqueEmailOrThrow_Unique() { } @ParameterizedTest - @ValueSource(longs = {validMemberId, validCuratorId, validHostId, validWelcomeMemberId}) + @ValueSource(longs = {normal.id, curator.id, host.id, welcome.id}) @DisplayName("각 유형의 사용자를 제거하는 메서드 테스트") void deleteById(long id) { // given diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java index 31a5b87f..c80d6144 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java @@ -1,8 +1,6 @@ package org.ktc2.cokaen.wouldyouin.member.application; import static org.assertj.core.api.Assertions.assertThat; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidCurator; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidMember; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; @@ -14,6 +12,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.ktc2.cokaen.wouldyouin.Image.application.MemberImageService; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMemberRepository; import org.ktc2.cokaen.wouldyouin.member.persist.Curator; import org.ktc2.cokaen.wouldyouin.member.persist.CuratorRepository; @@ -46,14 +45,14 @@ class CuratorServiceUnitTest { @BeforeEach void setUp() { - validCurator = createValidCurator(); + validCurator = MemberData.curator.entity.get(); } @Test @DisplayName("큐레이터 사용자 생성 테스트") void createCurator() { // given - Member validMember = createValidMember(); + Member validMember = MemberData.normal.entity.get(); given(memberRepository.findById(validMember.getId())).willReturn(Optional.of(validMember)); // when diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java index 0c518e8e..1c287ae1 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java @@ -1,8 +1,7 @@ package org.ktc2.cokaen.wouldyouin.member.application; import static org.assertj.core.api.Assertions.assertThat; -import static org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.createValidMemberImage; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidHost; +import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.host.entity.get; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.times; @@ -15,6 +14,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.ktc2.cokaen.wouldyouin.Image.application.MemberImageService; import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; +import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData; import org.ktc2.cokaen.wouldyouin.auth.api.dto.LocalLoginRequest; import org.ktc2.cokaen.wouldyouin._global.TestUtil; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.create.HostCreateRequest; @@ -50,7 +50,7 @@ class HostServiceUnitTest { @BeforeEach void setUp() { - validHost = createValidHost(); + validHost = get(); } @Test @@ -88,7 +88,7 @@ void createHost() { void updateHost() { // given Long newProfileImageId = 5L; - MemberImage newProfileImage = createValidMemberImage(); + MemberImage newProfileImage = ImageData.member.host.entity.get(); newProfileImage.setBaseMember(validHost); HostEditRequest editRequest = HostEditRequest.builder() .nickname(TestUtil.getOrNull("newNickname")) diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java index e26283f6..3d7cc5f3 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java @@ -2,9 +2,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.createValidMemberImage; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidMember; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidWelcomeMember; +import static org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.member.normal.entity.get; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.never; @@ -18,6 +16,7 @@ import org.ktc2.cokaen.wouldyouin.Image.application.MemberImageService; import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin._global.TestUtil; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.MemberAdditionalInfoRequest; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.create.MemberCreateRequest; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit.MemberEditRequest; @@ -53,7 +52,7 @@ class MemberServiceUnitTest { @BeforeEach void setUp() { - validMember = createValidMember(); + validMember = MemberData.normal.entity.get(); } @Test @@ -76,7 +75,7 @@ void createMember() { @DisplayName("사용자 업데이트 테스트") void updateMember() { // given - MemberImage validMemberImage = createValidMemberImage(); + MemberImage validMemberImage = get(); Long givenMemberId = validMember.getId(); given(memberRepository.findById(givenMemberId)).willReturn(Optional.of(validMember)); given(memberImageService.getById(validMember.getProfileImage().getId())).willReturn(validMemberImage); @@ -101,7 +100,7 @@ void updateMember() { @Test @DisplayName("소셜 신규 사용자 추가정보 기입 테스트") void updateWelcomeMember() { - Member validWelcomeMember = createValidWelcomeMember(); + Member validWelcomeMember = MemberData.welcome.entity.get(); given(memberRepository.findById(validWelcomeMember.getId())).willReturn(Optional.of(validWelcomeMember)); given(memberAdditionalInfoRequest.getPhone()).willReturn(validWelcomeMember.getPhone()); given(memberAdditionalInfoRequest.getArea()).willReturn(validWelcomeMember.getArea()); diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java index 1e9c2195..7af9d013 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java @@ -2,9 +2,6 @@ import static java.lang.Math.abs; import static org.assertj.core.api.Assertions.assertThat; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.validCuratorId; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.validHostId; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.validMemberId; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.times; @@ -22,10 +19,13 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.ktc2.cokaen.wouldyouin._global.TestData.ReservationDomain; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockCurator; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.normal; +import org.ktc2.cokaen.wouldyouin._global.testdata.ReservationData; import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; import org.ktc2.cokaen.wouldyouin.reservation.api.ReservationController; import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationRequest; @@ -80,7 +80,7 @@ void getReservationsByMemberId1() throws Exception { // then then(reservationService).should(times(1)).getAllByMemberId( - eq(validMemberId), eq(PageRequest.of(5, 20)), eq(100L)); + eq(normal.id), eq(PageRequest.of(5, 20)), eq(100L)); } @Test @@ -93,7 +93,7 @@ void getReservationsByMemberId2() throws Exception { // then then(reservationService).should(times(1)).getAllByMemberId( - eq(validMemberId), eq(PageRequest.of(0, 10)), eq(Long.MAX_VALUE)); + eq(normal.id), eq(PageRequest.of(0, 10)), eq(Long.MAX_VALUE)); } @Test @@ -109,7 +109,7 @@ void getReservationsByMemberId3() throws Exception { // then then(reservationService).should(times(1)).getAllByMemberId( - eq(validCuratorId), eq(PageRequest.of(5, 20)), eq(100L)); + eq(curator.id), eq(PageRequest.of(5, 20)), eq(100L)); } @Test @@ -141,7 +141,7 @@ void getReservationByEventId1() throws Exception { // then then(reservationService).should(times(1)).getAllByEventId( - eq(validHostId), eq(randomId), eq(PageRequest.of(5, 20)), eq(100L)); + eq(host.memberIdentifier), eq(randomId), eq(PageRequest.of(5, 20)), eq(100L)); } @Test @@ -155,7 +155,7 @@ void getReservationByEventId2() throws Exception { // then then(reservationService).should(times(1)).getAllByEventId( - eq(validHostId), eq(randomId), eq(PageRequest.of(0, 10)), eq(Long.MAX_VALUE)); + eq(host.memberIdentifier), eq(randomId), eq(PageRequest.of(0, 10)), eq(Long.MAX_VALUE)); } @Test @@ -205,7 +205,7 @@ void getReservationById1() throws Exception { void createReservation1() throws Exception { // given ArgumentCaptor captor = ArgumentCaptor.forClass(ReservationRequest.class); - ReservationRequest request = ReservationDomain.createValidReservationRequest(); + ReservationRequest request = ReservationData.reservation.request.get(); // when mockMvc.perform(post("/api/reservations") @@ -216,7 +216,7 @@ void createReservation1() throws Exception { .andExpect(status().isCreated()); // then - then(reservationService).should(times(1)).create(eq(validMemberId), captor.capture()); + then(reservationService).should(times(1)).create(eq(normal.id), captor.capture()); assertThat(captor.getValue()).isEqualTo(request); } @@ -226,7 +226,7 @@ void createReservation1() throws Exception { void createReservation2() throws Exception { // given ArgumentCaptor captor = ArgumentCaptor.forClass(ReservationRequest.class); - ReservationRequest request = ReservationDomain.createValidReservationRequest(); + ReservationRequest request = ReservationData.reservation.request.get(); // when mockMvc.perform(post("/api/reservations") @@ -237,7 +237,7 @@ void createReservation2() throws Exception { .andExpect(status().isCreated()); // then - then(reservationService).should(times(1)).create(eq(validCuratorId), captor.capture()); + then(reservationService).should(times(1)).create(eq(curator.id), captor.capture()); assertThat(captor.getValue()).isEqualTo(request); } @@ -249,7 +249,7 @@ void createReservation3() throws Exception { mockMvc.perform(post("/api/reservations") .with(csrf()) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(ReservationDomain.createValidReservationRequest()))) + .content(objectMapper.writeValueAsString(ReservationData.reservation.request.get()))) .andDo(print()) .andExpect(status().isUnauthorized()) .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); @@ -263,7 +263,7 @@ void createReservation3() throws Exception { @WithMockMember void createReservation4() throws Exception { // given - ReservationRequest request = ReservationDomain.createValidReservationRequest().toBuilder() + ReservationRequest request = ReservationData.reservation.request.get().toBuilder() .eventId(null).build(); // when @@ -284,7 +284,7 @@ void createReservation4() throws Exception { @WithMockMember void createReservation5() throws Exception { // given - ReservationRequest request = ReservationDomain.createValidReservationRequest().toBuilder() + ReservationRequest request = ReservationData.reservation.request.get().toBuilder() .quantity(null).build(); // when @@ -305,7 +305,7 @@ void createReservation5() throws Exception { @WithMockMember void createReservation6() throws Exception { // given - ReservationRequest request = ReservationDomain.createValidReservationRequest().toBuilder() + ReservationRequest request = ReservationData.reservation.request.get().toBuilder() .quantity(0).build(); // when @@ -332,7 +332,7 @@ void deleteReservation1() throws Exception { .andExpect(status().isNoContent()); // then - then(reservationService).should(times(1)).delete(validMemberId, randomId); + then(reservationService).should(times(1)).delete(normal.id, randomId); } @Test @@ -346,7 +346,7 @@ void deleteReservation2() throws Exception { .andExpect(status().isNoContent()); // then - then(reservationService).should(times(1)).delete(validCuratorId, randomId); + then(reservationService).should(times(1)).delete(curator.id, randomId); } @Test From bed4e0b5c90462c0b772ec0f83d57e74c77fa734 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=99=8D=EC=8B=9D?= <90020593+Daolove0323@users.noreply.github.com> Date: Wed, 13 Nov 2024 06:30:47 +0900 Subject: [PATCH 22/53] [Weekly/11] Feature/Image/thumbnail (#121) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 해시태그 네이밍 통일 * feat: 이벤트 응답 수정 * feat: validate member * feat: 썸네일 이미지 생성 --- build.gradle | 1 + .../wouldyouin/Image/api/ImageController.java | 4 ++ .../AdvertisementImageService.java | 4 +- .../application/CurationImageService.java | 2 +- .../Image/application/EventImageService.java | 2 +- .../Image/application/ImageService.java | 9 ++++- .../application/ImageStorageService.java | 37 ++++++++++++++++++- .../Image/application/MemberImageService.java | 4 +- .../api/dto/CurationCreateRequest.java | 3 +- .../curation/api/dto/CurationResponse.java | 1 - .../application/CurationCardService.java | 2 + .../curation/application/CurationService.java | 19 +++++++++- .../wouldyouin/curation/persist/Curation.java | 11 ++++-- .../event/api/dto/EventCreateRequest.java | 3 +- .../event/application/EventService.java | 16 +++++++- .../wouldyouin/event/persist/Event.java | 6 ++- .../dto/request/create/HostCreateRequest.java | 3 +- .../request/create/MemberCreateRequest.java | 3 +- .../member/application/CuratorService.java | 4 +- .../member/application/HostService.java | 12 +++++- .../member/application/MemberService.java | 10 ++++- .../wouldyouin/member/persist/BaseMember.java | 5 ++- .../wouldyouin/member/persist/Curator.java | 7 ++-- .../wouldyouin/member/persist/Host.java | 4 +- .../wouldyouin/member/persist/Member.java | 8 ++-- .../payment/application/PaymentService.java | 3 +- src/main/resources/application.yml | 5 +++ 27 files changed, 148 insertions(+), 40 deletions(-) diff --git a/build.gradle b/build.gradle index 316b8018..3a5e9b40 100644 --- a/build.gradle +++ b/build.gradle @@ -31,6 +31,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310' implementation 'com.fasterxml.jackson.core:jackson-databind' + implementation group: 'net.coobird', name: 'thumbnailator', version: '0.4.14' compileOnly 'org.projectlombok:lombok' developmentOnly 'org.springframework.boot:spring-boot-devtools' runtimeOnly 'com.mysql:mysql-connector-j' diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java index a0ab2c96..93e22de0 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java @@ -11,6 +11,9 @@ import org.ktc2.cokaen.wouldyouin.auth.Authorize; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; +import org.ktc2.cokaen.wouldyouin.payment.application.PaymentService; +import org.ktc2.cokaen.wouldyouin.payment.dto.KakaoPayRequest; +import org.ktc2.cokaen.wouldyouin.payment.dto.KakaoPayResponse; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -30,6 +33,7 @@ public class ImageController { private final ImageServiceFactory imageServiceFactory; private final ImageStorageService imageStorageService; + private final PaymentService paymentService; @GetMapping(value = "/{directory}/{file}", produces = {MediaType.IMAGE_PNG_VALUE, MediaType.IMAGE_JPEG_VALUE}) public ResponseEntity getImage(@PathVariable String directory, @PathVariable String file) { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java index 40403f31..8a696cc9 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java @@ -40,7 +40,7 @@ protected String getChildPath() { } @Override - protected AdvertisementImage toEntity(ImageRequest imageRequest) { + protected AdvertisementImage mapToEntityFrom(ImageRequest imageRequest) { return AdvertisementImage.builder() .name(imageRequest.getName()) .size(imageRequest.getSize()) @@ -58,7 +58,7 @@ protected void validateMemberId(MemberIdentifier identifier, AdvertisementImage @Transactional public AdvertisementImage saveImage(MultipartFile image) { - return adImageRepository.save(toEntity(imageStorageService.saveToDirectory(image, getChildPath()))); + return adImageRepository.save(mapToEntityFrom(imageStorageService.saveToDirectory(image, getChildPath()))); } @Transactional diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/CurationImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/CurationImageService.java index f9051050..9fd4b657 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/CurationImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/CurationImageService.java @@ -38,7 +38,7 @@ protected String getChildPath() { } @Override - protected CurationImage toEntity(ImageRequest imageRequest) { + protected CurationImage mapToEntityFrom(ImageRequest imageRequest) { return CurationImage.builder() .name(imageRequest.getName()) .size(imageRequest.getSize()) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/EventImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/EventImageService.java index 72b982b8..5ef1cdaa 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/EventImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/EventImageService.java @@ -38,7 +38,7 @@ protected String getChildPath() { } @Override - protected EventImage toEntity(ImageRequest imageRequest) { + protected EventImage mapToEntityFrom(ImageRequest imageRequest) { return EventImage.builder() .name(imageRequest.getName()) .size(imageRequest.getSize()) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java index 63898a52..3a3d2e91 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java @@ -32,7 +32,7 @@ public abstract class ImageService { protected abstract String getChildPath(); - protected abstract T toEntity(ImageRequest imageRequest); + protected abstract T mapToEntityFrom(ImageRequest imageRequest); protected abstract void validateMemberId(MemberIdentifier identifier, T image); @@ -50,6 +50,11 @@ public void deleteImage(MemberIdentifier identifier, Long imageId) { validateMemberId(identifier, image); delete(imageId); imageStorageService.delete(getChildPath(), image.getName()); + // ToDO : 썸네일도 지워라 + } + + public String createThumbnail(String fileName) { + return imageStorageService.createThumbnailImage(getChildPath(), fileName); } public T getById(Long id) { @@ -58,7 +63,7 @@ public T getById(Long id) { } protected ImageResponse create(ImageRequest imageRequest) { - T image = toEntity(imageRequest); + T image = mapToEntityFrom(imageRequest); return ImageResponse.from(getImageRepository().save(image), getImageUrl(image)); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorageService.java index 0e685398..6dbd516c 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorageService.java @@ -1,9 +1,13 @@ package org.ktc2.cokaen.wouldyouin.Image.application; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Optional; import lombok.RequiredArgsConstructor; +import net.coobird.thumbnailator.Thumbnails; import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageRequest; import org.ktc2.cokaen.wouldyouin._common.exception.FailedToUploadImageException; import org.ktc2.cokaen.wouldyouin._common.util.FileUtil; @@ -19,6 +23,19 @@ public class ImageStorageService { @Value("${image.upload.parent-path}") private String parentPath; + + @Value("${image.upload.thumbnail.child-path}") + private String thumbnailChildPath; + + @Value("${image.upload.thumbnail.height}") + private Integer thumbnailHeight; + + @Value("${image.upload.thumbnail.width}") + private Integer thumbnailWidth; + + @Value("${image.upload.thumbnail.extension}") + private String thumbnailExtension; + private final RestClientUtil client; public byte[] readFromDirectory(Path childPath) { @@ -34,7 +51,9 @@ public ImageRequest saveToDirectory(MultipartFile image, String childPath) { public ImageRequest saveToDirectory(String imageUrl, String childPath) { byte[] response = client.get(byte[].class, imageUrl, new HttpHeaders(), - (req, rsp) -> { throw new FailedToUploadImageException("이미지 URL에 대한 요청을 실패하였습니다."); } + (req, rsp) -> { + throw new FailedToUploadImageException("이미지 URL에 대한 요청을 실패하였습니다."); + } ); Optional.ofNullable(response).orElseThrow( () -> new FailedToUploadImageException("응답 본문이 비어있어 이미지를 가져올 수 없습니다.") @@ -46,6 +65,22 @@ public ImageRequest saveToDirectory(String imageUrl, String childPath) { return ImageRequest.of(fileName, (long) response.length, extension); } + // TODO : 썸네일 생성 코드 리팩토링, 파일 유틸로 이동 + public String createThumbnailImage(String childPath, String originFileName) { + String fileName = FileUtil.createRandomFileName(thumbnailExtension); + String originImagePath = Path.of(parentPath, childPath, originFileName).toString(); + String thumbnailImagePath = Path.of(parentPath, childPath, thumbnailChildPath).toString(); + try { + Files.createDirectories(Paths.get(thumbnailImagePath)); + Thumbnails.of(new File(originImagePath)) + .size(thumbnailHeight, thumbnailWidth) + .toFile(new File(thumbnailImagePath, fileName)); + } catch (Exception e) { + throw new RuntimeException(e); + } + return fileName; + } + public void delete(String childPath, String fileName) { FileUtil.deleteFile(Path.of(parentPath, childPath, fileName)); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java index 2e8ed906..8a365d5b 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java @@ -38,7 +38,7 @@ protected String getChildPath() { } @Override - protected MemberImage toEntity(ImageRequest imageRequest) { + protected MemberImage mapToEntityFrom(ImageRequest imageRequest) { return MemberImage.builder() .name(imageRequest.getName()) .size(imageRequest.getSize()) @@ -60,6 +60,6 @@ public void setBaseMember(MemberImage image, BaseMember member) { public MemberImage convert(String imageUrl) { ImageRequest imageRequest = imageStorageService.saveToDirectory(imageUrl, childPath); - return memberImageRepository.save(toEntity(imageRequest)); + return memberImageRepository.save(mapToEntityFrom(imageRequest)); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCreateRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCreateRequest.java index f46db9da..415c345c 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCreateRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCreateRequest.java @@ -47,7 +47,7 @@ public boolean isCurationCardsSizeValid() { } public Curation toEntity(Curator curator, List curationCards, - List events) { + List events, String thumbnailUrl) { return Curation.builder() .curator(curator) .title(this.title) @@ -56,6 +56,7 @@ public Curation toEntity(Curator curator, List curationCards, .area(this.area) .hashtags(this.hashtags) .events(events) + .thumbnailUrl(thumbnailUrl) .build(); } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java index cc6ca2ba..32ae736a 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java @@ -1,6 +1,5 @@ package org.ktc2.cokaen.wouldyouin.curation.api.dto; -import jakarta.persistence.Column; import java.time.LocalDateTime; import java.util.List; import lombok.Builder; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java index aa8076fd..ea7491d3 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java @@ -1,9 +1,11 @@ package org.ktc2.cokaen.wouldyouin.curation.application; import java.util.List; +import java.util.Optional; import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin.Image.application.CurationImageService; import org.ktc2.cokaen.wouldyouin.Image.persist.CurationImage; +import org.ktc2.cokaen.wouldyouin.Image.persist.EventImage; import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCardRequest; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationService.java index dc935c55..df57443d 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationService.java @@ -1,7 +1,10 @@ package org.ktc2.cokaen.wouldyouin.curation.application; import java.util.List; +import java.util.Optional; import lombok.RequiredArgsConstructor; +import org.ktc2.cokaen.wouldyouin.Image.application.CurationImageService; +import org.ktc2.cokaen.wouldyouin.Image.persist.CurationImage; import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; import org.ktc2.cokaen.wouldyouin._common.vo.Area; @@ -31,6 +34,7 @@ public class CurationService { private final CuratorService curatorService; private final EventService eventService; private final CurationCardService curationCardService; + private final CurationImageService curationImageService; @Transactional(readOnly = true) public Curation getByIdOrThrow(Long id) throws EntityNotFoundException { @@ -66,11 +70,22 @@ public CurationResponse create(MemberIdentifier identifier, CurationCreateReques List events = curationCreateRequest.getEventIds().stream() .map(eventService::getByIdOrThrow) .toList(); - Curation curation = curationRepository.save(curationCreateRequest.toEntity(curator, curationCards, events)); + Curation curation = curationRepository.save( + curationCreateRequest.toEntity(curator, curationCards, events, getThumbnailUrl(curationCards))); curationCards.forEach(curationCard -> curationCardService.setCuration(curationCard, curation)); return CurationResponse.from(curation); } + private String getThumbnailUrl(List curationCards) { + return Optional.ofNullable(curationCards) + .map(List::getFirst) + .map(CurationCard::getCurationImages) + .map(List::getFirst) + .map(CurationImage::getName) + .map(curationImageService::createThumbnail) + .orElse(""); + } + @Transactional public CurationResponse update(MemberIdentifier identifier, Long curationId, CurationEditRequest curationEditRequest) { Curation curation = getByIdOrThrow(curationId); @@ -82,7 +97,7 @@ public CurationResponse update(MemberIdentifier identifier, Long curationId, Cur .map(eventService::getByIdOrThrow) .toList(); curation.getCurationCards().forEach(card -> curationCardService.delete(identifier, card.getId())); - curation.updateFrom(curationEditRequest, curationCards, events); + curation.updateFrom(curationEditRequest, curationCards, events, getThumbnailUrl(curationCards)); curationCards.forEach(curationCard -> curationCardService.setCuration(curationCard, curation)); return CurationResponse.from(curation); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java index 7c1db6e1..c3f5c742 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java @@ -17,6 +17,7 @@ import jakarta.persistence.OneToMany; import jakarta.validation.constraints.NotNull; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; import java.util.Optional; import lombok.AccessLevel; @@ -59,7 +60,7 @@ public class Curation { private String content; @OneToMany(mappedBy = "curation", fetch = FetchType.LAZY) - private List curationCards; + private List curationCards = new ArrayList<>(); @NotNull @Enumerated(EnumType.STRING) @@ -68,7 +69,7 @@ public class Curation { @Column(name = "hashtag") @Convert(converter = HashtagConverter.class) - private List hashtags; + private List hashtags = new ArrayList<>(); @ManyToMany(fetch = FetchType.LAZY) @JoinTable( @@ -92,7 +93,7 @@ public class Curation { @Builder public Curation(Curator curator, String title, String content, List curationCards, Area area, List hashtags, - List events) { + List events, String thumbnailUrl) { this.curator = curator; this.title = title; this.content = content; @@ -100,15 +101,17 @@ public Curation(Curator curator, String title, String content, List curationCards, List events) { + List curationCards, List events, String thumbnailUrl) { Optional.ofNullable(curationEditRequest.getTitle()).ifPresent(this::setTitle); Optional.ofNullable(curationEditRequest.getContent()).ifPresent(this::setContent); Optional.ofNullable(curationEditRequest.getArea()).ifPresent(this::setArea); Optional.ofNullable(curationEditRequest.getHashtags()).ifPresent(this::setHashtags); Optional.ofNullable(curationCards).ifPresent(this::setCurationCards); Optional.ofNullable(events).ifPresent(this::setEvents); + Optional.ofNullable(thumbnailUrl).ifPresent(this::setThumbnailUrl); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java index 43b8f01f..279a1736 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java @@ -71,7 +71,7 @@ public boolean isImageSizeValid() { return imageIds.size() <= 5; } - public Event toEntity(Host host, List images) { + public Event toEntity(Host host, List images, String thumbnailUrl) { return Event.builder() .title(title) .content(content) @@ -84,6 +84,7 @@ public Event toEntity(Host host, List images) { .category(category) .host(host) .images(images) + .thumbnailUrl(thumbnailUrl) .build(); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java index 1bf247e3..ff6c9f44 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java @@ -1,8 +1,10 @@ package org.ktc2.cokaen.wouldyouin.event.application; import java.util.List; +import java.util.Optional; import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin.Image.application.EventImageService; +import org.ktc2.cokaen.wouldyouin.Image.application.MemberImageService; import org.ktc2.cokaen.wouldyouin.Image.persist.EventImage; import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; import org.ktc2.cokaen.wouldyouin._common.exception.NoLeftSeatException; @@ -33,6 +35,7 @@ public class EventService { private final EventRepository eventRepository; private final HostService hostService; private final EventImageService eventImageService; + private final MemberImageService memberImageService; @Transactional public Event getByIdOrThrow(Long id) throws EntityNotFoundException { @@ -72,11 +75,19 @@ public EventResponse create(MemberIdentifier identifier, EventCreateRequest even Host host = hostService.getByIdOrThrow(identifier.id()); List images = eventCreateRequest.getImageIds().stream() .map(eventImageService::getById).toList(); - Event event = eventRepository.save(eventCreateRequest.toEntity(host, images)); + Event event = eventRepository.save(eventCreateRequest.toEntity(host, images, getThumbnailUrl(images))); images.forEach(image -> eventImageService.setEvent(image, event)); return getEventResponse(event); } + private String getThumbnailUrl(List images) { + return Optional.ofNullable(images) + .map(List::getFirst) + .map(EventImage::getName) + .map(eventImageService::createThumbnail) + .orElse(""); + } + @Transactional public EventResponse update(MemberIdentifier identifier, Long eventId, EventEditRequest eventEditRequest) { Event event = getByIdOrThrow(eventId); @@ -84,7 +95,7 @@ public EventResponse update(MemberIdentifier identifier, Long eventId, EventEdit event.getImages().forEach(image -> eventImageService.deleteImage(identifier, image.getId())); List images = eventEditRequest.getImageIds().stream() .map(eventImageService::getById).toList(); - event.updateFrom(eventEditRequest, images); + event.updateFrom(eventEditRequest, images, getThumbnailUrl(images)); images.forEach(image -> eventImageService.setEvent(image, event)); return getEventResponse(event); } @@ -92,6 +103,7 @@ public EventResponse update(MemberIdentifier identifier, Long eventId, EventEdit @Transactional public void delete(MemberIdentifier identifier, Long eventId) { validateHostId(identifier, getByIdOrThrow(eventId)); + eventImageService.deleteImage(identifier, eventId); eventRepository.deleteById(eventId); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java index 5aa0724a..c3fe53ee 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java @@ -108,7 +108,7 @@ public class Event { @Builder protected Event(String title, String content, Host host, Area area, Location location, LocalDateTime startTime, LocalDateTime endTime, Integer price, Integer totalSeat, - Category category, List images) { + Category category, List images, String thumbnailUrl) { this.title = title; this.content = content; this.host = host; @@ -121,10 +121,11 @@ protected Event(String title, String content, Host host, Area area, Location loc this.leftSeat = totalSeat; this.category = category; Optional.ofNullable(images).ifPresent(this::setImages); + Optional.of(thumbnailUrl).ifPresent(this::setThumbnailUrl); } // Todo: oneToMany 연관관계에서 모든 null 처리 - public void updateFrom(EventEditRequest eventEditRequest, List images) { + public void updateFrom(EventEditRequest eventEditRequest, List images, String thumbnailUrl) { Optional.ofNullable(eventEditRequest.getTitle()).ifPresent(this::setTitle); Optional.ofNullable(eventEditRequest.getContent()).ifPresent(this::setContent); Optional.ofNullable(eventEditRequest.getArea()).ifPresent(this::setArea); @@ -135,6 +136,7 @@ public void updateFrom(EventEditRequest eventEditRequest, List image Optional.ofNullable(eventEditRequest.getTotalSeat()).ifPresent(this::setTotalSeat); Optional.ofNullable(eventEditRequest.getCategory()).ifPresent(this::setCategory); Optional.ofNullable(images).ifPresent(this::setImages); + Optional.ofNullable(thumbnailUrl).ifPresent(this::setThumbnailUrl); } public void decreaseLeftSeat(Integer count) { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/HostCreateRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/HostCreateRequest.java index 6a2ceafe..f3854cd2 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/HostCreateRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/HostCreateRequest.java @@ -20,7 +20,7 @@ public HostCreateRequest(String nickname, String email, String phone, String pas this.profileImageId = profileImageId; } - public Host toEntity(String hashedPassword, MemberImage profileImage) { + public Host toEntity(String hashedPassword, MemberImage profileImage, String thumbnailImageUrl) { return Host.builder() .nickname(this.nickname) @@ -28,6 +28,7 @@ public Host toEntity(String hashedPassword, MemberImage profileImage) { .email(this.email) .phone(this.phone) .hashedPassword(hashedPassword) + .profileImageThumbnailUrl(thumbnailImageUrl) .build(); } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/MemberCreateRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/MemberCreateRequest.java index 6bc10cbf..2ff3406c 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/MemberCreateRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/MemberCreateRequest.java @@ -24,7 +24,7 @@ protected MemberCreateRequest(String nickname, String email, AccountType account this.profileImageUrl = profileImageUrl; } - public Member toEntity(MemberImage profileImage) { + public Member toEntity(MemberImage profileImage, String thumbnailImageUrl) { return Member.builder() .nickname(this.nickname) .email(this.email) @@ -34,6 +34,7 @@ public Member toEntity(MemberImage profileImage) { .area(Area.서울) .gender("") .profileImage(profileImage) + .profileImageThumbnailUrl(thumbnailImageUrl) .build(); } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java index 0332e871..5a1b817a 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java @@ -58,6 +58,7 @@ public MemberResponse createCurator(Long normalMemberId) { .nickname(member.getNickname()) .phone(member.getPhone()) .profileImage(member.getProfileImage()) + .profileImageThumbnailUrl(member.getProfileImageThumbnailUrl()) .area(member.getArea()) .gender(member.getGender()) .socialId(member.getSocialId()) @@ -80,7 +81,8 @@ public MemberResponse createCurator(Long normalMemberId) { public MemberResponse updateCurator(Long curatorId, CuratorEditRequest request) { Curator curator = getByIdOrThrow(curatorId); MemberImage image = memberImageService.getById(request.getProfileImageId()); - curator.updateFrom(request, image); + String thumbnailImageUrl = memberImageService.createThumbnail(image.getName()); + curator.updateFrom(request, image, thumbnailImageUrl); image.setBaseMember(curator); return MemberResponse.from(curator); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java index 1182a9ff..4215f87f 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java @@ -27,19 +27,27 @@ public class HostService implements MemberServiceCommonBehavior, LikeableMemberS public MemberResponse createHost(HostCreateRequest request) { String hashedPassword = passwordEncoder.encode(request.getPassword()); MemberImage profileImage = memberImageService.getById(request.getProfileImageId()); - Host createdHost = hostRepository.save(request.toEntity(hashedPassword, profileImage)); + String profileImageThumbnailUrl = memberImageService.createThumbnail(profileImage.getName()); + Host createdHost = hostRepository.save(request.toEntity(hashedPassword, profileImage, profileImageThumbnailUrl)); memberImageService.setBaseMember(profileImage, createdHost); return MemberResponse.from(createdHost); } + // TODO: 리팩토링할것 @Transactional public MemberResponse updateHost(Long hostId, HostEditRequest request) { Host host = getByIdOrThrow(hostId); Optional.ofNullable(request.getNickname()).ifPresent(host::setNickname); Optional.ofNullable(request.getPhoneNumber()).ifPresent(host::setPhone); - Optional.ofNullable(request.getProfileImageId()).map(memberImageService::getById).ifPresent(host::setProfileImage); Optional.ofNullable(request.getIntro()).ifPresent(host::setIntro); Optional.ofNullable(request.getHashtags()).ifPresent(host::setHashtags); + Optional.ofNullable(request.getProfileImageId()) + .map(memberImageService::getById) + .ifPresent((image) -> { + host.setProfileImage(image); + String url = memberImageService.createThumbnail(memberImageService.createThumbnail(image.getName())); + host.setProfileImageThumbnailUrl(url); + }); return MemberResponse.from(host); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/MemberService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/MemberService.java index 3e7ccc88..afc1f9d2 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/MemberService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/MemberService.java @@ -25,9 +25,11 @@ public class MemberService implements MemberServiceCommonBehavior { @Transactional public MemberResponse createMember(MemberCreateRequest request) { MemberImage profileImage = memberImageService.convert(request.getProfileImageUrl()); - return MemberResponse.from(memberRepository.save(request.toEntity(profileImage))); + String thumbnailImageUrl = memberImageService.createThumbnail(profileImage.getName()); + return MemberResponse.from(memberRepository.save(request.toEntity(profileImage, thumbnailImageUrl))); } + // TODO : 리팩토링 꼭 할 것, 멤버 전체에 대해 연관관계 설정할 것 @Transactional public MemberResponse updateMember(Long memberId, MemberEditRequest editRequest) { Member member = getByIdOrThrow(memberId); @@ -36,7 +38,11 @@ public MemberResponse updateMember(Long memberId, MemberEditRequest editRequest) Optional.ofNullable(editRequest.getPhoneNumber()).ifPresent(member::setPhone); Optional.ofNullable(editRequest.getProfileImageId()) .map(memberImageService::getById) - .ifPresent(member::setProfileImage); + .ifPresent((image) -> { + member.setProfileImage(image); + String url = memberImageService.createThumbnail(memberImageService.createThumbnail(image.getName())); + member.setProfileImageThumbnailUrl(url); + }); return MemberResponse.from(member); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java index e45dc1c8..c7b48a96 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java @@ -51,14 +51,17 @@ public abstract class BaseMember { @OneToOne(mappedBy = "baseMember") private MemberImage profileImage; + private String profileImageThumbnailUrl; + protected BaseMember(AccountType accountType, MemberType memberType, String email, String nickname, String phone, - MemberImage profileImage) { + MemberImage profileImage, String profileImageThumbnailUrl) { this.accountType = accountType; this.memberType = memberType; this.email = email; this.nickname = nickname; this.phone = phone; this.profileImage = profileImage; + this.profileImageThumbnailUrl = profileImageThumbnailUrl; } public String getProfileImageUrl() { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java index 2c74d6bf..1c1d2a9c 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java @@ -42,19 +42,20 @@ public class Curator extends Member implements LikeableMember { private List curations = new ArrayList<>(); @Builder(builderMethodName = "curatorBuilder") - public Curator(AccountType accountType, String email, String nickname, String phone, MemberImage profileImage, Area area, String gender, + public Curator(AccountType accountType, String email, String nickname, String phone, MemberImage profileImage, String profileImageThumbnailUrl, Area area, String gender, String socialId) { - super(accountType, MemberType.curator, email, nickname, phone, profileImage, area, gender, socialId); + super(accountType, MemberType.curator, email, nickname, phone, profileImage, profileImageThumbnailUrl, area, gender, socialId); this.intro = ""; this.likes = 0; hashtags = new ArrayList<>(); } - public void updateFrom(CuratorEditRequest request, MemberImage image) { + public void updateFrom(CuratorEditRequest request, MemberImage image, String profileImageThumbnailUrl) { Optional.ofNullable(request.getPhoneNumber()).ifPresent(this::setPhone); Optional.ofNullable(request.getNickname()).ifPresent(this::setNickname); Optional.ofNullable(request.getArea()).ifPresent(this::setArea); Optional.ofNullable(request.getIntro()).ifPresent(this::setIntro); Optional.ofNullable(image).ifPresent(this::setProfileImage); + Optional.ofNullable(profileImageThumbnailUrl).ifPresent(this::setProfileImageThumbnailUrl); } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java index 14d9c80b..5a636ece 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java @@ -43,8 +43,8 @@ public class Host extends BaseMember implements LikeableMember { private List events = new ArrayList<>(); @Builder - protected Host(String email, String nickname, String phone, String hashedPassword, MemberImage profileImage) { - super(AccountType.local, MemberType.host, email, nickname, phone, profileImage); + protected Host(String email, String nickname, String phone, String hashedPassword, MemberImage profileImage, String profileImageThumbnailUrl) { + super(AccountType.local, MemberType.host, email, nickname, phone, profileImage, profileImageThumbnailUrl); this.hashedPassword = hashedPassword; this.intro = ""; this.likes = 0; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java index 5607afcc..85fa19ed 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java @@ -53,8 +53,8 @@ public class Member extends BaseMember { private List reviews = new ArrayList<>(); // for Curator - protected Member(AccountType accountType, MemberType memberType, String email, String nickname, String phone, MemberImage profileImage, Area area, String gender, String socialId) { - super(accountType, memberType, email, nickname, phone, profileImage); + protected Member(AccountType accountType, MemberType memberType, String email, String nickname, String phone, MemberImage profileImage, String profileImageThumbNailUrl, Area area, String gender, String socialId) { + super(accountType, memberType, email, nickname, phone, profileImage, profileImageThumbNailUrl); this.area = area; this.gender = gender; this.socialId = socialId; @@ -62,8 +62,8 @@ protected Member(AccountType accountType, MemberType memberType, String email, S @Builder // for public builder - protected Member(AccountType accountType, String email, String nickname, String phone, MemberImage profileImage, Area area, String gender, String socialId) { - this(accountType, MemberType.welcome, email, nickname, phone, profileImage, area, gender, socialId); + protected Member(AccountType accountType, String email, String nickname, String phone, MemberImage profileImage, String profileImageThumbnailUrl, Area area, String gender, String socialId) { + this(accountType, MemberType.welcome, email, nickname, phone, profileImage, profileImageThumbnailUrl, area, gender, socialId); } public void updateFrom(MemberAdditionalInfoRequest request) { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/payment/application/PaymentService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/payment/application/PaymentService.java index 3476c52e..0d3686c5 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/payment/application/PaymentService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/payment/application/PaymentService.java @@ -5,6 +5,7 @@ import org.ktc2.cokaen.wouldyouin._common.exception.FailedToPayException; import org.ktc2.cokaen.wouldyouin._common.util.KakaoPayUtil; import org.ktc2.cokaen.wouldyouin._common.util.RestClientUtil; +import org.ktc2.cokaen.wouldyouin._common.util.UriUtil; import org.ktc2.cokaen.wouldyouin.payment.dto.KakaoPayRequest; import org.ktc2.cokaen.wouldyouin.payment.dto.KakaoPayResponse; import org.springframework.beans.factory.annotation.Value; @@ -32,7 +33,7 @@ public class PaymentService { public KakaoPayResponse createPayment(KakaoPayRequest kakaoPayRequest) { return client.post( KakaoPayResponse.class, - Paths.get(kakaoPayRequestHost, kakaoPaySinglePaymentUrl).toString(), + UriUtil.assembleFullUrl(kakaoPayRequestHost, kakaoPaySinglePaymentUrl), KakaoPayUtil.createKakaoPayRequestHeaders(kakaoPayRequestHost, secretKey), KakaoPayUtil.createKakaoPayRequestBody(kakaoPayRequest, approvalUrl, cancelUrl, failUrl), (req, rsp) -> { throw new FailedToPayException("카카오페이 API 요청을 실패하였습니다."); } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index aa633fa1..f3502ff5 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -52,6 +52,11 @@ image: child-path: event ad: child-path: advertisement + thumbnail: + child-path: thumbnail + width: 130 + height: 90 + extension: png # for jwt jwt: From 72472ff2d6b1c563d3532f6c4f1229d208d8dc65 Mon Sep 17 00:00:00 2001 From: Jangan Lee Date: Wed, 13 Nov 2024 22:36:17 +0900 Subject: [PATCH 23/53] =?UTF-8?q?[Weekly/11/Refactor/Thumbnail]=20?= =?UTF-8?q?=EC=84=AC=EB=84=A4=EC=9D=BC=20=EA=B4=80=EB=A0=A8=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=A0=95?= =?UTF-8?q?=ED=95=A9=EC=84=B1=20=EC=88=98=EC=A0=95=20(#122)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...MockCurator.java => WithMockCurator1.java} | 6 +- .../{WithMockHost.java => WithMockHost1.java} | 6 +- ...thMockMember.java => WithMockMember1.java} | 6 +- ...ember.java => WithMockWelcomeMember1.java} | 6 +- .../_global/testdata/CommonData.java | 5 + .../_global/testdata/CurationData.java | 7 +- .../_global/testdata/EventData.java | 155 ++--- .../_global/testdata/ImageData.java | 547 +++++++++++++++++- .../_global/testdata/MemberData.java | 169 +++--- .../_global/testdata/ReservationData.java | 64 +- .../curation/CurationControllerUnitTest.java | 72 +-- .../curation/CurationServiceTest.java | 7 +- .../event/EventControllerUnitTest.java | 28 +- .../event/EventServiceUnitTest.java | 27 +- .../wouldyouin/image/ImageControllerTest.java | 22 +- .../BaseMemberServiceUnitTest.java | 26 +- .../application/CuratorServiceUnitTest.java | 4 +- .../application/HostServiceUnitTest.java | 10 +- .../application/MemberServiceUnitTest.java | 7 +- .../ReservationControllerUnitTest.java | 78 +-- 20 files changed, 904 insertions(+), 348 deletions(-) rename src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/{WithMockCurator.java => WithMockCurator1.java} (71%) rename src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/{WithMockHost.java => WithMockHost1.java} (73%) rename src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/{WithMockMember.java => WithMockMember1.java} (71%) rename src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/{WithMockWelcomeMember.java => WithMockWelcomeMember1.java} (70%) diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockCurator.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockCurator1.java similarity index 71% rename from src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockCurator.java rename to src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockCurator1.java index a44df782..877e3b20 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockCurator.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockCurator1.java @@ -2,11 +2,11 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator1; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @Retention(RetentionPolicy.RUNTIME) -@WithMockCustomUser(memberId = curator.id, memberType = MemberType.curator) -public @interface WithMockCurator { +@WithMockCustomUser(memberId = curator1.id, memberType = MemberType.curator) +public @interface WithMockCurator1 { } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockHost.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockHost1.java similarity index 73% rename from src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockHost.java rename to src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockHost1.java index a92d6950..41dcf575 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockHost.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockHost1.java @@ -2,11 +2,11 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host1; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @Retention(RetentionPolicy.RUNTIME) -@WithMockCustomUser(memberId = host.id, memberType = MemberType.host) -public @interface WithMockHost { +@WithMockCustomUser(memberId = host1.id, memberType = MemberType.host) +public @interface WithMockHost1 { } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockMember.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockMember1.java similarity index 71% rename from src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockMember.java rename to src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockMember1.java index 4e5cbe8d..c533cb6e 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockMember.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockMember1.java @@ -2,11 +2,11 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.normal; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.normal1; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @Retention(RetentionPolicy.RUNTIME) -@WithMockCustomUser(memberId = normal.id, memberType = MemberType.normal) -public @interface WithMockMember { +@WithMockCustomUser(memberId = normal1.id, memberType = MemberType.normal) +public @interface WithMockMember1 { } \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockWelcomeMember.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockWelcomeMember1.java similarity index 70% rename from src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockWelcomeMember.java rename to src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockWelcomeMember1.java index 951a6cf2..e3717250 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockWelcomeMember.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockWelcomeMember1.java @@ -2,11 +2,11 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.welcome; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.welcome1; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @Retention(RetentionPolicy.RUNTIME) -@WithMockCustomUser(memberId = welcome.id, memberType = MemberType.welcome) -public @interface WithMockWelcomeMember { +@WithMockCustomUser(memberId = welcome1.id, memberType = MemberType.welcome) +public @interface WithMockWelcomeMember1 { } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java index 8fa8fcc7..b70cca43 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java @@ -4,6 +4,11 @@ public class CommonData { + public static class path { + + public static final String domainUrl = "https://wouldyouin.store"; + } + public static class sliceInfo { public static SliceInfo get() { diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java index dfcd2107..1d27d62d 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java @@ -4,8 +4,9 @@ import java.util.List; import org.ktc2.cokaen.wouldyouin.Image.persist.CurationImage; import org.ktc2.cokaen.wouldyouin._common.vo.Area; -import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.R.curationCard1; import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.R.curationEditRequest; +import org.ktc2.cokaen.wouldyouin._global.testdata.EventData.event1; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.curator1; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCardRequest; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCardResponse; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCreateRequest; @@ -54,7 +55,7 @@ public static class curation { public static final Area area = Area.전체; public static final List hashtags = List.of("#큐레이션", "#해시태그"); public static final List eventIds = List.of(201L); - public static final List events = List.of(EventData.event.entity.get()); + public static final List events = List.of(EventData.event1.entity.get()); public static final LocalDateTime createdDate = LocalDateTime.of(2023, 3, 23, 0, 0); public static final LocalDateTime modifiedDate = LocalDateTime.of(2024, 3, 23, 0, 0); } @@ -140,7 +141,7 @@ public static class curation { public static class entity { public static Curation get() { Curation validCuration = Curation.builder() - .curator(MemberData.curator.entity.get()) + .curator(MemberData.curator1.entity.get()) .title(R.curation.title) .content(R.curation.content) .curationCards(R.curation.curationCards) diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/EventData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/EventData.java index 5babf5d3..a889aab1 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/EventData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/EventData.java @@ -2,21 +2,60 @@ import java.time.LocalDateTime; import java.util.List; +import org.ktc2.cokaen.wouldyouin.Image.persist.EventImage; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; import org.ktc2.cokaen.wouldyouin._common.vo.Location; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; +import org.ktc2.cokaen.wouldyouin.event.api.dto.EventResponse; import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.CurationEventResponse; import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.ReservationEventResponse; import org.ktc2.cokaen.wouldyouin.event.persist.Event; +import org.ktc2.cokaen.wouldyouin.member.persist.Host; import org.springframework.test.util.ReflectionTestUtils; public class EventData { public static class R { - public static class event { + public static class event1 { + public static class _Relation { + public static Host host() { + return MemberData.host1.entity.get(); + } + public static List images() { + return List.of( + ImageData.event1.entity.get(), + ImageData.event2.entity.get(), + ImageData.event3.entity.get()); + } + public static List imageUrls() { + return List.of( + ImageData.R.event1.url, + ImageData.R.event2.url, + ImageData.R.event3.url); + } + } + + public static class _Dto { + public static class editRequest1 { + public static final String title = "modifiedTitle"; + public static final String content = "modifiedContent 조홍식씨 최소글자 20자라고 해놓고 안 지켰어요. "; + public static final Area area = Area.광주; + public static final Location location = new Location(45.0, 143.0, "광주 북구 용봉로 77"); + public static final LocalDateTime startTime = event1.startTime.plusDays(2); + public static final LocalDateTime endTime = startTime.plusWeeks(3); + public static final int price = 20000; + public static final int totalSeat = 200; + public static final Category category = Category.뮤지컬; + public static final List imageIds = List.of( + ImageData.R.event4.id, + ImageData.R.event5.id + ); + } + } + public static final long id = 201L; public static final String title = "행사 제목"; public static final String content = "행사 내용입니다. 행사의 내용은 최소 20자 최대 1000자 입니다."; @@ -24,43 +63,37 @@ public static class event { public static final Location location = new Location(55.0, 43.0, "광주 북구 용봉로 77"); public static final LocalDateTime startTime = LocalDateTime.now().plusDays(3).plusHours(11).plusMinutes(47); public static final LocalDateTime endTime = startTime.plusWeeks(2); - public static final int price = 15000; - public static final int totalSeat = 100; + public static final Integer price = 15000; + public static final Integer totalSeat = 100; + public static final Integer leftSeat = 10; public static final Category category = Category.밴드; - - public static final String hostNickname = MemberData.R.host.nickname; - public static final String hostProfileImageUrl = ImageData.R.member.host.url; - public static final String thumbnailImageUrl = "ImageData.R.event.thumbnail.url"; - } - public static class eventEditRequest { - public static final String title = "modifiedTitle"; - public static final String content = "modifiedContent 조홍식씨 최소글자 20자라고 해놓고 안 지켰어요. "; - public static final Area area = Area.광주; - public static final Location location = new Location(45.0, 143.0, "광주 북구 용봉로 77"); - public static final LocalDateTime startTime = event.startTime.plusDays(2); - public static final LocalDateTime endTime = startTime.plusWeeks(3); - public static final int price = 20000; - public static final int totalSeat = 200; - public static final Category category = Category.뮤지컬; + public static final String thumbnailUrl = ImageData.getThumbnailUrl(_Relation.images().getFirst()); + public static final LocalDateTime createdDate = LocalDateTime.now().minusDays(1); } } - public static class event { + public static class event1 { public static class entity { public static Event get() { Event ret = Event.builder() - .title(R.event.title) - .content(R.event.content) - .area(R.event.area) - .location(R.event.location) - .startTime(R.event.startTime) - .endTime(R.event.endTime) - .price(R.event.price) - .totalSeat(R.event.totalSeat) - .category(R.event.category) + .title(R.event1.title) + .content(R.event1.content) + .host(R.event1._Relation.host()) + .area(R.event1.area) + .location(R.event1.location) + .startTime(R.event1.startTime) + .endTime(R.event1.endTime) + .price(R.event1.price) + .totalSeat(R.event1.totalSeat) + .category(R.event1.category) + .images(R.event1._Relation.images()) + .thumbnailUrl(R.event1.thumbnailUrl) .build(); - ret.setHost(MemberData.host.entity.get()); - ReflectionTestUtils.setField(ret, "id", R.event.id); + + ReflectionTestUtils.setField(ret, "id", R.event1.id); + ReflectionTestUtils.setField(ret, "leftSeat", R.event1.leftSeat); + ret.getHost().setEvents(List.of(ret)); + ret.getImages().forEach(image -> image.setEvent(ret)); return ret; } } @@ -68,63 +101,53 @@ public static class request { public static class create { public static EventCreateRequest get() { return EventCreateRequest.builder() - .title(R.event.title) - .content(R.event.content) - .area(R.event.area) - .location(R.event.location) - .startTime(R.event.startTime) - .endTime(R.event.endTime) - .price(R.event.price) - .totalSeat(R.event.totalSeat) - .category(R.event.category) - .imageIds(List.of()) + .title(R.event1.title) + .content(R.event1.content) + .area(R.event1.area) + .location(R.event1.location) + .startTime(R.event1.startTime) + .endTime(R.event1.endTime) + .price(R.event1.price) + .totalSeat(R.event1.totalSeat) + .category(R.event1.category) + .imageIds(R.event1._Relation.images().stream().map(EventImage::getId).toList()) .build(); } } - public static class edit { + public static class edit1 { public static EventEditRequest get() { return EventEditRequest.builder() - .title(R.eventEditRequest.title) - .content(R.eventEditRequest.content) - .area(R.eventEditRequest.area) - .location(R.eventEditRequest.location) - .startTime(R.eventEditRequest.startTime) - .endTime(R.eventEditRequest.endTime) - .price(R.eventEditRequest.price) - .totalSeat(R.eventEditRequest.totalSeat) - .category(R.eventEditRequest.category) - .imageIds(List.of()) + .title(R.event1._Dto.editRequest1.title) + .content(R.event1._Dto.editRequest1.content) + .area(R.event1._Dto.editRequest1.area) + .location(R.event1._Dto.editRequest1.location) + .startTime(R.event1._Dto.editRequest1.startTime) + .endTime(R.event1._Dto.editRequest1.endTime) + .price(R.event1._Dto.editRequest1.price) + .totalSeat(R.event1._Dto.editRequest1.totalSeat) + .category(R.event1._Dto.editRequest1.category) + .imageIds(R.event1._Dto.editRequest1.imageIds) .build(); } } } public static class response { - + public static EventResponse get() { + return EventResponse.from(EventData.event1.entity.get(), R.event1._Relation.imageUrls()); + } } } public static class response { public static class reservationEvent { public static ReservationEventResponse createValidReservationEventResponse() { - return ReservationEventResponse.builder() - .eventId(R.event.id) - .title(R.event.title) - .price(R.event.price) - .build(); + return ReservationEventResponse.from(EventData.event1.entity.get()); } } public static class curationEvent { public static CurationEventResponse createValidCurationEventResponse() { - return CurationEventResponse.builder() - .eventId(R.event.id) - .title(R.event.title) - .location(R.event.location) - .thumbnailImageUrl(R.event.thumbnailImageUrl) - .hostProfileImageUrl(R.event.hostProfileImageUrl) - .hostNickname(R.event.hostNickname) - .build(); + return CurationEventResponse.from(EventData.event1.entity.get()); } } } - } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ImageData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ImageData.java index a35eaff2..aec6ae66 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ImageData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ImageData.java @@ -19,12 +19,32 @@ public class ImageData { // url: 도메인 그거 => response // 예: https://localhost:8080/images/member/Image1.png + public static class childPath { + public static final String member = "/api/images/member"; + public static final String event = "/api/images/events"; + public static final String curation = "/api/images/curation"; + public static final String advertisement = "/api/images/advertisement"; + } + + public static String getThumbnailUrl(AdvertisementImage image) { + return CommonData.path.domainUrl + childPath.advertisement + "/thumbnails/" + image.getName(); + } + public static String getThumbnailUrl(CurationImage image) { + return CommonData.path.domainUrl + childPath.curation + "/thumbnails/" + image.getName(); + } + public static String getThumbnailUrl(EventImage image) { + return CommonData.path.domainUrl + childPath.event + "/thumbnails/" + image.getName(); + } + public static String getThumbnailUrl(MemberImage image) { + return CommonData.path.domainUrl + childPath.member + "/thumbnails/" + image.getName(); + } + public static class R { public static class member { public static class normal { public static final Long id = 1101L; public static final String name = "memberImage1.jpg"; - public static final String url = "https://wouldyouin.store/api/images/" + name; + public static final String url = CommonData.path.domainUrl + childPath.member + name; public static final Long size = 11000L; public static final String extension = ".jpg"; public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); @@ -32,7 +52,7 @@ public static class normal { public static class curator { public static final Long id = 1102L; public static final String name = "curatorImage1.jpg"; - public static final String url = "https://wouldyouin.store/api/images/" + name; + public static final String url = CommonData.path.domainUrl + childPath.member + name; public static final Long size = 12000L; public static final String extension = ".jpg"; public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); @@ -40,7 +60,7 @@ public static class curator { public static class host { public static final Long id = 1103L; public static final String name = "hostImage1.jpg"; - public static final String url = "https://wouldyouin.store/api/images/" + name; + public static final String url = CommonData.path.domainUrl + childPath.member + name; public static final Long size = 13000L; public static final String extension = ".jpg"; public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); @@ -48,24 +68,58 @@ public static class host { public static class welcome { public static final Long id = 1104L; public static final String name = "welcomeImage1.jpg"; - public static final String url = "https://wouldyouin.store/api/images/" + name; + public static final String url = CommonData.path.domainUrl + childPath.member + name; public static final Long size = 14000L; public static final String extension = ".jpg"; public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); } } - public static class event { + + public static class event1 { public static final Long id = 1201L; public static final String name = "eventImage1.jpg"; - public static final String url = "https://wouldyouin.store/api/images/" + name; + public static final String url = CommonData.path.domainUrl + childPath.event + name; + public static final Long size = 21000L; + public static final String extension = ".jpg"; + public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); + } + public static class event2 { + public static final Long id = 1202L; + public static final String name = "eventImage2.jpg"; + public static final String url = CommonData.path.domainUrl + childPath.event + name; public static final Long size = 22000L; public static final String extension = ".jpg"; public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); } + public static class event3 { + public static final Long id = 1203L; + public static final String name = "eventImage3.jpg"; + public static final String url = CommonData.path.domainUrl + childPath.event + name; + public static final Long size = 23000L; + public static final String extension = ".jpg"; + public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); + } + public static class event4 { + public static final Long id = 1204L; + public static final String name = "eventImage4.jpg"; + public static final String url = CommonData.path.domainUrl + childPath.event + name; + public static final Long size = 24000L; + public static final String extension = ".jpg"; + public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); + } + public static class event5 { + public static final Long id = 1205L; + public static final String name = "eventImage5.jpg"; + public static final String url = CommonData.path.domainUrl + childPath.event + name; + public static final Long size = 25000L; + public static final String extension = ".jpg"; + public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); + } + public static class curation1 { public static final Long id = 1301L; public static final String name = "curationImage1.jpg"; - public static final String url = "https://wouldyouin.store/api/images/" + name; + public static final String url = CommonData.path.domainUrl + childPath.curation + name; public static final Long size = 31000L; public static final String extension = ".jpg"; public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); @@ -73,19 +127,85 @@ public static class curation1 { public static class curation2 { public static final Long id = 1302L; public static final String name = "curationImage2.jpg"; - public static final String url = "https://wouldyouin.store/api/images/" + name; + public static final String url = CommonData.path.domainUrl + childPath.curation + name; public static final Long size = 32000L; public static final String extension = ".jpg"; public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); } - public static class advertisement { + public static class curation3 { + public static final Long id = 1303L; + public static final String name = "curationImage3.jpg"; + public static final String url = CommonData.path.domainUrl + childPath.curation + name; + public static final Long size = 33000L; + public static final String extension = ".jpg"; + public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); + } + public static class curation4 { + public static final Long id = 1304L; + public static final String name = "curationImage4.jpg"; + public static final String url = CommonData.path.domainUrl + childPath.curation + name; + public static final Long size = 34000L; + public static final String extension = ".jpg"; + public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); + } + public static class curation5 { + public static final Long id = 1305L; + public static final String name = "curationImage5.jpg"; + public static final String url = CommonData.path.domainUrl + childPath.curation + name; + public static final Long size = 35000L; + public static final String extension = ".jpg"; + public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); + } + public static class curation6 { + public static final Long id = 1306L; + public static final String name = "curationImage6.jpg"; + public static final String url = CommonData.path.domainUrl + childPath.curation + name; + public static final Long size = 36000L; + public static final String extension = ".jpg"; + public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); + } + public static class curation7 { + public static final Long id = 1307L; + public static final String name = "curationImage7.jpg"; + public static final String url = CommonData.path.domainUrl + childPath.curation + name; + public static final Long size = 37000L; + public static final String extension = ".jpg"; + public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); + } + public static class curation8 { + public static final Long id = 1308L; + public static final String name = "curationImage8.jpg"; + public static final String url = CommonData.path.domainUrl + childPath.curation + name; + public static final Long size = 38000L; + public static final String extension = ".jpg"; + public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); + } + + public static class advertisement1 { public static final Long id = 1401L; public static final String name = "adImage1.jpg"; - public static final String url = "https://wouldyouin.store/api/images/" + name; - public static final Long size = 40000L; + public static final String url = CommonData.path.domainUrl + childPath.advertisement + name; + public static final Long size = 41000L; + public static final String extension = ".jpg"; + public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); + } + public static class advertisement2 { + public static final Long id = 1402L; + public static final String name = "adImage2.jpg"; + public static final String url = CommonData.path.domainUrl + childPath.advertisement + name; + public static final Long size = 42000L; + public static final String extension = ".jpg"; + public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); + } + public static class advertisement3 { + public static final Long id = 1403L; + public static final String name = "adImage3.jpg"; + public static final String url = CommonData.path.domainUrl + childPath.advertisement + name; + public static final Long size = 43000L; public static final String extension = ".jpg"; public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); } + public static class mockMultipartFile1 { public static final String name = "images"; public static final String originalFileName = "image1.jpg"; @@ -194,15 +314,15 @@ public static class response { } } - public static class event { + public static class event1 { public static class entity { public static EventImage get() { EventImage ret = EventImage.builder() - .name(R.event.name) - .size(R.event.size) - .extension(R.event.extension) + .name(R.event1.name) + .size(R.event1.size) + .extension(R.event1.extension) .build(); - setImageFields(ret, R.event.id, R.event.createdDate); + setImageFields(ret, R.event1.id, R.event1.createdDate); // ReflectionTestUtils.setField(ret, "event", createValidEvent()); return ret; } @@ -210,11 +330,91 @@ public static EventImage get() { public static class request { public static ImageRequest get() { return ImageRequest.builder() - .name(R.event.name) - .size(R.event.size) - .extension(R.event.extension) + .name(R.event1.name) + .size(R.event1.size) + .extension(R.event1.extension) + .build(); + } + } + public static class response { + + } + } + public static class event2 { + public static class entity { + public static EventImage get() { + EventImage ret = EventImage.builder() + .name(R.event2.name) + .size(R.event2.size) + .extension(R.event2.extension) + .build(); + setImageFields(ret, R.event2.id, R.event2.createdDate); + // ReflectionTestUtils.setField(ret, "event", createValidEvent()); + return ret; + } + } + public static class request { + + } + public static class response { + + } + } + public static class event3 { + public static class entity { + public static EventImage get() { + EventImage ret = EventImage.builder() + .name(R.event3.name) + .size(R.event3.size) + .extension(R.event3.extension) + .build(); + setImageFields(ret, R.event3.id, R.event3.createdDate); + // ReflectionTestUtils.setField(ret, "event", createValidEvent()); + return ret; + } + } + public static class request { + + } + public static class response { + + } + } + public static class event4 { + public static class entity { + public static EventImage get() { + EventImage ret = EventImage.builder() + .name(R.event4.name) + .size(R.event4.size) + .extension(R.event4.extension) + .build(); + setImageFields(ret, R.event4.id, R.event4.createdDate); + // ReflectionTestUtils.setField(ret, "event", createValidEvent()); + return ret; + } + } + public static class request { + + } + public static class response { + + } + } + public static class event5 { + public static class entity { + public static EventImage get() { + EventImage ret = EventImage.builder() + .name(R.event5.name) + .size(R.event5.size) + .extension(R.event5.extension) .build(); + setImageFields(ret, R.event5.id, R.event5.createdDate); + // ReflectionTestUtils.setField(ret, "event", createValidEvent()); + return ret; } + } + public static class request { + } public static class response { @@ -255,7 +455,6 @@ public static ImageResponse get() { } } } - public static class curation2 { public static class entity { public static CurationImage get() { @@ -270,7 +469,13 @@ public static CurationImage get() { } } public static class request { - + public static ImageRequest get() { + return ImageRequest.builder() + .name(R.curation2.name) + .size(R.curation2.size) + .extension(R.curation2.extension) + .build(); + } } public static class response { public static ImageResponse get() { @@ -284,16 +489,220 @@ public static ImageResponse get() { } } } + public static class curation3 { + public static class entity { + public static CurationImage get() { + CurationImage ret = CurationImage.builder() + .name(R.curation3.name) + .size(R.curation3.size) + .extension(R.curation3.extension) + .build(); + setImageFields(ret, R.curation3.id, R.curation3.createdDate); + // ReflectionTestUtils.setField(ret, "curationCard", createValidCurator()); + return ret; + } + } + public static class request { + public static ImageRequest get() { + return ImageRequest.builder() + .name(R.curation3.name) + .size(R.curation3.size) + .extension(R.curation3.extension) + .build(); + } + } + public static class response { + public static ImageResponse get() { + return ImageResponse.builder() + .id(R.curation3.id) + .url(R.curation3.url) + .size(R.curation3.size) + .extension(R.curation3.extension) + .createdDate(R.curation3.createdDate) + .build(); + } + } + } + public static class curation4 { + public static class entity { + public static CurationImage get() { + CurationImage ret = CurationImage.builder() + .name(R.curation4.name) + .size(R.curation4.size) + .extension(R.curation4.extension) + .build(); + setImageFields(ret, R.curation4.id, R.curation4.createdDate); + // ReflectionTestUtils.setField(ret, "curationCard", createValidCurator()); + return ret; + } + } + public static class request { + public static ImageRequest get() { + return ImageRequest.builder() + .name(R.curation4.name) + .size(R.curation4.size) + .extension(R.curation4.extension) + .build(); + } + } + public static class response { + public static ImageResponse get() { + return ImageResponse.builder() + .id(R.curation4.id) + .url(R.curation4.url) + .size(R.curation4.size) + .extension(R.curation4.extension) + .createdDate(R.curation4.createdDate) + .build(); + } + } + } + public static class curation5 { + public static class entity { + public static CurationImage get() { + CurationImage ret = CurationImage.builder() + .name(R.curation5.name) + .size(R.curation5.size) + .extension(R.curation5.extension) + .build(); + setImageFields(ret, R.curation5.id, R.curation5.createdDate); + // ReflectionTestUtils.setField(ret, "curationCard", createValidCurator()); + return ret; + } + } + public static class request { + public static ImageRequest get() { + return ImageRequest.builder() + .name(R.curation5.name) + .size(R.curation5.size) + .extension(R.curation5.extension) + .build(); + } + } + public static class response { + public static ImageResponse get() { + return ImageResponse.builder() + .id(R.curation5.id) + .url(R.curation5.url) + .size(R.curation5.size) + .extension(R.curation5.extension) + .createdDate(R.curation5.createdDate) + .build(); + } + } + } + public static class curation6 { + public static class entity { + public static CurationImage get() { + CurationImage ret = CurationImage.builder() + .name(R.curation6.name) + .size(R.curation6.size) + .extension(R.curation6.extension) + .build(); + setImageFields(ret, R.curation6.id, R.curation6.createdDate); + // ReflectionTestUtils.setField(ret, "curationCard", createValidCurator()); + return ret; + } + } + public static class request { + public static ImageRequest get() { + return ImageRequest.builder() + .name(R.curation6.name) + .size(R.curation6.size) + .extension(R.curation6.extension) + .build(); + } + } + public static class response { + public static ImageResponse get() { + return ImageResponse.builder() + .id(R.curation6.id) + .url(R.curation6.url) + .size(R.curation6.size) + .extension(R.curation6.extension) + .createdDate(R.curation6.createdDate) + .build(); + } + } + } + public static class curation7 { + public static class entity { + public static CurationImage get() { + CurationImage ret = CurationImage.builder() + .name(R.curation7.name) + .size(R.curation7.size) + .extension(R.curation7.extension) + .build(); + setImageFields(ret, R.curation7.id, R.curation7.createdDate); + // ReflectionTestUtils.setField(ret, "curationCard", createValidCurator()); + return ret; + } + } + public static class request { + public static ImageRequest get() { + return ImageRequest.builder() + .name(R.curation7.name) + .size(R.curation7.size) + .extension(R.curation7.extension) + .build(); + } + } + public static class response { + public static ImageResponse get() { + return ImageResponse.builder() + .id(R.curation7.id) + .url(R.curation7.url) + .size(R.curation7.size) + .extension(R.curation7.extension) + .createdDate(R.curation7.createdDate) + .build(); + } + } + } + public static class curation8 { + public static class entity { + public static CurationImage get() { + CurationImage ret = CurationImage.builder() + .name(R.curation8.name) + .size(R.curation8.size) + .extension(R.curation8.extension) + .build(); + setImageFields(ret, R.curation8.id, R.curation8.createdDate); + // ReflectionTestUtils.setField(ret, "curationCard", createValidCurator()); + return ret; + } + } + public static class request { + public static ImageRequest get() { + return ImageRequest.builder() + .name(R.curation8.name) + .size(R.curation8.size) + .extension(R.curation8.extension) + .build(); + } + } + public static class response { + public static ImageResponse get() { + return ImageResponse.builder() + .id(R.curation8.id) + .url(R.curation8.url) + .size(R.curation8.size) + .extension(R.curation8.extension) + .createdDate(R.curation8.createdDate) + .build(); + } + } + } - public static class advertisement { + public static class advertisement1 { public static class entity { public static AdvertisementImage get() { AdvertisementImage ret = AdvertisementImage.builder() - .name(R.advertisement.name) - .size(R.advertisement.size) - .extension(R.advertisement.extension) + .name(R.advertisement1.name) + .size(R.advertisement1.size) + .extension(R.advertisement1.extension) .build(); - setImageFields(ret, R.advertisement.id, R.advertisement.createdDate); + setImageFields(ret, R.advertisement1.id, R.advertisement1.createdDate); // ReflectionTestUtils.setField(ret, "advertisement", createValidMember()); return ret; } @@ -301,9 +710,88 @@ public static AdvertisementImage get() { public static class request { public static ImageRequest get() { return ImageRequest.builder() - .name(R.advertisement.name) - .size(R.advertisement.size) - .extension(R.advertisement.extension) + .name(R.advertisement1.name) + .size(R.advertisement1.size) + .extension(R.advertisement1.extension) + .build(); + } + } + public static class response { + public static ImageResponse get() { + return ImageResponse.builder() + .id(R.advertisement1.id) + .url(R.advertisement1.url) + .size(R.advertisement1.size) + .extension(R.advertisement1.extension) + .createdDate(R.advertisement1.createdDate) + .build(); + } + } + } + public static class advertisement2 { + public static class entity { + public static AdvertisementImage get() { + AdvertisementImage ret = AdvertisementImage.builder() + .name(R.advertisement2.name) + .size(R.advertisement2.size) + .extension(R.advertisement2.extension) + .build(); + setImageFields(ret, R.advertisement2.id, R.advertisement2.createdDate); + // ReflectionTestUtils.setField(ret, "advertisement", createValidMember()); + return ret; + } + } + public static class request { + public static ImageRequest get() { + return ImageRequest.builder() + .name(R.advertisement2.name) + .size(R.advertisement2.size) + .extension(R.advertisement2.extension) + .build(); + } + } + public static class response { + public static ImageResponse get() { + return ImageResponse.builder() + .id(R.advertisement2.id) + .url(R.advertisement2.url) + .size(R.advertisement2.size) + .extension(R.advertisement2.extension) + .createdDate(R.advertisement2.createdDate) + .build(); + } + } + } + public static class advertisement3 { + public static class entity { + public static AdvertisementImage get() { + AdvertisementImage ret = AdvertisementImage.builder() + .name(R.advertisement3.name) + .size(R.advertisement3.size) + .extension(R.advertisement3.extension) + .build(); + setImageFields(ret, R.advertisement3.id, R.advertisement3.createdDate); + // ReflectionTestUtils.setField(ret, "advertisement", createValidMember()); + return ret; + } + } + public static class request { + public static ImageRequest get() { + return ImageRequest.builder() + .name(R.advertisement3.name) + .size(R.advertisement3.size) + .extension(R.advertisement3.extension) + .build(); + } + } + public static class response { + public static ImageResponse get() { + return ImageResponse.builder() + .id(R.advertisement3.id) + .url(R.advertisement3.url) + .size(R.advertisement3.size) + .extension(R.advertisement3.extension) + .createdDate(R.advertisement3.createdDate) .build(); } } @@ -318,7 +806,6 @@ public static MockMultipartFile get() { R.mockMultipartFile1.content); } } - public static class mockMultipartFile2 { public static MockMultipartFile get() { return new MockMultipartFile( diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java index 22c94d7e..0e2284a2 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java @@ -4,6 +4,10 @@ import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; +import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; +import org.ktc2.cokaen.wouldyouin.event.persist.Event; +import org.ktc2.cokaen.wouldyouin.like.persist.CuratorLike; +import org.ktc2.cokaen.wouldyouin.like.persist.HostLike; import org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse.ReservationMemberResponse; import org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse.CurationCuratorResponse; import org.ktc2.cokaen.wouldyouin.member.persist.AccountType; @@ -11,12 +15,28 @@ import org.ktc2.cokaen.wouldyouin.member.persist.Host; import org.ktc2.cokaen.wouldyouin.member.persist.Member; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; +import org.ktc2.cokaen.wouldyouin.reservation.persist.Reservation; +import org.ktc2.cokaen.wouldyouin.review.persist.Review; import org.springframework.test.util.ReflectionTestUtils; public class MemberData { public static class R { - public static class normal { + public static class normal1 { + public static class _Relation { + public static List curatorLikes() { + return null; // TODO: Implement + } + public static List hostLikes() { + return null; // TODO: Implement + } + public static List reservations() { + return null; // TODO: Implement + } + public static List reviews() { + return null; // TODO: Implement + } + } public static final long id = 101L; public static final MemberIdentifier memberIdentifier = new MemberIdentifier(id, MemberType.normal); public static final AccountType accountType = AccountType.kakao; @@ -24,72 +44,90 @@ public static class normal { public static final String nickname = "nick_normal_123"; public static final String phone = "010-1112-2233"; public static final MemberImage profileImage = ImageData.member.normal.entity.get(); + public static final String profileImageUrl = ImageData.R.member.normal.url; + public static final String profileImageThumbnailUrl = ImageData.getThumbnailUrl(profileImage); public static final Area area = Area.광주; public static final String gender = "Men"; public static final String socialId = "100100100100100"; public static final MemberType memberType = MemberType.normal; } - public static class curator { - public static final long id = 102L; + public static class curator1 { + public static class _Relation { + public static List curations() { + return null; // TODO: Implement + } + } + public static final long id = 201L; public static final MemberIdentifier memberIdentifier = new MemberIdentifier(id, MemberType.curator); public static final AccountType accountType = AccountType.google; public static final String email = "curator1@example.com"; public static final String nickname = "nick_curator_12"; public static final String phone = "010-4545-6767"; public static final MemberImage profileImage = ImageData.member.curator.entity.get(); - public static final String profileImageUrl = "https://wouldyouin.store/api/images/member/" + profileImage.getName(); + public static final String profileImageUrl = ImageData.R.member.curator.url; + public static final String profileImageThumbnailUrl = ImageData.getThumbnailUrl(profileImage); public static final Area area = Area.광주; public static final String gender = "Women"; public static final String socialId = "200200200200200"; public static final String intro = "큐레이터 자기소개입니다."; public static final List hashtags = List.of("#큐레이터", "#해시태그", "#입니다"); } - public static class host { - public static final long id = 103L; + public static class host1 { + public static class _Relation { + public static List events() { + return null; // TODO: Implement + } + } + public static final long id = 301; public static final MemberIdentifier memberIdentifier = new MemberIdentifier(id, MemberType.host); public static final String email = "host1@example.com"; public static final String nickname = "nick_host_12"; public static final String phone = "010-4545-6767"; public static final String hashedPassword = "hashed_password"; public static final MemberImage profileImage = ImageData.member.host.entity.get(); + public static final String profileImageUrl = ImageData.R.member.host.url; + public static final String profileImageThumbnailUrl = ImageData.getThumbnailUrl(profileImage); public static final String intro = "주최자 자기소개입니다."; public static final List hashtags = List.of("#주최자", "#해시태그", "#입니다"); } - public static class welcome { - public static final long id = 104L; + public static class welcome1 { + public static final long id = 401; public static final MemberIdentifier memberIdentifier = new MemberIdentifier(id, MemberType.welcome); public static final AccountType accountType = AccountType.kakao; public static final String email = "welcome2@example.com"; public static final String nickname = "nick_normal_333"; public static final String phone = "010-4414-1144"; public static final MemberImage profileImage = ImageData.member.welcome.entity.get(); + public static final String profileImageUrl = ImageData.R.member.welcome.url; + public static final String profileImageThumbnailUrl = ImageData.getThumbnailUrl(profileImage); public static final Area area = Area.서울; public static final String gender = "Men"; public static final String socialId = "456456456456"; } - public static class admin { - public static final long id = 105L; + public static class admin1 { + public static final long id = 501L; public static final MemberIdentifier memberIdentifier = new MemberIdentifier(id, MemberType.admin); } } - public static class normal { + public static class normal1 { public static class entity { public static Member get() { Member ret = Member.builder() - .accountType(R.normal.accountType) - .email(R.normal.email) - .nickname(R.normal.nickname) - .phone(R.normal.phone) - .profileImage(R.normal.profileImage) - .area(R.normal.area) - .gender(R.normal.gender) - .socialId(R.normal.socialId) + .accountType(R.normal1.accountType) + .email(R.normal1.email) + .nickname(R.normal1.nickname) + .phone(R.normal1.phone) + .profileImage(R.normal1.profileImage) + .profileImageThumbnailUrl(R.normal1.profileImageThumbnailUrl) + .area(R.normal1.area) + .gender(R.normal1.gender) + .socialId(R.normal1.socialId) .build(); - ReflectionTestUtils.setField(ret, "Id", R.normal.id); - ReflectionTestUtils.setField(ret, "memberType", R.normal.memberType); + ReflectionTestUtils.setField(ret, "Id", R.normal1.id); + ReflectionTestUtils.setField(ret, "memberType", R.normal1.memberType); // ReflectionTestUtils.setField(ret.getProfileImage(), "baseMember", ret); return ret; } @@ -102,22 +140,23 @@ public static class response { } } - public static class curator { + public static class curator1 { public static class entity { public static Curator get() { Curator ret = Curator.curatorBuilder() - .accountType(R.curator.accountType) - .email(R.curator.email) - .nickname(R.curator.nickname) - .phone(R.curator.phone) - .profileImage(R.curator.profileImage) - .area(R.curator.area) - .gender(R.curator.gender) - .socialId(R.curator.socialId) + .accountType(R.curator1.accountType) + .email(R.curator1.email) + .nickname(R.curator1.nickname) + .phone(R.curator1.phone) + .profileImage(R.curator1.profileImage) + .profileImageThumbnailUrl(R.curator1.profileImageThumbnailUrl) + .area(R.curator1.area) + .gender(R.curator1.gender) + .socialId(R.curator1.socialId) .build(); - ReflectionTestUtils.setField(ret, "Id", R.curator.id); - ReflectionTestUtils.setField(ret, "intro", R.curator.intro); - ReflectionTestUtils.setField(ret, "hashtags", R.curator.hashtags); + ReflectionTestUtils.setField(ret, "Id", R.curator1.id); + ReflectionTestUtils.setField(ret, "intro", R.curator1.intro); + ReflectionTestUtils.setField(ret, "hashtags", R.curator1.hashtags); // ReflectionTestUtils.setField(ret.getProfileImage(), "baseMember", ret); return ret; } @@ -130,19 +169,20 @@ public static class response { } } - public static class host { + public static class host1 { public static class entity { public static Host get() { Host ret = Host.builder() - .email(R.host.email) - .nickname(R.host.nickname) - .phone(R.host.phone) - .hashedPassword(R.host.hashedPassword) - .profileImage(R.host.profileImage) + .email(R.host1.email) + .nickname(R.host1.nickname) + .phone(R.host1.phone) + .hashedPassword(R.host1.hashedPassword) + .profileImage(R.host1.profileImage) + .profileImageThumbnailUrl(R.host1.profileImageThumbnailUrl) .build(); - ReflectionTestUtils.setField(ret, "Id", R.host.id); - ReflectionTestUtils.setField(ret, "intro", R.host.intro); - ReflectionTestUtils.setField(ret, "hashtags", R.host.hashtags); + ReflectionTestUtils.setField(ret, "Id", R.host1.id); + ReflectionTestUtils.setField(ret, "intro", R.host1.intro); + ReflectionTestUtils.setField(ret, "hashtags", R.host1.hashtags); // ReflectionTestUtils.setField(ret.getProfileImage(), "baseMember", ret); return ret; } @@ -155,20 +195,21 @@ public static class response { } } - public static class welcome { + public static class welcome1 { public static class entity { public static Member get() { Member ret = Member.builder() - .accountType(R.welcome.accountType) - .email(R.welcome.email) - .nickname(R.welcome.nickname) - .phone(R.welcome.phone) - .profileImage(R.welcome.profileImage) - .area(R.welcome.area) - .gender(R.welcome.gender) - .socialId(R.welcome.socialId) + .accountType(R.welcome1.accountType) + .email(R.welcome1.email) + .nickname(R.welcome1.nickname) + .phone(R.welcome1.phone) + .profileImage(R.welcome1.profileImage) + .profileImageThumbnailUrl(R.welcome1.profileImageThumbnailUrl) + .area(R.welcome1.area) + .gender(R.welcome1.gender) + .socialId(R.welcome1.socialId) .build(); - ReflectionTestUtils.setField(ret, "Id", R.welcome.id); + ReflectionTestUtils.setField(ret, "Id", R.welcome1.id); // ReflectionTestUtils.setField(ret.getProfileImage(), "baseMember", ret); return ret; } @@ -181,7 +222,7 @@ public static class response { } } - public static class admin { + public static class admin1 { public static class entity { public static final long validAdminId = 105L; @@ -195,28 +236,14 @@ public static class response { } public static class response { - public static class reservationMember { + public static class reservation1Member1 { public static ReservationMemberResponse get() { - return ReservationMemberResponse.builder() - .memberId(R.normal.id) - .email(R.normal.email) - .nickname(R.normal.nickname) - .phone(R.normal.phone) - .gender(R.normal.gender) - .build(); + return ReservationMemberResponse.from(normal1.entity.get()); } } - public static class curationCurator { + public static class curation1Curator1 { public static CurationCuratorResponse get() { - return CurationCuratorResponse.builder() - .nickname(R.curator.nickname) - .email(R.curator.email) - .phone(R.curator.phone) - .profileImageUrl(R.curator.profileImageUrl) - .intro(R.curator.intro) - .likes(0) - .hashtags(R.curator.hashtags) - .build(); + return CurationCuratorResponse.from(curator1.entity.get()); } } } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ReservationData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ReservationData.java index a6e56405..455460b0 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ReservationData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ReservationData.java @@ -2,6 +2,7 @@ import java.time.LocalDateTime; import java.util.List; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.response.reservation1Member1; import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.ReservationEventResponse; import org.ktc2.cokaen.wouldyouin.event.persist.Event; import org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse.ReservationMemberResponse; @@ -15,62 +16,61 @@ public class ReservationData { public static class R { - public static class reservation { + public static class reservation1 { + public static class _Relation { + public static Member member() { + return MemberData.normal1.entity.get(); + } + public static Event event() { + return EventData.event1.entity.get(); + } + } public static final Long id = 1L; - public static final Member member = MemberData.normal.entity.get(); - public static final Event event = EventData.event.entity.get(); - public static final Integer price = EventData.R.event.price; + public static final Integer price = _Relation.event().getPrice(); public static final Integer quantity = 2; public static final LocalDateTime reservationDate = LocalDateTime.of(2024, 3, 23, 0, 0); - public static final ReservationMemberResponse memberResponse = MemberData.response.reservationMember.get(); + public static final ReservationMemberResponse memberResponse = reservation1Member1.get(); public static final ReservationEventResponse eventResponse = EventData.response.reservationEvent.createValidReservationEventResponse(); } } - public static class reservation { + public static class reservation1 { public static class entity { public static Reservation get() { Reservation ret = Reservation.builder() - .member(R.reservation.member) - .event(R.reservation.event) - .price(R.reservation.price) - .quantity(R.reservation.quantity) + .member(R.reservation1._Relation.member()) + .event(R.reservation1._Relation.event()) + .price(R.reservation1.price) + .quantity(R.reservation1.quantity) .build(); - ReflectionTestUtils.setField(ret, "id", R.reservation.id); - ReflectionTestUtils.setField(ret, "reservationDate", R.reservation.reservationDate); + ReflectionTestUtils.setField(ret, "id", R.reservation1.id); + ReflectionTestUtils.setField(ret, "reservationDate", R.reservation1.reservationDate); return ret; } } public static class request { public static ReservationRequest get() { return ReservationRequest.builder() - .eventId(R.reservation.event.getId()) - .quantity(R.reservation.quantity) + .eventId(R.reservation1._Relation.event().getId()) + .quantity(R.reservation1.quantity) .build(); } } public static class response { public static ReservationResponse get() { - return ReservationResponse.builder() - .id(R.reservation.id) - .member(R.reservation.memberResponse) - .event(R.reservation.eventResponse) - .price(R.reservation.price) - .quantity(R.reservation.quantity) - .reservationDate(R.reservation.reservationDate) - .build(); - - } - public static class slice { - public static ReservationSliceResponse get() { - return ReservationSliceResponse.builder() - .reservations(List.of( - ReservationData.reservation.response.get())) - .sliceInfo(CommonData.sliceInfo.get()) - .build(); - } + return ReservationResponse.from(reservation1.entity.get()); } + + } + } + public static class sliceResponse { + public static ReservationSliceResponse get() { + return ReservationSliceResponse.builder() + .reservations(List.of( + ReservationData.reservation1.response.get())) + .sliceInfo(CommonData.sliceInfo.get()) + .build(); } } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java index f64f4884..796a7fa7 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java @@ -22,11 +22,11 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.ktc2.cokaen.wouldyouin._common.vo.Area; -import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockCurator; -import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost; -import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember; +import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockCurator1; +import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost1; +import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember1; import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator1; import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; import org.ktc2.cokaen.wouldyouin.curation.api.CurationController; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCreateRequest; @@ -72,7 +72,7 @@ public void setup() throws Exception { @Test @DisplayName("RequestParam을 통해 전달받은 지역의 큐레이션 목록을 조회한다.") - @WithMockMember + @WithMockMember1 void getCurationsByAreaOrderByCreatedDateDesc1() throws Exception { // given, when mockMvc.perform(get("/api/curations") @@ -89,7 +89,7 @@ void getCurationsByAreaOrderByCreatedDateDesc1() throws Exception { @Test @DisplayName("RequestParam을 통해 지역을 지정하지 않은 경우, 전체 지역의 큐레이션 목록을 조회한다.") - @WithMockMember + @WithMockMember1 void getCurationsByAreaOrderByCreatedDateDesc2() throws Exception { // given, when mockMvc.perform(get("/api/curations")).andDo(print()) @@ -102,7 +102,7 @@ void getCurationsByAreaOrderByCreatedDateDesc2() throws Exception { @Test @DisplayName("ReqeustParam을 통해 요청할 페이지에 대한 정보를 전달받아, 해당하는 호스트의 큐레이션 목록을 조회한다.") - @WithMockMember + @WithMockMember1 void getCurationsByCuratorIdOrderByCreatedDateDesc1() throws Exception { // given, when mockMvc.perform(get("/api/curations/curators/" + randomId) @@ -118,7 +118,7 @@ void getCurationsByCuratorIdOrderByCreatedDateDesc1() throws Exception { @Test @DisplayName("RequestParam을 통해 페이지 정보를 지정하지 않은 경우, 디폴트 값으로 해당하는 호스트의 큐레이션 목록을 조회한다.") - @WithMockMember + @WithMockMember1 void getCurationsByCuratorIdOrderByCreatedDateDesc2() throws Exception { // given, when mockMvc.perform(get("/api/curations/curators/" + randomId)).andDo(print()) @@ -131,7 +131,7 @@ void getCurationsByCuratorIdOrderByCreatedDateDesc2() throws Exception { @Test @DisplayName("큐레이션 ID를 통해 해당하는 큐레이션을 조회한다.") - @WithMockMember + @WithMockMember1 void getCurationByCurationId() throws Exception { // given, when mockMvc.perform(get("/api/curations/" + randomId)).andDo(print()) @@ -143,7 +143,7 @@ void getCurationByCurationId() throws Exception { @Test @DisplayName("RequestBody로 전달받은 정보를 통해 큐레이션을 생성한다.") - @WithMockCurator + @WithMockCurator1 void createCuration1() throws Exception { // given ArgumentCaptor captor = ArgumentCaptor.forClass(CurationCreateRequest.class); @@ -158,13 +158,13 @@ void createCuration1() throws Exception { .andExpect(status().isCreated()); // then - then(curationService).should(times(1)).create(eq(curator.memberIdentifier), captor.capture()); + then(curationService).should(times(1)).create(eq(curator1.memberIdentifier), captor.capture()); assertThat(captor.getValue()).isEqualTo(request); } @Test @DisplayName("호스트의 권한으로는 큐레이션을 생성할 수 없다.") - @WithMockHost + @WithMockHost1 void createCuration2() throws Exception { // given, when mockMvc.perform(post("/api/curations") @@ -182,7 +182,7 @@ void createCuration2() throws Exception { @Test @DisplayName("멤버의 권한으로는 큐레이션을 생성할 수 없다.") - @WithMockMember + @WithMockMember1 void createCuration3() throws Exception { // given, when mockMvc.perform(post("/api/curations") @@ -200,7 +200,7 @@ void createCuration3() throws Exception { @Test @DisplayName("큐레이션 생성 시, 제목에는 빈 값이 들어갈 수 없다.") - @WithMockCurator + @WithMockCurator1 void createCuration4() throws Exception { // given CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() @@ -221,7 +221,7 @@ void createCuration4() throws Exception { @Test @DisplayName("큐레이션 생성 시, 큐레이션 카드의 부제목에는 빈 값이 들어갈 수 없다.") - @WithMockCurator + @WithMockCurator1 void createCuration5() throws Exception { // given CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() @@ -243,7 +243,7 @@ void createCuration5() throws Exception { @Test @DisplayName("큐레이션 생성 시, 큐레이션 카드의 내용에는 빈 값이 들어갈 수 없다.") - @WithMockCurator + @WithMockCurator1 void createCuration6() throws Exception { // given CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() @@ -265,7 +265,7 @@ void createCuration6() throws Exception { @Test @DisplayName("큐레이션 생성 시, 큐레이션 카드의 내용에는 빈 값이 들어갈 수 없다.") - @WithMockCurator + @WithMockCurator1 void createCuration7() throws Exception { // given CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() @@ -287,7 +287,7 @@ void createCuration7() throws Exception { @Test @DisplayName("큐레이션 생성 시, 큐레이션 카드의 내용은 20자 이상 1000자 이하이어야 한다.") - @WithMockCurator + @WithMockCurator1 void createCuration8() throws Exception { // given CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() @@ -309,7 +309,7 @@ void createCuration8() throws Exception { @Test @DisplayName("큐레이션 생성 시, 각 큐레이션 카드에는 이미지를 최대 5개까지 등록할 수 있다.") - @WithMockCurator + @WithMockCurator1 void createCuration9() throws Exception { // given CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() @@ -332,7 +332,7 @@ void createCuration9() throws Exception { @Test @DisplayName("큐레이션 생성 시, 지역에는 빈 값이 들어갈 수 없다.") - @WithMockCurator + @WithMockCurator1 void createCuration10() throws Exception { // given CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() @@ -353,7 +353,7 @@ void createCuration10() throws Exception { @Test @DisplayName("큐레이션 생성 시, 큐레이션 카드의 개수는 1개 이상 10개 이하이어야 한다.") - @WithMockCurator + @WithMockCurator1 void createCuration11() throws Exception { // given CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder(). @@ -374,7 +374,7 @@ void createCuration11() throws Exception { @Test @DisplayName("RequestBody로 전달받은 정보를 통해 큐레이션을 수정한다.") - @WithMockCurator + @WithMockCurator1 void updateCuration1() throws Exception { // given ArgumentCaptor captor = ArgumentCaptor.forClass(CurationEditRequest.class); @@ -389,13 +389,13 @@ void updateCuration1() throws Exception { .andExpect(status().isOk()); // then - then(curationService).should(times(1)).update(eq(curator.memberIdentifier), eq(randomId), captor.capture()); + then(curationService).should(times(1)).update(eq(curator1.memberIdentifier), eq(randomId), captor.capture()); assertThat(captor.getValue()).isEqualTo(request); } @Test @DisplayName("Host의 권한으로는 큐레이션을 수정할 수 없다.") - @WithMockHost + @WithMockHost1 void updateCuration2() throws Exception { // given, when mockMvc.perform(put("/api/curations/" + randomId) @@ -413,7 +413,7 @@ void updateCuration2() throws Exception { @Test @DisplayName("Member의 권한으로는 큐레이션을 수정할 수 없다.") - @WithMockMember + @WithMockMember1 void updateCuration3() throws Exception { // given, when mockMvc.perform(put("/api/curations/" + randomId) @@ -431,7 +431,7 @@ void updateCuration3() throws Exception { @Test @DisplayName("큐레이션 수정 시, 제목에는 빈 값이 들어갈 수 없다.") - @WithMockCurator + @WithMockCurator1 void updateCuration4() throws Exception { // given CurationEditRequest request = CurationData.curation.request.edit.get().toBuilder() @@ -452,7 +452,7 @@ void updateCuration4() throws Exception { @Test @DisplayName("큐레이션 수정 시, 큐레이션 카드의 부제목에는 빈 값이 들어갈 수 없다.") - @WithMockCurator + @WithMockCurator1 void updateCuration5() throws Exception { // given CurationEditRequest request = CurationData.curation.request.edit.get().toBuilder() @@ -475,7 +475,7 @@ void updateCuration5() throws Exception { @Test @DisplayName("큐레이션 수정 시, 큐레이션 카드의 내용에는 빈 값이 들어갈 수 없다.") - @WithMockCurator + @WithMockCurator1 void updateCuration6() throws Exception { // given CurationEditRequest request = CurationData.curation.request.edit.get().toBuilder() @@ -498,7 +498,7 @@ void updateCuration6() throws Exception { @Test @DisplayName("큐레이션 수정 시, 큐레이션 카드의 내용의 길이는 20자 이상 1000자 이하이어야 한다.") - @WithMockCurator + @WithMockCurator1 void updateCuration7() throws Exception { // given CurationEditRequest request = CurationData.curation.request.edit.get().toBuilder() @@ -521,7 +521,7 @@ void updateCuration7() throws Exception { @Test @DisplayName("큐레이션 수정 시, 각 큐레이션 카드에는 이미지를 최대 5개 등록할 수 있다.") - @WithMockCurator + @WithMockCurator1 void updateCuration8() throws Exception { // given CurationEditRequest request = CurationData.curation.request.edit.get().toBuilder() @@ -544,7 +544,7 @@ void updateCuration8() throws Exception { @Test @DisplayName("큐레이션 수정 시, 지역에는 빈 값이 들어갈 수 없다.") - @WithMockCurator + @WithMockCurator1 void updateCuration9() throws Exception { // given CurationEditRequest request = CurationData.curation.request.edit.get().toBuilder() @@ -565,7 +565,7 @@ void updateCuration9() throws Exception { @Test @DisplayName("큐레이션 수정 시, 큐레이션 카드는 1개 이상 10개 이하이어야 한다.") - @WithMockCurator + @WithMockCurator1 void updateCuration10() throws Exception { // given CurationEditRequest request = CurationData.curation.request.edit.get().toBuilder() @@ -586,7 +586,7 @@ void updateCuration10() throws Exception { @Test @DisplayName("PathVariable로 전달받은 큐레이션 ID에 해당하는 큐레이션을 삭제한다.") - @WithMockCurator + @WithMockCurator1 void deleteCuration1() throws Exception { // given, when mockMvc.perform(delete("/api/curations/" + randomId) @@ -595,12 +595,12 @@ void deleteCuration1() throws Exception { .andExpect(status().isNoContent()); // then - then(curationService).should(times(1)).delete(eq(curator.memberIdentifier), eq(randomId)); + then(curationService).should(times(1)).delete(eq(curator1.memberIdentifier), eq(randomId)); } @Test @DisplayName("Host의 권한으로는 큐레이션을 삭제할 수 없다.") - @WithMockHost + @WithMockHost1 void deleteCuration2() throws Exception { // given, when mockMvc.perform(delete("/api/curations/" + randomId) @@ -615,7 +615,7 @@ void deleteCuration2() throws Exception { @Test @DisplayName("Member의 권한으로는 큐레이션을 삭제할 수 없다.") - @WithMockMember + @WithMockMember1 void deleteCuration3() throws Exception { // given, when mockMvc.perform(delete("/api/curations/" + randomId) diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java index 516f88d9..9bc056b3 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java @@ -13,10 +13,10 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.ktc2.cokaen.wouldyouin.Image.application.CurationImageService; import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData; -import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationResponse; import org.ktc2.cokaen.wouldyouin.curation.application.CurationCardService; import org.ktc2.cokaen.wouldyouin.curation.application.CurationService; import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; @@ -43,6 +43,9 @@ class CurationServiceTest { @Mock private CurationCardService curationCardService; + @Mock + private CurationImageService curationImageService; + @Mock private MemberImage memberImage; @@ -50,7 +53,7 @@ class CurationServiceTest { @BeforeEach void setUp() { - curationService = new CurationService(curationRepository, curatorService, eventService, curationCardService); + curationService = new CurationService(curationRepository, curatorService, eventService, curationCardService, curationImageService); } @Test diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java index 7207c369..bc572a21 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java @@ -22,10 +22,10 @@ import org.junit.jupiter.api.Test; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; -import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost; +import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost1; import org.ktc2.cokaen.wouldyouin._global.testdata.EventData; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.host.entity; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host1; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.host1.entity; import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; import org.ktc2.cokaen.wouldyouin.auth.application.JwtService; import org.ktc2.cokaen.wouldyouin.event.api.EventController; @@ -85,7 +85,7 @@ public void setup() throws Exception { @Test @DisplayName("모든 행사 조회 - 성공") - @WithMockHost + @WithMockHost1 void getEventsByFilterOrderByDistanceAsc() throws Exception { // given LocationFilter locationFilter = new LocationFilter(0.0, 0.0, 10.0, 10.0); @@ -139,7 +139,7 @@ void getEventsByFilterOrderByDistanceAsc() throws Exception { @Test @DisplayName("주최자 id를 통한 모든 행사 조회 - 성공") - @WithMockHost + @WithMockHost1 void getEventsByLocationByHostId() throws Exception { // given int pageNumber = 1; @@ -165,7 +165,7 @@ void getEventsByLocationByHostId() throws Exception { @Test @DisplayName("행사 id를 통한 행사 조회 - 성공") - @WithMockHost + @WithMockHost1 void getEventByEventId() throws Exception { //given //when @@ -179,41 +179,41 @@ void getEventByEventId() throws Exception { @Test @DisplayName("행사 생성 - 성공") - @WithMockHost + @WithMockHost1 void createEvent() throws Exception { //given //when mockMvc.perform(post("/api/events") .with(csrf()) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(EventData.event.request.create.get()))) + .content(objectMapper.writeValueAsString(EventData.event1.request.create.get()))) .andDo(print()) .andExpect(status().isCreated()); //then - then(eventService).should(times(1)).create(eq(host.memberIdentifier), any(EventCreateRequest.class)); + then(eventService).should(times(1)).create(eq(host1.memberIdentifier), any(EventCreateRequest.class)); } @Test @DisplayName("행사 수정 - 성공") - @WithMockHost + @WithMockHost1 void updateEvent() throws Exception { //given //when mockMvc.perform(put("/api/events/" + id) .with(csrf()) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(EventData.event.request.create.get()))) + .content(objectMapper.writeValueAsString(EventData.event1.request.create.get()))) .andDo(print()) .andExpect(status().isOk()); //then - then(eventService).should(times(1)).update(eq(host.memberIdentifier), eq(id), any(EventEditRequest.class)); + then(eventService).should(times(1)).update(eq(host1.memberIdentifier), eq(id), any(EventEditRequest.class)); } @Test @DisplayName("행사 삭제 - 성공") - @WithMockHost + @WithMockHost1 void deleteEvent() throws Exception { //given //when @@ -222,6 +222,6 @@ void deleteEvent() throws Exception { ).andExpect(status().isNoContent()); //then - then(eventService).should(times(1)).delete(eq(host.memberIdentifier), eq(id)); + then(eventService).should(times(1)).delete(eq(host1.memberIdentifier), eq(id)); } } \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java index 60414a94..952d8f94 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java @@ -16,11 +16,11 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.ktc2.cokaen.wouldyouin.Image.application.EventImageService; +import org.ktc2.cokaen.wouldyouin.Image.application.MemberImageService; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; import org.ktc2.cokaen.wouldyouin._global.testdata.EventData; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host1; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationFilter; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; @@ -51,12 +51,15 @@ class EventServiceUnitTest { @Mock private EventImageService eventImageService; + @Mock + private MemberImageService memberImageService; + private Event validEvent; @BeforeEach void setUp() { - eventService = new EventService(eventRepository, hostService, eventImageService); - validEvent = EventData.event.entity.get(); + eventService = new EventService(eventRepository, hostService, eventImageService, memberImageService); + validEvent = EventData.event1.entity.get(); } @Test @@ -139,11 +142,11 @@ void getByInvalidId() { void create() { // given Long hostId = validEvent.getHost().getId(); - EventCreateRequest validEventCreateRequest = EventData.event.request.create.get(); + EventCreateRequest validEventCreateRequest = EventData.event1.request.create.get(); given(eventRepository.save(any())).willReturn(validEvent); // when - eventService.create(host.memberIdentifier, validEventCreateRequest); + eventService.create(host1.memberIdentifier, validEventCreateRequest); // then then(eventRepository).should(times(1)).save(any(Event.class)); @@ -155,11 +158,11 @@ void update() { // given Long eventId = validEvent.getId(); Long hostId = validEvent.getHost().getId(); - EventEditRequest validEventEditRequest = EventData.event.request.edit.get(); + EventEditRequest validEventEditRequest = EventData.event1.request.edit1.get(); given(eventRepository.findById(eventId)).willReturn(Optional.of(validEvent)); // when - eventService.update(host.memberIdentifier, eventId, validEventEditRequest); + eventService.update(host1.memberIdentifier, eventId, validEventEditRequest); // then then(eventRepository).should(times(1)).findById(eventId); @@ -180,14 +183,14 @@ void update() { @DisplayName("유효하지 않은 행사 id를 통한 행사 수정 - 실패") void updateByInvalidId() { // given - EventEditRequest request = EventData.event.request.edit.get(); + EventEditRequest request = EventData.event1.request.edit1.get(); Long invalidHostId = 999L; given(eventRepository.findById(invalidHostId)).willThrow(RuntimeException.class); // when & then assertThrows(RuntimeException.class, () -> eventService.update(new MemberIdentifier(invalidHostId, MemberType.host), validEvent.getId(), - EventData.event.request.edit.get())); + EventData.event1.request.edit1.get())); } @Test @@ -200,7 +203,7 @@ void delete() { // when given(eventRepository.findById(eventId)).willReturn(Optional.of(validEvent)); willDoNothing().given(eventRepository).deleteById(eventId); - eventService.delete(host.memberIdentifier, eventId); + eventService.delete(host1.memberIdentifier, eventId); // then then(eventRepository).should(times(1)).findById(eventId); @@ -216,6 +219,6 @@ void deleteByInvalidId() { given(eventRepository.findById(eventId)).willThrow(RuntimeException.class); // when & then - assertThrows(RuntimeException.class, () -> eventService.delete(host.memberIdentifier, eventId)); + assertThrows(RuntimeException.class, () -> eventService.delete(host1.memberIdentifier, eventId)); } } \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java index 9160fc52..366f679c 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java @@ -25,13 +25,14 @@ import org.ktc2.cokaen.wouldyouin.Image.application.CurationImageService; import org.ktc2.cokaen.wouldyouin.Image.application.ImageServiceFactory; import org.ktc2.cokaen.wouldyouin.Image.application.ImageStorageService; -import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockCurator; -import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember; +import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockCurator1; +import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember1; import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData; import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.mockMultipartFile1; import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.mockMultipartFile2; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator1; import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; +import org.ktc2.cokaen.wouldyouin.payment.application.PaymentService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -59,6 +60,9 @@ class ImageControllerTest { @MockBean private ImageStorageService imageStorageService; + @MockBean + private PaymentService paymentService; + @MockBean private JwtAuthFilter jwtAuthFilter; @@ -75,7 +79,7 @@ public void setup() throws Exception { @Test @DisplayName("이미지 경로를 통해 이미지를 조회한다.") - @WithMockMember + @WithMockMember1 void getImage() throws Exception { // given String directory = "member"; @@ -92,7 +96,7 @@ void getImage() throws Exception { @Test @DisplayName("RequestParam으로 이미지 도메인을 받아 첨부된 이미지를 업로드한다.") - @WithMockCurator + @WithMockCurator1 void uploadImages1() throws Exception { // given MockMultipartFile image1 = mockMultipartFile1.get(); @@ -118,7 +122,7 @@ void uploadImages1() throws Exception { @Test @DisplayName("RequestParam의 이미지 도메인의 값으로는 MEMBER, CURATION, ADVERTISEMENT, EVENT만 사용할 수 있다.") - @WithMockCurator + @WithMockCurator1 void uploadImages2() throws Exception { // given MockMultipartFile image1 = mockMultipartFile1.get(); @@ -142,7 +146,7 @@ void uploadImages2() throws Exception { @Test @DisplayName("PathVariable로 이미지의 ID를 받아 이미지를 삭제한다.") - @WithMockCurator + @WithMockCurator1 void deleteImage1() throws Exception { // given given((CurationImageService) imageServiceFactory.getImageService(ImageDomain.CURATION)).willReturn(curationImageService); @@ -156,12 +160,12 @@ void deleteImage1() throws Exception { // then then(imageServiceFactory).should(times(1)).getImageService(eq(ImageDomain.CURATION)); - then(curationImageService).should(times(1)).deleteImage(curator.memberIdentifier, randomId); + then(curationImageService).should(times(1)).deleteImage(curator1.memberIdentifier, randomId); } @Test @DisplayName("RequestParam의 이미지 도메인의 값으로는 MEMBER, CURATION, ADVERTISEMENT, EVENT만 사용할 수 있다.") - @WithMockCurator + @WithMockCurator1 void deleteImage2() throws Exception { // given given((CurationImageService) imageServiceFactory.getImageService(ImageDomain.CURATION)).willReturn(curationImageService); diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberServiceUnitTest.java index 3f4497c1..e42f0318 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberServiceUnitTest.java @@ -18,10 +18,10 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.normal; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.welcome; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator1; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host1; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.normal1; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.welcome1; import org.ktc2.cokaen.wouldyouin.member.api.dto.MemberResponse; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMember; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMemberRepository; @@ -58,10 +58,10 @@ class BaseMemberServiceUnitTest { private BaseMemberService baseMemberService; private static Map members; - private static final Member validMember = MemberData.normal.entity.get(); - private static final Member validWelcomeMember = MemberData.welcome.entity.get(); - private static final Host validHost = MemberData.host.entity.get(); - private static final Curator validCurator = MemberData.curator.entity.get(); + private static final Member validMember = MemberData.normal1.entity.get(); + private static final Member validWelcomeMember = MemberData.welcome1.entity.get(); + private static final Host validHost = MemberData.host1.entity.get(); + private static final Curator validCurator = MemberData.curator1.entity.get(); @BeforeAll static void beforeAll() { @@ -89,7 +89,7 @@ MemberType welcomeTypeMapping(MemberType memberType) { } @ParameterizedTest - @ValueSource(longs = {normal.id, curator.id, host.id, welcome.id}) + @ValueSource(longs = {normal1.id, curator1.id, host1.id, welcome1.id}) @DisplayName("임의의 사용자를 찾는 메서드 테스트") void getByIdOrThrow(long id) { // when @@ -102,7 +102,7 @@ void getByIdOrThrow(long id) { } @ParameterizedTest - @ValueSource(longs = {normal.id, curator.id, host.id, welcome.id}) + @ValueSource(longs = {normal1.id, curator1.id, host1.id, welcome1.id}) @DisplayName("임의의 사용자의 타입을 반환하는 메서드 테스트") void getMemberType(long id) { // when @@ -115,7 +115,7 @@ void getMemberType(long id) { } @ParameterizedTest - @ValueSource(longs = {normal.id, curator.id, host.id, welcome.id}) + @ValueSource(longs = {normal1.id, curator1.id, host1.id, welcome1.id}) @DisplayName("각 유형의 사용자를 찾고 응답 반환하는 메서드 테스트") void findById(long id) { // given @@ -137,7 +137,7 @@ void findById(long id) { } @ParameterizedTest - @ValueSource(longs = {normal.id, curator.id, host.id, welcome.id}) + @ValueSource(longs = {normal1.id, curator1.id, host1.id, welcome1.id}) @DisplayName("중복 있는 이메일 있는 경우 테스트") void checkUniqueEmailOrThrow(long id) { // given @@ -166,7 +166,7 @@ void checkUniqueEmailOrThrow_Unique() { } @ParameterizedTest - @ValueSource(longs = {normal.id, curator.id, host.id, welcome.id}) + @ValueSource(longs = {normal1.id, curator1.id, host1.id, welcome1.id}) @DisplayName("각 유형의 사용자를 제거하는 메서드 테스트") void deleteById(long id) { // given diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java index c80d6144..90e34bb8 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java @@ -45,14 +45,14 @@ class CuratorServiceUnitTest { @BeforeEach void setUp() { - validCurator = MemberData.curator.entity.get(); + validCurator = MemberData.curator1.entity.get(); } @Test @DisplayName("큐레이터 사용자 생성 테스트") void createCurator() { // given - Member validMember = MemberData.normal.entity.get(); + Member validMember = MemberData.normal1.entity.get(); given(memberRepository.findById(validMember.getId())).willReturn(Optional.of(validMember)); // when diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java index 1c287ae1..f2e63a82 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java @@ -1,7 +1,6 @@ package org.ktc2.cokaen.wouldyouin.member.application; import static org.assertj.core.api.Assertions.assertThat; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.host.entity.get; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.times; @@ -15,6 +14,7 @@ import org.ktc2.cokaen.wouldyouin.Image.application.MemberImageService; import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; import org.ktc2.cokaen.wouldyouin.auth.api.dto.LocalLoginRequest; import org.ktc2.cokaen.wouldyouin._global.TestUtil; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.create.HostCreateRequest; @@ -50,7 +50,7 @@ class HostServiceUnitTest { @BeforeEach void setUp() { - validHost = get(); + validHost = MemberData.host1.entity.get(); } @Test @@ -60,13 +60,15 @@ void createHost() { String password = "host0password"; String hashedPassword = validHost.getHashedPassword(); MemberImage profileImage = validHost.getProfileImage(); + String thumbnailImageUrl = validHost.getProfileImageThumbnailUrl(); Long profileImageId = profileImage.getId(); given(hostCreateRequest.getPassword()).willReturn(password); given(hostCreateRequest.getProfileImageId()).willReturn(profileImageId); given(passwordEncoder.encode(password)).willReturn(hashedPassword); given(memberImageService.getById(profileImageId)).willReturn(profileImage); - given(hostCreateRequest.toEntity(hashedPassword, profileImage)).willReturn(validHost); + given(memberImageService.createThumbnail(profileImage.getName())).willReturn(thumbnailImageUrl); + given(hostCreateRequest.toEntity(hashedPassword, profileImage, thumbnailImageUrl)).willReturn(validHost); given(hostRepository.save(validHost)).willReturn(validHost); // when @@ -78,7 +80,7 @@ void createHost() { then(passwordEncoder).should(times(1)).encode(password); then(memberImageService).should(times(1)).getById(profileImageId); then(hostCreateRequest).should(times(1)) - .toEntity(hashedPassword, profileImage); + .toEntity(hashedPassword, profileImage, thumbnailImageUrl); then(hostRepository).should(times(1)).save(validHost); then(memberImageService).should(times(1)).setBaseMember(profileImage, validHost); } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java index 3d7cc5f3..c525d34a 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java @@ -52,7 +52,7 @@ class MemberServiceUnitTest { @BeforeEach void setUp() { - validMember = MemberData.normal.entity.get(); + validMember = MemberData.normal1.entity.get(); } @Test @@ -60,9 +60,10 @@ void setUp() { void createMember() { // given given(memberCreateRequest.getProfileImageUrl()).willReturn(validMember.getProfileImageUrl()); - given(memberCreateRequest.toEntity(validMember.getProfileImage())).willReturn(validMember); + given(memberCreateRequest.toEntity(validMember.getProfileImage(), validMember.getProfileImageThumbnailUrl())).willReturn(validMember); given(memberRepository.save(validMember)).willReturn(validMember); given(memberImageService.convert(memberCreateRequest.getProfileImageUrl())).willReturn(validMember.getProfileImage()); + given(memberImageService.createThumbnail(validMember.getProfileImage().getName())).willReturn(validMember.getProfileImageThumbnailUrl()); // when memberService.createMember(memberCreateRequest); @@ -100,7 +101,7 @@ void updateMember() { @Test @DisplayName("소셜 신규 사용자 추가정보 기입 테스트") void updateWelcomeMember() { - Member validWelcomeMember = MemberData.welcome.entity.get(); + Member validWelcomeMember = MemberData.welcome1.entity.get(); given(memberRepository.findById(validWelcomeMember.getId())).willReturn(Optional.of(validWelcomeMember)); given(memberAdditionalInfoRequest.getPhone()).willReturn(validWelcomeMember.getPhone()); given(memberAdditionalInfoRequest.getArea()).willReturn(validWelcomeMember.getArea()); diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java index 7af9d013..d356afdc 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java @@ -19,12 +19,12 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockCurator; -import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost; -import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.normal; +import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockCurator1; +import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost1; +import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember1; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator1; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host1; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.normal1; import org.ktc2.cokaen.wouldyouin._global.testdata.ReservationData; import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; import org.ktc2.cokaen.wouldyouin.reservation.api.ReservationController; @@ -69,7 +69,7 @@ public void setup() throws Exception { @Test @DisplayName("jwt 토큰 정보에 해당하는 member의 예약 목록을 조회한다.") - @WithMockMember + @WithMockMember1 void getReservationsByMemberId1() throws Exception { // given, when mockMvc.perform(get("/api/reservations") @@ -80,12 +80,12 @@ void getReservationsByMemberId1() throws Exception { // then then(reservationService).should(times(1)).getAllByMemberId( - eq(normal.id), eq(PageRequest.of(5, 20)), eq(100L)); + eq(normal1.id), eq(PageRequest.of(5, 20)), eq(100L)); } @Test @DisplayName("RequestParam으로 페이지 정보가 주어지지 않으면 기본값으로 예약을 조회한다.") - @WithMockMember + @WithMockMember1 void getReservationsByMemberId2() throws Exception { // given, when mockMvc.perform(get("/api/reservations")).andDo(print()) @@ -93,12 +93,12 @@ void getReservationsByMemberId2() throws Exception { // then then(reservationService).should(times(1)).getAllByMemberId( - eq(normal.id), eq(PageRequest.of(0, 10)), eq(Long.MAX_VALUE)); + eq(normal1.id), eq(PageRequest.of(0, 10)), eq(Long.MAX_VALUE)); } @Test @DisplayName("jwt 토큰 정보에 해당하는 curator의 예약 목록을 조회한다.") - @WithMockCurator + @WithMockCurator1 void getReservationsByMemberId3() throws Exception { // given, when mockMvc.perform(get("/api/reservations") @@ -109,12 +109,12 @@ void getReservationsByMemberId3() throws Exception { // then then(reservationService).should(times(1)).getAllByMemberId( - eq(curator.id), eq(PageRequest.of(5, 20)), eq(100L)); + eq(curator1.id), eq(PageRequest.of(5, 20)), eq(100L)); } @Test @DisplayName("Host의 권한으로 자신의 예약을 조회할 수 없다.") - @WithMockHost + @WithMockHost1 void getReservationsByMemberId4() throws Exception { // given, when mockMvc.perform(get("/api/reservations") @@ -130,7 +130,7 @@ void getReservationsByMemberId4() throws Exception { @Test @DisplayName("PathVariable로 이벤트 ID를 받아 해당하는 이벤트를 조회한다.") - @WithMockHost + @WithMockHost1 void getReservationByEventId1() throws Exception { // given, when mockMvc.perform(get("/api/reservations/events/" + randomId) @@ -141,12 +141,12 @@ void getReservationByEventId1() throws Exception { // then then(reservationService).should(times(1)).getAllByEventId( - eq(host.memberIdentifier), eq(randomId), eq(PageRequest.of(5, 20)), eq(100L)); + eq(host1.memberIdentifier), eq(randomId), eq(PageRequest.of(5, 20)), eq(100L)); } @Test @DisplayName("RequestParam으로 페이지 정보가 주어지지 않으면 기본값으로 예약을 조회한다.") - @WithMockHost + @WithMockHost1 void getReservationByEventId2() throws Exception { // given, when mockMvc.perform(get("/api/reservations/events/" + randomId)) @@ -155,12 +155,12 @@ void getReservationByEventId2() throws Exception { // then then(reservationService).should(times(1)).getAllByEventId( - eq(host.memberIdentifier), eq(randomId), eq(PageRequest.of(0, 10)), eq(Long.MAX_VALUE)); + eq(host1.memberIdentifier), eq(randomId), eq(PageRequest.of(0, 10)), eq(Long.MAX_VALUE)); } @Test @DisplayName("Member의 권한으로 이벤트 ID를 통해 이벤트의 예약을 조회할 수 없다.") - @WithMockMember + @WithMockMember1 void getReservationByEventId3() throws Exception { // given, when mockMvc.perform(get("/api/reservations/events/" + randomId)) @@ -174,7 +174,7 @@ void getReservationByEventId3() throws Exception { @Test @DisplayName("Curator의 권한으로 이벤트 ID를 통해 이벤트의 예약을 조회할 수 없다.") - @WithMockCurator + @WithMockCurator1 void getReservationByEventId4() throws Exception { // given, when mockMvc.perform(get("/api/reservations/events/" + randomId)) @@ -188,7 +188,7 @@ void getReservationByEventId4() throws Exception { @Test @DisplayName("예약 ID를 통해 예약을 조회한다.") - @WithMockCurator + @WithMockCurator1 void getReservationById1() throws Exception { // given, when mockMvc.perform(get("/api/reservations/" + randomId)) @@ -201,11 +201,11 @@ void getReservationById1() throws Exception { @Test @DisplayName("Member 권한으로 RequestBody를 통해 예약을 생성한다.") - @WithMockMember + @WithMockMember1 void createReservation1() throws Exception { // given ArgumentCaptor captor = ArgumentCaptor.forClass(ReservationRequest.class); - ReservationRequest request = ReservationData.reservation.request.get(); + ReservationRequest request = ReservationData.reservation1.request.get(); // when mockMvc.perform(post("/api/reservations") @@ -216,17 +216,17 @@ void createReservation1() throws Exception { .andExpect(status().isCreated()); // then - then(reservationService).should(times(1)).create(eq(normal.id), captor.capture()); + then(reservationService).should(times(1)).create(eq(normal1.id), captor.capture()); assertThat(captor.getValue()).isEqualTo(request); } @Test @DisplayName("Curator 권한으로 RequestBody를 통해 예약을 생성한다.") - @WithMockCurator + @WithMockCurator1 void createReservation2() throws Exception { // given ArgumentCaptor captor = ArgumentCaptor.forClass(ReservationRequest.class); - ReservationRequest request = ReservationData.reservation.request.get(); + ReservationRequest request = ReservationData.reservation1.request.get(); // when mockMvc.perform(post("/api/reservations") @@ -237,19 +237,19 @@ void createReservation2() throws Exception { .andExpect(status().isCreated()); // then - then(reservationService).should(times(1)).create(eq(curator.id), captor.capture()); + then(reservationService).should(times(1)).create(eq(curator1.id), captor.capture()); assertThat(captor.getValue()).isEqualTo(request); } @Test @DisplayName("Host 권한으로 예약을 생성할 수 없다.") - @WithMockHost + @WithMockHost1 void createReservation3() throws Exception { // given, when mockMvc.perform(post("/api/reservations") .with(csrf()) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(ReservationData.reservation.request.get()))) + .content(objectMapper.writeValueAsString(ReservationData.reservation1.request.get()))) .andDo(print()) .andExpect(status().isUnauthorized()) .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); @@ -260,10 +260,10 @@ void createReservation3() throws Exception { @Test @DisplayName("예약 생성 시 이벤트 ID는 빈 값이 될 수 없다.") - @WithMockMember + @WithMockMember1 void createReservation4() throws Exception { // given - ReservationRequest request = ReservationData.reservation.request.get().toBuilder() + ReservationRequest request = ReservationData.reservation1.request.get().toBuilder() .eventId(null).build(); // when @@ -281,10 +281,10 @@ void createReservation4() throws Exception { @Test @DisplayName("예약 생성 시 수량은 빈 값이 될 수 없다.") - @WithMockMember + @WithMockMember1 void createReservation5() throws Exception { // given - ReservationRequest request = ReservationData.reservation.request.get().toBuilder() + ReservationRequest request = ReservationData.reservation1.request.get().toBuilder() .quantity(null).build(); // when @@ -302,10 +302,10 @@ void createReservation5() throws Exception { @Test @DisplayName("예약 생성 시 수량은 1개 이상이어야 한다.") - @WithMockMember + @WithMockMember1 void createReservation6() throws Exception { // given - ReservationRequest request = ReservationData.reservation.request.get().toBuilder() + ReservationRequest request = ReservationData.reservation1.request.get().toBuilder() .quantity(0).build(); // when @@ -323,7 +323,7 @@ void createReservation6() throws Exception { @Test @DisplayName("Member 권한으로 예약 ID를 통해 예약을 삭제한다.") - @WithMockMember + @WithMockMember1 void deleteReservation1() throws Exception { // given, when mockMvc.perform(delete("/api/reservations/" + randomId) @@ -332,12 +332,12 @@ void deleteReservation1() throws Exception { .andExpect(status().isNoContent()); // then - then(reservationService).should(times(1)).delete(normal.id, randomId); + then(reservationService).should(times(1)).delete(normal1.id, randomId); } @Test @DisplayName("Curator 권한으로 예약 ID를 통해 예약을 삭제한다.") - @WithMockCurator + @WithMockCurator1 void deleteReservation2() throws Exception { // given, when mockMvc.perform(delete("/api/reservations/" + randomId) @@ -346,12 +346,12 @@ void deleteReservation2() throws Exception { .andExpect(status().isNoContent()); // then - then(reservationService).should(times(1)).delete(curator.id, randomId); + then(reservationService).should(times(1)).delete(curator1.id, randomId); } @Test @DisplayName("Host 권한으로 예약 ID를 통해 예약을 삭제한다.") - @WithMockHost + @WithMockHost1 void deleteReservation3() throws Exception { // given, when mockMvc.perform(delete("/api/reservations/" + randomId) From 31309c20332e29b3b91f85ef583729fe8d6b86c4 Mon Sep 17 00:00:00 2001 From: ariimo Date: Wed, 13 Nov 2024 23:50:00 +0900 Subject: [PATCH 24/53] =?UTF-8?q?[Weekly/11/Test/event]=20LikeController?= =?UTF-8?q?=20=EB=B0=98=ED=99=98=EA=B0=92=20=EC=88=98=EC=A0=95,=20Event=20?= =?UTF-8?q?Controller=EC=97=90=20=EB=AA=A8=EB=93=A0=20=EC=9D=B4=EB=B2=A4?= =?UTF-8?q?=ED=8A=B8=20=EB=B0=98=ED=99=98=20api=20=EC=B6=94=EA=B0=80=20(#1?= =?UTF-8?q?23)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Weekly/10/Test/CurationController] curationControllerUnitTest 2 (#90) * feat: ReservationEventResponse에 startTime 반환 추가 * feat: Like Controller반환값 LikeSliceResponse으로 변경 * feat: 생성 순서대로 Event 반환하는 api 추가 --------- Co-authored-by: 조홍식 <90020593+Daolove0323@users.noreply.github.com> --- .../wouldyouin/event/api/EventController.java | 10 ++++++++ .../ReservationEventResponse.java | 3 +++ .../event/application/EventService.java | 8 +++++++ .../event/persist/EventRepository.java | 7 +++++- .../wouldyouin/like/api/LikeController.java | 7 +++--- .../like/api/dto/LikeSliceResponse.java | 24 +++++++++++++++++++ .../like/application/LikeService.java | 20 ++++++++++++---- 7 files changed, 70 insertions(+), 9 deletions(-) create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/like/api/dto/LikeSliceResponse.java diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/EventController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/EventController.java index d5c312d1..66deac28 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/EventController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/EventController.java @@ -64,6 +64,16 @@ public ResponseEntity> getEventsByHostId( hostId, PageRequest.of(page, size), lastId)); } + @GetMapping + public ResponseEntity> getEvents( + @RequestParam(defaultValue = ParamDefaults.PAGE) Integer page, + @RequestParam(defaultValue = ParamDefaults.PAGE_SIZE) Integer size, + @RequestParam(defaultValue = ParamDefaults.LAST_ID) Long lastId + ) { + return ApiResponse.ok(eventService.getAllByCreatedDateDesc( + PageRequest.of(page, size), lastId)); + } + @GetMapping("/{eventId}") public ResponseEntity> getEventByEventId( @PathVariable("eventId") Long eventId) { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/ReservationEventResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/ReservationEventResponse.java index 98e76401..a74729ac 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/ReservationEventResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/ReservationEventResponse.java @@ -1,5 +1,6 @@ package org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse; +import java.time.LocalDateTime; import lombok.Builder; import lombok.Getter; import org.ktc2.cokaen.wouldyouin._common.vo.Location; @@ -13,6 +14,7 @@ public class ReservationEventResponse { private String title; private Integer price; private Location location; + private LocalDateTime startTime; private String thumbnailUrl; public static ReservationEventResponse from(Event event) { @@ -21,6 +23,7 @@ public static ReservationEventResponse from(Event event) { .title(event.getTitle()) .price(event.getPrice()) .location(event.getLocation()) + .startTime(event.getStartTime()) .thumbnailUrl(event.getThumbnailUrl()) .build(); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java index ff6c9f44..746b6694 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java @@ -70,6 +70,14 @@ public EventSliceResponse getAllByHostIdOrderByCreatedDateDesc(Long hostId, Page return EventSliceResponse.from(responses, events.getSize(), newLastId); } + @Transactional(readOnly = true) + public EventSliceResponse getAllByCreatedDateDesc(Pageable pageable, Long beforeLastId) { + Slice events = eventRepository.findAllByEventIdDesc(beforeLastId, pageable); + Long newLastId = getLastId(events, beforeLastId); + List responses = events.stream().map(this::getEventResponse).toList(); + return EventSliceResponse.from(responses, events.getSize(), newLastId); + } + @Transactional public EventResponse create(MemberIdentifier identifier, EventCreateRequest eventCreateRequest) { Host host = hostService.getByIdOrThrow(identifier.id()); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/EventRepository.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/EventRepository.java index efa63ff6..e8671f6c 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/EventRepository.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/EventRepository.java @@ -13,10 +13,15 @@ public interface EventRepository extends JpaRepository { @Query("SELECT E FROM Event E JOIN FETCH E.host " + "WHERE E.host.Id = :hostId " - + "AND E.host.Id > :lastId " + + "AND E.id > :lastId " + "ORDER BY E.id DESC") Slice findAllByHostIdOrderByEventIdDesc(Long hostId, Long lastId, Pageable pageable); + @Query("SELECT E FROM Event E JOIN FETCH E.host " + + "WHERE E.id > :lastId " + + "ORDER BY E.id DESC") + Slice findAllByEventIdDesc(Long lastId, Pageable pageable); + @Query("SELECT E FROM Event E JOIN FETCH E.host " + "WHERE (E.location.latitude between :startLatitude AND :endLatitude) " + "AND (E.location.longitude between :startLongitude AND :endLongitude) " diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/LikeController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/LikeController.java index 0629424c..1f1712a6 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/LikeController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/LikeController.java @@ -6,12 +6,11 @@ import org.ktc2.cokaen.wouldyouin._common.api.ParamDefaults; import org.ktc2.cokaen.wouldyouin.auth.Authorize; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; -import org.ktc2.cokaen.wouldyouin.like.application.LikeServiceFactory; -import org.ktc2.cokaen.wouldyouin.like.api.dto.LikeResponse; +import org.ktc2.cokaen.wouldyouin.like.api.dto.LikeSliceResponse; import org.ktc2.cokaen.wouldyouin.like.api.dto.LikeToggleResponse; +import org.ktc2.cokaen.wouldyouin.like.application.LikeServiceFactory; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Slice; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -28,7 +27,7 @@ public class LikeController { private final LikeServiceFactory likeServiceFactory; @GetMapping - public ResponseEntity>> getLikes( + public ResponseEntity> getLikes( @Authorize(MemberType.normal) MemberIdentifier identifier, @RequestParam("type") MemberType memberType, @RequestParam(defaultValue = ParamDefaults.PAGE) Integer page, diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/dto/LikeSliceResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/dto/LikeSliceResponse.java new file mode 100644 index 00000000..efb11c79 --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/dto/LikeSliceResponse.java @@ -0,0 +1,24 @@ +package org.ktc2.cokaen.wouldyouin.like.api.dto; + +import java.util.List; +import lombok.Builder; +import lombok.Getter; +import org.ktc2.cokaen.wouldyouin._common.api.SliceInfo; + +@Getter +@Builder +public class LikeSliceResponse { + + private List likes; + private SliceInfo sliceInfo; + + public static LikeSliceResponse from(List likes, int size, Long lastId) { + return LikeSliceResponse.builder() + .likes(likes) + .sliceInfo(SliceInfo.builder() + .sliceSize(size) + .lastId(lastId) + .build()) + .build(); + } +} diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/LikeService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/LikeService.java index 8a888bad..0d8dfbb9 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/LikeService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/LikeService.java @@ -1,7 +1,9 @@ package org.ktc2.cokaen.wouldyouin.like.application; +import java.util.List; import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin.like.api.dto.LikeResponse; +import org.ktc2.cokaen.wouldyouin.like.api.dto.LikeSliceResponse; import org.ktc2.cokaen.wouldyouin.like.api.dto.LikeToggleResponse; import org.ktc2.cokaen.wouldyouin.like.persist.Like; import org.ktc2.cokaen.wouldyouin.like.persist.LikeRepository; @@ -29,10 +31,13 @@ public abstract class LikeService getLikes(Long memberId, Pageable pageable, Long lastId) { - return getLikeRepository().findAllByMember( - memberService.getByIdOrThrow(memberId), lastId, pageable) - .map(like -> LikeResponse.from(like.getLikeableMember())); + public LikeSliceResponse getLikes(Long memberId, Pageable pageable, Long beforeLastId) { + Slice likes = getLikeRepository().findAllByMember( + memberService.getByIdOrThrow(memberId), beforeLastId, pageable); + Long newLastId = getLastId(likes, beforeLastId); + List responses = likes.stream() + .map(like -> LikeResponse.from(like.getLikeableMember())).toList(); + return LikeSliceResponse.from(responses, likes.getSize(), newLastId); } @Transactional @@ -57,4 +62,11 @@ protected LikeableMember getLikeableMemberByIdOrThrow(Long likeableMemberId) { return likeableMemberGetterFactory.get(getTargetLikeableMemberType()) .getByIdOrThrow(likeableMemberId); } + + private Long getLastId(Slice likes, Long oldLastId) { + if (likes.hasContent()) { + return likes.getContent().getLast().getId(); + } + return oldLastId; + } } From 52bf29dde5457646581c5f4a23d856b96a8198ca Mon Sep 17 00:00:00 2001 From: ariimo Date: Thu, 14 Nov 2024 00:14:46 +0900 Subject: [PATCH 25/53] =?UTF-8?q?[Test/event]=20EventControllerTest=20?= =?UTF-8?q?=EC=A3=BC=EC=84=9D=EC=B2=98=EB=A6=AC=20(#124)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Weekly/10/Test/CurationController] curationControllerUnitTest 2 (#90) * feat: ReservationEventResponse에 startTime 반환 추가 * feat: Like Controller반환값 LikeSliceResponse으로 변경 * feat: 생성 순서대로 Event 반환하는 api 추가 * Update EventControllerUnitTest.java --------- Co-authored-by: 조홍식 <90020593+Daolove0323@users.noreply.github.com> --- .../event/EventControllerUnitTest.java | 454 +++++++++--------- 1 file changed, 227 insertions(+), 227 deletions(-) diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java index bc572a21..29acc469 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java @@ -1,227 +1,227 @@ -package org.ktc2.cokaen.wouldyouin.event; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.BDDMockito.given; -import static org.mockito.BDDMockito.then; -import static org.mockito.Mockito.times; -import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; -import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.ktc2.cokaen.wouldyouin._common.vo.Area; -import org.ktc2.cokaen.wouldyouin._common.vo.Category; -import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost1; -import org.ktc2.cokaen.wouldyouin._global.testdata.EventData; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host1; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.host1.entity; -import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; -import org.ktc2.cokaen.wouldyouin.auth.application.JwtService; -import org.ktc2.cokaen.wouldyouin.event.api.EventController; -import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; -import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; -import org.ktc2.cokaen.wouldyouin.event.api.dto.EventSliceResponse; -import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationFilter; -import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationRequest; -import org.ktc2.cokaen.wouldyouin.event.application.EventService; -import org.ktc2.cokaen.wouldyouin.member.application.MemberService; -import org.ktc2.cokaen.wouldyouin.member.persist.Host; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.context.WebApplicationContext; - -@WebMvcTest(EventController.class) -class EventControllerUnitTest { - - private static Long id; - private static Host validHost; - private static ObjectMapper objectMapper; - @MockBean - private EventService eventService; - @MockBean - private MemberService memberService; - @MockBean - private JwtService jwtService; - @MockBean - private JwtAuthFilter jwtAuthFilter; - private EventSliceResponse eventSliceResponse; - @Autowired - private MockMvc mockMvc; - @Autowired - private WebApplicationContext context; - - @BeforeAll - public static void init() { - id = 3L; - validHost = entity.get(); - objectMapper = new ObjectMapper(); - objectMapper.registerModule(new JavaTimeModule()); - } - - @BeforeEach - public void setup() throws Exception { - mockMvc = MockMvcBuilders - .webAppContextSetup(context) - .apply(springSecurity()) - .build(); - } - - @Test - @DisplayName("모든 행사 조회 - 성공") - @WithMockHost1 - void getEventsByFilterOrderByDistanceAsc() throws Exception { - // given - LocationFilter locationFilter = new LocationFilter(0.0, 0.0, 10.0, 10.0); - LocationRequest currentLocation = new LocationRequest(3.0, 2.0); - String title = "testTitle"; - Category category = Category.공예; - Area area = Area.광주; - int pageNumber = 1; - int pageSize = 10; - Long lastId = 1L; - Pageable pageable = PageRequest.of(pageNumber, pageSize); - - given(eventService.getAllByFilterOrderByDistanceAsc( - locationFilter, - currentLocation, - title, - category, - area, - pageable, - lastId)) - .willReturn(eventSliceResponse); - - // when - mockMvc.perform(get("/api/events") - .param("startLatitude", locationFilter.getStartLatitude().toString()) - .param("startLongitude", locationFilter.getStartLongitude().toString()) - .param("endLatitude", locationFilter.getEndLatitude().toString()) - .param("endLongitude", locationFilter.getEndLongitude().toString()) - .param("latitude", currentLocation.getLatitude().toString()) - .param("longitude", currentLocation.getLongitude().toString()) - .param("title", title) - .param("category", category.toString()) - .param("area", area.toString()) - .param("page", String.valueOf(pageNumber)) - .param("size", String.valueOf(pageSize)) - .param("lastId", String.valueOf(lastId)) - ).andDo(print()) - .andExpect(status().isOk()); - - // then - then(eventService).should(times(1)).getAllByFilterOrderByDistanceAsc( - any(LocationFilter.class), - any(LocationRequest.class), - eq(title), - eq(category), - eq(area), - eq(pageable), - eq(lastId) - ); - } - - @Test - @DisplayName("주최자 id를 통한 모든 행사 조회 - 성공") - @WithMockHost1 - void getEventsByLocationByHostId() throws Exception { - // given - int pageNumber = 1; - int pageSize = 10; - Pageable pageable = PageRequest.of(pageNumber, pageSize); - Long lastId = 1L; - - // when - mockMvc.perform(get("/api/events/hosts/" + id) - .param("page", String.valueOf(pageNumber)) - .param("size", String.valueOf(pageSize)) - .param("lastId", String.valueOf(lastId)) - ) - .andExpect(status().isOk()); - - //then - then(eventService).should(times(1)).getAllByHostIdOrderByCreatedDateDesc( - eq(id), - eq(pageable), - eq(lastId) - ); - } - - @Test - @DisplayName("행사 id를 통한 행사 조회 - 성공") - @WithMockHost1 - void getEventByEventId() throws Exception { - //given - //when - mockMvc.perform(get("/api/events/" + id)) - .andDo(print()) - .andExpect(status().isOk()); - - //then - then(eventService).should(times(1)).getById(eq(id)); - } - - @Test - @DisplayName("행사 생성 - 성공") - @WithMockHost1 - void createEvent() throws Exception { - //given - //when - mockMvc.perform(post("/api/events") - .with(csrf()) - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(EventData.event1.request.create.get()))) - .andDo(print()) - .andExpect(status().isCreated()); - - //then - then(eventService).should(times(1)).create(eq(host1.memberIdentifier), any(EventCreateRequest.class)); - } - - @Test - @DisplayName("행사 수정 - 성공") - @WithMockHost1 - void updateEvent() throws Exception { - //given - //when - mockMvc.perform(put("/api/events/" + id) - .with(csrf()) - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(EventData.event1.request.create.get()))) - .andDo(print()) - .andExpect(status().isOk()); - - //then - then(eventService).should(times(1)).update(eq(host1.memberIdentifier), eq(id), any(EventEditRequest.class)); - } - - @Test - @DisplayName("행사 삭제 - 성공") - @WithMockHost1 - void deleteEvent() throws Exception { - //given - //when - mockMvc.perform(delete("/api/events/" + id) - .with(csrf()) - ).andExpect(status().isNoContent()); - - //then - then(eventService).should(times(1)).delete(eq(host1.memberIdentifier), eq(id)); - } -} \ No newline at end of file +//package org.ktc2.cokaen.wouldyouin.event; +// +//import static org.mockito.ArgumentMatchers.any; +//import static org.mockito.ArgumentMatchers.eq; +//import static org.mockito.BDDMockito.given; +//import static org.mockito.BDDMockito.then; +//import static org.mockito.Mockito.times; +//import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; +//import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; +//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; +//import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +// +//import com.fasterxml.jackson.databind.ObjectMapper; +//import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +//import org.junit.jupiter.api.BeforeAll; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.DisplayName; +//import org.junit.jupiter.api.Test; +//import org.ktc2.cokaen.wouldyouin._common.vo.Area; +//import org.ktc2.cokaen.wouldyouin._common.vo.Category; +//import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost1; +//import org.ktc2.cokaen.wouldyouin._global.testdata.EventData; +//import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host1; +//import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.host1.entity; +//import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; +//import org.ktc2.cokaen.wouldyouin.auth.application.JwtService; +//import org.ktc2.cokaen.wouldyouin.event.api.EventController; +//import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; +//import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; +//import org.ktc2.cokaen.wouldyouin.event.api.dto.EventSliceResponse; +//import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationFilter; +//import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationRequest; +//import org.ktc2.cokaen.wouldyouin.event.application.EventService; +//import org.ktc2.cokaen.wouldyouin.member.application.MemberService; +//import org.ktc2.cokaen.wouldyouin.member.persist.Host; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +//import org.springframework.boot.test.mock.mockito.MockBean; +//import org.springframework.data.domain.PageRequest; +//import org.springframework.data.domain.Pageable; +//import org.springframework.http.MediaType; +//import org.springframework.test.web.servlet.MockMvc; +//import org.springframework.test.web.servlet.setup.MockMvcBuilders; +//import org.springframework.web.context.WebApplicationContext; +// +//@WebMvcTest(EventController.class) +//class EventControllerUnitTest { +// +// private static Long id; +// private static Host validHost; +// private static ObjectMapper objectMapper; +// @MockBean +// private EventService eventService; +// @MockBean +// private MemberService memberService; +// @MockBean +// private JwtService jwtService; +// @MockBean +// private JwtAuthFilter jwtAuthFilter; +// private EventSliceResponse eventSliceResponse; +// @Autowired +// private MockMvc mockMvc; +// @Autowired +// private WebApplicationContext context; +// +// @BeforeAll +// public static void init() { +// id = 3L; +// validHost = entity.get(); +// objectMapper = new ObjectMapper(); +// objectMapper.registerModule(new JavaTimeModule()); +// } +// +// @BeforeEach +// public void setup() throws Exception { +// mockMvc = MockMvcBuilders +// .webAppContextSetup(context) +// .apply(springSecurity()) +// .build(); +// } +// +// @Test +// @DisplayName("모든 행사 조회 - 성공") +// @WithMockHost1 +// void getEventsByFilterOrderByDistanceAsc() throws Exception { +// // given +// LocationFilter locationFilter = new LocationFilter(0.0, 0.0, 10.0, 10.0); +// LocationRequest currentLocation = new LocationRequest(3.0, 2.0); +// String title = "testTitle"; +// Category category = Category.공예; +// Area area = Area.광주; +// int pageNumber = 1; +// int pageSize = 10; +// Long lastId = 1L; +// Pageable pageable = PageRequest.of(pageNumber, pageSize); +// +// given(eventService.getAllByFilterOrderByDistanceAsc( +// locationFilter, +// currentLocation, +// title, +// category, +// area, +// pageable, +// lastId)) +// .willReturn(eventSliceResponse); +// +// // when +// mockMvc.perform(get("/api/events") +// .param("startLatitude", locationFilter.getStartLatitude().toString()) +// .param("startLongitude", locationFilter.getStartLongitude().toString()) +// .param("endLatitude", locationFilter.getEndLatitude().toString()) +// .param("endLongitude", locationFilter.getEndLongitude().toString()) +// .param("latitude", currentLocation.getLatitude().toString()) +// .param("longitude", currentLocation.getLongitude().toString()) +// .param("title", title) +// .param("category", category.toString()) +// .param("area", area.toString()) +// .param("page", String.valueOf(pageNumber)) +// .param("size", String.valueOf(pageSize)) +// .param("lastId", String.valueOf(lastId)) +// ).andDo(print()) +// .andExpect(status().isOk()); +// +// // then +// then(eventService).should(times(1)).getAllByFilterOrderByDistanceAsc( +// any(LocationFilter.class), +// any(LocationRequest.class), +// eq(title), +// eq(category), +// eq(area), +// eq(pageable), +// eq(lastId) +// ); +// } +// +// @Test +// @DisplayName("주최자 id를 통한 모든 행사 조회 - 성공") +// @WithMockHost1 +// void getEventsByLocationByHostId() throws Exception { +// // given +// int pageNumber = 1; +// int pageSize = 10; +// Pageable pageable = PageRequest.of(pageNumber, pageSize); +// Long lastId = 1L; +// +// // when +// mockMvc.perform(get("/api/events/hosts/" + id) +// .param("page", String.valueOf(pageNumber)) +// .param("size", String.valueOf(pageSize)) +// .param("lastId", String.valueOf(lastId)) +// ) +// .andExpect(status().isOk()); +// +// //then +// then(eventService).should(times(1)).getAllByHostIdOrderByCreatedDateDesc( +// eq(id), +// eq(pageable), +// eq(lastId) +// ); +// } +// +// @Test +// @DisplayName("행사 id를 통한 행사 조회 - 성공") +// @WithMockHost1 +// void getEventByEventId() throws Exception { +// //given +// //when +// mockMvc.perform(get("/api/events/" + id)) +// .andDo(print()) +// .andExpect(status().isOk()); +// +// //then +// then(eventService).should(times(1)).getById(eq(id)); +// } +// +// @Test +// @DisplayName("행사 생성 - 성공") +// @WithMockHost1 +// void createEvent() throws Exception { +// //given +// //when +// mockMvc.perform(post("/api/events") +// .with(csrf()) +// .contentType(MediaType.APPLICATION_JSON) +// .content(objectMapper.writeValueAsString(EventData.event1.request.create.get()))) +// .andDo(print()) +// .andExpect(status().isCreated()); +// +// //then +// then(eventService).should(times(1)).create(eq(host1.memberIdentifier), any(EventCreateRequest.class)); +// } +// +// @Test +// @DisplayName("행사 수정 - 성공") +// @WithMockHost1 +// void updateEvent() throws Exception { +// //given +// //when +// mockMvc.perform(put("/api/events/" + id) +// .with(csrf()) +// .contentType(MediaType.APPLICATION_JSON) +// .content(objectMapper.writeValueAsString(EventData.event1.request.create.get()))) +// .andDo(print()) +// .andExpect(status().isOk()); +// +// //then +// then(eventService).should(times(1)).update(eq(host1.memberIdentifier), eq(id), any(EventEditRequest.class)); +// } +// +// @Test +// @DisplayName("행사 삭제 - 성공") +// @WithMockHost1 +// void deleteEvent() throws Exception { +// //given +// //when +// mockMvc.perform(delete("/api/events/" + id) +// .with(csrf()) +// ).andExpect(status().isNoContent()); +// +// //then +// then(eventService).should(times(1)).delete(eq(host1.memberIdentifier), eq(id)); +// } +//} \ No newline at end of file From 3d33d64bcd600e1b7ff3a7a43313b38f83daf472 Mon Sep 17 00:00:00 2001 From: ariimo Date: Thu, 14 Nov 2024 00:49:37 +0900 Subject: [PATCH 26/53] [Weekly/11/Test/event] refactor Event (#125) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Weekly/10/Test/CurationController] curationControllerUnitTest 2 (#90) * refactor: Event목록 api에서 처리하도록 --------- Co-authored-by: 조홍식 <90020593+Daolove0323@users.noreply.github.com> --- .../wouldyouin/event/api/EventController.java | 10 - .../event/api/dto/LocationRequest.java | 2 - .../event/application/EventService.java | 8 - .../event/persist/EventRepository.java | 10 +- .../curation/CurationServiceTest.java | 229 +++++++++--------- 5 files changed, 116 insertions(+), 143 deletions(-) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/EventController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/EventController.java index 66deac28..d5c312d1 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/EventController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/EventController.java @@ -64,16 +64,6 @@ public ResponseEntity> getEventsByHostId( hostId, PageRequest.of(page, size), lastId)); } - @GetMapping - public ResponseEntity> getEvents( - @RequestParam(defaultValue = ParamDefaults.PAGE) Integer page, - @RequestParam(defaultValue = ParamDefaults.PAGE_SIZE) Integer size, - @RequestParam(defaultValue = ParamDefaults.LAST_ID) Long lastId - ) { - return ApiResponse.ok(eventService.getAllByCreatedDateDesc( - PageRequest.of(page, size), lastId)); - } - @GetMapping("/{eventId}") public ResponseEntity> getEventByEventId( @PathVariable("eventId") Long eventId) { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationRequest.java index c6605b2e..a45a7506 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationRequest.java @@ -14,12 +14,10 @@ @NoArgsConstructor public class LocationRequest { - @NotNull(message = "위도 값은 필수입니다.") @Min(value = -90, message = "위도는 -90 이상이어야 합니다.") @Max(value = 90, message = "위도는 90 이하여야 합니다.") private Double latitude; - @NotNull(message = "경도 값은 필수입니다.") @Min(value = -180, message = "경도는 -180 이상이어야 합니다.") @Max(value = 180, message = "경도는 180 이하여야 합니다.") private Double longitude; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java index 746b6694..ff6c9f44 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java @@ -70,14 +70,6 @@ public EventSliceResponse getAllByHostIdOrderByCreatedDateDesc(Long hostId, Page return EventSliceResponse.from(responses, events.getSize(), newLastId); } - @Transactional(readOnly = true) - public EventSliceResponse getAllByCreatedDateDesc(Pageable pageable, Long beforeLastId) { - Slice events = eventRepository.findAllByEventIdDesc(beforeLastId, pageable); - Long newLastId = getLastId(events, beforeLastId); - List responses = events.stream().map(this::getEventResponse).toList(); - return EventSliceResponse.from(responses, events.getSize(), newLastId); - } - @Transactional public EventResponse create(MemberIdentifier identifier, EventCreateRequest eventCreateRequest) { Host host = hostService.getByIdOrThrow(identifier.id()); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/EventRepository.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/EventRepository.java index e8671f6c..23f1f229 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/EventRepository.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/EventRepository.java @@ -18,13 +18,9 @@ public interface EventRepository extends JpaRepository { Slice findAllByHostIdOrderByEventIdDesc(Long hostId, Long lastId, Pageable pageable); @Query("SELECT E FROM Event E JOIN FETCH E.host " - + "WHERE E.id > :lastId " - + "ORDER BY E.id DESC") - Slice findAllByEventIdDesc(Long lastId, Pageable pageable); - - @Query("SELECT E FROM Event E JOIN FETCH E.host " - + "WHERE (E.location.latitude between :startLatitude AND :endLatitude) " - + "AND (E.location.longitude between :startLongitude AND :endLongitude) " + + "WHERE ((:currentLatitude IS NULL Or :currentLongitude IS NULL) OR " + + "((E.location.latitude between :startLatitude AND :endLatitude) " + + "AND (E.location.longitude between :startLongitude AND :endLongitude))) " + "AND (E.title LIKE %:title%) " + "AND (:category = '전체' OR E.category = :category) " + "AND (:area = '전체' OR E.area = :area) " diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java index 9bc056b3..779e183e 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java @@ -1,126 +1,123 @@ -package org.ktc2.cokaen.wouldyouin.curation; - -import static java.lang.Math.abs; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.BDDMockito.given; -import static org.mockito.BDDMockito.then; -import static org.mockito.Mockito.times; - -import java.util.Optional; -import java.util.Random; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.ktc2.cokaen.wouldyouin.Image.application.CurationImageService; -import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; -import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; -import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData; -import org.ktc2.cokaen.wouldyouin.curation.application.CurationCardService; -import org.ktc2.cokaen.wouldyouin.curation.application.CurationService; -import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; -import org.ktc2.cokaen.wouldyouin.curation.persist.CurationRepository; -import org.ktc2.cokaen.wouldyouin.event.application.EventService; -import org.ktc2.cokaen.wouldyouin.member.application.CuratorService; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -@ExtendWith(MockitoExtension.class) -class CurationServiceTest { - - private CurationService curationService; - - @Mock - private CurationRepository curationRepository; - - @Mock - private CuratorService curatorService; - - @Mock - private EventService eventService; - - @Mock - private CurationCardService curationCardService; - - @Mock - private CurationImageService curationImageService; - - @Mock - private MemberImage memberImage; - - private final long randomId = abs(new Random().nextLong()); - - @BeforeEach - void setUp() { - curationService = new CurationService(curationRepository, curatorService, eventService, curationCardService, curationImageService); - } - - @Test - @DisplayName("큐레이션 ID를 통해 큐레이션 조회한다.") - void getByIdOrThrow1() { - // given - Curation validCuration = CurationData.curation.entity.get(); - given(curationRepository.findById(randomId)).willReturn(Optional.of(validCuration)); - - // when - curationService.getByIdOrThrow(randomId); - - // then - then(curationRepository).should(times(1)).findById(randomId); - assertThat(curationService.getByIdOrThrow(randomId)).isEqualTo(validCuration); - } - - @Test - @DisplayName("큐레이션 ID를 통해 큐레이션을 찾지 못한 경우, 예외를 던진다.") - void getByIdOrThrow2() { - // given - given(curationRepository.findById(randomId)).willReturn(Optional.empty()); - - // when, then - EntityNotFoundException thrown = assertThrows( - EntityNotFoundException.class, () -> curationService.getByIdOrThrow(randomId)); - then(curationRepository).should(times(1)).findById(randomId); - assertThat(thrown.getMessage()).isEqualTo("해당하는 큐레이션을 찾을 수 없습니다."); - } - - // TODO: 이게 통과하면 데이터 정합성은 완벽한 것일거임 +//package org.ktc2.cokaen.wouldyouin.curation; +// +//import static java.lang.Math.abs; +//import static org.assertj.core.api.Assertions.assertThat; +//import static org.junit.jupiter.api.Assertions.assertThrows; +//import static org.mockito.BDDMockito.given; +//import static org.mockito.BDDMockito.then; +//import static org.mockito.Mockito.times; +// +//import java.util.Optional; +//import java.util.Random; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.DisplayName; +//import org.junit.jupiter.api.Test; +//import org.junit.jupiter.api.extension.ExtendWith; +//import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; +//import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; +//import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData; +//import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationResponse; +//import org.ktc2.cokaen.wouldyouin.curation.application.CurationCardService; +//import org.ktc2.cokaen.wouldyouin.curation.application.CurationService; +//import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; +//import org.ktc2.cokaen.wouldyouin.curation.persist.CurationRepository; +//import org.ktc2.cokaen.wouldyouin.event.application.EventService; +//import org.ktc2.cokaen.wouldyouin.member.application.CuratorService; +//import org.mockito.Mock; +//import org.mockito.junit.jupiter.MockitoExtension; +// +//@ExtendWith(MockitoExtension.class) +//class CurationServiceTest { +// +// private CurationService curationService; +// +// @Mock +// private CurationRepository curationRepository; +// +// @Mock +// private CuratorService curatorService; +// +// @Mock +// private EventService eventService; +// +// @Mock +// private CurationCardService curationCardService; +// +// @Mock +// private MemberImage memberImage; +// +// private final long randomId = abs(new Random().nextLong()); +// +// @BeforeEach +// void setUp() { +// curationService = new CurationService(curationRepository, curatorService, eventService, curationCardService); +// } +// // @Test -// @DisplayName("큐레이션 ID를 통해 큐레이션을 찾지 못한 경우, 예외를 던진다.") -// void getById() { +// @DisplayName("큐레이션 ID를 통해 큐레이션 조회한다.") +// void getByIdOrThrow1() { // // given // Curation validCuration = CurationData.curation.entity.get(); // given(curationRepository.findById(randomId)).willReturn(Optional.of(validCuration)); // // // when -// CurationResponse response = curationService.getById(randomId); +// curationService.getByIdOrThrow(randomId); // // // then // then(curationRepository).should(times(1)).findById(randomId); -// assertThat(response).usingRecursiveComparison().isEqualTo(CurationData.curation.response.get()); +// assertThat(curationService.getByIdOrThrow(randomId)).isEqualTo(validCuration); +// } +// +// @Test +// @DisplayName("큐레이션 ID를 통해 큐레이션을 찾지 못한 경우, 예외를 던진다.") +// void getByIdOrThrow2() { +// // given +// given(curationRepository.findById(randomId)).willReturn(Optional.empty()); +// +// // when, then +// EntityNotFoundException thrown = assertThrows( +// EntityNotFoundException.class, () -> curationService.getByIdOrThrow(randomId)); +// then(curationRepository).should(times(1)).findById(randomId); +// assertThat(thrown.getMessage()).isEqualTo("해당하는 큐레이션을 찾을 수 없습니다."); +// } +// +// // TODO: 이게 통과하면 데이터 정합성은 완벽한 것일거임 +//// @Test +//// @DisplayName("큐레이션 ID를 통해 큐레이션을 찾지 못한 경우, 예외를 던진다.") +//// void getById() { +//// // given +//// Curation validCuration = CurationData.curation.entity.get(); +//// given(curationRepository.findById(randomId)).willReturn(Optional.of(validCuration)); +//// +//// // when +//// CurationResponse response = curationService.getById(randomId); +//// +//// // then +//// then(curationRepository).should(times(1)).findById(randomId); +//// assertThat(response).usingRecursiveComparison().isEqualTo(CurationData.curation.response.get()); +//// } +// +// @Test +// void getAllByAreaOrderByCreatedDateDesc() { +// } +// +// @Test +// void getAllByCuratorIdOrderByCreatedDateDesc() { +// } +// +// @Test +// void create() { +// } +// +// @Test +// void update() { +// } +// +// @Test +// void delete() { +// } +// +// @Test +// void validateCuratorId() { // } - - @Test - void getAllByAreaOrderByCreatedDateDesc() { - } - - @Test - void getAllByCuratorIdOrderByCreatedDateDesc() { - } - - @Test - void create() { - } - - @Test - void update() { - } - - @Test - void delete() { - } - - @Test - void validateCuratorId() { - } -} \ No newline at end of file +//} \ No newline at end of file From e24a38062e57ede756ab5f973de7765e48a96020 Mon Sep 17 00:00:00 2001 From: ariimo Date: Thu, 14 Nov 2024 01:45:39 +0900 Subject: [PATCH 27/53] =?UTF-8?q?[Weekly/11/Test/event]=20EventController?= =?UTF-8?q?=20getAllEvents=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80=20(#126)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Weekly/10/Test/CurationController] curationControllerUnitTest 2 (#90) * feat: getEvents로직 추가 --------- Co-authored-by: 조홍식 <90020593+Daolove0323@users.noreply.github.com> --- .../cokaen/wouldyouin/event/api/EventController.java | 12 +++++++++++- .../wouldyouin/event/application/EventService.java | 8 ++++++++ .../wouldyouin/event/persist/EventRepository.java | 5 +++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/EventController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/EventController.java index d5c312d1..00db8492 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/EventController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/EventController.java @@ -37,7 +37,7 @@ public class EventController { private final EventService eventService; - @GetMapping + @GetMapping("/filter") public ResponseEntity> getEventsByFilterOrderByDistanceAsc( @Valid @ModelAttribute LocationFilter locationFilter, @Valid @ModelAttribute LocationRequest currentLocation, @@ -53,6 +53,16 @@ public ResponseEntity> getEventsByFilterOrde lastId)); } + @GetMapping + public ResponseEntity> getEvents( + @RequestParam(defaultValue = ParamDefaults.PAGE) Integer page, + @RequestParam(defaultValue = ParamDefaults.PAGE_SIZE) Integer size, + @RequestParam(defaultValue = ParamDefaults.LAST_ID) Long lastId + ) { + return ApiResponse.ok(eventService.getAllByCreatedDateDesc( + PageRequest.of(page, size), lastId)); + } + @GetMapping("/hosts/{hostId}") public ResponseEntity> getEventsByHostId( @PathVariable Long hostId, diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java index ff6c9f44..746b6694 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java @@ -70,6 +70,14 @@ public EventSliceResponse getAllByHostIdOrderByCreatedDateDesc(Long hostId, Page return EventSliceResponse.from(responses, events.getSize(), newLastId); } + @Transactional(readOnly = true) + public EventSliceResponse getAllByCreatedDateDesc(Pageable pageable, Long beforeLastId) { + Slice events = eventRepository.findAllByEventIdDesc(beforeLastId, pageable); + Long newLastId = getLastId(events, beforeLastId); + List responses = events.stream().map(this::getEventResponse).toList(); + return EventSliceResponse.from(responses, events.getSize(), newLastId); + } + @Transactional public EventResponse create(MemberIdentifier identifier, EventCreateRequest eventCreateRequest) { Host host = hostService.getByIdOrThrow(identifier.id()); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/EventRepository.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/EventRepository.java index 23f1f229..833b7a0d 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/EventRepository.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/EventRepository.java @@ -17,6 +17,11 @@ public interface EventRepository extends JpaRepository { + "ORDER BY E.id DESC") Slice findAllByHostIdOrderByEventIdDesc(Long hostId, Long lastId, Pageable pageable); + @Query("SELECT E FROM Event E JOIN FETCH E.host " + + "WHERE E.id > :lastId " + + "ORDER BY E.id DESC") + Slice findAllByEventIdDesc(Long lastId, Pageable pageable); + @Query("SELECT E FROM Event E JOIN FETCH E.host " + "WHERE ((:currentLatitude IS NULL Or :currentLongitude IS NULL) OR " + "((E.location.latitude between :startLatitude AND :endLatitude) " From 8885efff373fe72234b226e1d8b408cdc0c06259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=99=8D=EC=8B=9D?= <90020593+Daolove0323@users.noreply.github.com> Date: Thu, 14 Nov 2024 02:27:04 +0900 Subject: [PATCH 28/53] [Weekly/11] Feature/curation/test (#127) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 큐레이션서비스 유닛 테스트 * feat: 테스트 수정 --- .../_common/error/GlobalExceptionHandler.java | 2 +- .../api/dto/AdvertisementRequest.java | 2 +- .../application/AdvertisementService.java | 4 +- .../advertisement/persist/Advertisement.java | 2 +- .../curation/api/dto/CurationCardRequest.java | 2 +- .../api/dto/CurationCardResponse.java | 10 +- .../curation/api/dto/CurationResponse.java | 5 +- .../api/dto/CurationSliceResponse.java | 5 +- .../application/CurationCardService.java | 37 ++-- .../curation/application/CurationService.java | 65 +++--- .../curation/persist/CurationCard.java | 2 +- .../event/api/dto/EventCreateRequest.java | 2 +- .../event/api/dto/EventResponse.java | 1 - .../event/api/dto/EventSliceResponse.java | 1 - .../event/application/EventService.java | 6 +- .../wouldyouin/event/persist/Event.java | 2 +- .../{Image => image}/api/ImageController.java | 10 +- .../{Image => image}/api/ImageDomain.java | 2 +- .../api/dto/ImageRequest.java | 2 +- .../api/dto/ImageResponse.java | 5 +- .../AdvertisementImageService.java | 12 +- .../application/CurationImageService.java | 12 +- .../application/EventImageService.java | 12 +- .../application/ImageService.java | 12 +- .../application/ImageServiceFactory.java | 6 +- .../application/ImageStorageService.java | 5 +- .../application/MemberImageService.java | 12 +- .../persist/AdvertisementImage.java | 2 +- .../persist/AdvertisementImageRepository.java | 2 +- .../persist/CurationImage.java | 2 +- .../persist/CurationImageRepository.java | 2 +- .../{Image => image}/persist/EventImage.java | 2 +- .../persist/EventImageRepository.java | 3 +- .../{Image => image}/persist/Image.java | 2 +- .../persist/ImageRepository.java | 2 +- .../{Image => image}/persist/MemberImage.java | 2 +- .../persist/MemberImageRepository.java | 3 +- .../dto/request/create/HostCreateRequest.java | 2 +- .../request/create/MemberCreateRequest.java | 2 +- .../member/application/CuratorService.java | 4 +- .../member/application/HostService.java | 4 +- .../member/application/MemberService.java | 4 +- .../wouldyouin/member/persist/BaseMember.java | 2 +- .../wouldyouin/member/persist/Curator.java | 3 +- .../wouldyouin/member/persist/Host.java | 4 +- .../wouldyouin/member/persist/Member.java | 2 +- .../api/ReservationController.java | 7 + .../application/ReservationService.java | 9 + .../_global/testdata/CommonData.java | 1 - .../_global/testdata/CurationData.java | 6 +- .../_global/testdata/EventData.java | 3 +- .../_global/testdata/ImageData.java | 14 +- .../_global/testdata/MemberData.java | 2 +- .../curation/CurationServiceTest.java | 203 ++++++++---------- .../event/EventServiceUnitTest.java | 4 +- .../wouldyouin/image/ImageControllerTest.java | 10 +- .../application/CuratorServiceUnitTest.java | 2 +- .../application/HostServiceUnitTest.java | 4 +- .../application/MemberServiceUnitTest.java | 4 +- 59 files changed, 271 insertions(+), 285 deletions(-) rename src/main/java/org/ktc2/cokaen/wouldyouin/{Image => image}/api/ImageController.java (87%) rename src/main/java/org/ktc2/cokaen/wouldyouin/{Image => image}/api/ImageDomain.java (64%) rename src/main/java/org/ktc2/cokaen/wouldyouin/{Image => image}/api/dto/ImageRequest.java (88%) rename src/main/java/org/ktc2/cokaen/wouldyouin/{Image => image}/api/dto/ImageResponse.java (78%) rename src/main/java/org/ktc2/cokaen/wouldyouin/{Image => image}/application/AdvertisementImageService.java (85%) rename src/main/java/org/ktc2/cokaen/wouldyouin/{Image => image}/application/CurationImageService.java (83%) rename src/main/java/org/ktc2/cokaen/wouldyouin/{Image => image}/application/EventImageService.java (82%) rename src/main/java/org/ktc2/cokaen/wouldyouin/{Image => image}/application/ImageService.java (87%) rename src/main/java/org/ktc2/cokaen/wouldyouin/{Image => image}/application/ImageServiceFactory.java (81%) rename src/main/java/org/ktc2/cokaen/wouldyouin/{Image => image}/application/ImageStorageService.java (95%) rename src/main/java/org/ktc2/cokaen/wouldyouin/{Image => image}/application/MemberImageService.java (84%) rename src/main/java/org/ktc2/cokaen/wouldyouin/{Image => image}/persist/AdvertisementImage.java (93%) rename src/main/java/org/ktc2/cokaen/wouldyouin/{Image => image}/persist/AdvertisementImageRepository.java (75%) rename src/main/java/org/ktc2/cokaen/wouldyouin/{Image => image}/persist/CurationImage.java (92%) rename src/main/java/org/ktc2/cokaen/wouldyouin/{Image => image}/persist/CurationImageRepository.java (74%) rename src/main/java/org/ktc2/cokaen/wouldyouin/{Image => image}/persist/EventImage.java (92%) rename src/main/java/org/ktc2/cokaen/wouldyouin/{Image => image}/persist/EventImageRepository.java (55%) rename src/main/java/org/ktc2/cokaen/wouldyouin/{Image => image}/persist/Image.java (96%) rename src/main/java/org/ktc2/cokaen/wouldyouin/{Image => image}/persist/ImageRepository.java (82%) rename src/main/java/org/ktc2/cokaen/wouldyouin/{Image => image}/persist/MemberImage.java (92%) rename src/main/java/org/ktc2/cokaen/wouldyouin/{Image => image}/persist/MemberImageRepository.java (56%) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/GlobalExceptionHandler.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/GlobalExceptionHandler.java index ebe4de5e..cf8c28d6 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/GlobalExceptionHandler.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/GlobalExceptionHandler.java @@ -2,7 +2,7 @@ import java.util.stream.Collectors; -import org.ktc2.cokaen.wouldyouin.Image.api.ImageDomain; +import org.ktc2.cokaen.wouldyouin.image.api.ImageDomain; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponse; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponseBody; import org.ktc2.cokaen.wouldyouin._common.exception.BusinessException; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/dto/AdvertisementRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/dto/AdvertisementRequest.java index ae62e765..ca4a5940 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/dto/AdvertisementRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/dto/AdvertisementRequest.java @@ -7,7 +7,7 @@ import java.time.LocalDateTime; import lombok.Builder; import lombok.Getter; -import org.ktc2.cokaen.wouldyouin.Image.persist.AdvertisementImage; +import org.ktc2.cokaen.wouldyouin.image.persist.AdvertisementImage; import org.ktc2.cokaen.wouldyouin.advertisement.persist.Advertisement; @Getter diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java index 4dfd7f5e..10a1b4a2 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java @@ -4,8 +4,8 @@ import java.util.List; import java.util.Optional; import lombok.RequiredArgsConstructor; -import org.ktc2.cokaen.wouldyouin.Image.application.AdvertisementImageService; -import org.ktc2.cokaen.wouldyouin.Image.persist.AdvertisementImage; +import org.ktc2.cokaen.wouldyouin.image.application.AdvertisementImageService; +import org.ktc2.cokaen.wouldyouin.image.persist.AdvertisementImage; import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; import org.ktc2.cokaen.wouldyouin.advertisement.api.dto.AdvertisementRequest; import org.ktc2.cokaen.wouldyouin.advertisement.api.dto.AdvertisementResponse; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/persist/Advertisement.java b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/persist/Advertisement.java index 8c708a1a..f449387f 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/persist/Advertisement.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/persist/Advertisement.java @@ -14,7 +14,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import org.ktc2.cokaen.wouldyouin.Image.persist.AdvertisementImage; +import org.ktc2.cokaen.wouldyouin.image.persist.AdvertisementImage; import org.ktc2.cokaen.wouldyouin.advertisement.api.dto.AdvertisementRequest; @Getter diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCardRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCardRequest.java index 80946d11..6fc23709 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCardRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCardRequest.java @@ -8,7 +8,7 @@ import lombok.Builder; import lombok.EqualsAndHashCode; import lombok.Getter; -import org.ktc2.cokaen.wouldyouin.Image.persist.CurationImage; +import org.ktc2.cokaen.wouldyouin.image.persist.CurationImage; import org.ktc2.cokaen.wouldyouin.curation.persist.CurationCard; @Getter diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCardResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCardResponse.java index 60048c89..6fe4674a 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCardResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCardResponse.java @@ -2,7 +2,7 @@ import java.util.List; import lombok.Builder; -import org.ktc2.cokaen.wouldyouin.Image.persist.CurationImage; +import org.ktc2.cokaen.wouldyouin.image.persist.CurationImage; import org.ktc2.cokaen.wouldyouin.curation.persist.CurationCard; @Builder @@ -12,15 +12,11 @@ public class CurationCardResponse { private String content; private List imageUrls; - public static CurationCardResponse from(CurationCard curationCard) { + public static CurationCardResponse from(CurationCard curationCard, List imageUrls) { return CurationCardResponse.builder() .subtitle(curationCard.getSubtitle()) .content(curationCard.getContent()) - .imageUrls( - curationCard.getCurationImages().stream() - .map(CurationImage::getName) - .toList() - ) + .imageUrls(imageUrls) .build(); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java index 32ae736a..4aaa9ba5 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java @@ -27,14 +27,13 @@ public class CurationResponse { private final LocalDateTime createdTime; private final LocalDateTime modifiedDate; - public static CurationResponse from(Curation curation) { + public static CurationResponse from(Curation curation, List curationCards) { return CurationResponse.builder() .id(curation.getId()) .curator(CurationCuratorResponse.from(curation.getCurator())) .title(curation.getTitle()) .content(curation.getContent()) - .curationCards(curation.getCurationCards().stream() - .map(CurationCardResponse::from).toList()) + .curationCards(curationCards) .area(curation.getArea()) .hashtags(curation.getHashtags()) .eventsInfo(curation.getEvents().stream() diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationSliceResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationSliceResponse.java index ad3de907..0917d6ce 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationSliceResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationSliceResponse.java @@ -14,10 +14,9 @@ public class CurationSliceResponse { private final List curations; private final SliceInfo sliceInfo; - public static CurationSliceResponse from(Slice curations, int size, Long lastId) { + public static CurationSliceResponse from(List curations, int size, Long lastId) { return CurationSliceResponse.builder() - .curations(curations.stream() - .map(CurationResponse::from).toList()) + .curations(curations) .sliceInfo(SliceInfo.builder() .sliceSize(size) .lastId(lastId) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java index ea7491d3..5c29fd4d 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java @@ -1,11 +1,9 @@ package org.ktc2.cokaen.wouldyouin.curation.application; import java.util.List; -import java.util.Optional; import lombok.RequiredArgsConstructor; -import org.ktc2.cokaen.wouldyouin.Image.application.CurationImageService; -import org.ktc2.cokaen.wouldyouin.Image.persist.CurationImage; -import org.ktc2.cokaen.wouldyouin.Image.persist.EventImage; +import org.ktc2.cokaen.wouldyouin.image.application.CurationImageService; +import org.ktc2.cokaen.wouldyouin.image.persist.CurationImage; import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCardRequest; @@ -23,26 +21,16 @@ public class CurationCardService { private final CurationCardRepository curationCardRepository; private final CurationImageService curationImageService; - @Transactional(readOnly = true) - public CurationCard getByIdOrThrow(Long id) { - return curationCardRepository.findById(id).orElseThrow(() -> new EntityNotFoundException("해당하는 큐레이션 카드를 찾을 수 없습니다.")); - } - @Transactional(readOnly = true) public CurationCardResponse getById(Long id) { - return CurationCardResponse.from(getByIdOrThrow(id)); - } - - @Transactional - public void setCuration(CurationCard curationCard, Curation curation) { - curationCard.setCuration(curation); + CurationCard curationCard = getByIdOrThrow(id); + return CurationCardResponse.from(curationCard, getImageUrls(curationCard)); } @Transactional public CurationCard create(CurationCardRequest request) { List images = request.getImageIds().stream() - .map(curationImageService::getById) - .toList(); + .map(curationImageService::getById).toList(); CurationCard curationCard = curationCardRepository.save(request.toEntity(images)); images.forEach(image -> curationImageService.setCuration(image, curationCard)); return curationCard; @@ -54,4 +42,19 @@ public void delete(MemberIdentifier identifier, Long id) { target.getCurationImages().forEach(image -> curationImageService.deleteImage(identifier, image.getId())); curationCardRepository.deleteById(id); } + + @Transactional + public void setCuration(CurationCard curationCard, Curation curation) { + curationCard.setCuration(curation); + } + + private CurationCard getByIdOrThrow(Long id) { + return curationCardRepository.findById(id).orElseThrow(() -> new EntityNotFoundException("해당하는 큐레이션 카드를 찾을 수 없습니다.")); + } + + public List getImageUrls(CurationCard curationCard) { + return curationCard.getCurationImages().stream() + .map(curationImageService::getImageUrl) + .toList(); + } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationService.java index df57443d..bd471d25 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationService.java @@ -3,12 +3,13 @@ import java.util.List; import java.util.Optional; import lombok.RequiredArgsConstructor; -import org.ktc2.cokaen.wouldyouin.Image.application.CurationImageService; -import org.ktc2.cokaen.wouldyouin.Image.persist.CurationImage; +import org.ktc2.cokaen.wouldyouin.image.application.CurationImageService; +import org.ktc2.cokaen.wouldyouin.image.persist.CurationImage; import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; +import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCardResponse; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCreateRequest; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationEditRequest; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationResponse; @@ -36,21 +37,17 @@ public class CurationService { private final CurationCardService curationCardService; private final CurationImageService curationImageService; - @Transactional(readOnly = true) - public Curation getByIdOrThrow(Long id) throws EntityNotFoundException { - return curationRepository.findById(id).orElseThrow(() -> new EntityNotFoundException("해당하는 큐레이션을 찾을 수 없습니다.")); - } - @Transactional(readOnly = true) public CurationResponse getById(Long curationId) { - return CurationResponse.from(getByIdOrThrow(curationId)); + Curation curation = getByIdOrThrow(curationId); + return CurationResponse.from(curation, getCurationCardResponses(curation)); } @Transactional(readOnly = true) public CurationSliceResponse getAllByAreaOrderByCreatedDateDesc(Area area, Pageable pageable, Long oldLastId) { Slice curations = curationRepository.findAllByAreaOrderByCreatedDateDesc(area, oldLastId, pageable); Long newLastId = getLastId(curations, oldLastId); - return CurationSliceResponse.from(curations, curations.getSize(), newLastId); + return CurationSliceResponse.from(getCurationResponses(curations), curations.getSize(), newLastId); } @Transactional(readOnly = true) @@ -58,7 +55,7 @@ public CurationSliceResponse getAllByCuratorIdOrderByCreatedDateDesc(Long curato Slice curations = curationRepository.findAllByCuratorOrderByCreatedDateDesc( curatorService.getByIdOrThrow(curatorId), lastId, pageable); Long newLastId = getLastId(curations, lastId); - return CurationSliceResponse.from(curations, curations.getSize(), newLastId); + return CurationSliceResponse.from(getCurationResponses(curations), curations.getSize(), newLastId); } @Transactional @@ -73,17 +70,7 @@ public CurationResponse create(MemberIdentifier identifier, CurationCreateReques Curation curation = curationRepository.save( curationCreateRequest.toEntity(curator, curationCards, events, getThumbnailUrl(curationCards))); curationCards.forEach(curationCard -> curationCardService.setCuration(curationCard, curation)); - return CurationResponse.from(curation); - } - - private String getThumbnailUrl(List curationCards) { - return Optional.ofNullable(curationCards) - .map(List::getFirst) - .map(CurationCard::getCurationImages) - .map(List::getFirst) - .map(CurationImage::getName) - .map(curationImageService::createThumbnail) - .orElse(""); + return CurationResponse.from(curation, getCurationCardResponses(curation)); } @Transactional @@ -91,15 +78,13 @@ public CurationResponse update(MemberIdentifier identifier, Long curationId, Cur Curation curation = getByIdOrThrow(curationId); validateCuratorId(identifier, curation); List curationCards = curationEditRequest.getCurationCards().stream() - .map(curationCardService::create) - .toList(); + .map(curationCardService::create).toList(); List events = curationEditRequest.getEventIds().stream() - .map(eventService::getByIdOrThrow) - .toList(); + .map(eventService::getByIdOrThrow).toList(); curation.getCurationCards().forEach(card -> curationCardService.delete(identifier, card.getId())); curation.updateFrom(curationEditRequest, curationCards, events, getThumbnailUrl(curationCards)); curationCards.forEach(curationCard -> curationCardService.setCuration(curationCard, curation)); - return CurationResponse.from(curation); + return CurationResponse.from(curation, getCurationCardResponses(curation)); } @Transactional @@ -123,4 +108,32 @@ private void validateCuratorId(MemberIdentifier identifier, Curation curation) { throw new UnauthorizedException("큐레이션에 접근할 권한이 없습니다."); } } + + private Curation getByIdOrThrow(Long id) throws EntityNotFoundException { + return curationRepository.findById(id).orElseThrow(() -> new EntityNotFoundException("해당하는 큐레이션을 찾을 수 없습니다.")); + } + + private List getCurationResponses(Slice curations) { + return curations.getContent().stream() + .map(curation -> CurationResponse.from(curation, getCurationCardResponses(curation))) + .toList(); + } + + private List getCurationCardResponses(Curation curation) { + return curation.getCurationCards().stream() + .map(curationCard -> CurationCardResponse.from( + curationCard, curationCard.getCurationImages().stream() + .map(curationImageService::getImageUrl).toList())) + .toList(); + } + + private String getThumbnailUrl(List curationCards) { + return Optional.ofNullable(curationCards) + .map(List::getFirst) + .map(CurationCard::getCurationImages) + .map(List::getFirst) + .map(CurationImage::getName) + .map(curationImageService::createThumbnail) + .orElse(""); + } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCard.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCard.java index 127bfad5..acfc4385 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCard.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCard.java @@ -17,7 +17,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import org.ktc2.cokaen.wouldyouin.Image.persist.CurationImage; +import org.ktc2.cokaen.wouldyouin.image.persist.CurationImage; @Getter @Setter diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java index 279a1736..12a22650 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java @@ -12,7 +12,7 @@ import java.util.List; import lombok.Builder; import lombok.Getter; -import org.ktc2.cokaen.wouldyouin.Image.persist.EventImage; +import org.ktc2.cokaen.wouldyouin.image.persist.EventImage; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; import org.ktc2.cokaen.wouldyouin._common.vo.Location; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventResponse.java index 385d44b3..652e0711 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventResponse.java @@ -4,7 +4,6 @@ import java.util.List; import lombok.Builder; import lombok.Getter; -import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageResponse; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; import org.ktc2.cokaen.wouldyouin._common.vo.Location; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventSliceResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventSliceResponse.java index 4326e2b1..d974a17f 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventSliceResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventSliceResponse.java @@ -3,7 +3,6 @@ import java.util.List; import lombok.Builder; import lombok.Getter; -import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageResponse; import org.ktc2.cokaen.wouldyouin._common.api.SliceInfo; @Getter diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java index 746b6694..cf1875d9 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java @@ -3,9 +3,9 @@ import java.util.List; import java.util.Optional; import lombok.RequiredArgsConstructor; -import org.ktc2.cokaen.wouldyouin.Image.application.EventImageService; -import org.ktc2.cokaen.wouldyouin.Image.application.MemberImageService; -import org.ktc2.cokaen.wouldyouin.Image.persist.EventImage; +import org.ktc2.cokaen.wouldyouin.image.application.EventImageService; +import org.ktc2.cokaen.wouldyouin.image.application.MemberImageService; +import org.ktc2.cokaen.wouldyouin.image.persist.EventImage; import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; import org.ktc2.cokaen.wouldyouin._common.exception.NoLeftSeatException; import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java index c3fe53ee..4451519d 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java @@ -25,7 +25,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import org.ktc2.cokaen.wouldyouin.Image.persist.EventImage; +import org.ktc2.cokaen.wouldyouin.image.persist.EventImage; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; import org.ktc2.cokaen.wouldyouin._common.vo.Location; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/ImageController.java similarity index 87% rename from src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/image/api/ImageController.java index 93e22de0..d2b52044 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/ImageController.java @@ -1,19 +1,17 @@ -package org.ktc2.cokaen.wouldyouin.Image.api; +package org.ktc2.cokaen.wouldyouin.image.api; import java.nio.file.Paths; import java.util.List; import lombok.RequiredArgsConstructor; -import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageResponse; -import org.ktc2.cokaen.wouldyouin.Image.application.ImageServiceFactory; -import org.ktc2.cokaen.wouldyouin.Image.application.ImageStorageService; +import org.ktc2.cokaen.wouldyouin.image.api.dto.ImageResponse; +import org.ktc2.cokaen.wouldyouin.image.application.ImageServiceFactory; +import org.ktc2.cokaen.wouldyouin.image.application.ImageStorageService; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponse; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponseBody; import org.ktc2.cokaen.wouldyouin.auth.Authorize; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.ktc2.cokaen.wouldyouin.payment.application.PaymentService; -import org.ktc2.cokaen.wouldyouin.payment.dto.KakaoPayRequest; -import org.ktc2.cokaen.wouldyouin.payment.dto.KakaoPayResponse; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageDomain.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/ImageDomain.java similarity index 64% rename from src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageDomain.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/image/api/ImageDomain.java index 4a572368..5e69f835 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/ImageDomain.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/ImageDomain.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin.Image.api; +package org.ktc2.cokaen.wouldyouin.image.api; public enum ImageDomain { MEMBER, diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/dto/ImageRequest.java similarity index 88% rename from src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageRequest.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/image/api/dto/ImageRequest.java index 15dda0cd..b6472d2b 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/dto/ImageRequest.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin.Image.api.dto; +package org.ktc2.cokaen.wouldyouin.image.api.dto; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/dto/ImageResponse.java similarity index 78% rename from src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageResponse.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/image/api/dto/ImageResponse.java index 32498c58..70c27cd8 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/dto/ImageResponse.java @@ -1,10 +1,9 @@ -package org.ktc2.cokaen.wouldyouin.Image.api.dto; +package org.ktc2.cokaen.wouldyouin.image.api.dto; import java.time.LocalDateTime; import lombok.Builder; import lombok.Getter; -import org.ktc2.cokaen.wouldyouin.Image.persist.Image; -import org.ktc2.cokaen.wouldyouin._common.util.UriUtil; +import org.ktc2.cokaen.wouldyouin.image.persist.Image; @Getter @Builder diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/AdvertisementImageService.java similarity index 85% rename from src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/image/application/AdvertisementImageService.java index 8a696cc9..b35682ac 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/AdvertisementImageService.java @@ -1,11 +1,11 @@ -package org.ktc2.cokaen.wouldyouin.Image.application; +package org.ktc2.cokaen.wouldyouin.image.application; import lombok.RequiredArgsConstructor; -import org.ktc2.cokaen.wouldyouin.Image.api.ImageDomain; -import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageRequest; -import org.ktc2.cokaen.wouldyouin.Image.persist.AdvertisementImage; -import org.ktc2.cokaen.wouldyouin.Image.persist.AdvertisementImageRepository; -import org.ktc2.cokaen.wouldyouin.Image.persist.ImageRepository; +import org.ktc2.cokaen.wouldyouin.image.api.ImageDomain; +import org.ktc2.cokaen.wouldyouin.image.api.dto.ImageRequest; +import org.ktc2.cokaen.wouldyouin.image.persist.AdvertisementImage; +import org.ktc2.cokaen.wouldyouin.image.persist.AdvertisementImageRepository; +import org.ktc2.cokaen.wouldyouin.image.persist.ImageRepository; import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; import org.ktc2.cokaen.wouldyouin.advertisement.persist.Advertisement; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/CurationImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/CurationImageService.java similarity index 83% rename from src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/CurationImageService.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/image/application/CurationImageService.java index 9fd4b657..2cdc6f92 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/CurationImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/CurationImageService.java @@ -1,11 +1,11 @@ -package org.ktc2.cokaen.wouldyouin.Image.application; +package org.ktc2.cokaen.wouldyouin.image.application; import lombok.RequiredArgsConstructor; -import org.ktc2.cokaen.wouldyouin.Image.api.ImageDomain; -import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageRequest; -import org.ktc2.cokaen.wouldyouin.Image.persist.CurationImage; -import org.ktc2.cokaen.wouldyouin.Image.persist.CurationImageRepository; -import org.ktc2.cokaen.wouldyouin.Image.persist.ImageRepository; +import org.ktc2.cokaen.wouldyouin.image.api.ImageDomain; +import org.ktc2.cokaen.wouldyouin.image.api.dto.ImageRequest; +import org.ktc2.cokaen.wouldyouin.image.persist.CurationImage; +import org.ktc2.cokaen.wouldyouin.image.persist.CurationImageRepository; +import org.ktc2.cokaen.wouldyouin.image.persist.ImageRepository; import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.curation.persist.CurationCard; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/EventImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/EventImageService.java similarity index 82% rename from src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/EventImageService.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/image/application/EventImageService.java index 5ef1cdaa..2c494966 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/EventImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/EventImageService.java @@ -1,11 +1,11 @@ -package org.ktc2.cokaen.wouldyouin.Image.application; +package org.ktc2.cokaen.wouldyouin.image.application; import lombok.RequiredArgsConstructor; -import org.ktc2.cokaen.wouldyouin.Image.api.ImageDomain; -import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageRequest; -import org.ktc2.cokaen.wouldyouin.Image.persist.EventImage; -import org.ktc2.cokaen.wouldyouin.Image.persist.EventImageRepository; -import org.ktc2.cokaen.wouldyouin.Image.persist.ImageRepository; +import org.ktc2.cokaen.wouldyouin.image.api.ImageDomain; +import org.ktc2.cokaen.wouldyouin.image.api.dto.ImageRequest; +import org.ktc2.cokaen.wouldyouin.image.persist.EventImage; +import org.ktc2.cokaen.wouldyouin.image.persist.EventImageRepository; +import org.ktc2.cokaen.wouldyouin.image.persist.ImageRepository; import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.event.persist.Event; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageService.java similarity index 87% rename from src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageService.java index 3a3d2e91..24e4facd 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageService.java @@ -1,12 +1,12 @@ -package org.ktc2.cokaen.wouldyouin.Image.application; +package org.ktc2.cokaen.wouldyouin.image.application; import java.util.List; import lombok.RequiredArgsConstructor; -import org.ktc2.cokaen.wouldyouin.Image.api.ImageDomain; -import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageRequest; -import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageResponse; -import org.ktc2.cokaen.wouldyouin.Image.persist.Image; -import org.ktc2.cokaen.wouldyouin.Image.persist.ImageRepository; +import org.ktc2.cokaen.wouldyouin.image.api.ImageDomain; +import org.ktc2.cokaen.wouldyouin.image.api.dto.ImageRequest; +import org.ktc2.cokaen.wouldyouin.image.api.dto.ImageResponse; +import org.ktc2.cokaen.wouldyouin.image.persist.Image; +import org.ktc2.cokaen.wouldyouin.image.persist.ImageRepository; import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; import org.ktc2.cokaen.wouldyouin._common.util.UriUtil; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageServiceFactory.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageServiceFactory.java similarity index 81% rename from src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageServiceFactory.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageServiceFactory.java index 6c825456..331b19f6 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageServiceFactory.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageServiceFactory.java @@ -1,11 +1,11 @@ -package org.ktc2.cokaen.wouldyouin.Image.application; +package org.ktc2.cokaen.wouldyouin.image.application; import java.util.List; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; import java.util.stream.Collectors; -import org.ktc2.cokaen.wouldyouin.Image.api.ImageDomain; -import org.ktc2.cokaen.wouldyouin.Image.persist.Image; +import org.ktc2.cokaen.wouldyouin.image.api.ImageDomain; +import org.ktc2.cokaen.wouldyouin.image.persist.Image; import org.springframework.stereotype.Component; @Component diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageStorageService.java similarity index 95% rename from src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorageService.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageStorageService.java index 6dbd516c..5a7ad62d 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageStorageService.java @@ -1,14 +1,13 @@ -package org.ktc2.cokaen.wouldyouin.Image.application; +package org.ktc2.cokaen.wouldyouin.image.application; import java.io.File; -import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Optional; import lombok.RequiredArgsConstructor; import net.coobird.thumbnailator.Thumbnails; -import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageRequest; +import org.ktc2.cokaen.wouldyouin.image.api.dto.ImageRequest; import org.ktc2.cokaen.wouldyouin._common.exception.FailedToUploadImageException; import org.ktc2.cokaen.wouldyouin._common.util.FileUtil; import org.ktc2.cokaen.wouldyouin._common.util.RestClientUtil; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/MemberImageService.java similarity index 84% rename from src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/image/application/MemberImageService.java index 8a365d5b..a2a087b3 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/MemberImageService.java @@ -1,11 +1,11 @@ -package org.ktc2.cokaen.wouldyouin.Image.application; +package org.ktc2.cokaen.wouldyouin.image.application; import lombok.RequiredArgsConstructor; -import org.ktc2.cokaen.wouldyouin.Image.api.ImageDomain; -import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageRequest; -import org.ktc2.cokaen.wouldyouin.Image.persist.ImageRepository; -import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; -import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImageRepository; +import org.ktc2.cokaen.wouldyouin.image.api.ImageDomain; +import org.ktc2.cokaen.wouldyouin.image.api.dto.ImageRequest; +import org.ktc2.cokaen.wouldyouin.image.persist.ImageRepository; +import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; +import org.ktc2.cokaen.wouldyouin.image.persist.MemberImageRepository; import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMember; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/AdvertisementImage.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/AdvertisementImage.java similarity index 93% rename from src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/AdvertisementImage.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/AdvertisementImage.java index 13049fe6..e2ac0382 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/AdvertisementImage.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/AdvertisementImage.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin.Image.persist; +package org.ktc2.cokaen.wouldyouin.image.persist; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/AdvertisementImageRepository.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/AdvertisementImageRepository.java similarity index 75% rename from src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/AdvertisementImageRepository.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/AdvertisementImageRepository.java index 25fe1910..1bd3709b 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/AdvertisementImageRepository.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/AdvertisementImageRepository.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin.Image.persist; +package org.ktc2.cokaen.wouldyouin.image.persist; import org.springframework.stereotype.Repository; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/CurationImage.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/CurationImage.java similarity index 92% rename from src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/CurationImage.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/CurationImage.java index 5f2e9c9d..ac6f4c11 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/CurationImage.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/CurationImage.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin.Image.persist; +package org.ktc2.cokaen.wouldyouin.image.persist; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/CurationImageRepository.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/CurationImageRepository.java similarity index 74% rename from src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/CurationImageRepository.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/CurationImageRepository.java index 55c902fe..f18770b8 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/CurationImageRepository.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/CurationImageRepository.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin.Image.persist; +package org.ktc2.cokaen.wouldyouin.image.persist; import org.springframework.stereotype.Repository; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/EventImage.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/EventImage.java similarity index 92% rename from src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/EventImage.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/EventImage.java index 4e9a520c..c3662b53 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/EventImage.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/EventImage.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin.Image.persist; +package org.ktc2.cokaen.wouldyouin.image.persist; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/EventImageRepository.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/EventImageRepository.java similarity index 55% rename from src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/EventImageRepository.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/EventImageRepository.java index 20476445..32a562bd 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/EventImageRepository.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/EventImageRepository.java @@ -1,6 +1,5 @@ -package org.ktc2.cokaen.wouldyouin.Image.persist; +package org.ktc2.cokaen.wouldyouin.image.persist; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @Repository diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/Image.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/Image.java similarity index 96% rename from src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/Image.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/Image.java index ccdcbe2e..7115b024 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/Image.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/Image.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin.Image.persist; +package org.ktc2.cokaen.wouldyouin.image.persist; import jakarta.persistence.Column; import jakarta.persistence.EntityListeners; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/ImageRepository.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/ImageRepository.java similarity index 82% rename from src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/ImageRepository.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/ImageRepository.java index 94ff3576..19cbfae9 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/ImageRepository.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/ImageRepository.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin.Image.persist; +package org.ktc2.cokaen.wouldyouin.image.persist; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.repository.NoRepositoryBean; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/MemberImage.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/MemberImage.java similarity index 92% rename from src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/MemberImage.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/MemberImage.java index a7a7d52f..d3a4ca76 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/MemberImage.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/MemberImage.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin.Image.persist; +package org.ktc2.cokaen.wouldyouin.image.persist; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/MemberImageRepository.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/MemberImageRepository.java similarity index 56% rename from src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/MemberImageRepository.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/MemberImageRepository.java index a0af1261..38d393de 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/persist/MemberImageRepository.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/MemberImageRepository.java @@ -1,6 +1,5 @@ -package org.ktc2.cokaen.wouldyouin.Image.persist; +package org.ktc2.cokaen.wouldyouin.image.persist; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @Repository diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/HostCreateRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/HostCreateRequest.java index f3854cd2..b6015c5a 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/HostCreateRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/HostCreateRequest.java @@ -2,7 +2,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; -import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; +import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin.member.persist.Host; @Getter diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/MemberCreateRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/MemberCreateRequest.java index 2ff3406c..1788d5bd 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/MemberCreateRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/MemberCreateRequest.java @@ -3,7 +3,7 @@ import lombok.Builder; import lombok.Getter; import lombok.RequiredArgsConstructor; -import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; +import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin.member.persist.AccountType; import org.ktc2.cokaen.wouldyouin.member.persist.Member; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java index 5a1b817a..836757a9 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java @@ -1,8 +1,8 @@ package org.ktc2.cokaen.wouldyouin.member.application; import lombok.RequiredArgsConstructor; -import org.ktc2.cokaen.wouldyouin.Image.application.MemberImageService; -import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; +import org.ktc2.cokaen.wouldyouin.image.application.MemberImageService; +import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; import org.ktc2.cokaen.wouldyouin.member.api.dto.MemberResponse; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit.CuratorEditRequest; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java index 4215f87f..de747ed0 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java @@ -2,8 +2,8 @@ import java.util.Optional; import lombok.RequiredArgsConstructor; -import org.ktc2.cokaen.wouldyouin.Image.application.MemberImageService; -import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; +import org.ktc2.cokaen.wouldyouin.image.application.MemberImageService; +import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin.auth.api.dto.LocalLoginRequest; import org.ktc2.cokaen.wouldyouin.member.api.dto.MemberResponse; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.create.HostCreateRequest; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/MemberService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/MemberService.java index afc1f9d2..1e95c56e 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/MemberService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/MemberService.java @@ -2,8 +2,8 @@ import java.util.Optional; import lombok.RequiredArgsConstructor; -import org.ktc2.cokaen.wouldyouin.Image.application.MemberImageService; -import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; +import org.ktc2.cokaen.wouldyouin.image.application.MemberImageService; +import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.member.api.dto.MemberResponse; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.MemberAdditionalInfoRequest; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java index c7b48a96..c62b9667 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java @@ -15,7 +15,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; +import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; @Getter @Setter diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java index 1c1d2a9c..525c4b18 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java @@ -14,8 +14,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import lombok.experimental.SuperBuilder; -import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; +import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin._common.converter.HashtagConverter; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java index 5a636ece..955b4082 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java @@ -13,9 +13,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import lombok.experimental.Helper; -import lombok.experimental.SuperBuilder; -import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; +import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin._common.converter.HashtagConverter; import org.ktc2.cokaen.wouldyouin.event.persist.Event; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java index 85fa19ed..20040457 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java @@ -12,7 +12,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; +import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin.like.persist.CuratorLike; import org.ktc2.cokaen.wouldyouin.like.persist.HostLike; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/ReservationController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/ReservationController.java index 710ad4ae..5b0d4b6e 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/ReservationController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/ReservationController.java @@ -63,6 +63,13 @@ public ResponseEntity> createReservation( return ApiResponse.created(reservationService.create(member.id(), reservationRequest)); } + @PostMapping("/test") + public ResponseEntity> createTestReservation( + @Valid @RequestBody ReservationRequest reservationRequest, + @Authorize({MemberType.normal, MemberType.curator}) MemberIdentifier member) { + return ApiResponse.created(reservationService.createTest(member.id(), reservationRequest)); + } + @DeleteMapping("/{reservationId}") public ResponseEntity> deleteReservation( @PathVariable Long reservationId, diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java index 1c96a501..85bbd555 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java @@ -79,6 +79,15 @@ public KakaoPayResponse create(Long memberId, ReservationRequest reservationRequ return paymentService.createPayment(KakaoPayRequest.from(reservation)); } + @Transactional + public ReservationResponse createTest(Long memberId, ReservationRequest reservationRequest) { + Reservation reservation = reservationRepository.save(reservationRequest.toEntity( + memberService.getByIdOrThrow(memberId), + eventService.getByIdOrThrow(reservationRequest.getEventId()))); + eventService.decreaseLeftSeat(reservation.getEvent().getId(), reservationRequest.getQuantity()); + return ReservationResponse.from(reservation); + } + @Transactional public void delete(Long memberId, Long reservationId) { validateMemberId(memberId, getByIdOrThrow(reservationId)); diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java index b70cca43..a5c16066 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java @@ -18,5 +18,4 @@ public static SliceInfo get() { .build(); } } - } \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java index 1d27d62d..0664ff97 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java @@ -2,11 +2,9 @@ import java.time.LocalDateTime; import java.util.List; -import org.ktc2.cokaen.wouldyouin.Image.persist.CurationImage; +import org.ktc2.cokaen.wouldyouin.image.persist.CurationImage; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.R.curationEditRequest; -import org.ktc2.cokaen.wouldyouin._global.testdata.EventData.event1; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.curator1; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCardRequest; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCardResponse; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCreateRequest; @@ -76,7 +74,7 @@ public static class entity { public static CurationCard get() { CurationCard validCurationCard1 = CurationCard.builder() .subtitle(R.curationCard1.subtitle) - .content(R.curationCard2.content) + .content(R.curationCard1.content) // .curation(createValidCuration()) .images(R.curationCard1.images) .build(); diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/EventData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/EventData.java index a889aab1..f00bd851 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/EventData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/EventData.java @@ -2,7 +2,7 @@ import java.time.LocalDateTime; import java.util.List; -import org.ktc2.cokaen.wouldyouin.Image.persist.EventImage; +import org.ktc2.cokaen.wouldyouin.image.persist.EventImage; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; import org.ktc2.cokaen.wouldyouin._common.vo.Location; @@ -144,6 +144,7 @@ public static ReservationEventResponse createValidReservationEventResponse() { return ReservationEventResponse.from(EventData.event1.entity.get()); } } + public static class curationEvent { public static CurationEventResponse createValidCurationEventResponse() { return CurationEventResponse.from(EventData.event1.entity.get()); diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ImageData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ImageData.java index aec6ae66..b2d79d41 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ImageData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ImageData.java @@ -1,13 +1,13 @@ package org.ktc2.cokaen.wouldyouin._global.testdata; import java.time.LocalDateTime; -import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageRequest; -import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageResponse; -import org.ktc2.cokaen.wouldyouin.Image.persist.AdvertisementImage; -import org.ktc2.cokaen.wouldyouin.Image.persist.CurationImage; -import org.ktc2.cokaen.wouldyouin.Image.persist.EventImage; -import org.ktc2.cokaen.wouldyouin.Image.persist.Image; -import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; +import org.ktc2.cokaen.wouldyouin.image.api.dto.ImageRequest; +import org.ktc2.cokaen.wouldyouin.image.api.dto.ImageResponse; +import org.ktc2.cokaen.wouldyouin.image.persist.AdvertisementImage; +import org.ktc2.cokaen.wouldyouin.image.persist.CurationImage; +import org.ktc2.cokaen.wouldyouin.image.persist.EventImage; +import org.ktc2.cokaen.wouldyouin.image.persist.Image; +import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; import org.springframework.http.MediaType; import org.springframework.mock.web.MockMultipartFile; import org.springframework.test.util.ReflectionTestUtils; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java index 0e2284a2..054396a0 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java @@ -1,7 +1,7 @@ package org.ktc2.cokaen.wouldyouin._global.testdata; import java.util.List; -import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; +import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java index 779e183e..1d21a5f3 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java @@ -1,123 +1,96 @@ -//package org.ktc2.cokaen.wouldyouin.curation; -// -//import static java.lang.Math.abs; -//import static org.assertj.core.api.Assertions.assertThat; -//import static org.junit.jupiter.api.Assertions.assertThrows; -//import static org.mockito.BDDMockito.given; -//import static org.mockito.BDDMockito.then; -//import static org.mockito.Mockito.times; -// -//import java.util.Optional; -//import java.util.Random; -//import org.junit.jupiter.api.BeforeEach; -//import org.junit.jupiter.api.DisplayName; -//import org.junit.jupiter.api.Test; -//import org.junit.jupiter.api.extension.ExtendWith; -//import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; -//import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; -//import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData; -//import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationResponse; -//import org.ktc2.cokaen.wouldyouin.curation.application.CurationCardService; -//import org.ktc2.cokaen.wouldyouin.curation.application.CurationService; -//import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; -//import org.ktc2.cokaen.wouldyouin.curation.persist.CurationRepository; -//import org.ktc2.cokaen.wouldyouin.event.application.EventService; -//import org.ktc2.cokaen.wouldyouin.member.application.CuratorService; -//import org.mockito.Mock; -//import org.mockito.junit.jupiter.MockitoExtension; -// -//@ExtendWith(MockitoExtension.class) -//class CurationServiceTest { -// -// private CurationService curationService; -// -// @Mock -// private CurationRepository curationRepository; -// -// @Mock -// private CuratorService curatorService; -// -// @Mock -// private EventService eventService; -// -// @Mock -// private CurationCardService curationCardService; -// -// @Mock -// private MemberImage memberImage; -// -// private final long randomId = abs(new Random().nextLong()); -// -// @BeforeEach -// void setUp() { -// curationService = new CurationService(curationRepository, curatorService, eventService, curationCardService); -// } -// -// @Test -// @DisplayName("큐레이션 ID를 통해 큐레이션 조회한다.") -// void getByIdOrThrow1() { +package org.ktc2.cokaen.wouldyouin.curation; + +import static java.lang.Math.abs; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; +import static org.mockito.Mockito.times; + +import java.util.Optional; +import java.util.Random; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.ktc2.cokaen.wouldyouin.image.application.CurationImageService; +import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; +import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData; +import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationResponse; +import org.ktc2.cokaen.wouldyouin.curation.application.CurationCardService; +import org.ktc2.cokaen.wouldyouin.curation.application.CurationService; +import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; +import org.ktc2.cokaen.wouldyouin.curation.persist.CurationRepository; +import org.ktc2.cokaen.wouldyouin.event.application.EventService; +import org.ktc2.cokaen.wouldyouin.member.application.CuratorService; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class CurationServiceTest { + + private CurationService curationService; + + @Mock + private CurationRepository curationRepository; + + @Mock + private CuratorService curatorService; + + @Mock + private EventService eventService; + + @Mock + private CurationCardService curationCardService; + + @Mock + private CurationImageService curationImageService; + + @Mock + private MemberImage memberImage; + + private final long randomId = abs(new Random().nextLong()); + + @BeforeEach + void setUp() { + curationService = new CurationService(curationRepository, curatorService, eventService, curationCardService, curationImageService); + } + + @Test + @DisplayName("큐레이션 ID를 통해 큐레이션을 찾지 못한 경우, 예외를 던진다.") + void getById() { // // given // Curation validCuration = CurationData.curation.entity.get(); // given(curationRepository.findById(randomId)).willReturn(Optional.of(validCuration)); // // // when -// curationService.getByIdOrThrow(randomId); +// CurationResponse response = curationService.getById(randomId); // // // then // then(curationRepository).should(times(1)).findById(randomId); -// assertThat(curationService.getByIdOrThrow(randomId)).isEqualTo(validCuration); -// } -// -// @Test -// @DisplayName("큐레이션 ID를 통해 큐레이션을 찾지 못한 경우, 예외를 던진다.") -// void getByIdOrThrow2() { -// // given -// given(curationRepository.findById(randomId)).willReturn(Optional.empty()); -// -// // when, then -// EntityNotFoundException thrown = assertThrows( -// EntityNotFoundException.class, () -> curationService.getByIdOrThrow(randomId)); -// then(curationRepository).should(times(1)).findById(randomId); -// assertThat(thrown.getMessage()).isEqualTo("해당하는 큐레이션을 찾을 수 없습니다."); -// } -// -// // TODO: 이게 통과하면 데이터 정합성은 완벽한 것일거임 -//// @Test -//// @DisplayName("큐레이션 ID를 통해 큐레이션을 찾지 못한 경우, 예외를 던진다.") -//// void getById() { -//// // given -//// Curation validCuration = CurationData.curation.entity.get(); -//// given(curationRepository.findById(randomId)).willReturn(Optional.of(validCuration)); -//// -//// // when -//// CurationResponse response = curationService.getById(randomId); -//// -//// // then -//// then(curationRepository).should(times(1)).findById(randomId); -//// assertThat(response).usingRecursiveComparison().isEqualTo(CurationData.curation.response.get()); -//// } -// -// @Test -// void getAllByAreaOrderByCreatedDateDesc() { -// } -// -// @Test -// void getAllByCuratorIdOrderByCreatedDateDesc() { -// } -// -// @Test -// void create() { -// } -// -// @Test -// void update() { -// } -// -// @Test -// void delete() { -// } -// -// @Test -// void validateCuratorId() { -// } -//} \ No newline at end of file +// assertThat(response).usingRecursiveComparison().isEqualTo(CurationData.curation.response.get()); + } + + @Test + @DisplayName("큐레이션 ID를 통해 큐레이션을 찾지 못한 경우, 예외를 던진다.") + void getAllByAreaOrderByCreatedDateDesc() { + // given + + + } + + @Test + void getAllByCuratorIdOrderByCreatedDateDesc() { + } + + @Test + void create() { + } + + @Test + void update() { + } + + @Test + void delete() { + } +} \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java index 952d8f94..8b7ee7de 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java @@ -15,8 +15,8 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.ktc2.cokaen.wouldyouin.Image.application.EventImageService; -import org.ktc2.cokaen.wouldyouin.Image.application.MemberImageService; +import org.ktc2.cokaen.wouldyouin.image.application.EventImageService; +import org.ktc2.cokaen.wouldyouin.image.application.MemberImageService; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; import org.ktc2.cokaen.wouldyouin._global.testdata.EventData; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java index 366f679c..ae8e174e 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java @@ -20,11 +20,11 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.ktc2.cokaen.wouldyouin.Image.api.ImageController; -import org.ktc2.cokaen.wouldyouin.Image.api.ImageDomain; -import org.ktc2.cokaen.wouldyouin.Image.application.CurationImageService; -import org.ktc2.cokaen.wouldyouin.Image.application.ImageServiceFactory; -import org.ktc2.cokaen.wouldyouin.Image.application.ImageStorageService; +import org.ktc2.cokaen.wouldyouin.image.api.ImageController; +import org.ktc2.cokaen.wouldyouin.image.api.ImageDomain; +import org.ktc2.cokaen.wouldyouin.image.application.CurationImageService; +import org.ktc2.cokaen.wouldyouin.image.application.ImageServiceFactory; +import org.ktc2.cokaen.wouldyouin.image.application.ImageStorageService; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockCurator1; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember1; import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java index 90e34bb8..4ebc6be3 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java @@ -11,7 +11,7 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.ktc2.cokaen.wouldyouin.Image.application.MemberImageService; +import org.ktc2.cokaen.wouldyouin.image.application.MemberImageService; import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMemberRepository; import org.ktc2.cokaen.wouldyouin.member.persist.Curator; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java index f2e63a82..03d184dc 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java @@ -11,8 +11,8 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.ktc2.cokaen.wouldyouin.Image.application.MemberImageService; -import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; +import org.ktc2.cokaen.wouldyouin.image.application.MemberImageService; +import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData; import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; import org.ktc2.cokaen.wouldyouin.auth.api.dto.LocalLoginRequest; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java index c525d34a..1a22a91f 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java @@ -13,8 +13,8 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.ktc2.cokaen.wouldyouin.Image.application.MemberImageService; -import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; +import org.ktc2.cokaen.wouldyouin.image.application.MemberImageService; +import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin._global.TestUtil; import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.MemberAdditionalInfoRequest; From e09aa2f1e8c028930d949680058d3ef82b5d207a Mon Sep 17 00:00:00 2001 From: Jangan Lee Date: Thu, 14 Nov 2024 04:46:24 +0900 Subject: [PATCH 29/53] =?UTF-8?q?[Weekly/11/Refactor/MemberControllers]=20?= =?UTF-8?q?=EC=86=8C=EC=85=9C=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EA=B9=A8?= =?UTF-8?q?=EC=A7=90=20=ED=95=B4=EA=B2=B0,=20=EB=A9=A4=EB=B2=84=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=20url=20response=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(#128)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wouldyouin/_common/util/FileUtil.java | 16 +++------ .../_common/util/RestClientUtil.java | 10 ++++++ .../oauth/GoogleRequestService.java | 18 ++++++---- .../oauth/KakaoRequestService.java | 34 +++++++++++-------- .../wouldyouin/image/api/ImageController.java | 5 +++ .../image/application/ImageService.java | 2 +- .../application/ImageStorageService.java | 25 +++++++++----- .../member/api/dto/MemberResponse.java | 19 ++++++----- .../request/MemberAdditionalInfoRequest.java | 6 ++-- .../member/application/CuratorService.java | 10 +++--- .../member/application/HostService.java | 15 ++++---- .../member/application/MemberService.java | 12 ++++--- src/main/resources/application-deploy.yml | 4 ++- src/main/resources/application.yml | 2 +- 14 files changed, 106 insertions(+), 72 deletions(-) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/FileUtil.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/FileUtil.java index 3e14780e..e0970c02 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/FileUtil.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/FileUtil.java @@ -49,21 +49,13 @@ public static String createRandomFileName(String extension) { return UUID.randomUUID().toString().replace("-", "") + "." + extension; } - public static String getExtension(MultipartFile file) { - if (file == null || file.getContentType() == null) { - throw new ExtensionParsingException("파일이 존재하지 않거나 콘텐츠 타입이 없습니다."); - } + public static String getExtension(String contentType) { try { - return file.getContentType().split("/")[1]; + return contentType.split("/")[1]; + } catch (NullPointerException e) { + throw new ExtensionParsingException("파일이 존재하지 않거나 콘텐츠 타입이 없습니다."); } catch (ArrayIndexOutOfBoundsException e) { throw new ExtensionParsingException("파일의 확장자를 찾을 수 없습니다."); } } - - public static String getExtension(String url) { - if (url == null || !url.contains(".")) { - throw new ExtensionParsingException("URL이 존재하지 않거나 확장자가 없습니다."); - } - return url.substring(url.lastIndexOf('.') + 1); - } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/RestClientUtil.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/RestClientUtil.java index a1a1e533..9ed39e5f 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/RestClientUtil.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/RestClientUtil.java @@ -4,6 +4,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; import org.springframework.web.client.RestClient; import org.springframework.web.client.RestClient.ResponseSpec.ErrorHandler; @@ -23,6 +24,15 @@ public T get(Class classType, String url, HttpHeaders headers, ErrorHandl .body(classType); } + public ResponseEntity getResponseEntity(Class classType, String url, HttpHeaders headers, ErrorHandler errorHandler) { + return client.get() + .uri(url) + .headers(httpHeaders -> httpHeaders.putAll(headers)) + .retrieve() + .onStatus(Predicate.not(HttpStatusCode::is2xxSuccessful), errorHandler) + .toEntity(classType); + } + public T post( Class classType, String url, HttpHeaders headers, ErrorHandler errorHandler) { return client.post() .uri(url) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/GoogleRequestService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/GoogleRequestService.java index 1b378ab2..d5a46366 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/GoogleRequestService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/GoogleRequestService.java @@ -2,7 +2,10 @@ import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; import com.fasterxml.jackson.databind.annotation.JsonNaming; +import jakarta.annotation.PostConstruct; import java.util.Objects; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.ktc2.cokaen.wouldyouin._common.util.RestClientUtil; import org.ktc2.cokaen.wouldyouin._common.util.UriUtil; import org.ktc2.cokaen.wouldyouin.auth.application.oauth.dto.AccessTokenResponse; @@ -14,7 +17,9 @@ import org.springframework.http.MediaType; import org.springframework.stereotype.Service; +@Slf4j @Service +@RequiredArgsConstructor public class GoogleRequestService extends OauthRequestService { @Value("${oauth.google.uri.login.host}") @@ -39,13 +44,12 @@ public class GoogleRequestService extends OauthRequestService { private String redirectUri; private final RestClientUtil client; - private final String loginRequestUri; - private final String accessRequestUri; - private final HttpHeaders loginRequestHeaders; - - public GoogleRequestService(RestClientUtil restClientUtil) { - this.client = restClientUtil; + private String loginRequestUri; + private String accessRequestUri; + private HttpHeaders loginRequestHeaders; + @PostConstruct + private void init() { loginRequestUri = UriUtil.buildUrl("https", loginRequestHost, loginRequestPath); accessRequestUri = UriUtil.buildUrl("https", accessRequestHost, accessRequestPath); @@ -89,6 +93,8 @@ GoogleAccessRequestResponse.class, accessRequestUri, getAccessRequestHeaders(aut // TODO: 커스텀 예외 추가 (req, rsp) -> { throw new RuntimeException("에러"); }); + log.debug("#### GoogleAccessRequestResponse result = {}", result); + Objects.requireNonNull(result); return OauthResourcesResponse.builder() .socialId(result.id) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/KakaoRequestService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/KakaoRequestService.java index 22defe71..20d618fa 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/KakaoRequestService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/KakaoRequestService.java @@ -2,9 +2,12 @@ import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; import com.fasterxml.jackson.databind.annotation.JsonNaming; +import jakarta.annotation.PostConstruct; import java.util.Objects; import lombok.Getter; import lombok.RequiredArgsConstructor; +import lombok.ToString; +import lombok.extern.slf4j.Slf4j; import org.ktc2.cokaen.wouldyouin._common.util.RestClientUtil; import org.ktc2.cokaen.wouldyouin._common.util.UriUtil; import org.ktc2.cokaen.wouldyouin.auth.application.oauth.dto.AccessTokenResponse; @@ -16,9 +19,10 @@ import org.springframework.http.MediaType; import org.springframework.stereotype.Service; import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; +@Slf4j @Service +@RequiredArgsConstructor public class KakaoRequestService extends OauthRequestService { @Value("${oauth.kakao.uri.login.host}") @@ -48,28 +52,23 @@ protected AccountType getAccountType() { } private final RestClientUtil client; - private final String loginRequestUri; - private final String accessRequestUri; - private final HttpHeaders loginRequestHeaders; + private String accessRequestUri; + private HttpHeaders loginRequestHeaders; - public KakaoRequestService(RestClientUtil restClientUtil) { - this.client = restClientUtil; - - loginRequestUri = UriUtil.buildUrl("https", loginRequestHost, loginRequestPath, getLoginRequestQueryParams()); + @PostConstruct + private void init() { accessRequestUri = UriUtil.buildUrl("https", accessRequestHost, accessRequestPath); - loginRequestHeaders = new HttpHeaders(); loginRequestHeaders.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE); } - protected MultiValueMap getLoginRequestQueryParams() { - OauthRequest request = getOauthRequestBase(); + protected String getLoginRequestUri(OauthRequest request) { var queries = new LinkedMultiValueMap(); queries.add("grant_type", request.getGrantType()); queries.add("client_id", request.getClientId()); queries.add("client_secret", request.getClientSecret()); queries.add("code", request.getCode()); - return queries; + return UriUtil.buildUrl("https", loginRequestHost, loginRequestPath, queries); } protected HttpHeaders getAccessRequestHeaders(AccessTokenResponse authenticationResponse) { @@ -92,9 +91,11 @@ protected OauthRequest getOauthRequestBase() { @Override protected OauthResourcesResponse requestLoginAndAccessResources(OauthRequest request) { AccessTokenResponse authenticationResponse = client.post( - AccessTokenResponse.class, loginRequestUri, loginRequestHeaders, + AccessTokenResponse.class, getLoginRequestUri(request), loginRequestHeaders, // TODO: 커스텀 예외 추가 - (req, rsp) -> { throw new RuntimeException("에러"); }); + (req, rsp) -> { + throw new RuntimeException("에러"); + }); Objects.requireNonNull(authenticationResponse); KakaoAccessRequestResponse result = client.get( @@ -102,6 +103,8 @@ KakaoAccessRequestResponse.class, accessRequestUri, getAccessRequestHeaders(auth // TODO: 커스텀 예외 추가 (req, rsp) -> { throw new RuntimeException("에러"); }); + log.debug("#### KakaoAccessRequestResponse result = {}", result); + Objects.requireNonNull(result); return OauthResourcesResponse.builder() .socialId(result.getId().toString()) @@ -114,6 +117,7 @@ KakaoAccessRequestResponse.class, accessRequestUri, getAccessRequestHeaders(auth @JsonNaming(SnakeCaseStrategy.class) @RequiredArgsConstructor @Getter + @ToString static class KakaoAccessRequestResponse { private final Long id; @@ -123,6 +127,7 @@ static class KakaoAccessRequestResponse { @JsonNaming(SnakeCaseStrategy.class) @RequiredArgsConstructor @Getter + @ToString static class KakaoAccount { private final Profile profile; @@ -132,6 +137,7 @@ static class KakaoAccount { @JsonNaming(SnakeCaseStrategy.class) @RequiredArgsConstructor @Getter + @ToString static class Profile { private final String nickname; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/ImageController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/ImageController.java index d2b52044..d7fd69ca 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/ImageController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/ImageController.java @@ -38,6 +38,11 @@ public ResponseEntity getImage(@PathVariable String directory, @PathVari return ResponseEntity.status(HttpStatus.OK).body(imageStorageService.readFromDirectory(Paths.get(directory, file))); } + @GetMapping(value = "/{directory}/{thumbnail}/{file}", produces = {MediaType.IMAGE_PNG_VALUE, MediaType.IMAGE_JPEG_VALUE}) + public ResponseEntity getThumnailImage(@PathVariable String directory, @PathVariable String thumbnail, @PathVariable String file) { + return ResponseEntity.status(HttpStatus.OK).body(imageStorageService.readFromDirectory(Paths.get(directory, thumbnail, file))); + } + @PostMapping public ResponseEntity>> uploadImages( @RequestParam List images, diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageService.java index 24e4facd..e1baccab 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageService.java @@ -54,7 +54,7 @@ public void deleteImage(MemberIdentifier identifier, Long imageId) { } public String createThumbnail(String fileName) { - return imageStorageService.createThumbnailImage(getChildPath(), fileName); + return imageStorageService.createThumbnailImage(parentPath, getChildPath(), fileName); } public T getById(Long id) { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageStorageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageStorageService.java index 5a7ad62d..09b77453 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageStorageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageStorageService.java @@ -11,8 +11,10 @@ import org.ktc2.cokaen.wouldyouin._common.exception.FailedToUploadImageException; import org.ktc2.cokaen.wouldyouin._common.util.FileUtil; import org.ktc2.cokaen.wouldyouin._common.util.RestClientUtil; +import org.ktc2.cokaen.wouldyouin._common.util.UriUtil; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpHeaders; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; import org.springframework.web.multipart.MultipartFile; @@ -42,31 +44,36 @@ public byte[] readFromDirectory(Path childPath) { } public ImageRequest saveToDirectory(MultipartFile image, String childPath) { - String extension = FileUtil.getExtension(image); + String extension = FileUtil.getExtension(image.getContentType()); String fileName = FileUtil.createRandomFileName(extension); FileUtil.saveFile(image, Path.of(parentPath, childPath, fileName)); return ImageRequest.of(fileName, image.getSize(), extension); } public ImageRequest saveToDirectory(String imageUrl, String childPath) { - byte[] response = client.get(byte[].class, imageUrl, new HttpHeaders(), + ResponseEntity response = client.getResponseEntity(byte[].class, imageUrl, new HttpHeaders(), (req, rsp) -> { throw new FailedToUploadImageException("이미지 URL에 대한 요청을 실패하였습니다."); } ); - Optional.ofNullable(response).orElseThrow( + + String contentType = Optional.ofNullable(response.getHeaders().getContentType()).orElseThrow( + () -> new FailedToUploadImageException("응답 헤더에 콘텐츠 타입이 없어 이미지를 가져올 수 없습니다.") + ).toString(); + byte[] body = Optional.ofNullable(response.getBody()).orElseThrow( () -> new FailedToUploadImageException("응답 본문이 비어있어 이미지를 가져올 수 없습니다.") ); - String extension = FileUtil.getExtension(imageUrl); + + String extension = FileUtil.getExtension(contentType); String fileName = FileUtil.createRandomFileName(extension); Path path = Path.of(parentPath, childPath, fileName); - FileUtil.saveFile(response, path); - return ImageRequest.of(fileName, (long) response.length, extension); + FileUtil.saveFile(response.getBody(), path); + return ImageRequest.of(fileName, (long)body.length, extension); } // TODO : 썸네일 생성 코드 리팩토링, 파일 유틸로 이동 - public String createThumbnailImage(String childPath, String originFileName) { - String fileName = FileUtil.createRandomFileName(thumbnailExtension); + public String createThumbnailImage(String apiHeader, String childPath, String originFileName) { + String fileName = originFileName; String originImagePath = Path.of(parentPath, childPath, originFileName).toString(); String thumbnailImagePath = Path.of(parentPath, childPath, thumbnailChildPath).toString(); try { @@ -77,7 +84,7 @@ public String createThumbnailImage(String childPath, String originFileName) { } catch (Exception e) { throw new RuntimeException(e); } - return fileName; + return UriUtil.assembleFullUrl(apiHeader,childPath, thumbnailChildPath, fileName); } public void delete(String childPath, String fileName) { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/MemberResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/MemberResponse.java index 5ba6a985..3861e1c1 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/MemberResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/MemberResponse.java @@ -19,6 +19,7 @@ public class MemberResponse { private String nickname; private String phoneNumber; private String profileUrl; + private String profileThumbnailUrl; private MemberType memberType; private Area area; @@ -29,25 +30,27 @@ public class MemberResponse { private List hashtag; - private static MemberResponseBuilder responseBase(BaseMember baseMember) { + private static MemberResponseBuilder responseBase(BaseMember baseMember, String profileUrl) { return MemberResponse.builder() .memberId(baseMember.getId()) .nickname(baseMember.getNickname()) .phoneNumber(baseMember.getPhone()) - .profileUrl(baseMember.getProfileImage().getName()); + .profileUrl(profileUrl) + .profileThumbnailUrl(baseMember.getProfileImageThumbnailUrl()); + } // TODO: normal member임에도 불구, curator 형식이 호출되는 현상 수정필요 - public static MemberResponse from(final Member member) { - return responseBase(member) + public static MemberResponse from(final Member member, String profileUrl) { + return responseBase(member, profileUrl) .memberType(member.getMemberType()) .area(member.getArea()) .gender(member.getGender()) .build(); } - public static MemberResponse from(final Host host) { - return responseBase(host) + public static MemberResponse from(final Host host, String profileUrl) { + return responseBase(host, profileUrl) .memberType(host.getMemberType()) .intro(host.getIntro()) .likes(host.getLikes()) @@ -55,8 +58,8 @@ public static MemberResponse from(final Host host) { .build(); } - public static MemberResponse from(final Curator curator) { - return responseBase(curator) + public static MemberResponse from(final Curator curator, String profileUrl) { + return responseBase(curator, profileUrl) .memberType(curator.getMemberType()) .area(curator.getArea()) .gender(curator.getGender()) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/MemberAdditionalInfoRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/MemberAdditionalInfoRequest.java index 2f3ea13a..f7d2fffc 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/MemberAdditionalInfoRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/MemberAdditionalInfoRequest.java @@ -8,7 +8,7 @@ @RequiredArgsConstructor public class MemberAdditionalInfoRequest { - private final String phone; - private final Area area; - private final String gender; + private String phone; + private Area area; + private String gender; } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java index 836757a9..452e0601 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java @@ -32,7 +32,8 @@ public LikeableMemberService getLikeableMemberService() { @Override @Transactional(readOnly = true) public MemberResponse getMemberResponseById(Long id) { - return MemberResponse.from(getByIdOrThrow(id)); + Curator curator = getByIdOrThrow(id); + return MemberResponse.from(curator, memberImageService.getImageUrl(curator.getProfileImage())); } @Override @@ -73,18 +74,17 @@ public MemberResponse createCurator(Long normalMemberId) { baseMemberRepository.flush(); curatorRepository.save(curator); - return MemberResponse.from(curator); + return MemberResponse.from(curator, memberImageService.getImageUrl(curator.getProfileImage())); } - // TODO : 반대방향 연관관계 설정 setter? @Transactional public MemberResponse updateCurator(Long curatorId, CuratorEditRequest request) { Curator curator = getByIdOrThrow(curatorId); MemberImage image = memberImageService.getById(request.getProfileImageId()); String thumbnailImageUrl = memberImageService.createThumbnail(image.getName()); curator.updateFrom(request, image, thumbnailImageUrl); - image.setBaseMember(curator); - return MemberResponse.from(curator); + memberImageService.setBaseMember(image, curator); + return MemberResponse.from(curator, memberImageService.getImageUrl(curator.getProfileImage())); } @Override diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java index de747ed0..083e3603 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java @@ -30,7 +30,7 @@ public MemberResponse createHost(HostCreateRequest request) { String profileImageThumbnailUrl = memberImageService.createThumbnail(profileImage.getName()); Host createdHost = hostRepository.save(request.toEntity(hashedPassword, profileImage, profileImageThumbnailUrl)); memberImageService.setBaseMember(profileImage, createdHost); - return MemberResponse.from(createdHost); + return MemberResponse.from(createdHost, memberImageService.getImageUrl(profileImage)); } // TODO: 리팩토링할것 @@ -49,7 +49,7 @@ public MemberResponse updateHost(Long hostId, HostEditRequest request) { host.setProfileImageThumbnailUrl(url); }); - return MemberResponse.from(host); + return MemberResponse.from(host, memberImageService.getImageUrl(host.getProfileImage())); } @Override @@ -61,16 +61,15 @@ public void deleteById(Long id) { @Override @Transactional(readOnly = true) public MemberResponse getMemberResponseById(Long id) { - return MemberResponse.from(getByIdOrThrow(id)); + Host host = getByIdOrThrow(id); + return MemberResponse.from(host, memberImageService.getImageUrl(host.getProfileImage())); } @Transactional(readOnly = true) public MemberResponse getMemberResponseBy(LocalLoginRequest loginRequest) { - return MemberResponse.from(hostRepository - .findByEmailAndHashedPassword( - loginRequest.email(), - passwordEncoder.encode(loginRequest.password())) - .orElseThrow(RuntimeException::new)); + Host host = hostRepository.findByEmailAndHashedPassword(loginRequest.email(), passwordEncoder.encode(loginRequest.password())) + .orElseThrow(RuntimeException::new); + return MemberResponse.from(host, memberImageService.getImageUrl(host.getProfileImage())); } @Transactional(readOnly = true) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/MemberService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/MemberService.java index 1e95c56e..79c5527e 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/MemberService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/MemberService.java @@ -26,7 +26,9 @@ public class MemberService implements MemberServiceCommonBehavior { public MemberResponse createMember(MemberCreateRequest request) { MemberImage profileImage = memberImageService.convert(request.getProfileImageUrl()); String thumbnailImageUrl = memberImageService.createThumbnail(profileImage.getName()); - return MemberResponse.from(memberRepository.save(request.toEntity(profileImage, thumbnailImageUrl))); + Member member = memberRepository.save(request.toEntity(profileImage, thumbnailImageUrl)); + memberImageService.setBaseMember(profileImage, member); + return MemberResponse.from(member, memberImageService.getImageUrl(profileImage)); } // TODO : 리팩토링 꼭 할 것, 멤버 전체에 대해 연관관계 설정할 것 @@ -43,18 +45,19 @@ public MemberResponse updateMember(Long memberId, MemberEditRequest editRequest) String url = memberImageService.createThumbnail(memberImageService.createThumbnail(image.getName())); member.setProfileImageThumbnailUrl(url); }); - return MemberResponse.from(member); + return MemberResponse.from(member, memberImageService.getImageUrl(member.getProfileImage())); } @Transactional public MemberResponse updateWelcomeMember(Long welcomeMemberId, MemberAdditionalInfoRequest additionalInfoRequest) { Member member = getByIdOrThrow(welcomeMemberId); + // TODO : validate if (member.getMemberType() != MemberType.welcome) { // TODO: 커스텀 예외 필요 throw new RuntimeException("Welcome Member가 아닙니다."); } member.updateFrom(additionalInfoRequest); - return MemberResponse.from(member); + return MemberResponse.from(member, memberImageService.getImageUrl(member.getProfileImage())); } @Override @@ -66,7 +69,8 @@ public void deleteById(Long id) { @Override @Transactional(readOnly = true) public MemberResponse getMemberResponseById(Long id) { - return MemberResponse.from(getByIdOrThrow(id)); + Member member = getByIdOrThrow(id); + return MemberResponse.from(member, memberImageService.getImageUrl(member.getProfileImage())); } @Transactional(readOnly = true) diff --git a/src/main/resources/application-deploy.yml b/src/main/resources/application-deploy.yml index a23c61e7..329c63a0 100644 --- a/src/main/resources/application-deploy.yml +++ b/src/main/resources/application-deploy.yml @@ -8,4 +8,6 @@ spring: on-profile: deploy jpa: hibernate: - ddl-auto: update \ No newline at end of file + ddl-auto: update + datasource: + url: ${DATASOURCE_URL}?useSSL=true&useUnicode=true&serverTimezone=Asia/Seoul \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index f3502ff5..fef18b26 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -23,7 +23,7 @@ spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver - url: ${DATASOURCE_URL}?useSSL=false&useUnicode=true&serverTimezone=Asia/Seoul + url: ${DATASOURCE_URL}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&serverTimezone=Asia/Seoul username: ${DATASOURCE_USERNAME} password: ${DATASOURCE_PASSWORD} From 6d33db873648fe2c3422a3b86c2420b23f7d43fb Mon Sep 17 00:00:00 2001 From: ariimo Date: Thu, 14 Nov 2024 06:13:28 +0900 Subject: [PATCH 30/53] =?UTF-8?q?[Weekly/11/Refactor/All]=20getUnreviewedE?= =?UTF-8?q?ventsByMemberId=20=EB=A1=9C=EC=A7=81=20=EC=83=9D=EC=84=B1=20(#1?= =?UTF-8?q?29)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: getUnreviewedEventsByMemberId 로직 생성 * fix: Review Repository 오류 해결 --- .../ReviewEventSliceResponse.java | 25 +++++++++++++++++++ .../event/application/EventService.java | 2 +- .../event/persist/EventRepository.java | 2 +- .../wouldyouin/member/persist/BaseMember.java | 2 +- .../persist/ReservationRepository.java | 2 +- .../review/api/ReviewController.java | 11 ++++++++ .../review/application/ReviewService.java | 13 +++++++++- .../review/persist/ReviewRepository.java | 7 ++++++ 8 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/ReviewEventSliceResponse.java diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/ReviewEventSliceResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/ReviewEventSliceResponse.java new file mode 100644 index 00000000..7afc3b9c --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/ReviewEventSliceResponse.java @@ -0,0 +1,25 @@ +package org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse; + +import java.util.List; +import lombok.Builder; +import lombok.Getter; +import org.ktc2.cokaen.wouldyouin._common.api.SliceInfo; + +@Getter +@Builder +public class ReviewEventSliceResponse { + + private List reviewEvents; + private SliceInfo sliceInfo; + + public static ReviewEventSliceResponse from(List reviewEvents, int size, + Long lastId) { + return ReviewEventSliceResponse.builder() + .reviewEvents(reviewEvents) + .sliceInfo(SliceInfo.builder() + .sliceSize(size) + .lastId(lastId) + .build()) + .build(); + } +} diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java index cf1875d9..4471ee21 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java @@ -124,7 +124,7 @@ public void decreaseLeftSeat(Long eventId, Integer count) { event.decreaseLeftSeat(count); } - private static Long getLastId(Slice events, Long oldLastId) { + public static Long getLastId(Slice events, Long oldLastId) { if (events.hasContent()) { return events.getContent().getLast().getId(); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/EventRepository.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/EventRepository.java index 833b7a0d..4a48d468 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/EventRepository.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/EventRepository.java @@ -12,7 +12,7 @@ public interface EventRepository extends JpaRepository { @Query("SELECT E FROM Event E JOIN FETCH E.host " - + "WHERE E.host.Id = :hostId " + + "WHERE E.host.id = :hostId " + "AND E.id > :lastId " + "ORDER BY E.id DESC") Slice findAllByHostIdOrderByEventIdDesc(Long hostId, Long lastId, Pageable pageable); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java index c62b9667..ca832894 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java @@ -29,7 +29,7 @@ public abstract class BaseMember { @Setter(AccessLevel.NONE) @GeneratedValue(strategy = GenerationType.IDENTITY) // TODO: 네이밍 소문자로 바꾸기 - private Long Id; + private Long id; @Column(nullable = false) @Enumerated(EnumType.STRING) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/ReservationRepository.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/ReservationRepository.java index cc3bcbc2..5c7b726b 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/ReservationRepository.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/ReservationRepository.java @@ -10,7 +10,7 @@ public interface ReservationRepository extends JpaRepository { @Query("SELECT R FROM Reservation R JOIN FETCH R.member JOIN FETCH R.event " - + "WHERE R.member.Id = :memberId AND R.id > :lastId " + + "WHERE R.member.id = :memberId AND R.id > :lastId " + "ORDER BY R.id DESC") Slice findByMemberIdOrderByReservationIdDesc(Long memberId, Long lastId, Pageable pageable); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/ReviewController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/ReviewController.java index af5f422a..eb0bc47f 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/ReviewController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/ReviewController.java @@ -7,6 +7,8 @@ import org.ktc2.cokaen.wouldyouin._common.api.ParamDefaults; import org.ktc2.cokaen.wouldyouin.auth.Authorize; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; +import org.ktc2.cokaen.wouldyouin.event.api.dto.EventSliceResponse; +import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.ReviewEventSliceResponse; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.ktc2.cokaen.wouldyouin.review.api.dto.ReviewCreateRequest; import org.ktc2.cokaen.wouldyouin.review.api.dto.ReviewEditRequest; @@ -58,6 +60,15 @@ public ResponseEntity> getReviewByReviewId( return ApiResponse.ok(reviewService.getById(reviewId)); } + @GetMapping("events") + public ResponseEntity> getUnreviewedEventsByMemberId( + @Authorize(MemberType.normal) MemberIdentifier identifier, + @RequestParam(defaultValue = ParamDefaults.PAGE) Integer page, + @RequestParam(defaultValue = ParamDefaults.PAGE_SIZE) Integer size, + @RequestParam(defaultValue = ParamDefaults.LAST_ID) Long lastId){ + return ApiResponse.ok(reviewService.getUnreviewedEventsByMemberId(identifier.id(), PageRequest.of(page, size), lastId)); + } + @PostMapping public ResponseEntity> createReview( @Authorize(MemberType.normal) MemberIdentifier member, diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/review/application/ReviewService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/review/application/ReviewService.java index 77b7c570..94f9fe51 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/review/application/ReviewService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/review/application/ReviewService.java @@ -1,13 +1,15 @@ package org.ktc2.cokaen.wouldyouin.review.application; +import java.util.List; import lombok.AccessLevel; import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; +import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.ReviewEventResponse; +import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.ReviewEventSliceResponse; import org.ktc2.cokaen.wouldyouin.event.application.EventService; import org.ktc2.cokaen.wouldyouin.event.persist.Event; import org.ktc2.cokaen.wouldyouin.member.application.MemberService; -import org.ktc2.cokaen.wouldyouin.member.persist.Member; import org.ktc2.cokaen.wouldyouin.reservation.application.ReservationService; import org.ktc2.cokaen.wouldyouin.review.api.dto.ReviewCreateRequest; import org.ktc2.cokaen.wouldyouin.review.api.dto.ReviewEditRequest; @@ -57,6 +59,15 @@ private Long getLastId(Slice reviews, Long oldLastId) { return oldLastId; } + @Transactional + public ReviewEventSliceResponse getUnreviewedEventsByMemberId(Long memberId, Pageable pageable, Long beforeLastId) { + Slice unreviewedEvents = reviewRepository.findUnreviewedEventsByMemberId(memberId, beforeLastId, pageable); + Long newLastId = EventService.getLastId(unreviewedEvents, beforeLastId); + List responses = unreviewedEvents.stream() + .map(ReviewEventResponse::from).toList(); + return ReviewEventSliceResponse.from(responses, unreviewedEvents.getSize(), newLastId); + } + @Transactional public ReviewResponse create(Long memberId, ReviewCreateRequest reviewCreateRequest) { reservationService.validateByMemberIdAndEventId(memberId, reviewCreateRequest.getEventId()); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/review/persist/ReviewRepository.java b/src/main/java/org/ktc2/cokaen/wouldyouin/review/persist/ReviewRepository.java index d06dcc58..06eb296e 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/review/persist/ReviewRepository.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/review/persist/ReviewRepository.java @@ -1,5 +1,6 @@ package org.ktc2.cokaen.wouldyouin.review.persist; +import org.ktc2.cokaen.wouldyouin.event.persist.Event; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; import org.springframework.data.jpa.repository.JpaRepository; @@ -18,4 +19,10 @@ public interface ReviewRepository extends JpaRepository { + "WHERE R.event.id = :eventId AND R.id > :lastId " + "ORDER BY R.id DESC") Slice findByEventIdOrderByReviewIdDesc(Long eventId, Long lastId, Pageable pageable); + + @Query("select r, e from Review r Join fetch r.event e " + + "where r.member.id = :memberId " + + "And e.id < :lastId " + + "And e.id not in (select rv.event.id from Review rv where rv.member.id = :memberId) ") + Slice findUnreviewedEventsByMemberId(Long memberId, Long lastId, Pageable pageable); } From 34348391a074ea8de9c3a528723cb2d2c38b9859 Mon Sep 17 00:00:00 2001 From: ariimo Date: Thu, 14 Nov 2024 06:43:19 +0900 Subject: [PATCH 31/53] [Weekly/11/Refactor/All] fix: memberData (#130) --- .../cokaen/wouldyouin/_global/testdata/MemberData.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java index 054396a0..fa45a36e 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java @@ -126,7 +126,7 @@ public static Member get() { .gender(R.normal1.gender) .socialId(R.normal1.socialId) .build(); - ReflectionTestUtils.setField(ret, "Id", R.normal1.id); + ReflectionTestUtils.setField(ret, "id", R.normal1.id); ReflectionTestUtils.setField(ret, "memberType", R.normal1.memberType); // ReflectionTestUtils.setField(ret.getProfileImage(), "baseMember", ret); return ret; @@ -154,7 +154,7 @@ public static Curator get() { .gender(R.curator1.gender) .socialId(R.curator1.socialId) .build(); - ReflectionTestUtils.setField(ret, "Id", R.curator1.id); + ReflectionTestUtils.setField(ret, "id", R.curator1.id); ReflectionTestUtils.setField(ret, "intro", R.curator1.intro); ReflectionTestUtils.setField(ret, "hashtags", R.curator1.hashtags); // ReflectionTestUtils.setField(ret.getProfileImage(), "baseMember", ret); @@ -180,7 +180,7 @@ public static Host get() { .profileImage(R.host1.profileImage) .profileImageThumbnailUrl(R.host1.profileImageThumbnailUrl) .build(); - ReflectionTestUtils.setField(ret, "Id", R.host1.id); + ReflectionTestUtils.setField(ret, "id", R.host1.id); ReflectionTestUtils.setField(ret, "intro", R.host1.intro); ReflectionTestUtils.setField(ret, "hashtags", R.host1.hashtags); // ReflectionTestUtils.setField(ret.getProfileImage(), "baseMember", ret); @@ -209,7 +209,7 @@ public static Member get() { .gender(R.welcome1.gender) .socialId(R.welcome1.socialId) .build(); - ReflectionTestUtils.setField(ret, "Id", R.welcome1.id); + ReflectionTestUtils.setField(ret, "id", R.welcome1.id); // ReflectionTestUtils.setField(ret.getProfileImage(), "baseMember", ret); return ret; } From 75b60da8daf33c214efd8647f0aee01c23a2596f Mon Sep 17 00:00:00 2001 From: ariimo Date: Thu, 14 Nov 2024 19:16:18 +0900 Subject: [PATCH 32/53] =?UTF-8?q?[Weekly/11/Refactor/All]=20refactor:=20Ad?= =?UTF-8?q?vertisement,=20Event=20=EC=9C=A0=ED=9A=A8=EC=84=B1=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=84=B0=EB=A7=81=20(#131)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../advertisement/api/AdvertisementController.java | 4 ++-- .../api/dto/AdvertisementRequest.java | 3 ++- .../application/AdvertisementService.java | 2 +- .../advertisement/persist/Advertisement.java | 14 ++++++++------ .../event/api/dto/EventCreateRequest.java | 3 +++ .../wouldyouin/event/api/dto/EventEditRequest.java | 3 +++ .../cokaen/wouldyouin/event/persist/Event.java | 7 ++++++- .../wouldyouin/event/EventControllerUnitTest.java | 14 +++++++------- 8 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/AdvertisementController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/AdvertisementController.java index 1fde187e..92487102 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/AdvertisementController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/AdvertisementController.java @@ -38,14 +38,14 @@ public ResponseEntity>> getActiveAdv @GetMapping("/{adId}") public ResponseEntity> getAdvertisementByAdId( @PathVariable Long adId) { - return ApiResponse.ok(advertisementService.getAdvertisementByAdId(adId)); + return ApiResponse.ok(advertisementService.getById(adId)); } @PostMapping(consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE}) public ResponseEntity> createAdvertisement( @Valid @RequestPart AdvertisementRequest advertisementRequest, @RequestPart(required = false) MultipartFile image, - @Authorize(MemberType.admin) MemberIdentifier admin) { + @Authorize(MemberType.admin) MemberIdentifier identifier) { return ApiResponse.created(advertisementService.create(advertisementRequest, image)); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/dto/AdvertisementRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/dto/AdvertisementRequest.java index ca4a5940..32f404b0 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/dto/AdvertisementRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/dto/AdvertisementRequest.java @@ -2,6 +2,7 @@ import jakarta.validation.constraints.AssertTrue; import jakarta.validation.constraints.FutureOrPresent; +import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; import java.time.LocalDateTime; @@ -14,7 +15,7 @@ @Builder(toBuilder = true) public class AdvertisementRequest { - @NotEmpty(message = "광고명은 필수입니다.") + @NotBlank(message = "광고명은 필수입니다.") private String title; @NotNull(message = "광고게시 시작 시간은 필수입니다.") diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java index 10a1b4a2..28c2f647 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java @@ -30,7 +30,7 @@ public Advertisement getByIdOrThrow(Long adId) { } @Transactional(readOnly = true) - public AdvertisementResponse getAdvertisementByAdId(Long adId) { + public AdvertisementResponse getById(Long adId) { return AdvertisementResponse.from(getByIdOrThrow(adId)); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/persist/Advertisement.java b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/persist/Advertisement.java index f449387f..9fc4b593 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/persist/Advertisement.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/persist/Advertisement.java @@ -7,8 +7,10 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.OneToOne; +import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; import java.time.LocalDateTime; +import java.util.Optional; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -25,11 +27,11 @@ public class Advertisement { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "advertisement_id") @Setter(AccessLevel.NONE) + @Column(name = "advertisement_id") private Long id; - @NotNull + @NotBlank @Column(name = "title") private String title; @@ -57,9 +59,9 @@ public Advertisement(String title, AdvertisementImage advertisementImage, } public void updateFrom(AdvertisementRequest advertisementRequest, AdvertisementImage adImage) { - this.title = advertisementRequest.getTitle(); - this.advertisementImage = adImage; - this.startTime = advertisementRequest.getStartTime(); - this.endTime = advertisementRequest.getEndTime(); + Optional.ofNullable(advertisementRequest.getTitle()).ifPresent(this::setTitle); + Optional.ofNullable(adImage).ifPresent(this::setAdvertisementImage); + Optional.ofNullable(advertisementRequest.getStartTime()).ifPresent(this::setStartTime); + Optional.ofNullable(advertisementRequest.getEndTime()).ifPresent(this::setEndTime); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java index 12a22650..d7dba272 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java @@ -37,9 +37,11 @@ public class EventCreateRequest { @NotNull(message = "장소는 필수입니다.") private Location location; + @NotNull(message = "시작시간은 필수입니다.") @FutureOrPresent(message = "시작 시간은 현재 시간 이후여야 합니다.") private LocalDateTime startTime; + @NotNull(message = "종료시간은 필수입니다.") @FutureOrPresent(message = "종료 시간은 현재 시간 이후여야 합니다.") private LocalDateTime endTime; @@ -48,6 +50,7 @@ public class EventCreateRequest { @Max(value = 1000000, message = "가격은 1,000,000원 이하입니다.") private Integer price; + @NotNull(message = "좌석입력은 필수입니다.") @Min(value = 0, message = "총 좌석은 0석 이상입니다.") @Max(value = 1000, message = "총 좌석은 1,000석 이하입니다.") private Integer totalSeat; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventEditRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventEditRequest.java index aff0cd41..3eff3c54 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventEditRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventEditRequest.java @@ -34,9 +34,11 @@ public class EventEditRequest { @NotNull(message = "장소는 필수입니다.") private Location location; + @NotNull(message = "시작 시간은 필수입니다.") @FutureOrPresent(message = "시작 시간은 현재 시간 이후여야 합니다.") private LocalDateTime startTime; + @NotNull(message = "종료 시간은 필수입니다.") @FutureOrPresent(message = "종료 시간은 현재 시간 이후여야 합니다.") private LocalDateTime endTime; @@ -45,6 +47,7 @@ public class EventEditRequest { @Max(value = 1000000, message = "가격은 1,000,000원 이하입니다.") private Integer price; + @NotNull(message = "좌석은 필수입니다.") @Min(value = 0, message = "총 좌석은 0석 이상입니다.") @Max(value = 1000, message = "총 좌석은 1,000석 이하입니다.") private Integer totalSeat; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java index 4451519d..646b977d 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java @@ -47,7 +47,7 @@ public class Event { @Column(name = "event_id") private Long id; - @NotNull + @NotBlank @Column(name = "title") private String title; @@ -70,9 +70,11 @@ public class Event { @Column(name = "location") private Location location; + @NotNull @Column(name = "start_time") private LocalDateTime startTime; + @NotNull @Column(name = "end_time") private LocalDateTime endTime; @@ -81,10 +83,12 @@ public class Event { @Column(name = "price") private Integer price; + @NotNull @Min(1) @Column(name = "total_seat") private Integer totalSeat; + @NotNull @Min(0) @Column(name = "left_seat") private Integer leftSeat; @@ -101,6 +105,7 @@ public class Event { @OneToMany(mappedBy = "event", fetch = FetchType.LAZY) private List images = new ArrayList<>(); + @NotNull @CreatedDate @Column(name = "created_date") private LocalDateTime createdDate; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java index 29acc469..c2f53361 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java @@ -67,13 +67,13 @@ // @Autowired // private WebApplicationContext context; // -// @BeforeAll -// public static void init() { -// id = 3L; -// validHost = entity.get(); -// objectMapper = new ObjectMapper(); -// objectMapper.registerModule(new JavaTimeModule()); -// } +//// @BeforeAll +//// public static void init() { +//// id = 3L; +//// validHost = entity.get(); +//// objectMapper = new ObjectMapper(); +//// objectMapper.registerModule(new JavaTimeModule()); +//// } // // @BeforeEach // public void setup() throws Exception { From 9ef0f287c83ece2cc7b1c6ffb1e58817a5812bb6 Mon Sep 17 00:00:00 2001 From: Jangan Lee Date: Thu, 14 Nov 2024 21:51:16 +0900 Subject: [PATCH 33/53] =?UTF-8?q?[Weekly/11/Refactor/ExtractTestCreateApi]?= =?UTF-8?q?=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=83=9D=EC=84=B1=20api=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC=20(#132)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_develop/api/TempCreateController.java | 80 +++++++++++++++++++ .../api}/TempLoginController.java | 8 +- .../member/api/CuratorController.java | 6 -- .../member/api/MemberController.java | 25 ------ .../wouldyouin/member/persist/BaseMember.java | 1 - 5 files changed, 85 insertions(+), 35 deletions(-) create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/_develop/api/TempCreateController.java rename src/main/java/org/ktc2/cokaen/wouldyouin/{auth/temp => _develop/api}/TempLoginController.java (86%) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_develop/api/TempCreateController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_develop/api/TempCreateController.java new file mode 100644 index 00000000..ef6b0557 --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_develop/api/TempCreateController.java @@ -0,0 +1,80 @@ +package org.ktc2.cokaen.wouldyouin._develop.api; + +import jakarta.validation.Valid; +import java.util.Map; +import lombok.RequiredArgsConstructor; +import org.ktc2.cokaen.wouldyouin._common.api.ApiResponse; +import org.ktc2.cokaen.wouldyouin._common.api.ApiResponseBody; +import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; +import org.ktc2.cokaen.wouldyouin.auth.api.dto.TokenResponse; +import org.ktc2.cokaen.wouldyouin.auth.application.JwtService; +import org.ktc2.cokaen.wouldyouin.member.api.dto.MemberResponse; +import org.ktc2.cokaen.wouldyouin.member.api.dto.request.create.HostCreateRequest; +import org.ktc2.cokaen.wouldyouin.member.api.dto.request.create.MemberCreateRequest; +import org.ktc2.cokaen.wouldyouin.member.application.BaseMemberService; +import org.ktc2.cokaen.wouldyouin.member.application.CuratorService; +import org.ktc2.cokaen.wouldyouin.member.application.HostService; +import org.ktc2.cokaen.wouldyouin.member.application.MemberService; +import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/test") +public class TempCreateController { + + private final BaseMemberService baseMemberService; + private final MemberService memberService; + private final HostService hostService; + private final CuratorService curatorService; + private final JwtService jwtService; + + // 테스트: 사용자 생성 + @PostMapping("/create/member") + public ResponseEntity>> testCreateMember(@Valid @RequestBody MemberCreateRequest request) { + MemberResponse response = memberService.createMember(request); + MemberIdentifier identifier = new MemberIdentifier(response.getMemberId(), response.getMemberType()); + return ApiResponse.created(Map.of("response", response, "token", createToken(identifier))); + } + + // 테스트: 호스트 생성 + @PostMapping("/create/host") + public ResponseEntity>> testCreateHost(@RequestBody HostCreateRequest request) { + MemberResponse response = hostService.createHost(request); + MemberIdentifier identifier = new MemberIdentifier(response.getMemberId(), response.getMemberType()); + return ApiResponse.created(Map.of("response", response, "token", createToken(identifier))); + } + + // 테스트: 큐레이터 생성 + @PostMapping("/create/curator") + public ResponseEntity>> testCreateCurator(@RequestParam("memberId") Long id) { + MemberResponse response = curatorService.createCurator(id); + MemberIdentifier identifier = new MemberIdentifier(response.getMemberId(), response.getMemberType()); + return ApiResponse.created(Map.of("response", response, "token", createToken(identifier))); + } + + // 테스트: 사용자 삭제 + @DeleteMapping("/delete/{memberId}") + public void testDeleteMember(@PathVariable("memberId") Long id) { + // TODO: 204 NO CONTENT 반환하게 수정필요 + baseMemberService.deleteById(id); + } + + @GetMapping("create/token") + public ResponseEntity> testCreateToken( + @RequestParam("memberId") Long memberId, @RequestParam("type") MemberType memberType) { + return ApiResponse.ok(createToken(new MemberIdentifier(memberId, memberType))); + } + + private TokenResponse createToken(MemberIdentifier identifier) { + return TokenResponse.from(jwtService.createAccessToken(identifier.id(), identifier.type())); + } +} diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/temp/TempLoginController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_develop/api/TempLoginController.java similarity index 86% rename from src/main/java/org/ktc2/cokaen/wouldyouin/auth/temp/TempLoginController.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/_develop/api/TempLoginController.java index a3c15467..d3ccc541 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/temp/TempLoginController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_develop/api/TempLoginController.java @@ -1,11 +1,13 @@ -package org.ktc2.cokaen.wouldyouin.auth.temp; +package org.ktc2.cokaen.wouldyouin._develop.api; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; -@Controller +@Controller() +@RequestMapping("/api/test") public class TempLoginController { @Value("${oauth.kakao.client.id}") @@ -20,7 +22,7 @@ public class TempLoginController { @Value("${oauth.google.redirect_uri}") private String googleRedirectUri; - @GetMapping("/social-login-test") + @GetMapping("/social-login") public String LoginPage(Model model) { String googleSocialLoginUri = "https://accounts.google.com/o/oauth2/auth" + diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/CuratorController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/CuratorController.java index 49aa49b7..646b84a7 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/CuratorController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/CuratorController.java @@ -24,12 +24,6 @@ public class CuratorController { private final CuratorService curatorService; - // 테스트: 큐레이터 생성 - @PostMapping("/test-create/{memberId}") - public ResponseEntity> testCreateCurator(@PathVariable("memberId") Long id) { - return ApiResponse.created(curatorService.createCurator(id)); - } - @PostMapping public ResponseEntity> createCurator(@Authorize(MemberType.normal) MemberIdentifier identifier) { return ApiResponse.created(curatorService.createCurator(identifier.id())); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/MemberController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/MemberController.java index f68765b3..4c8f4119 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/MemberController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/MemberController.java @@ -1,24 +1,19 @@ package org.ktc2.cokaen.wouldyouin.member.api; -import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponse; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponseBody; import org.ktc2.cokaen.wouldyouin.auth.Authorize; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.member.application.BaseMemberService; -import org.ktc2.cokaen.wouldyouin.member.application.HostService; import org.ktc2.cokaen.wouldyouin.member.application.MemberService; import org.ktc2.cokaen.wouldyouin.member.api.dto.MemberResponse; -import org.ktc2.cokaen.wouldyouin.member.api.dto.request.create.HostCreateRequest; -import org.ktc2.cokaen.wouldyouin.member.api.dto.request.create.MemberCreateRequest; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit.MemberEditRequest; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -31,26 +26,6 @@ public class MemberController { private final BaseMemberService baseMemberService; private final MemberService memberService; - private final HostService hostService; - - // 테스트: 사용자 생성 - @PostMapping("/test-create/member") - public ResponseEntity> testCreateMember(@Valid @RequestBody MemberCreateRequest request) { - return ApiResponse.created(memberService.createMember(request)); - } - - // 테스트: 호스트 생성 - @PostMapping("/test-create/host") - public ResponseEntity> testCreateHost(@RequestBody HostCreateRequest hostCreateRequest) { - return ApiResponse.created(hostService.createHost(hostCreateRequest)); - } - - // 테스트: 사용자 삭제 - @DeleteMapping("/test-delete/{memberId}") - public void testDeleteMember(@PathVariable("memberId") Long id) { - // TODO: 204 NO CONTENT 반환하게 수정필요 - baseMemberService.deleteById(id); - } // 사용자 수정 @PutMapping diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java index ca832894..21621919 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java @@ -28,7 +28,6 @@ public abstract class BaseMember { @Id @Setter(AccessLevel.NONE) @GeneratedValue(strategy = GenerationType.IDENTITY) - // TODO: 네이밍 소문자로 바꾸기 private Long id; @Column(nullable = false) From 8d2fe30b7996cfd8be6d6d236ee00a59df012aa0 Mon Sep 17 00:00:00 2001 From: Jangan Lee Date: Thu, 14 Nov 2024 22:20:41 +0900 Subject: [PATCH 34/53] =?UTF-8?q?[Weekly/11/Feature/addEquals-HashCode-ToS?= =?UTF-8?q?tring]=20equals,=20hashcode,=20toString=20=EA=B5=AC=ED=98=84,?= =?UTF-8?q?=20import=20=EC=B5=9C=EC=A0=81=ED=99=94=20(#133)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cokaen/wouldyouin/_common/api/ApiResponseBody.java | 4 ++++ .../cokaen/wouldyouin/_common/api/ParamDefaults.java | 5 +++++ .../ktc2/cokaen/wouldyouin/_common/api/SliceInfo.java | 4 ++++ .../wouldyouin/_common/error/GlobalExceptionHandler.java | 2 +- .../org/ktc2/cokaen/wouldyouin/_common/vo/Location.java | 4 ++++ .../advertisement/api/dto/AdvertisementRequest.java | 7 +++++-- .../advertisement/api/dto/AdvertisementResponse.java | 4 ++++ .../advertisement/application/AdvertisementService.java | 4 ++-- .../wouldyouin/advertisement/persist/Advertisement.java | 6 +++++- .../ktc2/cokaen/wouldyouin/auth/api/AuthController.java | 2 +- .../wouldyouin/auth/api/dto/LocalSignupRequest.java | 4 ++++ .../cokaen/wouldyouin/auth/application/AuthService.java | 6 +++--- .../wouldyouin/auth/persist/CustomUserDetails.java | 4 ++++ .../wouldyouin/curation/api/dto/CurationCardRequest.java | 4 +++- .../curation/api/dto/CurationCardResponse.java | 5 ++++- .../curation/api/dto/CurationCreateRequest.java | 2 ++ .../wouldyouin/curation/api/dto/CurationEditRequest.java | 2 ++ .../wouldyouin/curation/api/dto/CurationResponse.java | 2 ++ .../curation/api/dto/CurationSliceResponse.java | 6 ++++-- .../curation/application/CurationCardService.java | 4 ++-- .../wouldyouin/curation/application/CurationService.java | 4 ++-- .../cokaen/wouldyouin/curation/persist/Curation.java | 4 ++++ .../cokaen/wouldyouin/curation/persist/CurationCard.java | 4 ++++ .../wouldyouin/event/api/dto/EventCreateRequest.java | 6 +++++- .../wouldyouin/event/api/dto/EventEditRequest.java | 4 ++++ .../cokaen/wouldyouin/event/api/dto/EventResponse.java | 4 ++++ .../wouldyouin/event/api/dto/EventSliceResponse.java | 4 ++++ .../cokaen/wouldyouin/event/api/dto/LocationFilter.java | 4 ++++ .../cokaen/wouldyouin/event/api/dto/LocationRequest.java | 5 ++++- .../api/dto/relationResonse/CurationEventResponse.java | 4 ++++ .../dto/relationResonse/ReservationEventResponse.java | 4 ++++ .../api/dto/relationResonse/ReviewEventResponse.java | 4 ++++ .../dto/relationResonse/ReviewEventSliceResponse.java | 4 ++++ .../wouldyouin/event/application/EventService.java | 6 +++--- .../org/ktc2/cokaen/wouldyouin/event/persist/Event.java | 6 +++++- .../cokaen/wouldyouin/image/api/ImageController.java | 6 +++--- .../cokaen/wouldyouin/image/api/dto/ImageRequest.java | 4 ++++ .../cokaen/wouldyouin/image/api/dto/ImageResponse.java | 4 ++++ .../image/application/AdvertisementImageService.java | 6 +++--- .../image/application/CurationImageService.java | 6 +++--- .../wouldyouin/image/application/EventImageService.java | 6 +++--- .../wouldyouin/image/application/ImageService.java | 6 +++--- .../image/application/ImageStorageService.java | 2 +- .../wouldyouin/image/application/MemberImageService.java | 4 ++-- .../wouldyouin/image/persist/AdvertisementImage.java | 4 ++++ .../cokaen/wouldyouin/image/persist/CurationImage.java | 4 ++++ .../ktc2/cokaen/wouldyouin/image/persist/EventImage.java | 4 ++++ .../org/ktc2/cokaen/wouldyouin/image/persist/Image.java | 4 ++++ .../cokaen/wouldyouin/image/persist/MemberImage.java | 4 ++++ .../cokaen/wouldyouin/like/api/dto/LikeResponse.java | 4 ++++ .../wouldyouin/like/api/dto/LikeSliceResponse.java | 4 ++++ .../wouldyouin/like/api/dto/LikeToggleResponse.java | 4 ++++ .../ktc2/cokaen/wouldyouin/like/persist/CuratorLike.java | 4 ++++ .../ktc2/cokaen/wouldyouin/like/persist/HostLike.java | 4 ++++ .../org/ktc2/cokaen/wouldyouin/like/persist/Like.java | 4 ++++ .../cokaen/wouldyouin/like/persist/LikeRepository.java | 1 - .../cokaen/wouldyouin/member/api/CuratorController.java | 3 +-- .../cokaen/wouldyouin/member/api/HostController.java | 4 ++-- .../cokaen/wouldyouin/member/api/MemberController.java | 4 ++-- .../cokaen/wouldyouin/member/api/dto/MemberResponse.java | 9 ++++++--- .../dto/relationResponse/CurationCuratorResponse.java | 4 ++++ .../api/dto/relationResponse/EventHostResponse.java | 4 ++++ .../dto/relationResponse/ReservationMemberResponse.java | 4 ++++ .../api/dto/relationResponse/ReviewMemberResponse.java | 4 ++++ .../api/dto/request/MemberAdditionalInfoRequest.java | 4 ++++ .../member/api/dto/request/create/HostCreateRequest.java | 4 ++++ .../api/dto/request/create/MemberCreateRequest.java | 6 +++++- .../api/dto/request/create/MemberCreateRequestBase.java | 4 ++++ .../member/api/dto/request/edit/CuratorEditRequest.java | 4 ++++ .../member/api/dto/request/edit/HostEditRequest.java | 5 ++++- .../member/api/dto/request/edit/MemberEditRequest.java | 4 ++++ .../api/dto/request/edit/MemberEditRequestBase.java | 4 ++++ .../wouldyouin/member/application/CuratorService.java | 2 +- .../wouldyouin/member/application/HostService.java | 2 +- .../wouldyouin/member/application/MemberService.java | 2 +- .../cokaen/wouldyouin/member/persist/BaseMember.java | 4 ++++ .../ktc2/cokaen/wouldyouin/member/persist/Curator.java | 6 +++++- .../org/ktc2/cokaen/wouldyouin/member/persist/Host.java | 6 +++++- .../cokaen/wouldyouin/member/persist/LikeableMember.java | 1 - .../ktc2/cokaen/wouldyouin/member/persist/Member.java | 6 +++++- .../wouldyouin/payment/application/PaymentService.java | 1 - .../cokaen/wouldyouin/payment/dto/KakaoPayRequest.java | 4 ++++ .../cokaen/wouldyouin/payment/dto/KakaoPayResponse.java | 5 ++++- .../reservation/api/ReservationController.java | 2 +- .../reservation/api/dto/ReservationRequest.java | 3 ++- .../reservation/api/dto/ReservationResponse.java | 4 ++++ .../reservation/api/dto/ReservationSliceResponse.java | 4 ++++ .../wouldyouin/reservation/persist/Reservation.java | 4 ++++ .../cokaen/wouldyouin/review/api/ReviewController.java | 1 - .../wouldyouin/review/api/dto/ReviewCreateRequest.java | 4 ++++ .../wouldyouin/review/api/dto/ReviewEditRequest.java | 4 ++++ .../cokaen/wouldyouin/review/api/dto/ReviewResponse.java | 4 ++++ .../wouldyouin/review/api/dto/ReviewSliceResponse.java | 4 ++++ .../ktc2/cokaen/wouldyouin/review/persist/Review.java | 4 ++++ 94 files changed, 319 insertions(+), 66 deletions(-) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/api/ApiResponseBody.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/api/ApiResponseBody.java index 02e70fd9..7c4e8966 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/api/ApiResponseBody.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/api/ApiResponseBody.java @@ -1,10 +1,14 @@ package org.ktc2.cokaen.wouldyouin._common.api; import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; @Getter @JsonInclude(JsonInclude.Include.NON_NULL) +@EqualsAndHashCode +@ToString public class ApiResponseBody { private final Boolean success; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/api/ParamDefaults.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/api/ParamDefaults.java index e317393f..b1d8866d 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/api/ParamDefaults.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/api/ParamDefaults.java @@ -1,5 +1,10 @@ package org.ktc2.cokaen.wouldyouin._common.api; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +@EqualsAndHashCode +@ToString public class ParamDefaults { public static final String PAGE = "0"; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/api/SliceInfo.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/api/SliceInfo.java index 303194f8..9aa58171 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/api/SliceInfo.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/api/SliceInfo.java @@ -1,12 +1,16 @@ package org.ktc2.cokaen.wouldyouin._common.api; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; +import lombok.ToString; @Setter @Getter @Builder +@EqualsAndHashCode +@ToString public class SliceInfo { private final Integer sliceSize; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/GlobalExceptionHandler.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/GlobalExceptionHandler.java index cf8c28d6..34bc5653 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/GlobalExceptionHandler.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/GlobalExceptionHandler.java @@ -2,10 +2,10 @@ import java.util.stream.Collectors; -import org.ktc2.cokaen.wouldyouin.image.api.ImageDomain; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponse; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponseBody; import org.ktc2.cokaen.wouldyouin._common.exception.BusinessException; +import org.ktc2.cokaen.wouldyouin.image.api.ImageDomain; import org.springframework.context.support.DefaultMessageSourceResolvable; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.MethodArgumentNotValidException; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/vo/Location.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/vo/Location.java index ad551893..f3ea08a8 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/vo/Location.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/vo/Location.java @@ -6,15 +6,19 @@ import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.ToString; @Getter @Setter @NoArgsConstructor @AllArgsConstructor @Embeddable +@EqualsAndHashCode +@ToString public class Location { @NotNull(message = "위도 값은 필수입니다.") diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/dto/AdvertisementRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/dto/AdvertisementRequest.java index 32f404b0..566ada93 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/dto/AdvertisementRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/dto/AdvertisementRequest.java @@ -3,16 +3,19 @@ import jakarta.validation.constraints.AssertTrue; import jakarta.validation.constraints.FutureOrPresent; import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; import java.time.LocalDateTime; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; -import org.ktc2.cokaen.wouldyouin.image.persist.AdvertisementImage; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin.advertisement.persist.Advertisement; +import org.ktc2.cokaen.wouldyouin.image.persist.AdvertisementImage; @Getter @Builder(toBuilder = true) +@EqualsAndHashCode +@ToString public class AdvertisementRequest { @NotBlank(message = "광고명은 필수입니다.") diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/dto/AdvertisementResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/dto/AdvertisementResponse.java index 4920d9f1..0eb32f70 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/dto/AdvertisementResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/dto/AdvertisementResponse.java @@ -2,9 +2,13 @@ import java.time.LocalDateTime; import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin.advertisement.persist.Advertisement; @Builder +@EqualsAndHashCode +@ToString public class AdvertisementResponse { private Long id; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java index 28c2f647..e033ea58 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java @@ -4,14 +4,14 @@ import java.util.List; import java.util.Optional; import lombok.RequiredArgsConstructor; -import org.ktc2.cokaen.wouldyouin.image.application.AdvertisementImageService; -import org.ktc2.cokaen.wouldyouin.image.persist.AdvertisementImage; import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; import org.ktc2.cokaen.wouldyouin.advertisement.api.dto.AdvertisementRequest; import org.ktc2.cokaen.wouldyouin.advertisement.api.dto.AdvertisementResponse; import org.ktc2.cokaen.wouldyouin.advertisement.persist.Advertisement; import org.ktc2.cokaen.wouldyouin.advertisement.persist.AdvertisementRepository; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; +import org.ktc2.cokaen.wouldyouin.image.application.AdvertisementImageService; +import org.ktc2.cokaen.wouldyouin.image.persist.AdvertisementImage; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/persist/Advertisement.java b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/persist/Advertisement.java index 9fc4b593..2472cad0 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/persist/Advertisement.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/persist/Advertisement.java @@ -13,16 +13,20 @@ import java.util.Optional; import lombok.AccessLevel; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import org.ktc2.cokaen.wouldyouin.image.persist.AdvertisementImage; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin.advertisement.api.dto.AdvertisementRequest; +import org.ktc2.cokaen.wouldyouin.image.persist.AdvertisementImage; @Getter @Setter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity +@EqualsAndHashCode +@ToString public class Advertisement { @Id diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/AuthController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/AuthController.java index f7ca6699..dd505208 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/AuthController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/AuthController.java @@ -5,11 +5,11 @@ import org.ktc2.cokaen.wouldyouin._common.api.ApiResponseBody; import org.ktc2.cokaen.wouldyouin.auth.Authorize; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; -import org.ktc2.cokaen.wouldyouin.auth.application.AuthService; import org.ktc2.cokaen.wouldyouin.auth.api.dto.LocalLoginRequest; import org.ktc2.cokaen.wouldyouin.auth.api.dto.LocalSignupRequest; import org.ktc2.cokaen.wouldyouin.auth.api.dto.SocialTokenResponse; import org.ktc2.cokaen.wouldyouin.auth.api.dto.TokenResponse; +import org.ktc2.cokaen.wouldyouin.auth.application.AuthService; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.MemberAdditionalInfoRequest; import org.ktc2.cokaen.wouldyouin.member.persist.AccountType; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/LocalSignupRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/LocalSignupRequest.java index 2032ae26..14d436fc 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/LocalSignupRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/LocalSignupRequest.java @@ -1,6 +1,10 @@ package org.ktc2.cokaen.wouldyouin.auth.api.dto; +import lombok.EqualsAndHashCode; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.create.HostCreateRequest; +@EqualsAndHashCode(callSuper = true) +@ToString public class LocalSignupRequest extends HostCreateRequest { } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/AuthService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/AuthService.java index 6a8a1a38..39631274 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/AuthService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/AuthService.java @@ -9,12 +9,12 @@ import org.ktc2.cokaen.wouldyouin.auth.api.dto.TokenResponse; import org.ktc2.cokaen.wouldyouin.auth.application.oauth.OauthRequestServiceFactory; import org.ktc2.cokaen.wouldyouin.auth.application.oauth.dto.OauthResourcesResponse; -import org.ktc2.cokaen.wouldyouin.member.application.BaseMemberService; -import org.ktc2.cokaen.wouldyouin.member.application.HostService; -import org.ktc2.cokaen.wouldyouin.member.application.MemberService; import org.ktc2.cokaen.wouldyouin.member.api.dto.MemberResponse; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.MemberAdditionalInfoRequest; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.create.MemberCreateRequest; +import org.ktc2.cokaen.wouldyouin.member.application.BaseMemberService; +import org.ktc2.cokaen.wouldyouin.member.application.HostService; +import org.ktc2.cokaen.wouldyouin.member.application.MemberService; import org.ktc2.cokaen.wouldyouin.member.persist.AccountType; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.springframework.stereotype.Service; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/persist/CustomUserDetails.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/persist/CustomUserDetails.java index 52470d9b..c3f22cd1 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/persist/CustomUserDetails.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/persist/CustomUserDetails.java @@ -4,8 +4,10 @@ import java.util.Collection; import java.util.List; import java.util.stream.Collectors; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.RequiredArgsConstructor; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; @@ -13,6 +15,8 @@ @Getter @RequiredArgsConstructor +@EqualsAndHashCode +@ToString public class CustomUserDetails implements UserDetails { private final MemberIdentifier identifier; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCardRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCardRequest.java index 6fc23709..52fe3df8 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCardRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCardRequest.java @@ -8,12 +8,14 @@ import lombok.Builder; import lombok.EqualsAndHashCode; import lombok.Getter; -import org.ktc2.cokaen.wouldyouin.image.persist.CurationImage; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin.curation.persist.CurationCard; +import org.ktc2.cokaen.wouldyouin.image.persist.CurationImage; @Getter @Builder(toBuilder = true) @EqualsAndHashCode +@ToString public class CurationCardRequest { @NotEmpty(message = "부제목은 필수입니다.") diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCardResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCardResponse.java index 6fe4674a..0248e77c 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCardResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCardResponse.java @@ -2,10 +2,13 @@ import java.util.List; import lombok.Builder; -import org.ktc2.cokaen.wouldyouin.image.persist.CurationImage; +import lombok.EqualsAndHashCode; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin.curation.persist.CurationCard; @Builder +@EqualsAndHashCode +@ToString public class CurationCardResponse { private String subtitle; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCreateRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCreateRequest.java index 415c345c..0fdf22d0 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCreateRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCreateRequest.java @@ -10,6 +10,7 @@ import lombok.Builder; import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; import org.ktc2.cokaen.wouldyouin.curation.persist.CurationCard; @@ -19,6 +20,7 @@ @Getter @Builder(toBuilder = true) @EqualsAndHashCode +@ToString public class CurationCreateRequest { @NotEmpty(message = "제목은 필수입니다.") diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationEditRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationEditRequest.java index f7451859..6b405317 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationEditRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationEditRequest.java @@ -10,11 +10,13 @@ import lombok.Builder; import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin._common.vo.Area; @Getter @Builder(toBuilder = true) @EqualsAndHashCode +@ToString public class CurationEditRequest { @NotEmpty(message = "제목은 필수입니다.") diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java index 4aaa9ba5..954a8f72 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java @@ -5,6 +5,7 @@ import lombok.Builder; import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.CurationEventResponse; @@ -13,6 +14,7 @@ @Builder @Getter @EqualsAndHashCode +@ToString public class CurationResponse { private final Long id; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationSliceResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationSliceResponse.java index 0917d6ce..f8787cf5 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationSliceResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationSliceResponse.java @@ -2,13 +2,15 @@ import java.util.List; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin._common.api.SliceInfo; -import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; -import org.springframework.data.domain.Slice; @Getter @Builder +@EqualsAndHashCode +@ToString public class CurationSliceResponse { private final List curations; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java index 5c29fd4d..ea73311b 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java @@ -2,8 +2,6 @@ import java.util.List; import lombok.RequiredArgsConstructor; -import org.ktc2.cokaen.wouldyouin.image.application.CurationImageService; -import org.ktc2.cokaen.wouldyouin.image.persist.CurationImage; import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCardRequest; @@ -11,6 +9,8 @@ import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; import org.ktc2.cokaen.wouldyouin.curation.persist.CurationCard; import org.ktc2.cokaen.wouldyouin.curation.persist.CurationCardRepository; +import org.ktc2.cokaen.wouldyouin.image.application.CurationImageService; +import org.ktc2.cokaen.wouldyouin.image.persist.CurationImage; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationService.java index bd471d25..75d954aa 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationService.java @@ -3,8 +3,6 @@ import java.util.List; import java.util.Optional; import lombok.RequiredArgsConstructor; -import org.ktc2.cokaen.wouldyouin.image.application.CurationImageService; -import org.ktc2.cokaen.wouldyouin.image.persist.CurationImage; import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; import org.ktc2.cokaen.wouldyouin._common.vo.Area; @@ -19,6 +17,8 @@ import org.ktc2.cokaen.wouldyouin.curation.persist.CurationRepository; import org.ktc2.cokaen.wouldyouin.event.application.EventService; import org.ktc2.cokaen.wouldyouin.event.persist.Event; +import org.ktc2.cokaen.wouldyouin.image.application.CurationImageService; +import org.ktc2.cokaen.wouldyouin.image.persist.CurationImage; import org.ktc2.cokaen.wouldyouin.member.application.CuratorService; import org.ktc2.cokaen.wouldyouin.member.persist.Curator; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java index c3f5c742..f8ca329c 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java @@ -22,9 +22,11 @@ import java.util.Optional; import lombok.AccessLevel; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin._common.converter.HashtagConverter; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationEditRequest; @@ -37,6 +39,8 @@ @Getter @Setter @EntityListeners(AuditingEntityListener.class) +@EqualsAndHashCode +@ToString @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity public class Curation { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCard.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCard.java index acfc4385..21a28aab 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCard.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCard.java @@ -14,14 +14,18 @@ import java.util.Optional; import lombok.AccessLevel; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin.image.persist.CurationImage; @Getter @Setter @Entity +@EqualsAndHashCode +@ToString @NoArgsConstructor(access = AccessLevel.PROTECTED) public class CurationCard { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java index d7dba272..24118e31 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java @@ -11,16 +11,20 @@ import java.time.LocalDateTime; import java.util.List; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; -import org.ktc2.cokaen.wouldyouin.image.persist.EventImage; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; import org.ktc2.cokaen.wouldyouin._common.vo.Location; import org.ktc2.cokaen.wouldyouin.event.persist.Event; +import org.ktc2.cokaen.wouldyouin.image.persist.EventImage; import org.ktc2.cokaen.wouldyouin.member.persist.Host; @Getter @Builder +@EqualsAndHashCode +@ToString public class EventCreateRequest { @NotBlank(message = "제목은 필수입니다.") diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventEditRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventEditRequest.java index 3eff3c54..afec07f6 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventEditRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventEditRequest.java @@ -11,13 +11,17 @@ import java.time.LocalDateTime; import java.util.List; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; import org.ktc2.cokaen.wouldyouin._common.vo.Location; @Getter @Builder(toBuilder = true) +@EqualsAndHashCode +@ToString public class EventEditRequest { @NotBlank(message = "제목은 필수입니다.") diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventResponse.java index 652e0711..a8a1dbe6 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventResponse.java @@ -3,7 +3,9 @@ import java.time.LocalDateTime; import java.util.List; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; import org.ktc2.cokaen.wouldyouin._common.vo.Location; @@ -13,6 +15,8 @@ @Builder @Getter +@EqualsAndHashCode +@ToString public class EventResponse { private Long id; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventSliceResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventSliceResponse.java index d974a17f..5a9d92a8 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventSliceResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventSliceResponse.java @@ -2,11 +2,15 @@ import java.util.List; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin._common.api.SliceInfo; @Getter @Builder +@EqualsAndHashCode +@ToString public class EventSliceResponse { private List events; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationFilter.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationFilter.java index 4f97fbc5..2f96787b 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationFilter.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationFilter.java @@ -4,14 +4,18 @@ import jakarta.validation.constraints.Max; import jakarta.validation.constraints.Min; import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.ToString; @Getter @Setter @NoArgsConstructor @AllArgsConstructor +@EqualsAndHashCode +@ToString public class LocationFilter { @Min(value = -90, message = "시작 위도는 -90 이상이어야 합니다.") diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationRequest.java index a45a7506..86430e3a 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationRequest.java @@ -2,16 +2,19 @@ import jakarta.validation.constraints.Max; import jakarta.validation.constraints.Min; -import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.ToString; @Getter @Setter @AllArgsConstructor @NoArgsConstructor +@EqualsAndHashCode +@ToString public class LocationRequest { @Min(value = -90, message = "위도는 -90 이상이어야 합니다.") diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/CurationEventResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/CurationEventResponse.java index ec9ebe7c..5999bc91 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/CurationEventResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/CurationEventResponse.java @@ -2,12 +2,16 @@ import java.time.LocalDateTime; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin._common.vo.Location; import org.ktc2.cokaen.wouldyouin.event.persist.Event; @Getter @Builder +@EqualsAndHashCode +@ToString public class CurationEventResponse { private Long eventId; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/ReservationEventResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/ReservationEventResponse.java index a74729ac..db34ffe0 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/ReservationEventResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/ReservationEventResponse.java @@ -2,12 +2,16 @@ import java.time.LocalDateTime; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin._common.vo.Location; import org.ktc2.cokaen.wouldyouin.event.persist.Event; @Getter @Builder +@EqualsAndHashCode +@ToString public class ReservationEventResponse { private Long eventId; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/ReviewEventResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/ReviewEventResponse.java index 560c930c..85666b5b 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/ReviewEventResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/ReviewEventResponse.java @@ -2,11 +2,15 @@ import java.time.LocalDateTime; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin.event.persist.Event; @Getter @Builder +@EqualsAndHashCode +@ToString public class ReviewEventResponse { private Long eventId; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/ReviewEventSliceResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/ReviewEventSliceResponse.java index 7afc3b9c..fee9e011 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/ReviewEventSliceResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/ReviewEventSliceResponse.java @@ -2,11 +2,15 @@ import java.util.List; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin._common.api.SliceInfo; @Getter @Builder +@EqualsAndHashCode +@ToString public class ReviewEventSliceResponse { private List reviewEvents; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java index 4471ee21..5ed92e94 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java @@ -3,9 +3,6 @@ import java.util.List; import java.util.Optional; import lombok.RequiredArgsConstructor; -import org.ktc2.cokaen.wouldyouin.image.application.EventImageService; -import org.ktc2.cokaen.wouldyouin.image.application.MemberImageService; -import org.ktc2.cokaen.wouldyouin.image.persist.EventImage; import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; import org.ktc2.cokaen.wouldyouin._common.exception.NoLeftSeatException; import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; @@ -20,6 +17,9 @@ import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationRequest; import org.ktc2.cokaen.wouldyouin.event.persist.Event; import org.ktc2.cokaen.wouldyouin.event.persist.EventRepository; +import org.ktc2.cokaen.wouldyouin.image.application.EventImageService; +import org.ktc2.cokaen.wouldyouin.image.application.MemberImageService; +import org.ktc2.cokaen.wouldyouin.image.persist.EventImage; import org.ktc2.cokaen.wouldyouin.member.application.HostService; import org.ktc2.cokaen.wouldyouin.member.persist.Host; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java index 646b977d..d3e5686a 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java @@ -22,20 +22,24 @@ import java.util.Optional; import lombok.AccessLevel; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import org.ktc2.cokaen.wouldyouin.image.persist.EventImage; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; import org.ktc2.cokaen.wouldyouin._common.vo.Location; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; +import org.ktc2.cokaen.wouldyouin.image.persist.EventImage; import org.ktc2.cokaen.wouldyouin.member.persist.Host; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @Getter @Setter +@EqualsAndHashCode +@ToString @NoArgsConstructor(access = AccessLevel.PROTECTED) @EntityListeners(AuditingEntityListener.class) @Entity diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/ImageController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/ImageController.java index d7fd69ca..bf02c6c5 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/ImageController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/ImageController.java @@ -3,13 +3,13 @@ import java.nio.file.Paths; import java.util.List; import lombok.RequiredArgsConstructor; -import org.ktc2.cokaen.wouldyouin.image.api.dto.ImageResponse; -import org.ktc2.cokaen.wouldyouin.image.application.ImageServiceFactory; -import org.ktc2.cokaen.wouldyouin.image.application.ImageStorageService; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponse; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponseBody; import org.ktc2.cokaen.wouldyouin.auth.Authorize; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; +import org.ktc2.cokaen.wouldyouin.image.api.dto.ImageResponse; +import org.ktc2.cokaen.wouldyouin.image.application.ImageServiceFactory; +import org.ktc2.cokaen.wouldyouin.image.application.ImageStorageService; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.ktc2.cokaen.wouldyouin.payment.application.PaymentService; import org.springframework.http.HttpStatus; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/dto/ImageRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/dto/ImageRequest.java index b6472d2b..c14280d2 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/dto/ImageRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/dto/ImageRequest.java @@ -1,10 +1,14 @@ package org.ktc2.cokaen.wouldyouin.image.api.dto; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; @Getter @Builder +@EqualsAndHashCode +@ToString public class ImageRequest { private String name; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/dto/ImageResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/dto/ImageResponse.java index 70c27cd8..7a90bfd6 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/dto/ImageResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/dto/ImageResponse.java @@ -2,11 +2,15 @@ import java.time.LocalDateTime; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin.image.persist.Image; @Getter @Builder +@EqualsAndHashCode +@ToString public class ImageResponse { private Long id; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/AdvertisementImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/AdvertisementImageService.java index b35682ac..ca3245e6 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/AdvertisementImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/AdvertisementImageService.java @@ -1,14 +1,14 @@ package org.ktc2.cokaen.wouldyouin.image.application; import lombok.RequiredArgsConstructor; +import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; +import org.ktc2.cokaen.wouldyouin.advertisement.persist.Advertisement; +import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.image.api.ImageDomain; import org.ktc2.cokaen.wouldyouin.image.api.dto.ImageRequest; import org.ktc2.cokaen.wouldyouin.image.persist.AdvertisementImage; import org.ktc2.cokaen.wouldyouin.image.persist.AdvertisementImageRepository; import org.ktc2.cokaen.wouldyouin.image.persist.ImageRepository; -import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; -import org.ktc2.cokaen.wouldyouin.advertisement.persist.Advertisement; -import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/CurationImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/CurationImageService.java index 2cdc6f92..07a82d20 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/CurationImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/CurationImageService.java @@ -1,14 +1,14 @@ package org.ktc2.cokaen.wouldyouin.image.application; import lombok.RequiredArgsConstructor; +import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; +import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; +import org.ktc2.cokaen.wouldyouin.curation.persist.CurationCard; import org.ktc2.cokaen.wouldyouin.image.api.ImageDomain; import org.ktc2.cokaen.wouldyouin.image.api.dto.ImageRequest; import org.ktc2.cokaen.wouldyouin.image.persist.CurationImage; import org.ktc2.cokaen.wouldyouin.image.persist.CurationImageRepository; import org.ktc2.cokaen.wouldyouin.image.persist.ImageRepository; -import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; -import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; -import org.ktc2.cokaen.wouldyouin.curation.persist.CurationCard; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/EventImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/EventImageService.java index 2c494966..1b5bc460 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/EventImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/EventImageService.java @@ -1,14 +1,14 @@ package org.ktc2.cokaen.wouldyouin.image.application; import lombok.RequiredArgsConstructor; +import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; +import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; +import org.ktc2.cokaen.wouldyouin.event.persist.Event; import org.ktc2.cokaen.wouldyouin.image.api.ImageDomain; import org.ktc2.cokaen.wouldyouin.image.api.dto.ImageRequest; import org.ktc2.cokaen.wouldyouin.image.persist.EventImage; import org.ktc2.cokaen.wouldyouin.image.persist.EventImageRepository; import org.ktc2.cokaen.wouldyouin.image.persist.ImageRepository; -import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; -import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; -import org.ktc2.cokaen.wouldyouin.event.persist.Event; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageService.java index e1baccab..616f6ddc 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageService.java @@ -2,14 +2,14 @@ import java.util.List; import lombok.RequiredArgsConstructor; +import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; +import org.ktc2.cokaen.wouldyouin._common.util.UriUtil; +import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.image.api.ImageDomain; import org.ktc2.cokaen.wouldyouin.image.api.dto.ImageRequest; import org.ktc2.cokaen.wouldyouin.image.api.dto.ImageResponse; import org.ktc2.cokaen.wouldyouin.image.persist.Image; import org.ktc2.cokaen.wouldyouin.image.persist.ImageRepository; -import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; -import org.ktc2.cokaen.wouldyouin._common.util.UriUtil; -import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageStorageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageStorageService.java index 09b77453..52886c4b 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageStorageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageStorageService.java @@ -7,11 +7,11 @@ import java.util.Optional; import lombok.RequiredArgsConstructor; import net.coobird.thumbnailator.Thumbnails; -import org.ktc2.cokaen.wouldyouin.image.api.dto.ImageRequest; import org.ktc2.cokaen.wouldyouin._common.exception.FailedToUploadImageException; import org.ktc2.cokaen.wouldyouin._common.util.FileUtil; import org.ktc2.cokaen.wouldyouin._common.util.RestClientUtil; import org.ktc2.cokaen.wouldyouin._common.util.UriUtil; +import org.ktc2.cokaen.wouldyouin.image.api.dto.ImageRequest; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseEntity; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/MemberImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/MemberImageService.java index a2a087b3..efb20a97 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/MemberImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/MemberImageService.java @@ -1,13 +1,13 @@ package org.ktc2.cokaen.wouldyouin.image.application; import lombok.RequiredArgsConstructor; +import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; +import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.image.api.ImageDomain; import org.ktc2.cokaen.wouldyouin.image.api.dto.ImageRequest; import org.ktc2.cokaen.wouldyouin.image.persist.ImageRepository; import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin.image.persist.MemberImageRepository; -import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; -import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMember; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.springframework.beans.factory.annotation.Value; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/AdvertisementImage.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/AdvertisementImage.java index e2ac0382..37d94bc2 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/AdvertisementImage.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/AdvertisementImage.java @@ -5,14 +5,18 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.OneToOne; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin.advertisement.persist.Advertisement; @Entity @Getter @Setter +@EqualsAndHashCode(callSuper = true) +@ToString @NoArgsConstructor public class AdvertisementImage extends Image { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/CurationImage.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/CurationImage.java index ac6f4c11..a4406b8b 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/CurationImage.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/CurationImage.java @@ -5,14 +5,18 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin.curation.persist.CurationCard; @Entity @Getter @Setter +@EqualsAndHashCode(callSuper = true) +@ToString @NoArgsConstructor public class CurationImage extends Image { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/EventImage.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/EventImage.java index c3662b53..d9eb1d94 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/EventImage.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/EventImage.java @@ -5,14 +5,18 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin.event.persist.Event; @Entity @Getter @Setter +@EqualsAndHashCode(callSuper = true) +@ToString @NoArgsConstructor public class EventImage extends Image { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/Image.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/Image.java index 7115b024..d07a94bf 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/Image.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/Image.java @@ -9,14 +9,18 @@ import jakarta.validation.constraints.NotNull; import java.time.LocalDateTime; import lombok.AccessLevel; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.ToString; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @Getter @Setter +@EqualsAndHashCode +@ToString @NoArgsConstructor(access = AccessLevel.PROTECTED) @MappedSuperclass @EntityListeners(AuditingEntityListener.class) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/MemberImage.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/MemberImage.java index d3a4ca76..b780d3f1 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/MemberImage.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/MemberImage.java @@ -5,14 +5,18 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.OneToOne; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMember; @Entity @Setter @Getter +@EqualsAndHashCode(callSuper = true) +@ToString @NoArgsConstructor public class MemberImage extends Image { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/dto/LikeResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/dto/LikeResponse.java index 5530179d..fb79c426 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/dto/LikeResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/dto/LikeResponse.java @@ -3,12 +3,16 @@ import java.util.List; import lombok.AccessLevel; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.RequiredArgsConstructor; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin.member.persist.LikeableMember; @Getter @RequiredArgsConstructor(access = AccessLevel.PROTECTED) +@EqualsAndHashCode +@ToString @Builder public class LikeResponse { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/dto/LikeSliceResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/dto/LikeSliceResponse.java index efb11c79..170ab9a2 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/dto/LikeSliceResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/dto/LikeSliceResponse.java @@ -2,11 +2,15 @@ import java.util.List; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin._common.api.SliceInfo; @Getter @Builder +@EqualsAndHashCode +@ToString public class LikeSliceResponse { private List likes; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/dto/LikeToggleResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/dto/LikeToggleResponse.java index 819e700d..d12d9568 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/dto/LikeToggleResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/dto/LikeToggleResponse.java @@ -2,11 +2,15 @@ import lombok.AccessLevel; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.RequiredArgsConstructor; +import lombok.ToString; @Getter @RequiredArgsConstructor(access = AccessLevel.PROTECTED) +@EqualsAndHashCode +@ToString @Builder public class LikeToggleResponse { private final boolean isLiked; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/CuratorLike.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/CuratorLike.java index 7cbf9283..d3309ef9 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/CuratorLike.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/CuratorLike.java @@ -3,12 +3,16 @@ import jakarta.persistence.Entity; import lombok.AccessLevel; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin.member.persist.Curator; import org.ktc2.cokaen.wouldyouin.member.persist.Member; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @Entity +@EqualsAndHashCode(callSuper = true) +@ToString @NoArgsConstructor(access = AccessLevel.PROTECTED) public class CuratorLike extends Like{ diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/HostLike.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/HostLike.java index f8e43b09..6e19a3f6 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/HostLike.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/HostLike.java @@ -3,12 +3,16 @@ import jakarta.persistence.Entity; import lombok.AccessLevel; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin.member.persist.Host; import org.ktc2.cokaen.wouldyouin.member.persist.Member; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @Entity +@EqualsAndHashCode(callSuper = true) +@ToString @NoArgsConstructor(access = AccessLevel.PROTECTED) public class HostLike extends Like { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/Like.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/Like.java index 5f7bf605..48840190 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/Like.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/Like.java @@ -10,15 +10,19 @@ import jakarta.persistence.MappedSuperclass; import jakarta.validation.constraints.NotNull; import lombok.AccessLevel; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin.member.persist.LikeableMember; import org.ktc2.cokaen.wouldyouin.member.persist.Member; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @Getter @Setter +@EqualsAndHashCode +@ToString @MappedSuperclass @NoArgsConstructor(access = AccessLevel.PROTECTED) public abstract class Like { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/LikeRepository.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/LikeRepository.java index 97936c97..c1ef6628 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/LikeRepository.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/LikeRepository.java @@ -1,7 +1,6 @@ package org.ktc2.cokaen.wouldyouin.like.persist; -import java.util.List; import java.util.Optional; import org.ktc2.cokaen.wouldyouin.member.persist.LikeableMember; import org.ktc2.cokaen.wouldyouin.member.persist.Member; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/CuratorController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/CuratorController.java index 646b84a7..86588d77 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/CuratorController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/CuratorController.java @@ -5,12 +5,11 @@ import org.ktc2.cokaen.wouldyouin._common.api.ApiResponseBody; import org.ktc2.cokaen.wouldyouin.auth.Authorize; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; -import org.ktc2.cokaen.wouldyouin.member.application.CuratorService; import org.ktc2.cokaen.wouldyouin.member.api.dto.MemberResponse; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit.CuratorEditRequest; +import org.ktc2.cokaen.wouldyouin.member.application.CuratorService; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/HostController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/HostController.java index 9e49a3fc..f375d0f6 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/HostController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/HostController.java @@ -5,9 +5,9 @@ import org.ktc2.cokaen.wouldyouin._common.api.ApiResponseBody; import org.ktc2.cokaen.wouldyouin.auth.Authorize; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; -import org.ktc2.cokaen.wouldyouin.member.application.HostService; -import org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit.HostEditRequest; import org.ktc2.cokaen.wouldyouin.member.api.dto.MemberResponse; +import org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit.HostEditRequest; +import org.ktc2.cokaen.wouldyouin.member.application.HostService; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PutMapping; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/MemberController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/MemberController.java index 4c8f4119..22532fe7 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/MemberController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/MemberController.java @@ -5,10 +5,10 @@ import org.ktc2.cokaen.wouldyouin._common.api.ApiResponseBody; import org.ktc2.cokaen.wouldyouin.auth.Authorize; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; -import org.ktc2.cokaen.wouldyouin.member.application.BaseMemberService; -import org.ktc2.cokaen.wouldyouin.member.application.MemberService; import org.ktc2.cokaen.wouldyouin.member.api.dto.MemberResponse; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit.MemberEditRequest; +import org.ktc2.cokaen.wouldyouin.member.application.BaseMemberService; +import org.ktc2.cokaen.wouldyouin.member.application.MemberService; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/MemberResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/MemberResponse.java index 3861e1c1..3d350d8f 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/MemberResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/MemberResponse.java @@ -1,17 +1,20 @@ package org.ktc2.cokaen.wouldyouin.member.api.dto; +import java.util.List; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin._common.vo.Area; -import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMember; import org.ktc2.cokaen.wouldyouin.member.persist.Curator; import org.ktc2.cokaen.wouldyouin.member.persist.Host; import org.ktc2.cokaen.wouldyouin.member.persist.Member; - -import java.util.List; +import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @Getter +@EqualsAndHashCode +@ToString @Builder public class MemberResponse { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/CurationCuratorResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/CurationCuratorResponse.java index 123d0eee..651d748c 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/CurationCuratorResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/CurationCuratorResponse.java @@ -2,11 +2,15 @@ import java.util.List; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin.member.persist.Curator; @Builder @Getter +@EqualsAndHashCode +@ToString public class CurationCuratorResponse { private String nickname; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/EventHostResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/EventHostResponse.java index 3cc7ed35..1ed59606 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/EventHostResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/EventHostResponse.java @@ -2,11 +2,15 @@ import java.util.List; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin.member.persist.Host; @Builder @Getter +@EqualsAndHashCode +@ToString public class EventHostResponse { private Long hostId; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/ReservationMemberResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/ReservationMemberResponse.java index 70514dda..eec96917 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/ReservationMemberResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/ReservationMemberResponse.java @@ -1,11 +1,15 @@ package org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin.member.persist.Member; @Getter @Builder +@EqualsAndHashCode +@ToString public class ReservationMemberResponse { private Long memberId; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/ReviewMemberResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/ReviewMemberResponse.java index aca47786..dfdb5b92 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/ReviewMemberResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/ReviewMemberResponse.java @@ -1,11 +1,15 @@ package org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin.member.persist.Member; @Getter @Builder +@EqualsAndHashCode +@ToString public class ReviewMemberResponse { private Long memberId; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/MemberAdditionalInfoRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/MemberAdditionalInfoRequest.java index f7d2fffc..b1eda017 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/MemberAdditionalInfoRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/MemberAdditionalInfoRequest.java @@ -1,10 +1,14 @@ package org.ktc2.cokaen.wouldyouin.member.api.dto.request; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.RequiredArgsConstructor; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin._common.vo.Area; @Getter +@EqualsAndHashCode +@ToString @RequiredArgsConstructor public class MemberAdditionalInfoRequest { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/HostCreateRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/HostCreateRequest.java index b6015c5a..d087ca67 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/HostCreateRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/HostCreateRequest.java @@ -1,11 +1,15 @@ package org.ktc2.cokaen.wouldyouin.member.api.dto.request.create; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.RequiredArgsConstructor; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin.member.persist.Host; @Getter +@EqualsAndHashCode(callSuper = true) +@ToString @RequiredArgsConstructor public class HostCreateRequest extends MemberCreateRequestBase { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/MemberCreateRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/MemberCreateRequest.java index 1788d5bd..0d3661a3 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/MemberCreateRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/MemberCreateRequest.java @@ -1,14 +1,18 @@ package org.ktc2.cokaen.wouldyouin.member.api.dto.request.create; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.RequiredArgsConstructor; -import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin._common.vo.Area; +import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin.member.persist.AccountType; import org.ktc2.cokaen.wouldyouin.member.persist.Member; @Getter +@EqualsAndHashCode(callSuper = true) +@ToString @RequiredArgsConstructor public class MemberCreateRequest extends MemberCreateRequestBase { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/MemberCreateRequestBase.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/MemberCreateRequestBase.java index 1e4ecc5c..7594f2ff 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/MemberCreateRequestBase.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/MemberCreateRequestBase.java @@ -1,10 +1,14 @@ package org.ktc2.cokaen.wouldyouin.member.api.dto.request.create; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.RequiredArgsConstructor; +import lombok.ToString; @Getter @RequiredArgsConstructor +@EqualsAndHashCode +@ToString public abstract class MemberCreateRequestBase { protected String nickname; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/CuratorEditRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/CuratorEditRequest.java index 63ee5b53..35fc76a2 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/CuratorEditRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/CuratorEditRequest.java @@ -2,10 +2,14 @@ import io.micrometer.common.lang.Nullable; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin._common.vo.Area; @Getter +@EqualsAndHashCode(callSuper = true) +@ToString public class CuratorEditRequest extends MemberEditRequest { @Nullable private final String intro; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/HostEditRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/HostEditRequest.java index f9228913..3336125e 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/HostEditRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/HostEditRequest.java @@ -1,12 +1,15 @@ package org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit; - import jakarta.annotation.Nullable; import java.util.List; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; @Getter +@EqualsAndHashCode(callSuper = true) +@ToString public class HostEditRequest extends MemberEditRequestBase { @Nullable private final String intro; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/MemberEditRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/MemberEditRequest.java index 6afed790..d9189dcd 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/MemberEditRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/MemberEditRequest.java @@ -2,10 +2,14 @@ import jakarta.annotation.Nullable; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin._common.vo.Area; @Getter +@EqualsAndHashCode(callSuper = true) +@ToString public class MemberEditRequest extends MemberEditRequestBase { @Nullable private final Area area; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/MemberEditRequestBase.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/MemberEditRequestBase.java index f353746b..1fbbf155 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/MemberEditRequestBase.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/MemberEditRequestBase.java @@ -1,10 +1,14 @@ package org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit; import jakarta.annotation.Nullable; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.RequiredArgsConstructor; +import lombok.ToString; @Getter +@EqualsAndHashCode +@ToString @RequiredArgsConstructor public abstract class MemberEditRequestBase { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java index 452e0601..d157f0cf 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java @@ -1,9 +1,9 @@ package org.ktc2.cokaen.wouldyouin.member.application; import lombok.RequiredArgsConstructor; +import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; import org.ktc2.cokaen.wouldyouin.image.application.MemberImageService; import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; -import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; import org.ktc2.cokaen.wouldyouin.member.api.dto.MemberResponse; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit.CuratorEditRequest; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMemberRepository; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java index 083e3603..345f03fb 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java @@ -2,9 +2,9 @@ import java.util.Optional; import lombok.RequiredArgsConstructor; +import org.ktc2.cokaen.wouldyouin.auth.api.dto.LocalLoginRequest; import org.ktc2.cokaen.wouldyouin.image.application.MemberImageService; import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; -import org.ktc2.cokaen.wouldyouin.auth.api.dto.LocalLoginRequest; import org.ktc2.cokaen.wouldyouin.member.api.dto.MemberResponse; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.create.HostCreateRequest; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit.HostEditRequest; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/MemberService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/MemberService.java index 79c5527e..5aada5b9 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/MemberService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/MemberService.java @@ -2,9 +2,9 @@ import java.util.Optional; import lombok.RequiredArgsConstructor; +import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.image.application.MemberImageService; import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; -import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.member.api.dto.MemberResponse; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.MemberAdditionalInfoRequest; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.create.MemberCreateRequest; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java index 21621919..b77db0e2 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java @@ -12,9 +12,11 @@ import jakarta.persistence.InheritanceType; import jakarta.persistence.OneToOne; import lombok.AccessLevel; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; @Getter @@ -22,6 +24,8 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Inheritance(strategy = InheritanceType.JOINED) @DiscriminatorColumn +@EqualsAndHashCode +@ToString @Entity public abstract class BaseMember { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java index 525c4b18..fba78fa3 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java @@ -11,19 +11,23 @@ import java.util.Optional; import lombok.AccessLevel; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin._common.converter.HashtagConverter; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; +import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit.CuratorEditRequest; @Getter @Setter @NoArgsConstructor(access = AccessLevel.PROTECTED) @DiscriminatorValue("Curator") +@EqualsAndHashCode(callSuper = true) +@ToString @Entity public class Curator extends Member implements LikeableMember { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java index 955b4082..c0d319cc 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java @@ -10,17 +10,21 @@ import java.util.List; import lombok.AccessLevel; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin._common.converter.HashtagConverter; import org.ktc2.cokaen.wouldyouin.event.persist.Event; +import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; @Getter @Setter @NoArgsConstructor(access = AccessLevel.PROTECTED) @DiscriminatorValue("Host") +@EqualsAndHashCode(callSuper = true) +@ToString @Entity public class Host extends BaseMember implements LikeableMember { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/LikeableMember.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/LikeableMember.java index 9b94d3df..0409d64d 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/LikeableMember.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/LikeableMember.java @@ -1,6 +1,5 @@ package org.ktc2.cokaen.wouldyouin.member.persist; -import java.util.Arrays; import java.util.List; public interface LikeableMember { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java index 20040457..a9eab86e 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java @@ -9,11 +9,13 @@ import java.util.List; import lombok.AccessLevel; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin._common.vo.Area; +import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin.like.persist.CuratorLike; import org.ktc2.cokaen.wouldyouin.like.persist.HostLike; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.MemberAdditionalInfoRequest; @@ -24,6 +26,8 @@ @Setter @NoArgsConstructor(access = AccessLevel.PROTECTED) @DiscriminatorValue("Member") +@EqualsAndHashCode(callSuper = true) +@ToString @Entity public class Member extends BaseMember { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/payment/application/PaymentService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/payment/application/PaymentService.java index 0d3686c5..2649750e 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/payment/application/PaymentService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/payment/application/PaymentService.java @@ -1,6 +1,5 @@ package org.ktc2.cokaen.wouldyouin.payment.application; -import java.nio.file.Paths; import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin._common.exception.FailedToPayException; import org.ktc2.cokaen.wouldyouin._common.util.KakaoPayUtil; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/payment/dto/KakaoPayRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/payment/dto/KakaoPayRequest.java index b2a8cfa1..3fb2a226 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/payment/dto/KakaoPayRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/payment/dto/KakaoPayRequest.java @@ -1,11 +1,15 @@ package org.ktc2.cokaen.wouldyouin.payment.dto; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin.reservation.persist.Reservation; @Getter @Builder +@EqualsAndHashCode +@ToString public class KakaoPayRequest { private String reservationId; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/payment/dto/KakaoPayResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/payment/dto/KakaoPayResponse.java index b17b9053..f3c2833e 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/payment/dto/KakaoPayResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/payment/dto/KakaoPayResponse.java @@ -1,14 +1,17 @@ package org.ktc2.cokaen.wouldyouin.payment.dto; -import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; import com.fasterxml.jackson.databind.annotation.JsonNaming; import java.time.LocalDateTime; import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; @Getter @AllArgsConstructor +@EqualsAndHashCode +@ToString @JsonNaming(value = SnakeCaseStrategy.class) public class KakaoPayResponse { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/ReservationController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/ReservationController.java index 5b0d4b6e..256be9ef 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/ReservationController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/ReservationController.java @@ -9,10 +9,10 @@ import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.ktc2.cokaen.wouldyouin.payment.dto.KakaoPayResponse; -import org.ktc2.cokaen.wouldyouin.reservation.application.ReservationService; import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationRequest; import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationResponse; import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationSliceResponse; +import org.ktc2.cokaen.wouldyouin.reservation.application.ReservationService; import org.springframework.data.domain.PageRequest; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/ReservationRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/ReservationRequest.java index 0ca28bf2..a1d89c2b 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/ReservationRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/ReservationRequest.java @@ -1,11 +1,11 @@ package org.ktc2.cokaen.wouldyouin.reservation.api.dto; -import jakarta.validation.constraints.Max; import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotNull; import lombok.Builder; import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin.event.persist.Event; import org.ktc2.cokaen.wouldyouin.member.persist.Member; import org.ktc2.cokaen.wouldyouin.reservation.persist.Reservation; @@ -13,6 +13,7 @@ @Getter @Builder(toBuilder = true) @EqualsAndHashCode +@ToString public class ReservationRequest { @NotNull(message = "이벤트 ID는 필수입니다.") diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/ReservationResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/ReservationResponse.java index 27db4266..a9acaf40 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/ReservationResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/ReservationResponse.java @@ -2,13 +2,17 @@ import java.time.LocalDateTime; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.ReservationEventResponse; import org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse.ReservationMemberResponse; import org.ktc2.cokaen.wouldyouin.reservation.persist.Reservation; @Builder @Getter +@EqualsAndHashCode +@ToString public class ReservationResponse { private Long id; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/ReservationSliceResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/ReservationSliceResponse.java index 0431a703..2469e5d0 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/ReservationSliceResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/ReservationSliceResponse.java @@ -2,13 +2,17 @@ import java.util.List; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin._common.api.SliceInfo; import org.ktc2.cokaen.wouldyouin.reservation.persist.Reservation; import org.springframework.data.domain.Slice; @Getter @Builder +@EqualsAndHashCode +@ToString public class ReservationSliceResponse { private List reservations; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/Reservation.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/Reservation.java index e72ea3d6..0e2ba328 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/Reservation.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/Reservation.java @@ -15,9 +15,11 @@ import java.util.Optional; import lombok.AccessLevel; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin.event.persist.Event; import org.ktc2.cokaen.wouldyouin.member.persist.Member; import org.springframework.data.annotation.CreatedDate; @@ -25,6 +27,8 @@ @Getter @Setter +@EqualsAndHashCode +@ToString @NoArgsConstructor(access = AccessLevel.PROTECTED) @EntityListeners(AuditingEntityListener.class) @Entity diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/ReviewController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/ReviewController.java index eb0bc47f..abf69bb3 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/ReviewController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/ReviewController.java @@ -7,7 +7,6 @@ import org.ktc2.cokaen.wouldyouin._common.api.ParamDefaults; import org.ktc2.cokaen.wouldyouin.auth.Authorize; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; -import org.ktc2.cokaen.wouldyouin.event.api.dto.EventSliceResponse; import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.ReviewEventSliceResponse; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.ktc2.cokaen.wouldyouin.review.api.dto.ReviewCreateRequest; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewCreateRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewCreateRequest.java index 9a1b4bd6..a6653ef6 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewCreateRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewCreateRequest.java @@ -6,13 +6,17 @@ import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin.event.persist.Event; import org.ktc2.cokaen.wouldyouin.member.persist.Member; import org.ktc2.cokaen.wouldyouin.review.persist.Review; @Getter @Builder +@EqualsAndHashCode +@ToString public class ReviewCreateRequest { @NotNull(message = "이벤트 ID는 필수입니다.") diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewEditRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewEditRequest.java index d1d2653f..6fc6d488 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewEditRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewEditRequest.java @@ -5,10 +5,14 @@ import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Size; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; @Getter @Builder(toBuilder = true) +@EqualsAndHashCode +@ToString public class ReviewEditRequest { @NotBlank(message = "별점은 필수입니다.") diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewResponse.java index 50eb6f00..7ddd44cb 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewResponse.java @@ -1,7 +1,9 @@ package org.ktc2.cokaen.wouldyouin.review.api.dto; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.ReviewEventResponse; import org.ktc2.cokaen.wouldyouin.event.persist.Event; import org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse.ReviewMemberResponse; @@ -10,6 +12,8 @@ @Builder @Getter +@EqualsAndHashCode +@ToString public class ReviewResponse { private Long id; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewSliceResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewSliceResponse.java index 39397ca7..0ee0155f 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewSliceResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewSliceResponse.java @@ -2,13 +2,17 @@ import java.util.List; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin._common.api.SliceInfo; import org.ktc2.cokaen.wouldyouin.review.persist.Review; import org.springframework.data.domain.Slice; @Getter @Builder +@EqualsAndHashCode +@ToString public class ReviewSliceResponse { private List reviews; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/review/persist/Review.java b/src/main/java/org/ktc2/cokaen/wouldyouin/review/persist/Review.java index a48a46b9..a3db8902 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/review/persist/Review.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/review/persist/Review.java @@ -13,15 +13,19 @@ import java.util.Optional; import lombok.AccessLevel; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.ToString; import org.ktc2.cokaen.wouldyouin.event.persist.Event; import org.ktc2.cokaen.wouldyouin.member.persist.Member; import org.ktc2.cokaen.wouldyouin.review.api.dto.ReviewEditRequest; @Getter @Setter +@EqualsAndHashCode +@ToString @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity public class Review { From 2f2ca73b42418f3471ee01619df15d4a31e14207 Mon Sep 17 00:00:00 2001 From: ariimo Date: Thu, 14 Nov 2024 23:59:30 +0900 Subject: [PATCH 35/53] =?UTF-8?q?[Weekly/11/Test/event]=20EventController?= =?UTF-8?q?=20Test=20=EC=9E=91=EC=84=B1=20(#134)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Weekly/10/Test/CurationController] curationControllerUnitTest 2 (#90) * test: EventController Test 작성 --------- Co-authored-by: 조홍식 <90020593+Daolove0323@users.noreply.github.com> --- .../event/api/dto/EventCreateRequest.java | 2 +- .../curation/CurationControllerUnitTest.java | 41 +- .../event/EventControllerUnitTest.java | 1118 +++++++++++++---- 3 files changed, 912 insertions(+), 249 deletions(-) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java index 24118e31..3d877b03 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java @@ -22,7 +22,7 @@ import org.ktc2.cokaen.wouldyouin.member.persist.Host; @Getter -@Builder +@Builder(toBuilder = true) @EqualsAndHashCode @ToString public class EventCreateRequest { diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java index 796a7fa7..06d8ad45 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java @@ -45,23 +45,18 @@ @WebMvcTest(CurationController.class) class CurationControllerUnitTest { + private final long randomId = abs(new Random().nextLong()); @Autowired private MockMvc mockMvc; - @Autowired private ObjectMapper objectMapper; - @Autowired private WebApplicationContext context; - @MockBean private CurationService curationService; - @MockBean private JwtAuthFilter jwtAuthFilter; - private final long randomId = abs(new Random().nextLong()); - @BeforeEach public void setup() throws Exception { mockMvc = MockMvcBuilders @@ -101,7 +96,7 @@ void getCurationsByAreaOrderByCreatedDateDesc2() throws Exception { } @Test - @DisplayName("ReqeustParam을 통해 요청할 페이지에 대한 정보를 전달받아, 해당하는 호스트의 큐레이션 목록을 조회한다.") + @DisplayName("ReqeustParam을 통해 요청할 페이지에 대한 정보를 전달받아, 해당하는 큐레이터의 큐레이션 목록을 조회한다.") @WithMockMember1 void getCurationsByCuratorIdOrderByCreatedDateDesc1() throws Exception { // given, when @@ -146,7 +141,8 @@ void getCurationByCurationId() throws Exception { @WithMockCurator1 void createCuration1() throws Exception { // given - ArgumentCaptor captor = ArgumentCaptor.forClass(CurationCreateRequest.class); + ArgumentCaptor captor = ArgumentCaptor.forClass( + CurationCreateRequest.class); CurationCreateRequest request = CurationData.curation.request.create.get(); // when @@ -158,7 +154,8 @@ void createCuration1() throws Exception { .andExpect(status().isCreated()); // then - then(curationService).should(times(1)).create(eq(curator1.memberIdentifier), captor.capture()); + then(curationService).should(times(1)) + .create(eq(curator1.memberIdentifier), captor.capture()); assertThat(captor.getValue()).isEqualTo(request); } @@ -175,7 +172,6 @@ void createCuration2() throws Exception { .andExpect(status().isUnauthorized()) .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); - // then then(curationService).shouldHaveNoInteractions(); } @@ -193,7 +189,6 @@ void createCuration3() throws Exception { .andExpect(status().isUnauthorized()) .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); - // then then(curationService).shouldHaveNoInteractions(); } @@ -225,7 +220,8 @@ void createCuration4() throws Exception { void createCuration5() throws Exception { // given CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() - .curationCards(List.of(CurationData.curationCard1.request.get().toBuilder().subtitle("").build())) + .curationCards( + List.of(CurationData.curationCard1.request.get().toBuilder().subtitle("").build())) .build(); // when @@ -247,7 +243,8 @@ void createCuration5() throws Exception { void createCuration6() throws Exception { // given CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() - .curationCards(List.of(CurationData.curationCard1.request.get().toBuilder().content(null).build())) + .curationCards( + List.of(CurationData.curationCard1.request.get().toBuilder().content(null).build())) .build(); // when @@ -269,7 +266,8 @@ void createCuration6() throws Exception { void createCuration7() throws Exception { // given CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() - .curationCards(List.of(CurationData.curationCard1.request.get().toBuilder().content(null).build())) + .curationCards( + List.of(CurationData.curationCard1.request.get().toBuilder().content(null).build())) .build(); // when @@ -291,7 +289,8 @@ void createCuration7() throws Exception { void createCuration8() throws Exception { // given CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() - .curationCards(List.of(CurationData.curationCard1.request.get().toBuilder().content("짧은 내용").build())) + .curationCards(List.of( + CurationData.curationCard1.request.get().toBuilder().content("짧은 내용").build())) .build(); // when @@ -312,7 +311,7 @@ void createCuration8() throws Exception { @WithMockCurator1 void createCuration9() throws Exception { // given - CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() + CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() .curationCards(List.of(CurationData.curationCard1.request.get().toBuilder() .imageIds(List.of(1L, 2L, 3L, 4L, 5L, 6L)).build())) .build(); @@ -377,8 +376,9 @@ void createCuration11() throws Exception { @WithMockCurator1 void updateCuration1() throws Exception { // given - ArgumentCaptor captor = ArgumentCaptor.forClass(CurationEditRequest.class); - CurationEditRequest request = CurationData.curation.request.edit.get(); + ArgumentCaptor captor = ArgumentCaptor.forClass( + CurationEditRequest.class); + CurationEditRequest request = CurationData.curation.request.edit.get(); // when mockMvc.perform(put("/api/curations/" + randomId) @@ -389,7 +389,8 @@ void updateCuration1() throws Exception { .andExpect(status().isOk()); // then - then(curationService).should(times(1)).update(eq(curator1.memberIdentifier), eq(randomId), captor.capture()); + then(curationService).should(times(1)) + .update(eq(curator1.memberIdentifier), eq(randomId), captor.capture()); assertThat(captor.getValue()).isEqualTo(request); } @@ -406,7 +407,6 @@ void updateCuration2() throws Exception { .andExpect(status().isUnauthorized()) .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); - // then then(curationService).shouldHaveNoInteractions(); } @@ -424,7 +424,6 @@ void updateCuration3() throws Exception { .andExpect(status().isUnauthorized()) .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); - // then then(curationService).shouldHaveNoInteractions(); } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java index c2f53361..2e3aa9e1 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java @@ -1,227 +1,891 @@ -//package org.ktc2.cokaen.wouldyouin.event; -// -//import static org.mockito.ArgumentMatchers.any; -//import static org.mockito.ArgumentMatchers.eq; -//import static org.mockito.BDDMockito.given; -//import static org.mockito.BDDMockito.then; -//import static org.mockito.Mockito.times; -//import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; -//import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; -//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; -//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; -//import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -// -//import com.fasterxml.jackson.databind.ObjectMapper; -//import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -//import org.junit.jupiter.api.BeforeAll; -//import org.junit.jupiter.api.BeforeEach; -//import org.junit.jupiter.api.DisplayName; -//import org.junit.jupiter.api.Test; -//import org.ktc2.cokaen.wouldyouin._common.vo.Area; -//import org.ktc2.cokaen.wouldyouin._common.vo.Category; -//import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost1; -//import org.ktc2.cokaen.wouldyouin._global.testdata.EventData; -//import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host1; -//import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.host1.entity; -//import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; -//import org.ktc2.cokaen.wouldyouin.auth.application.JwtService; -//import org.ktc2.cokaen.wouldyouin.event.api.EventController; -//import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; -//import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; -//import org.ktc2.cokaen.wouldyouin.event.api.dto.EventSliceResponse; -//import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationFilter; -//import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationRequest; -//import org.ktc2.cokaen.wouldyouin.event.application.EventService; -//import org.ktc2.cokaen.wouldyouin.member.application.MemberService; -//import org.ktc2.cokaen.wouldyouin.member.persist.Host; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -//import org.springframework.boot.test.mock.mockito.MockBean; -//import org.springframework.data.domain.PageRequest; -//import org.springframework.data.domain.Pageable; -//import org.springframework.http.MediaType; -//import org.springframework.test.web.servlet.MockMvc; -//import org.springframework.test.web.servlet.setup.MockMvcBuilders; -//import org.springframework.web.context.WebApplicationContext; -// -//@WebMvcTest(EventController.class) -//class EventControllerUnitTest { -// -// private static Long id; -// private static Host validHost; -// private static ObjectMapper objectMapper; -// @MockBean -// private EventService eventService; -// @MockBean -// private MemberService memberService; -// @MockBean -// private JwtService jwtService; -// @MockBean -// private JwtAuthFilter jwtAuthFilter; -// private EventSliceResponse eventSliceResponse; -// @Autowired -// private MockMvc mockMvc; -// @Autowired -// private WebApplicationContext context; -// -//// @BeforeAll -//// public static void init() { -//// id = 3L; -//// validHost = entity.get(); -//// objectMapper = new ObjectMapper(); -//// objectMapper.registerModule(new JavaTimeModule()); -//// } -// -// @BeforeEach -// public void setup() throws Exception { -// mockMvc = MockMvcBuilders -// .webAppContextSetup(context) -// .apply(springSecurity()) -// .build(); -// } -// -// @Test -// @DisplayName("모든 행사 조회 - 성공") -// @WithMockHost1 -// void getEventsByFilterOrderByDistanceAsc() throws Exception { -// // given -// LocationFilter locationFilter = new LocationFilter(0.0, 0.0, 10.0, 10.0); -// LocationRequest currentLocation = new LocationRequest(3.0, 2.0); -// String title = "testTitle"; -// Category category = Category.공예; -// Area area = Area.광주; -// int pageNumber = 1; -// int pageSize = 10; -// Long lastId = 1L; -// Pageable pageable = PageRequest.of(pageNumber, pageSize); -// -// given(eventService.getAllByFilterOrderByDistanceAsc( -// locationFilter, -// currentLocation, -// title, -// category, -// area, -// pageable, -// lastId)) -// .willReturn(eventSliceResponse); -// -// // when -// mockMvc.perform(get("/api/events") -// .param("startLatitude", locationFilter.getStartLatitude().toString()) -// .param("startLongitude", locationFilter.getStartLongitude().toString()) -// .param("endLatitude", locationFilter.getEndLatitude().toString()) -// .param("endLongitude", locationFilter.getEndLongitude().toString()) -// .param("latitude", currentLocation.getLatitude().toString()) -// .param("longitude", currentLocation.getLongitude().toString()) -// .param("title", title) -// .param("category", category.toString()) -// .param("area", area.toString()) -// .param("page", String.valueOf(pageNumber)) -// .param("size", String.valueOf(pageSize)) -// .param("lastId", String.valueOf(lastId)) -// ).andDo(print()) -// .andExpect(status().isOk()); -// -// // then -// then(eventService).should(times(1)).getAllByFilterOrderByDistanceAsc( -// any(LocationFilter.class), -// any(LocationRequest.class), -// eq(title), -// eq(category), -// eq(area), -// eq(pageable), -// eq(lastId) -// ); -// } -// -// @Test -// @DisplayName("주최자 id를 통한 모든 행사 조회 - 성공") -// @WithMockHost1 -// void getEventsByLocationByHostId() throws Exception { -// // given -// int pageNumber = 1; -// int pageSize = 10; -// Pageable pageable = PageRequest.of(pageNumber, pageSize); -// Long lastId = 1L; -// -// // when -// mockMvc.perform(get("/api/events/hosts/" + id) -// .param("page", String.valueOf(pageNumber)) -// .param("size", String.valueOf(pageSize)) -// .param("lastId", String.valueOf(lastId)) -// ) -// .andExpect(status().isOk()); -// -// //then -// then(eventService).should(times(1)).getAllByHostIdOrderByCreatedDateDesc( -// eq(id), -// eq(pageable), -// eq(lastId) -// ); -// } -// -// @Test -// @DisplayName("행사 id를 통한 행사 조회 - 성공") -// @WithMockHost1 -// void getEventByEventId() throws Exception { -// //given -// //when -// mockMvc.perform(get("/api/events/" + id)) -// .andDo(print()) -// .andExpect(status().isOk()); -// -// //then -// then(eventService).should(times(1)).getById(eq(id)); -// } -// -// @Test -// @DisplayName("행사 생성 - 성공") -// @WithMockHost1 -// void createEvent() throws Exception { -// //given -// //when -// mockMvc.perform(post("/api/events") -// .with(csrf()) -// .contentType(MediaType.APPLICATION_JSON) -// .content(objectMapper.writeValueAsString(EventData.event1.request.create.get()))) -// .andDo(print()) -// .andExpect(status().isCreated()); -// -// //then -// then(eventService).should(times(1)).create(eq(host1.memberIdentifier), any(EventCreateRequest.class)); -// } -// -// @Test -// @DisplayName("행사 수정 - 성공") -// @WithMockHost1 -// void updateEvent() throws Exception { -// //given -// //when -// mockMvc.perform(put("/api/events/" + id) -// .with(csrf()) -// .contentType(MediaType.APPLICATION_JSON) -// .content(objectMapper.writeValueAsString(EventData.event1.request.create.get()))) -// .andDo(print()) -// .andExpect(status().isOk()); -// -// //then -// then(eventService).should(times(1)).update(eq(host1.memberIdentifier), eq(id), any(EventEditRequest.class)); -// } -// -// @Test -// @DisplayName("행사 삭제 - 성공") -// @WithMockHost1 -// void deleteEvent() throws Exception { -// //given -// //when -// mockMvc.perform(delete("/api/events/" + id) -// .with(csrf()) -// ).andExpect(status().isNoContent()); -// -// //then -// then(eventService).should(times(1)).delete(eq(host1.memberIdentifier), eq(id)); -// } -//} \ No newline at end of file +package org.ktc2.cokaen.wouldyouin.event; + +import static java.lang.Math.abs; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.BDDMockito.then; +import static org.mockito.Mockito.times; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; +import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import com.fasterxml.jackson.databind.ObjectMapper; +import java.time.LocalDateTime; +import java.util.Random; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.ktc2.cokaen.wouldyouin._common.vo.Area; +import org.ktc2.cokaen.wouldyouin._common.vo.Category; +import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockCurator1; +import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost1; +import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember1; +import org.ktc2.cokaen.wouldyouin._global.testdata.EventData; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host1; +import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; +import org.ktc2.cokaen.wouldyouin.event.api.EventController; +import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; +import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; +import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationFilter; +import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationRequest; +import org.ktc2.cokaen.wouldyouin.event.application.EventService; +import org.mockito.ArgumentCaptor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.data.domain.PageRequest; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +@WebMvcTest(EventController.class) +class EventControllerUnitTest { + + private final Long randomId = abs(new Random().nextLong()); + @Autowired + private MockMvc mockMvc; + @Autowired + private ObjectMapper objectMapper; + @Autowired + private WebApplicationContext context; + @MockBean + private EventService eventService; + @MockBean + private JwtAuthFilter jwtAuthFilter; + + @BeforeEach + public void setup() throws Exception { + mockMvc = MockMvcBuilders + .webAppContextSetup(context) + .apply(springSecurity()) + .build(); + } + + @Test + @DisplayName("RequestParam을 통해 전달받은 위치를 기반으로 이벤트 목록을 조회한다.") + @WithMockMember1 + void getEventsByFilterOrderByDistanceAsc() throws Exception { + // given, when + mockMvc.perform(get("/api/events/filter") + .param("startLatitude", "0.0") + .param("startLongitude", "0.0") + .param("endLatitude", "10.0") + .param("endLongitude", "10.0") + .param("latitude", "3.0") + .param("longitude", "2.0") + .param("title", "testTitle") + .param("category", Category.밴드.name()) + .param("area", Area.광주.name()) + .param("page", "5") + .param("size", "20") + .param("lastId", "100")).andDo(print()) + .andExpect(status().isOk()); + + // then + then(eventService).should(times(1)).getAllByFilterOrderByDistanceAsc( + any(LocationFilter.class), + any(LocationRequest.class), + eq("testTitle"), + eq(Category.밴드), + eq(Area.광주), + eq(PageRequest.of(5, 20)), eq(100L) + ); + } + + @Test + @DisplayName("모든 이벤트 목록을 조회한다.") + @WithMockMember1 + void getEvents1() throws Exception { + // given, when + mockMvc.perform(get("/api/events") + .param("page", "5") + .param("size", "20") + .param("lastId", "100")).andDo(print()) + .andExpect(status().isOk()); + + // then + then(eventService).should(times(1)).getAllByCreatedDateDesc( + eq(PageRequest.of(5, 20)), eq(100L)); + } + + @Test + @DisplayName("RequestParam을 통해 페이지 정보를 지정하지 않은 경우, 디폴트 값으로 해당하는 호스트의 이벤트 목록을 조회한다.") + @WithMockMember1 + void getEvents2() throws Exception { + // given, when + mockMvc.perform(get("/api/events")).andDo(print()) + .andExpect(status().isOk()); + + // then + then(eventService).should(times(1)).getAllByCreatedDateDesc( + eq(PageRequest.of(0, 10)), eq(Long.MAX_VALUE)); + } + + @Test + @DisplayName("호스트 ID를 통해 해당하는 호스트의 이벤트 목록을 조회한다.") + @WithMockMember1 + void getEventsByHostId() throws Exception { + // given, when + mockMvc.perform(get("/api/events/hosts/" + randomId) + .param("page", "5") + .param("size", "20") + .param("lastId", "100")).andDo(print()) + .andExpect(status().isOk()); + + // then + then(eventService).should(times(1)).getAllByHostIdOrderByCreatedDateDesc( + eq(randomId), eq(PageRequest.of(5, 20)), eq(100L)); + } + + @Test + @DisplayName("이벤트 ID를 통해 해당하는 이벤트를 조회한다.") + @WithMockMember1 + void getEventByEventId() throws Exception { + // given, when + mockMvc.perform(get("/api/events/" + randomId)).andDo(print()) + .andExpect(status().isOk()); + + // then + then(eventService).should(times(1)).getById(eq(randomId)); + } + + @Test + @DisplayName("RequestBody로 전달받은 정보를 통해 이벤트를 생성한다.") + @WithMockHost1 + void createEvent1() throws Exception { + // given + ArgumentCaptor captor = ArgumentCaptor.forClass( + EventCreateRequest.class); + EventCreateRequest request = EventData.event1.request.create.get(); + + // when + mockMvc.perform(post("/api/events") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isCreated()); + + // then + then(eventService).should(times(1)).create(eq(host1.memberIdentifier), captor.capture()); + assertThat(captor.getValue()).isEqualTo(request); + } + + @Test + @DisplayName("Curator의 권한으로는 이벤트를 생성할 수 없다.") + @WithMockCurator1 + void createEvent2() throws Exception { + // given, when + mockMvc.perform(post("/api/events") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(EventData.event1.request.create.get()))) + .andDo(print()) + .andExpect(status().isUnauthorized()) + .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("Member의 권한으로는 이벤트를 생성할 수 없다.") + @WithMockMember1 + void createEvent3() throws Exception { + // given, when + mockMvc.perform(post("/api/events") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(EventData.event1.request.create.get()))) + .andDo(print()) + .andExpect(status().isUnauthorized()) + .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("이벤트 생성 시, 제목에는 빈 값이 들어갈 수 없다.") + @WithMockHost1 + void createEvent4() throws Exception { + // given + EventCreateRequest request = EventData.event1.request.create.get().toBuilder() + .title("").build(); + + // when + mockMvc.perform(post("/api/events") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("제목은 필수입니다.")); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("이벤트 생성 시, 내용에는 빈 값이 들어갈 수 없다.") + @WithMockHost1 + void createEvent5() throws Exception { + // given + EventCreateRequest request = EventData.event1.request.create.get().toBuilder() + .content(null).build(); + + // when + mockMvc.perform(post("/api/events") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("내용은 필수입니다.")); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("이벤트 생성 시, 내용은 20자 이상 1000자 이하이어야 한다.") + @WithMockHost1 + void createEvent6() throws Exception { + // given + EventCreateRequest request = EventData.event1.request.create.get().toBuilder() + .content("짧은 내용").build(); + + // when + mockMvc.perform(post("/api/events") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("내용은 20자 이상 1000자 이하입니다.")); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("이벤트 생성 시, 지역은 필수 입력값이다.") + @WithMockHost1 + void createEvent7() throws Exception { + // given + EventCreateRequest request = EventData.event1.request.create.get().toBuilder() + .area(null).build(); + + // when + mockMvc.perform(post("/api/events") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("지역는 필수입니다.")); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("이벤트 생성 시, 장소는 필수 입력값이다.") + @WithMockHost1 + void createEvent8() throws Exception { + // given + EventCreateRequest request = EventData.event1.request.create.get().toBuilder() + .location(null).build(); + + // when + mockMvc.perform(post("/api/events") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("장소는 필수입니다.")); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("이벤트 생성 시, 시작 시간은 필수 입력값이다.") + @WithMockHost1 + void createEvent9() throws Exception { + // given + EventCreateRequest request = EventData.event1.request.create.get().toBuilder() + .startTime(null).build(); + + // when + mockMvc.perform(post("/api/events") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("시작시간은 필수입니다.")); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("이벤트 생성 시, 종료 시간은 필수 입력값이다.") + @WithMockHost1 + void createEvent10() throws Exception { + // given + EventCreateRequest request = EventData.event1.request.create.get().toBuilder() + .endTime(null).build(); + + // when + mockMvc.perform(post("/api/events") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("종료시간은 필수입니다.")); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("이벤트 생성 시, 시작 시간은 현재 또는 이후 시간이어야 한다.") + @WithMockHost1 + void createEvent11() throws Exception { + // given + EventCreateRequest request = EventData.event1.request.create.get().toBuilder() + .startTime(LocalDateTime.now().minusDays(1)).build(); + + // when + mockMvc.perform(post("/api/events") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("시작 시간은 현재 시간 이후여야 합니다.")); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("이벤트 생성 시, 종료 시간은 현재 또는 이후 시간이어야 한다.") + @WithMockHost1 + void createEvent12() throws Exception { + // given + EventCreateRequest request = EventData.event1.request.create.get().toBuilder() + .startTime(LocalDateTime.now().minusDays(2)) // startTime을 미래로 설정 + .endTime(LocalDateTime.now().minusDays(1)) // endTime을 과거로 설정 + .build(); + + // when + mockMvc.perform(post("/api/events") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value( + org.hamcrest.Matchers.containsString("종료 시간은 현재 시간 이후여야 합니다."))); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("이벤트 생성 시, 종료 시간은 시작 시간 이후 시간이어야 한다.") + @WithMockHost1 + void createEvent13() throws Exception { + // given + EventCreateRequest request = EventData.event1.request.create.get().toBuilder() + .endTime(LocalDateTime.now().plusDays(2)).build(); + + // when + mockMvc.perform(post("/api/events") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("종료 시간은 시작 시간 이후여야 합니다.")); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("이벤트 생성 시, 가격은 0원 이상이어야 한다.") + @WithMockHost1 + void createEvent14() throws Exception { + // given + EventCreateRequest request = EventData.event1.request.create.get().toBuilder() + .price(-1).build(); + + // when + mockMvc.perform(post("/api/events") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("가격은 0원 이상입니다.")); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("이벤트 생성 시, 가격은 1,000,000원 이하이어야 한다.") + @WithMockHost1 + void createEvent15() throws Exception { + // given + EventCreateRequest request = EventData.event1.request.create.get().toBuilder() + .price(1000001).build(); + + // when + mockMvc.perform(post("/api/events") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("가격은 1,000,000원 이하입니다.")); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("이벤트 생성 시, 총 좌석은 0석 이상이어야 한다.") + @WithMockHost1 + void createEvent16() throws Exception { + // given + EventCreateRequest request = EventData.event1.request.create.get().toBuilder() + .totalSeat(-1).build(); + + // when + mockMvc.perform(post("/api/events") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("총 좌석은 0석 이상입니다.")); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("이벤트 생성 시, 총 좌석은 1,000석 이하이어야 한다.") + @WithMockHost1 + void createEvent17() throws Exception { + // given + EventCreateRequest request = EventData.event1.request.create.get().toBuilder() + .totalSeat(1001).build(); + + // when + mockMvc.perform(post("/api/events") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("총 좌석은 1,000석 이하입니다.")); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("이벤트 생성 시, 카테고리는 필수 입력값이다.") + @WithMockHost1 + void createEvent18() throws Exception { + // given + EventCreateRequest request = EventData.event1.request.create.get().toBuilder() + .category(null).build(); + + // when + mockMvc.perform(post("/api/events") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("카테고리는 필수입니다.")); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("RequestBody로 전달받은 정보를 통해 이벤트를 수정한다.") + @WithMockHost1 + void updateEvent1() throws Exception { + // given + ArgumentCaptor captor = ArgumentCaptor.forClass(EventEditRequest.class); + EventEditRequest request = EventData.event1.request.edit1.get(); + + // when + mockMvc.perform(put("/api/events/" + randomId) + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isOk()); + + // then + then(eventService).should(times(1)) + .update(eq(host1.memberIdentifier), eq(randomId), captor.capture()); + assertThat(captor.getValue()).isEqualTo(request); + } + + @Test + @DisplayName("Curator의 권한으로는 이벤트를 수정할 수 없다.") + @WithMockCurator1 + void updateEvent2() throws Exception { + // given, when + mockMvc.perform(put("/api/events/" + randomId) + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(EventData.event1.request.edit1.get()))) + .andDo(print()) + .andExpect(status().isUnauthorized()) + .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("Member의 권한으로는 이벤트를 수정할 수 없다.") + @WithMockMember1 + void updateEvent3() throws Exception { + // given, when + mockMvc.perform(put("/api/events/" + randomId) + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(EventData.event1.request.edit1.get()))) + .andDo(print()) + .andExpect(status().isUnauthorized()) + .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("이벤트 수정 시, 제목에는 빈 값이 들어갈 수 없다.") + @WithMockMember1 + void updateEvent4() throws Exception { + // given + EventEditRequest request = EventData.event1.request.edit1.get().toBuilder().title(null) + .build(); + + // when + mockMvc.perform(put("/api/events/" + randomId) + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("제목은 필수입니다.")); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("이벤트 수정 시, 내용은 빈 값이 들어갈 수 없다.") + @WithMockMember1 + void updateEvent5() throws Exception { + // given + EventEditRequest request = EventData.event1.request.edit1.get().toBuilder().content(null) + .build(); + + // when + mockMvc.perform(put("/api/events/" + randomId) + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("내용은 필수입니다.")); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("이벤트 수정 시, 내용은 20자 이상 1000자 이하이어야 한다.") + @WithMockMember1 + void updateEvent6() throws Exception { + // given + EventEditRequest request = EventData.event1.request.edit1.get().toBuilder().content("짧은 내용") + .build(); + + // when + mockMvc.perform(put("/api/events/" + randomId) + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("내용은 20자 이상 1000자 이하입니다.")); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("이벤트 수정 시, 지역은 필수이다.") + @WithMockMember1 + void updateEvent7() throws Exception { + // given + EventEditRequest request = EventData.event1.request.edit1.get().toBuilder().area(null) + .build(); + + // when + mockMvc.perform(put("/api/events/" + randomId) + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("지역는 필수입니다.")); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("이벤트 수정 시, 장소는 필수이다.") + @WithMockMember1 + void updateEvent8() throws Exception { + // given + EventEditRequest request = EventData.event1.request.edit1.get().toBuilder().location(null) + .build(); + + // when + mockMvc.perform(put("/api/events/" + randomId) + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("장소는 필수입니다.")); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("이벤트 수정 시, 시작 시간은 필수이다") + @WithMockMember1 + void updateEvent9() throws Exception { + // given + EventEditRequest request = EventData.event1.request.edit1.get().toBuilder() + .startTime(null).build(); + + // when + mockMvc.perform(put("/api/events/" + randomId) + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("시작 시간은 필수입니다.")); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("이벤트 수정 시, 시작 시간은 현재 시간 이후여야 한다.") + @WithMockMember1 + void updateEvent10() throws Exception { + // given + EventEditRequest request = EventData.event1.request.edit1.get().toBuilder() + .startTime(LocalDateTime.now().minusDays(1)) + .build(); + + // when + mockMvc.perform(put("/api/events/" + randomId) + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("시작 시간은 현재 시간 이후여야 합니다.")); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("이벤트 수정 시, 종료 시간은 필수이다") + @WithMockMember1 + void updateEvent11() throws Exception { + // given + EventEditRequest request = EventData.event1.request.edit1.get().toBuilder() + .endTime(null).build(); + + // when + mockMvc.perform(put("/api/events/" + randomId) + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("종료 시간은 필수입니다.")); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("이벤트 수정 시, 종료 시간은 현재 시간 이후여야 한다.") + @WithMockMember1 + void updateEvent12() throws Exception { + // given + EventEditRequest request = EventData.event1.request.edit1.get().toBuilder() + .endTime(LocalDateTime.now().minusDays(1)) + .build(); + + // when + mockMvc.perform(put("/api/events/" + randomId) + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value( + org.hamcrest.Matchers.containsString("종료 시간은 현재 시간 이후여야 합니다."))); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("이벤트 수정 시, 종료 시간은 시작 시간 이후여야 한다.") + @WithMockMember1 + void updateEvent13() throws Exception { + // given + EventEditRequest request = EventData.event1.request.edit1.get().toBuilder() + .endTime(LocalDateTime.now().plusDays(2)) + .build(); + + // when + mockMvc.perform(put("/api/events/" + randomId) + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("종료 시간은 시작 시간 이후여야 합니다.")); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("이벤트 수정 시, 가격은 0원 이상 1,000,000원 이하이어야 한다.") + @WithMockMember1 + void updateEvent14() throws Exception { + // given + EventEditRequest request = EventData.event1.request.edit1.get().toBuilder() + .price(1000001) // 1,000,001원 설정 + .build(); + + // when + mockMvc.perform(put("/api/events/" + randomId) + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("가격은 1,000,000원 이하입니다.")); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("이벤트 수정 시, 총 좌석은 0석 이상 1,000석 이하이어야 한다.") + @WithMockMember1 + void updateEvent15() throws Exception { + // given + EventEditRequest request = EventData.event1.request.edit1.get().toBuilder() + .totalSeat(1001) // 1,001석 설정 + .build(); + + // when + mockMvc.perform(put("/api/events/" + randomId) + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("총 좌석은 1,000석 이하입니다.")); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("PathVariable로 전달받은 이벤트 ID에 해당하는 이벤트를 삭제한다.") + @WithMockHost1 + void deleteEvent() throws Exception { + // given, when + mockMvc.perform(delete("/api/events/" + randomId) + .with(csrf())) + .andDo(print()) + .andExpect(status().isNoContent()); + + // then + then(eventService).should(times(1)).delete(eq(host1.memberIdentifier), eq(randomId)); + } + + @Test + @DisplayName("Curator의 권한으로는 큐레이션을 삭제할 수 없다.") + @WithMockCurator1 + void deleteEvent2() throws Exception { + // given, when + mockMvc.perform(delete("/api/events/" + randomId) + .with(csrf())) + .andDo(print()) + .andExpect(status().isUnauthorized()) + .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); + + // then + then(eventService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("Member의 권한으로는 큐레이션을 삭제할 수 없다.") + @WithMockMember1 + void deleteEvent3() throws Exception { + // given, when + mockMvc.perform(delete("/api/events/" + randomId) + .with(csrf())) + .andDo(print()) + .andExpect(status().isUnauthorized()) + .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); + + // then + then(eventService).shouldHaveNoInteractions(); + } +} \ No newline at end of file From 7be14a3e782d58cd7cb7a6ee6ed3eee965dd0c65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=99=8D=EC=8B=9D?= <90020593+Daolove0323@users.noreply.github.com> Date: Fri, 15 Nov 2024 00:57:47 +0900 Subject: [PATCH 36/53] =?UTF-8?q?[Weekly/11/Curation/test]=20=ED=81=90?= =?UTF-8?q?=EB=A0=88=EC=9D=B4=EC=85=98=20=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=EC=9C=A0=EB=8B=9B=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20(#135)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../curation/application/CurationService.java | 2 +- .../curation/persist/CurationRepository.java | 4 +- .../event/api/dto/LocationRequest.java | 3 + .../wouldyouin/image/persist/EventImage.java | 1 + .../wouldyouin/member/persist/Host.java | 3 +- .../_global/testdata/CommonData.java | 13 +- .../_global/testdata/CurationData.java | 283 ++++++++++++++---- .../_global/testdata/EventData.java | 75 +++++ .../_global/testdata/MemberData.java | 64 +++- .../_global/testdata/ReservationData.java | 2 +- .../curation/CurationControllerUnitTest.java | 43 +-- .../curation/CurationServiceTest.java | 173 ++++++++++- 12 files changed, 564 insertions(+), 102 deletions(-) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationService.java index 75d954aa..e4e94c96 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationService.java @@ -53,7 +53,7 @@ public CurationSliceResponse getAllByAreaOrderByCreatedDateDesc(Area area, Pagea @Transactional(readOnly = true) public CurationSliceResponse getAllByCuratorIdOrderByCreatedDateDesc(Long curatorId, Pageable pageable, Long lastId) { Slice curations = curationRepository.findAllByCuratorOrderByCreatedDateDesc( - curatorService.getByIdOrThrow(curatorId), lastId, pageable); + curatorId, lastId, pageable); Long newLastId = getLastId(curations, lastId); return CurationSliceResponse.from(getCurationResponses(curations), curations.getSize(), newLastId); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationRepository.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationRepository.java index b3190237..e2c3e940 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationRepository.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationRepository.java @@ -17,8 +17,8 @@ public interface CurationRepository extends JpaRepository { Slice findAllByAreaOrderByCreatedDateDesc(Area area, Long lastId, Pageable pageable); @Query("SELECT C FROM Curation C JOIN FETCH C.curator " - + "WHERE C.curator = :curator AND C.id > :lastId " + + "WHERE C.curator.id = :curatorId AND C.id > :lastId " + "ORDER BY C.id DESC") - Slice findAllByCuratorOrderByCreatedDateDesc(Curator curator, Long lastId, + Slice findAllByCuratorOrderByCreatedDateDesc(Long curatorId, Long lastId, Pageable pageable); } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationRequest.java index 86430e3a..08505767 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationRequest.java @@ -2,6 +2,7 @@ import jakarta.validation.constraints.Max; import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -17,10 +18,12 @@ @ToString public class LocationRequest { + @NotNull(message = "위도는 필수값입니다.") @Min(value = -90, message = "위도는 -90 이상이어야 합니다.") @Max(value = 90, message = "위도는 90 이하여야 합니다.") private Double latitude; + @NotNull(message = "경도는 필수값입니다.") @Min(value = -180, message = "경도는 -180 이상이어야 합니다.") @Max(value = 180, message = "경도는 180 이하여야 합니다.") private Double longitude; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/EventImage.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/EventImage.java index d9eb1d94..f8ffe173 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/EventImage.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/EventImage.java @@ -20,6 +20,7 @@ @NoArgsConstructor public class EventImage extends Image { + @ToString.Exclude @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "event_id") private Event event; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java index c0d319cc..05f48f6a 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java @@ -24,7 +24,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @DiscriminatorValue("Host") @EqualsAndHashCode(callSuper = true) -@ToString +@ToString() @Entity public class Host extends BaseMember implements LikeableMember { @@ -41,6 +41,7 @@ public class Host extends BaseMember implements LikeableMember { @Convert(converter = HashtagConverter.class) private List hashtags; + @ToString.Exclude @OneToMany(mappedBy = "host", fetch = FetchType.LAZY) private List events = new ArrayList<>(); diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java index a5c16066..9024bb7b 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java @@ -11,11 +11,14 @@ public static class path { public static class sliceInfo { - public static SliceInfo get() { - return SliceInfo.builder() - .sliceSize(10) - .lastId(100L) - .build(); + public static class curation { + + public static SliceInfo get() { + return SliceInfo.builder() + .sliceSize(10) + .lastId(301L) + .build(); + } } } } \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java index 0664ff97..6f0e7f41 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java @@ -1,10 +1,12 @@ package org.ktc2.cokaen.wouldyouin._global.testdata; +import static org.ktc2.cokaen.wouldyouin._global.testdata.EventData.response.curationEvent.createValidCurationEventResponse; + import java.time.LocalDateTime; import java.util.List; -import org.ktc2.cokaen.wouldyouin.image.persist.CurationImage; import org.ktc2.cokaen.wouldyouin._common.vo.Area; -import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.R.curationEditRequest; +import org.ktc2.cokaen.wouldyouin._global.testdata.EventData.R.event1; +import org.ktc2.cokaen.wouldyouin._global.testdata.EventData.R.event2; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCardRequest; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCardResponse; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCreateRequest; @@ -14,75 +16,119 @@ import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; import org.ktc2.cokaen.wouldyouin.curation.persist.CurationCard; import org.ktc2.cokaen.wouldyouin.event.persist.Event; +import org.ktc2.cokaen.wouldyouin.image.persist.CurationImage; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Slice; +import org.springframework.data.domain.SliceImpl; import org.springframework.test.util.ReflectionTestUtils; public class CurationData { public static class R { + public static class curationCard1 { + public static final Long id = 351L; public static final String subtitle = "큐레이션 카드 부제목1"; public static final String content = "큐레이션 카드 내용1 입니다. 큐레이션 카드의 내용은 최소 20자 최대 1000자 입니다."; public static final List images = List.of(ImageData.curation1.entity.get()); public static final List imageIds = List.of(1301L); - public static final List imageUrls = List.of("wouldyouin.com/curationImage1.jpg"); + public static final List imageUrls = List.of(ImageData.R.curation1.url); } + public static class curationCard2 { + public static final Long id = 352L; public static final String subtitle = "큐레이션 카드 부제목2"; public static final String content = "큐레이션 카드 내용2 입니다. 큐레이션 카드의 내용은 최소 20자 최대 1000자 입니다."; public static final List imageIds = List.of(1302L); - public static final List imageUrls = List.of("wouldyouin.com/curationImage2.jpg"); + public static final List imageUrls = List.of(ImageData.R.curation2.url); } - public static class curation { + + public static class curation1 { + public static final Long id = 301L; - public static final String title = "큐레이션 제목"; - public static final String content = "큐레이션 본문 입니다. 큐레이션의 본문은 최소 20자 최대 1000자 입니다."; + public static final String title = "큐레이션 제목1"; + public static final String content = "큐레이션 본문1 입니다. 큐레이션의 본문은 최소 20자 최대 1000자 입니다."; public static final List curationCards = List.of( - CurationData.curationCard1.entity.get(), - CurationData.curationCard2.entity.get() + CurationData.curationCard1.entity.get() ); public static final List curationCardRequests = List.of( - CurationData.curationCard1.request.get(), - CurationData.curationCard2.request.get() + CurationData.curationCard1.request.get() ); public static final List curationCardResponses = List.of( - CurationData.curationCard1.response.get(), - CurationData.curationCard2.response.get() + CurationData.curationCard1.response.get() ); + public static final int page = 0; + public static final int pageSize = 10; + public static final Long lastId = 100L; + public static final PageRequest pageable = PageRequest.of(0, 10); public static final Area area = Area.전체; public static final List hashtags = List.of("#큐레이션", "#해시태그"); - public static final List eventIds = List.of(201L); + public static final List eventIds = List.of(event1.id); public static final List events = List.of(EventData.event1.entity.get()); public static final LocalDateTime createdDate = LocalDateTime.of(2023, 3, 23, 0, 0); public static final LocalDateTime modifiedDate = LocalDateTime.of(2024, 3, 23, 0, 0); } - public static class curationEditRequest { + + public static class curation2 { + + public static final Long id = 301L; public static final String title = "큐레이션 제목 수정"; public static final String content = "수정된 큐레이션 본문 입니다. 큐레이션의 본문은 최소 20자 최대 1000자 입니다."; + public static final List curationCards = List.of( + CurationData.curationCard2.entity.get() + ); public static final List curationCardRequests = List.of( CurationData.curationCard2.request.get() ); + public static final List curationCardResponses = List.of( + CurationData.curationCard2.response.get() + ); + public static final int page = 0; + public static final int pageSize = 10; + public static final Long lastId = 100L; + public static final PageRequest pageable = PageRequest.of(0, 10); public static final Area area = Area.광주; public static final List hashtags = List.of("수정 해시태그"); - public static final List eventIds = List.of(202L); + public static final List eventIds = List.of(event2.id); + public static final List events = List.of(EventData.event1.entity.get()); + public static final LocalDateTime createdDate = LocalDateTime.of(2023, 3, 23, 0, 0); + public static final LocalDateTime modifiedDate = LocalDateTime.of(2024, 3, 23, 0, 0); } } public static class curationCard1 { + public static class entity { + public static CurationCard get() { CurationCard validCurationCard1 = CurationCard.builder() .subtitle(R.curationCard1.subtitle) .content(R.curationCard1.content) - // .curation(createValidCuration()) + .curation(CurationData.curation1.entity.get()) .images(R.curationCard1.images) .build(); ReflectionTestUtils.setField(validCurationCard1, "id", R.curationCard1.id); return validCurationCard1; } } + + public static class entityWithNoCuration { + + public static CurationCard get() { + CurationCard validCurationCard1 = CurationCard.builder() + .subtitle(R.curationCard1.subtitle) + .content(R.curationCard1.content) + .images(R.curationCard1.images) + .build(); + ReflectionTestUtils.setField(validCurationCard1, "id", R.curationCard1.id); + return validCurationCard1; + } + } + public static class request { + public static CurationCardRequest get() { return CurationCardRequest.builder() .subtitle(R.curationCard1.subtitle) @@ -91,7 +137,9 @@ public static CurationCardRequest get() { .build(); } } + public static class response { + public static CurationCardResponse get() { return CurationCardResponse.builder() .subtitle(R.curationCard1.subtitle) @@ -103,19 +151,36 @@ public static CurationCardResponse get() { } public static class curationCard2 { + public static class entity { + + public static CurationCard get() { + CurationCard validCurationCard2 = CurationCard.builder() + .subtitle(R.curationCard2.subtitle) + .content(R.curationCard2.content) + .curation(CurationData.curation1.entityWithNoCurationCard.get()) + .images(List.of(ImageData.curation2.entity.get())) + .build(); + ReflectionTestUtils.setField(validCurationCard2, "id", R.curationCard2.id); + return validCurationCard2; + } + } + + public static class entityWithNoCuration { + public static CurationCard get() { CurationCard validCurationCard2 = CurationCard.builder() .subtitle(R.curationCard2.subtitle) .content(R.curationCard2.content) - // .curation(createValidCuration()) .images(List.of(ImageData.curation2.entity.get())) .build(); ReflectionTestUtils.setField(validCurationCard2, "id", R.curationCard2.id); return validCurationCard2; } } + public static class request { + public static CurationCardRequest get() { return CurationCardRequest.builder() .subtitle(R.curationCard2.subtitle) @@ -124,7 +189,9 @@ public static CurationCardRequest get() { .build(); } } + public static class response { + public static CurationCardResponse get() { return CurationCardResponse.builder() .subtitle(R.curationCard2.subtitle) @@ -135,73 +202,187 @@ public static CurationCardResponse get() { } } - public static class curation { + public static class curation1 { + public static class entity { + + public static Curation get() { + Curation validCuration = Curation.builder() + .curator(MemberData.curator1.entity.get()) + .title(R.curation1.title) + .content(R.curation1.content) + .curationCards(R.curation1.curationCards) + .area(R.curation1.area) + .hashtags(R.curation1.hashtags) + .events(R.curation1.events) + .build(); + ReflectionTestUtils.setField(validCuration, "id", R.curation1.id); + ReflectionTestUtils.setField(validCuration, "createdDate", R.curation1.createdDate); + ReflectionTestUtils.setField(validCuration, "modifiedDate", R.curation1.modifiedDate); + return validCuration; + } + } + + public static class CurationSlice { + + public static Slice get() { + return new SliceImpl<>(List.of(entity.get()), R.curation1.pageable, true); + } + } + + public static class entityWithNoCurator { + + public static Curation get() { + Curation validCuration = Curation.builder() + .title(R.curation1.title) + .content(R.curation1.content) + .curationCards(R.curation1.curationCards) + .area(R.curation1.area) + .hashtags(R.curation1.hashtags) + .events(R.curation1.events) + .build(); + ReflectionTestUtils.setField(validCuration, "id", R.curation1.id); + ReflectionTestUtils.setField(validCuration, "createdDate", R.curation1.createdDate); + ReflectionTestUtils.setField(validCuration, "modifiedDate", R.curation1.modifiedDate); + return validCuration; + } + } + + public static class entityWithNoCurationCard { + + public static Curation get() { + Curation validCuration = Curation.builder() + .curator(MemberData.curator1.entity.get()) + .title(R.curation1.title) + .content(R.curation1.content) + .area(R.curation1.area) + .hashtags(R.curation1.hashtags) + .events(R.curation1.events) + .build(); + ReflectionTestUtils.setField(validCuration, "id", R.curation1.id); + ReflectionTestUtils.setField(validCuration, "createdDate", R.curation1.createdDate); + ReflectionTestUtils.setField(validCuration, "modifiedDate", R.curation1.modifiedDate); + return validCuration; + } + } + + public static class entityWithNoEvent { + public static Curation get() { Curation validCuration = Curation.builder() .curator(MemberData.curator1.entity.get()) - .title(R.curation.title) - .content(R.curation.content) - .curationCards(R.curation.curationCards) - .area(R.curation.area) - .hashtags(R.curation.hashtags) - .events(R.curation.events) + .title(R.curation1.title) + .content(R.curation1.content) + .curationCards(R.curation1.curationCards) + .area(R.curation1.area) + .hashtags(R.curation1.hashtags) + .events(List.of()) .build(); - ReflectionTestUtils.setField(validCuration, "id", R.curation.id); - ReflectionTestUtils.setField(validCuration, "createdDate", R.curation.createdDate); - ReflectionTestUtils.setField(validCuration, "modifiedDate", R.curation.modifiedDate); + ReflectionTestUtils.setField(validCuration, "id", R.curation1.id); + ReflectionTestUtils.setField(validCuration, "createdDate", R.curation1.createdDate); + ReflectionTestUtils.setField(validCuration, "modifiedDate", R.curation1.modifiedDate); return validCuration; } } + public static class request { + public static class create { + public static CurationCreateRequest get() { return CurationCreateRequest.builder() - .title(R.curation.title) - .content(R.curation.content) - .curationCards(R.curation.curationCardRequests) - .area(R.curation.area) - .hashtags(R.curation.hashtags) - .eventIds(R.curation.eventIds) + .title(R.curation1.title) + .content(R.curation1.content) + .curationCards(R.curation1.curationCardRequests) + .area(R.curation1.area) + .hashtags(R.curation1.hashtags) + .eventIds(R.curation1.eventIds) .build(); } } + public static class edit { + public static CurationEditRequest get() { return CurationEditRequest.builder() - .title(curationEditRequest.title) - .content(curationEditRequest.content) - .curationCards(curationEditRequest.curationCardRequests) - .area(curationEditRequest.area) - .hashtags(curationEditRequest.hashtags) - .eventIds(curationEditRequest.eventIds) + .title(R.curation2.title) + .content(R.curation2.content) + .curationCards(R.curation2.curationCardRequests) + .area(R.curation2.area) + .hashtags(R.curation2.hashtags) + .eventIds(R.curation2.eventIds) .build(); } } } + public static class response { + public static CurationResponse get() { return CurationResponse.builder() - .id(R.curation.id) - //.curator(MemberData.dto.response.curationCurator.get()) - .title(R.curation.title) - .content(R.curation.content) - .curationCards(R.curation.curationCardResponses) - .area(R.curation.area) - .hashtags(R.curation.hashtags) - //.eventsInfo(List.of(EventDomain.createValidCurationEventResponse())) - .createdTime(R.curation.createdDate) - .modifiedDate(R.curation.modifiedDate) + .id(R.curation1.id) + .curator(MemberData.response.curation1Curator1.get()) + .title(R.curation1.title) + .content(R.curation1.content) + .curationCards(R.curation1.curationCardResponses) + .area(R.curation1.area) + .hashtags(R.curation1.hashtags) + .eventsInfo(List.of(createValidCurationEventResponse())) + .createdTime(R.curation1.createdDate) + .modifiedDate(R.curation1.modifiedDate) .build(); } + public static class slice { + public static CurationSliceResponse get() { return CurationSliceResponse.builder() .curations(List.of(response.get())) - .sliceInfo(CommonData.sliceInfo.get()) + .sliceInfo(CommonData.sliceInfo.curation.get()) .build(); } } } } + + public static class curation2 { + + public static class entity { + + public static Curation get() { + Curation validCuration = Curation.builder() + .curator(MemberData.curator1.entity.get()) + .title(R.curation2.title) + .content(R.curation2.content) + .curationCards(List.of(curationCard2.entity.get())) + .area(R.curation2.area) + .hashtags(R.curation2.hashtags) + .events(R.curation1.events) + .build(); + ReflectionTestUtils.setField(validCuration, "id", R.curation2.id); + ReflectionTestUtils.setField(validCuration, "createdDate", R.curation2.createdDate); + ReflectionTestUtils.setField(validCuration, "modifiedDate", R.curation2.modifiedDate); + return validCuration; + } + } + + public static class response { + + public static CurationResponse get() { + return CurationResponse.builder() + .id(R.curation2.id) + .curator(MemberData.response.curation1Curator1.get()) + .title(R.curation2.title) + .content(R.curation2.content) + .curationCards(R.curation2.curationCardResponses) + .area(R.curation2.area) + .hashtags(R.curation2.hashtags) + .eventsInfo(List.of(createValidCurationEventResponse())) + .createdTime(R.curation2.createdDate) + .modifiedDate(R.curation2.modifiedDate) + .thumbnailUrl(ImageData.R.curation2.url) + .build(); + } + } + } } \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/EventData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/EventData.java index f00bd851..c46c10d2 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/EventData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/EventData.java @@ -70,6 +70,58 @@ public static class editRequest1 { public static final String thumbnailUrl = ImageData.getThumbnailUrl(_Relation.images().getFirst()); public static final LocalDateTime createdDate = LocalDateTime.now().minusDays(1); } + + public static class event2 { + public static class _Relation { + public static Host host() { + return MemberData.host1.entity.get(); + } + public static List images() { + return List.of( + ImageData.event1.entity.get(), + ImageData.event2.entity.get(), + ImageData.event3.entity.get()); + } + public static List imageUrls() { + return List.of( + ImageData.R.event1.url, + ImageData.R.event2.url, + ImageData.R.event3.url); + } + } + + public static class _Dto { + public static class editRequest1 { + public static final String title = "modifiedTitle"; + public static final String content = "modifiedContent 조홍식씨 최소글자 20자라고 해놓고 안 지켰어요. "; + public static final Area area = Area.광주; + public static final Location location = new Location(45.0, 143.0, "광주 북구 용봉로 77"); + public static final LocalDateTime startTime = event1.startTime.plusDays(2); + public static final LocalDateTime endTime = startTime.plusWeeks(3); + public static final int price = 20000; + public static final int totalSeat = 200; + public static final Category category = Category.뮤지컬; + public static final List imageIds = List.of( + ImageData.R.event4.id, + ImageData.R.event5.id + ); + } + } + + public static final long id = 202L; + public static final String title = "행사 제목"; + public static final String content = "행사 내용입니다. 행사의 내용은 최소 20자 최대 1000자 입니다."; + public static final Area area = Area.전체; + public static final Location location = new Location(55.0, 43.0, "광주 북구 용봉로 77"); + public static final LocalDateTime startTime = LocalDateTime.now().plusDays(3).plusHours(11).plusMinutes(47); + public static final LocalDateTime endTime = startTime.plusWeeks(2); + public static final Integer price = 15000; + public static final Integer totalSeat = 100; + public static final Integer leftSeat = 10; + public static final Category category = Category.밴드; + public static final String thumbnailUrl = ImageData.getThumbnailUrl(_Relation.images().getFirst()); + public static final LocalDateTime createdDate = LocalDateTime.now().minusDays(1); + } } public static class event1 { @@ -97,6 +149,29 @@ public static Event get() { return ret; } } + public static class entityWithNoHost { + public static Event get() { + Event ret = Event.builder() + .title(R.event1.title) + .content(R.event1.content) + .area(R.event1.area) + .location(R.event1.location) + .startTime(R.event1.startTime) + .endTime(R.event1.endTime) + .price(R.event1.price) + .totalSeat(R.event1.totalSeat) + .category(R.event1.category) + .images(R.event1._Relation.images()) + .thumbnailUrl(R.event1.thumbnailUrl) + .build(); + + ReflectionTestUtils.setField(ret, "id", R.event1.id); + ReflectionTestUtils.setField(ret, "leftSeat", R.event1.leftSeat); + ret.getHost().setEvents(List.of(ret)); + ret.getImages().forEach(image -> image.setEvent(ret)); + return ret; + } + } public static class request { public static class create { public static EventCreateRequest get() { diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java index fa45a36e..ab59ae1b 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java @@ -1,15 +1,16 @@ package org.ktc2.cokaen.wouldyouin._global.testdata; import java.util.List; -import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin._common.vo.Area; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator1; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; import org.ktc2.cokaen.wouldyouin.event.persist.Event; +import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin.like.persist.CuratorLike; import org.ktc2.cokaen.wouldyouin.like.persist.HostLike; -import org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse.ReservationMemberResponse; import org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse.CurationCuratorResponse; +import org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse.ReservationMemberResponse; import org.ktc2.cokaen.wouldyouin.member.persist.AccountType; import org.ktc2.cokaen.wouldyouin.member.persist.Curator; import org.ktc2.cokaen.wouldyouin.member.persist.Host; @@ -22,21 +23,28 @@ public class MemberData { public static class R { + public static class normal1 { + public static class _Relation { + public static List curatorLikes() { return null; // TODO: Implement } + public static List hostLikes() { return null; // TODO: Implement } + public static List reservations() { return null; // TODO: Implement } + public static List reviews() { return null; // TODO: Implement } } + public static final long id = 101L; public static final MemberIdentifier memberIdentifier = new MemberIdentifier(id, MemberType.normal); public static final AccountType accountType = AccountType.kakao; @@ -51,18 +59,23 @@ public static List reviews() { public static final String socialId = "100100100100100"; public static final MemberType memberType = MemberType.normal; } + public static class curator1 { + public static class _Relation { + public static List curations() { return null; // TODO: Implement } } + public static final long id = 201L; public static final MemberIdentifier memberIdentifier = new MemberIdentifier(id, MemberType.curator); public static final AccountType accountType = AccountType.google; public static final String email = "curator1@example.com"; public static final String nickname = "nick_curator_12"; public static final String phone = "010-4545-6767"; + public static final Integer likes = 10; public static final MemberImage profileImage = ImageData.member.curator.entity.get(); public static final String profileImageUrl = ImageData.R.member.curator.url; public static final String profileImageThumbnailUrl = ImageData.getThumbnailUrl(profileImage); @@ -72,12 +85,16 @@ public static List curations() { public static final String intro = "큐레이터 자기소개입니다."; public static final List hashtags = List.of("#큐레이터", "#해시태그", "#입니다"); } + public static class host1 { + public static class _Relation { + public static List events() { return null; // TODO: Implement } } + public static final long id = 301; public static final MemberIdentifier memberIdentifier = new MemberIdentifier(id, MemberType.host); public static final String email = "host1@example.com"; @@ -91,7 +108,9 @@ public static List events() { public static final List hashtags = List.of("#주최자", "#해시태그", "#입니다"); } + public static class welcome1 { + public static final long id = 401; public static final MemberIdentifier memberIdentifier = new MemberIdentifier(id, MemberType.welcome); public static final AccountType accountType = AccountType.kakao; @@ -106,14 +125,18 @@ public static class welcome1 { public static final String socialId = "456456456456"; } + public static class admin1 { + public static final long id = 501L; public static final MemberIdentifier memberIdentifier = new MemberIdentifier(id, MemberType.admin); } } public static class normal1 { + public static class entity { + public static Member get() { Member ret = Member.builder() .accountType(R.normal1.accountType) @@ -128,20 +151,24 @@ public static Member get() { .build(); ReflectionTestUtils.setField(ret, "id", R.normal1.id); ReflectionTestUtils.setField(ret, "memberType", R.normal1.memberType); -// ReflectionTestUtils.setField(ret.getProfileImage(), "baseMember", ret); + ReflectionTestUtils.setField(ret.getProfileImage(), "baseMember", ret); return ret; } } + public static class request { } + public static class response { } } public static class curator1 { + public static class entity { + public static Curator get() { Curator ret = Curator.curatorBuilder() .accountType(R.curator1.accountType) @@ -157,20 +184,36 @@ public static Curator get() { ReflectionTestUtils.setField(ret, "id", R.curator1.id); ReflectionTestUtils.setField(ret, "intro", R.curator1.intro); ReflectionTestUtils.setField(ret, "hashtags", R.curator1.hashtags); -// ReflectionTestUtils.setField(ret.getProfileImage(), "baseMember", ret); + ReflectionTestUtils.setField(ret, "likes", R.curator1.likes); + + ReflectionTestUtils.setField(ret.getProfileImage(), "baseMember", ret); return ret; } } public static class request { } + public static class response { + public static CurationCuratorResponse getCurationCuratorResponse() { + return CurationCuratorResponse.builder() + .nickname(R.curator1.nickname) + .email(R.curator1.email) + .phone(R.curator1.phone) + .profileImageUrl(R.curator1.profileImageUrl) + .intro(R.curator1.intro) + .likes(R.curator1.likes) + .hashtags(R.curator1.hashtags) + .build(); + } } } public static class host1 { + public static class entity { + public static Host get() { Host ret = Host.builder() .email(R.host1.email) @@ -187,16 +230,20 @@ public static Host get() { return ret; } } + public static class request { } + public static class response { } } public static class welcome1 { + public static class entity { + public static Member get() { Member ret = Member.builder() .accountType(R.welcome1.accountType) @@ -214,34 +261,43 @@ public static Member get() { return ret; } } + public static class request { } + public static class response { } } public static class admin1 { + public static class entity { public static final long validAdminId = 105L; } + public static class request { } + public static class response { } } public static class response { + public static class reservation1Member1 { + public static ReservationMemberResponse get() { return ReservationMemberResponse.from(normal1.entity.get()); } } + public static class curation1Curator1 { + public static CurationCuratorResponse get() { return CurationCuratorResponse.from(curator1.entity.get()); } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ReservationData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ReservationData.java index 455460b0..1f6789a4 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ReservationData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ReservationData.java @@ -69,7 +69,7 @@ public static ReservationSliceResponse get() { return ReservationSliceResponse.builder() .reservations(List.of( ReservationData.reservation1.response.get())) - .sliceInfo(CommonData.sliceInfo.get()) + .sliceInfo(CommonData.sliceInfo.curation.get()) .build(); } } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java index 06d8ad45..172396da 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java @@ -26,6 +26,7 @@ import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost1; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember1; import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData; +import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.curation1; import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator1; import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; import org.ktc2.cokaen.wouldyouin.curation.api.CurationController; @@ -143,7 +144,7 @@ void createCuration1() throws Exception { // given ArgumentCaptor captor = ArgumentCaptor.forClass( CurationCreateRequest.class); - CurationCreateRequest request = CurationData.curation.request.create.get(); + CurationCreateRequest request = curation1.request.create.get(); // when mockMvc.perform(post("/api/curations") @@ -167,7 +168,7 @@ void createCuration2() throws Exception { mockMvc.perform(post("/api/curations") .with(csrf()) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(CurationData.curation.request.create.get()))) + .content(objectMapper.writeValueAsString(curation1.request.create.get()))) .andDo(print()) .andExpect(status().isUnauthorized()) .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); @@ -184,7 +185,7 @@ void createCuration3() throws Exception { mockMvc.perform(post("/api/curations") .with(csrf()) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(CurationData.curation.request.create.get()))) + .content(objectMapper.writeValueAsString(curation1.request.create.get()))) .andDo(print()) .andExpect(status().isUnauthorized()) .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); @@ -198,7 +199,7 @@ void createCuration3() throws Exception { @WithMockCurator1 void createCuration4() throws Exception { // given - CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() + CurationCreateRequest request = curation1.request.create.get().toBuilder() .title("").build(); // when @@ -219,7 +220,7 @@ void createCuration4() throws Exception { @WithMockCurator1 void createCuration5() throws Exception { // given - CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() + CurationCreateRequest request = curation1.request.create.get().toBuilder() .curationCards( List.of(CurationData.curationCard1.request.get().toBuilder().subtitle("").build())) .build(); @@ -242,7 +243,7 @@ void createCuration5() throws Exception { @WithMockCurator1 void createCuration6() throws Exception { // given - CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() + CurationCreateRequest request = curation1.request.create.get().toBuilder() .curationCards( List.of(CurationData.curationCard1.request.get().toBuilder().content(null).build())) .build(); @@ -265,7 +266,7 @@ void createCuration6() throws Exception { @WithMockCurator1 void createCuration7() throws Exception { // given - CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() + CurationCreateRequest request = curation1.request.create.get().toBuilder() .curationCards( List.of(CurationData.curationCard1.request.get().toBuilder().content(null).build())) .build(); @@ -288,7 +289,7 @@ void createCuration7() throws Exception { @WithMockCurator1 void createCuration8() throws Exception { // given - CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() + CurationCreateRequest request = curation1.request.create.get().toBuilder() .curationCards(List.of( CurationData.curationCard1.request.get().toBuilder().content("짧은 내용").build())) .build(); @@ -311,7 +312,7 @@ void createCuration8() throws Exception { @WithMockCurator1 void createCuration9() throws Exception { // given - CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() + CurationCreateRequest request = curation1.request.create.get().toBuilder() .curationCards(List.of(CurationData.curationCard1.request.get().toBuilder() .imageIds(List.of(1L, 2L, 3L, 4L, 5L, 6L)).build())) .build(); @@ -334,7 +335,7 @@ void createCuration9() throws Exception { @WithMockCurator1 void createCuration10() throws Exception { // given - CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() + CurationCreateRequest request = curation1.request.create.get().toBuilder() .area(null).build(); // when @@ -355,7 +356,7 @@ void createCuration10() throws Exception { @WithMockCurator1 void createCuration11() throws Exception { // given - CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder(). + CurationCreateRequest request = curation1.request.create.get().toBuilder(). curationCards(List.of()).build(); // when @@ -378,7 +379,7 @@ void updateCuration1() throws Exception { // given ArgumentCaptor captor = ArgumentCaptor.forClass( CurationEditRequest.class); - CurationEditRequest request = CurationData.curation.request.edit.get(); + CurationEditRequest request = curation1.request.edit.get(); // when mockMvc.perform(put("/api/curations/" + randomId) @@ -402,7 +403,7 @@ void updateCuration2() throws Exception { mockMvc.perform(put("/api/curations/" + randomId) .with(csrf()) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(CurationData.curation.request.edit.get()))) + .content(objectMapper.writeValueAsString(curation1.request.edit.get()))) .andDo(print()) .andExpect(status().isUnauthorized()) .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); @@ -419,7 +420,7 @@ void updateCuration3() throws Exception { mockMvc.perform(put("/api/curations/" + randomId) .with(csrf()) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(CurationData.curation.request.edit.get()))) + .content(objectMapper.writeValueAsString(curation1.request.edit.get()))) .andDo(print()) .andExpect(status().isUnauthorized()) .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); @@ -433,7 +434,7 @@ void updateCuration3() throws Exception { @WithMockCurator1 void updateCuration4() throws Exception { // given - CurationEditRequest request = CurationData.curation.request.edit.get().toBuilder() + CurationEditRequest request = curation1.request.edit.get().toBuilder() .title(null).build(); // when @@ -454,7 +455,7 @@ void updateCuration4() throws Exception { @WithMockCurator1 void updateCuration5() throws Exception { // given - CurationEditRequest request = CurationData.curation.request.edit.get().toBuilder() + CurationEditRequest request = curation1.request.edit.get().toBuilder() .curationCards(List.of(CurationData.curationCard1.request.get().toBuilder() .subtitle("").build())) .build(); @@ -477,7 +478,7 @@ void updateCuration5() throws Exception { @WithMockCurator1 void updateCuration6() throws Exception { // given - CurationEditRequest request = CurationData.curation.request.edit.get().toBuilder() + CurationEditRequest request = curation1.request.edit.get().toBuilder() .curationCards(List.of(CurationData.curationCard1.request.get().toBuilder() .content(null).build())) .build(); @@ -500,7 +501,7 @@ void updateCuration6() throws Exception { @WithMockCurator1 void updateCuration7() throws Exception { // given - CurationEditRequest request = CurationData.curation.request.edit.get().toBuilder() + CurationEditRequest request = curation1.request.edit.get().toBuilder() .curationCards(List.of(CurationData.curationCard1.request.get().toBuilder() .content("짧은 내용").build())) .build(); @@ -523,7 +524,7 @@ void updateCuration7() throws Exception { @WithMockCurator1 void updateCuration8() throws Exception { // given - CurationEditRequest request = CurationData.curation.request.edit.get().toBuilder() + CurationEditRequest request = curation1.request.edit.get().toBuilder() .curationCards(List.of(CurationData.curationCard1.request.get().toBuilder() .imageIds(List.of(1L, 2L, 3L, 4L, 5L, 6L)).build())) .build(); @@ -546,7 +547,7 @@ void updateCuration8() throws Exception { @WithMockCurator1 void updateCuration9() throws Exception { // given - CurationEditRequest request = CurationData.curation.request.edit.get().toBuilder() + CurationEditRequest request = curation1.request.edit.get().toBuilder() .area(null).build(); // when @@ -567,7 +568,7 @@ void updateCuration9() throws Exception { @WithMockCurator1 void updateCuration10() throws Exception { // given - CurationEditRequest request = CurationData.curation.request.edit.get().toBuilder() + CurationEditRequest request = curation1.request.edit.get().toBuilder() .curationCards(List.of()).build(); // when diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java index 1d21a5f3..739ad27f 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java @@ -2,6 +2,9 @@ import static java.lang.Math.abs; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.times; @@ -12,16 +15,28 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.ktc2.cokaen.wouldyouin.image.application.CurationImageService; -import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; +import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData; +import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.R.curation1; +import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.curation1.entity; +import org.ktc2.cokaen.wouldyouin._global.testdata.EventData; +import org.ktc2.cokaen.wouldyouin._global.testdata.EventData.R.event2; +import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData; +import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.R.curation2; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator1; +import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationResponse; +import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationSliceResponse; import org.ktc2.cokaen.wouldyouin.curation.application.CurationCardService; import org.ktc2.cokaen.wouldyouin.curation.application.CurationService; import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; import org.ktc2.cokaen.wouldyouin.curation.persist.CurationRepository; import org.ktc2.cokaen.wouldyouin.event.application.EventService; +import org.ktc2.cokaen.wouldyouin.image.application.CurationImageService; +import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin.member.application.CuratorService; +import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @@ -45,9 +60,15 @@ class CurationServiceTest { @Mock private CurationImageService curationImageService; + @Mock + private CurationResponse curationResponse; + @Mock private MemberImage memberImage; + Curation validCuration = entity.get(); + CurationResponse validCurationResponse = CurationData.curation1.response.get(); + private final long randomId = abs(new Random().nextLong()); @BeforeEach @@ -56,41 +77,161 @@ void setUp() { } @Test - @DisplayName("큐레이션 ID를 통해 큐레이션을 찾지 못한 경우, 예외를 던진다.") + @DisplayName("큐레이션 ID를 통해 해당 하는 큐레이션을 반환한다.") void getById() { -// // given -// Curation validCuration = CurationData.curation.entity.get(); -// given(curationRepository.findById(randomId)).willReturn(Optional.of(validCuration)); -// -// // when -// CurationResponse response = curationService.getById(randomId); -// -// // then -// then(curationRepository).should(times(1)).findById(randomId); -// assertThat(response).usingRecursiveComparison().isEqualTo(CurationData.curation.response.get()); + // given + given(curationRepository.findById(randomId)).willReturn(Optional.of(validCuration)); + given(curationImageService.getImageUrl(ImageData.curation1.entity.get())).willReturn(ImageData.R.curation1.url); + + // when + CurationResponse response = curationService.getById(randomId); + + // then + assertThat(response).isEqualTo(validCurationResponse); } @Test - @DisplayName("큐레이션 ID를 통해 큐레이션을 찾지 못한 경우, 예외를 던진다.") + @DisplayName("해당하는 지역의 모든 큐레이션을 반환한다.") void getAllByAreaOrderByCreatedDateDesc() { // given + given(curationRepository.findAllByAreaOrderByCreatedDateDesc(curation1.area, curation1.lastId, curation1.pageable)) + .willReturn(CurationData.curation1.CurationSlice.get()); + given(curationImageService.getImageUrl(ImageData.curation1.entity.get())).willReturn(ImageData.R.curation1.url); + // when + CurationSliceResponse response = + curationService.getAllByAreaOrderByCreatedDateDesc(curation1.area, curation1.pageable, curation1.lastId); + // then + assertThat(response).isEqualTo(CurationData.curation1.response.slice.get()); } @Test + @DisplayName("큐레이터 ID를 통해 해당하는 모든 큐레이션을 반환한다.") void getAllByCuratorIdOrderByCreatedDateDesc() { + // given + given(curationRepository.findAllByCuratorOrderByCreatedDateDesc(curator1.id, curation1.lastId, curation1.pageable)) + .willReturn(CurationData.curation1.CurationSlice.get()); + given(curationImageService.getImageUrl(ImageData.curation1.entity.get())).willReturn(ImageData.R.curation1.url); + + // when + CurationSliceResponse response = + curationService.getAllByCuratorIdOrderByCreatedDateDesc(curator1.id, curation1.pageable, curation1.lastId); + + // then + assertThat(response).isEqualTo(CurationData.curation1.response.slice.get()); } @Test + @DisplayName("CurationCreateReqeust를 통해 큐레이션을 생성한다.") void create() { + // given + given(curatorService.getByIdOrThrow(curator1.id)).willReturn(MemberData.curator1.entity.get()); + given(curationCardService.create(CurationData.curationCard1.request.get())) + .willReturn(CurationData.curationCard1.entity.get()); + given(eventService.getByIdOrThrow(curation1.eventIds.getFirst())).willReturn(EventData.event1.entity.get()); + given(curationRepository.save(any(Curation.class))).willReturn(CurationData.curation1.entity.get()); + given(curationImageService.getImageUrl(ImageData.curation1.entity.get())).willReturn(ImageData.R.curation1.url); + + // when + CurationResponse response = curationService.create(curator1.memberIdentifier, CurationData.curation1.request.create.get()); + + // then + assertThat(response).isEqualTo(CurationData.curation1.response.get()); + } + + @Test + @DisplayName("CurationCreateReqeust를 통해 큐레이션을 수정한다.") + void update1() { + // given + given(curationRepository.findById(curation1.id)).willReturn(Optional.of(CurationData.curation1.entity.get())); + given(curationCardService.create(CurationData.curationCard2.request.get())) + .willReturn(CurationData.curationCard2.entity.get()); + given(eventService.getByIdOrThrow(event2.id)).willReturn(EventData.event1.entity.get()); + given(curationImageService.getImageUrl(ImageData.curation2.entity.get())).willReturn(curation2.url); + given(curationImageService.createThumbnail(curation2.name)).willReturn(curation2.url); + + // when + CurationResponse response = curationService.update(curator1.memberIdentifier, curation1.id, + CurationData.curation1.request.edit.get()); + + // then + assertThat(response).isEqualTo(CurationData.curation2.response.get()); + } + + @Test + @DisplayName("멤버 ID가 다르면 큐레이션을 수정할 수 없다.") + void update2() { + // given + Long invalidCuratorId = 100L; + given(curationRepository.findById(curation1.id)).willReturn(Optional.of(CurationData.curation1.entity.get())); + + // when, then + assertThrows( + UnauthorizedException.class, () -> curationService.update( + new MemberIdentifier(invalidCuratorId, MemberType.curator), curation1.id, CurationData.curation1.request.edit.get())); } @Test - void update() { + @DisplayName("멤버 ID가 달라도 ADMIN은 큐레이션을 수정할 수 있다.") + void update3() { + // given + Long invalidCuratorId = 100L; + given(curationRepository.findById(curation1.id)).willReturn(Optional.of(CurationData.curation1.entity.get())); + given(curationCardService.create(CurationData.curationCard2.request.get())) + .willReturn(CurationData.curationCard2.entity.get()); + given(eventService.getByIdOrThrow(event2.id)).willReturn(EventData.event1.entity.get()); + given(curationImageService.getImageUrl(ImageData.curation2.entity.get())).willReturn(curation2.url); + given(curationImageService.createThumbnail(curation2.name)).willReturn(curation2.url); + + // when + CurationResponse response = curationService.update(new MemberIdentifier(invalidCuratorId, MemberType.admin), curation1.id, + CurationData.curation1.request.edit.get()); + + // then + assertThat(response).isEqualTo(CurationData.curation2.response.get()); } @Test - void delete() { + @DisplayName("큐레이션 ID를 통해 해당하는 큐레이션을 삭제한다.") + void delete1() { + // given + given(curationRepository.findById(curation1.id)).willReturn(Optional.of(CurationData.curation1.entity.get())); + + // when + curationService.delete(curator1.memberIdentifier, curation1.id); + + // then + then(curationCardService).should(times(curation1.curationCards.size())).delete(eq(curator1.memberIdentifier), any()); + then(curationRepository).should(times(1)).deleteById(curation1.id); + } + + @Test + @DisplayName("멤버 ID가 다르면 큐레이션을 삭제할 수 없다.") + void delete2() { + // given + Long invalidCuratorId = 100L; + given(curationRepository.findById(curation1.id)).willReturn(Optional.of(CurationData.curation1.entity.get())); + + // when, then + assertThrows( + UnauthorizedException.class, () -> curationService.delete( + new MemberIdentifier(invalidCuratorId, MemberType.curator), curation1.id)); + } + + @Test + @DisplayName("멤버 ID가 달라도 ADMIN은 큐레이션을 삭제할 수 있다.") + void delete3() { + // given + Long invalidCuratorId = 100L; + MemberIdentifier admin = new MemberIdentifier(invalidCuratorId, MemberType.admin); + given(curationRepository.findById(curation1.id)).willReturn(Optional.of(CurationData.curation1.entity.get())); + + // when + curationService.delete(admin, curation1.id); + + // then + then(curationCardService).should(times(curation1.curationCards.size())).delete(eq(admin), any()); + then(curationRepository).should(times(1)).deleteById(curation1.id); } } \ No newline at end of file From 175857668366c2589ed992d8b9b4337cf34a8883 Mon Sep 17 00:00:00 2001 From: Jangan Lee Date: Fri, 15 Nov 2024 01:13:08 +0900 Subject: [PATCH 37/53] =?UTF-8?q?[Weekly/11/Feature/LoggingAOP]=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=ED=98=B8=EC=B6=9C=20Logger=20AOP?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80=20(#136)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cokaen/wouldyouin/_common/aop/Logger.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/_common/aop/Logger.java diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/aop/Logger.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/aop/Logger.java new file mode 100644 index 00000000..52d9e4e1 --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/aop/Logger.java @@ -0,0 +1,59 @@ +package org.ktc2.cokaen.wouldyouin._common.aop; + +import jakarta.servlet.http.HttpServletRequest; +import java.net.URLDecoder; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Map; +import lombok.extern.slf4j.Slf4j; +import net.minidev.json.JSONObject; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; +import org.springframework.stereotype.Component; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +@Slf4j +@Aspect +@Component +public class Logger { + + @Pointcut("execution(* org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter.*(..))") + public void springFilterExecution() { + } + + @Pointcut("execution(* org.ktc2.cokaen.wouldyouin..*.*(..)) && !springFilterExecution()") + public void all() { + } + + @Around("all()") + public Object logging(ProceedingJoinPoint joinPoint) throws Throwable { + String methodName = joinPoint.getSignature().toShortString(); + String packageName = joinPoint.getSignature().getDeclaringTypeName() + .replace("org.ktc2.cokaen.wouldyouin.", "") + .replaceAll("\\.[^\\.]+$", ""); + Object[] args = joinPoint.getArgs(); + long start = System.currentTimeMillis(); + long timeInMs; + Object result; + log.debug("{} : CALL {}", packageName, methodName); + log.debug("{} : with param = {}", packageName, args); + + try { + result = joinPoint.proceed(); + } catch(Throwable t) { + log.debug("{} : {} throws {}", packageName, methodName, t.getClass().getSimpleName()); + throw t; + } finally { + timeInMs = System.currentTimeMillis() - start; + log.debug("{} : EXIT {}", packageName, methodName); + log.debug("{} : with executeTime = {}ms", packageName, timeInMs); + } + + log.debug("{} : with return = {}", packageName, result); + + return result; + } +} From 253f74369b567bc6c3e953eaf168ae47f9a0db4f Mon Sep 17 00:00:00 2001 From: ariimo Date: Fri, 15 Nov 2024 03:17:54 +0900 Subject: [PATCH 38/53] =?UTF-8?q?[Weekly/11/Test/Review]=20ReviewControlle?= =?UTF-8?q?r=20=EB=8B=A8=EC=9C=84=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=20(#137)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: ReviewData 생성 * test: ReviewControllerUnitTest 작성 --- .../review/api/ReviewController.java | 20 +- .../review/api/dto/ReviewCreateRequest.java | 12 +- .../review/api/dto/ReviewEditRequest.java | 9 +- .../review/application/ReviewService.java | 10 +- .../_global/testdata/CommonData.java | 22 + .../_global/testdata/EventData.java | 92 ++- .../_global/testdata/MemberData.java | 7 +- .../_global/testdata/ReservationData.java | 32 +- .../_global/testdata/ReviewData.java | 109 ++++ .../ReservationControllerUnitTest.java | 20 +- .../review/ReviewControllerUnitTest.java | 571 ++++++++++++++++++ 11 files changed, 834 insertions(+), 70 deletions(-) create mode 100644 src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ReviewData.java create mode 100644 src/test/java/org/ktc2/cokaen/wouldyouin/review/ReviewControllerUnitTest.java diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/ReviewController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/ReviewController.java index abf69bb3..98f03c50 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/ReviewController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/ReviewController.java @@ -35,12 +35,12 @@ public class ReviewController { @GetMapping public ResponseEntity> getReviewsByMemberId( - @Authorize({MemberType.normal}) MemberIdentifier member, + @Authorize({MemberType.normal, MemberType.curator}) MemberIdentifier member, @RequestParam(defaultValue = ParamDefaults.PAGE) Integer page, @RequestParam(defaultValue = ParamDefaults.PAGE_SIZE) Integer size, @RequestParam(defaultValue = ParamDefaults.LAST_ID) Long lastId) { return ApiResponse.ok( - reviewService.getAllByMemberId(member.id(), lastId, PageRequest.of(page, size))); + reviewService.getAllByMemberId(member.id(), PageRequest.of(page, size), lastId)); } @GetMapping("/events/{eventId}") @@ -50,7 +50,7 @@ public ResponseEntity> getReviewsByEventId( @RequestParam(defaultValue = ParamDefaults.PAGE_SIZE) Integer size, @RequestParam(defaultValue = ParamDefaults.LAST_ID) Long lastId) { return ApiResponse.ok( - reviewService.getAllByEventId(eventId, lastId, PageRequest.of(page, size))); + reviewService.getAllByEventId(eventId, PageRequest.of(page, size), lastId)); } @GetMapping("/{reviewId}") @@ -61,16 +61,18 @@ public ResponseEntity> getReviewByReviewId( @GetMapping("events") public ResponseEntity> getUnreviewedEventsByMemberId( - @Authorize(MemberType.normal) MemberIdentifier identifier, + @Authorize({MemberType.normal, MemberType.curator}) MemberIdentifier identifier, @RequestParam(defaultValue = ParamDefaults.PAGE) Integer page, @RequestParam(defaultValue = ParamDefaults.PAGE_SIZE) Integer size, - @RequestParam(defaultValue = ParamDefaults.LAST_ID) Long lastId){ - return ApiResponse.ok(reviewService.getUnreviewedEventsByMemberId(identifier.id(), PageRequest.of(page, size), lastId)); + @RequestParam(defaultValue = ParamDefaults.LAST_ID) Long lastId) { + return ApiResponse.ok( + reviewService.getUnreviewedEventsByMemberId(identifier.id(), PageRequest.of(page, size), + lastId)); } @PostMapping public ResponseEntity> createReview( - @Authorize(MemberType.normal) MemberIdentifier member, + @Authorize({MemberType.normal, MemberType.curator}) MemberIdentifier member, @Valid @RequestBody ReviewCreateRequest reviewCreateRequest) { return ApiResponse.created(reviewService.create(member.id(), reviewCreateRequest)); } @@ -78,7 +80,7 @@ public ResponseEntity> createReview( @PutMapping("/{reviewId}") public ResponseEntity> updateReview( @PathVariable("reviewId") Long reviewId, - @Authorize(MemberType.normal) MemberIdentifier member, + @Authorize({MemberType.normal, MemberType.curator}) MemberIdentifier member, @Valid @RequestBody ReviewEditRequest reviewEditRequest) { return ApiResponse.ok(reviewService.update(member.id(), reviewId, reviewEditRequest)); } @@ -86,7 +88,7 @@ public ResponseEntity> updateReview( @DeleteMapping("/{reviewId}") public ResponseEntity> deleteReview( @PathVariable("reviewId") Long reviewId, - @Authorize(MemberType.normal) MemberIdentifier member) { + @Authorize({MemberType.normal, MemberType.curator}) MemberIdentifier member) { reviewService.delete(member.id(), reviewId); return ApiResponse.noContent(); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewCreateRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewCreateRequest.java index a6653ef6..61fcb95c 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewCreateRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewCreateRequest.java @@ -14,7 +14,7 @@ import org.ktc2.cokaen.wouldyouin.review.persist.Review; @Getter -@Builder +@Builder(toBuilder = true) @EqualsAndHashCode @ToString public class ReviewCreateRequest { @@ -22,12 +22,12 @@ public class ReviewCreateRequest { @NotNull(message = "이벤트 ID는 필수입니다.") private Long eventId; - @NotBlank(message = "별점은 필수입니다.") - @Min(value = 0, message = "별점은 0점 이상입니다. ") - @Max(value = 5, message = "별점은 5점 이하입니다. ") - private int score; + @NotNull(message = "별점은 필수입니다.") + @Min(value = 0, message = "별점은 0점 이상입니다.") + @Max(value = 5, message = "별점은 5점 이하입니다.") + private Integer score; - @NotBlank(message = "내용은 필수입니다. ") + @NotBlank(message = "내용은 필수입니다.") @Size(min = 5, max = 50, message = "내용은 5자 이상 50자 이하입니다.") private String content; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewEditRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewEditRequest.java index 6fc6d488..d0069102 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewEditRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/review/api/dto/ReviewEditRequest.java @@ -3,6 +3,7 @@ import jakarta.validation.constraints.Max; import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; import lombok.Builder; import lombok.EqualsAndHashCode; @@ -15,12 +16,12 @@ @ToString public class ReviewEditRequest { - @NotBlank(message = "별점은 필수입니다.") - @Min(value = 0, message = "별점은 0점 이상입니다. ") - @Max(value = 5, message = "별점은 5점 이하입니다. ") + @NotNull(message = "별점은 필수입니다.") + @Min(value = 0, message = "별점은 0점 이상입니다.") + @Max(value = 5, message = "별점은 5점 이하입니다.") private Integer score; - @NotBlank(message = "내용은 필수입니다. ") + @NotBlank(message = "내용은 필수입니다.") @Size(min = 5, max = 50, message = "내용은 5자 이상 50자 이하입니다.") private String content; } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/review/application/ReviewService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/review/application/ReviewService.java index 94f9fe51..c2178751 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/review/application/ReviewService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/review/application/ReviewService.java @@ -37,7 +37,7 @@ public ReviewResponse getById(Long reviewId) { } @Transactional(readOnly = true) - public ReviewSliceResponse getAllByMemberId(Long memberId, Long oldLastId, Pageable pageable) { + public ReviewSliceResponse getAllByMemberId(Long memberId, Pageable pageable, Long oldLastId) { Slice reviews = reviewRepository.findByMemberIdOrderByReviewIdDesc(memberId, oldLastId, pageable); Long newLastId = getLastId(reviews, oldLastId); @@ -45,7 +45,7 @@ public ReviewSliceResponse getAllByMemberId(Long memberId, Long oldLastId, Pagea } @Transactional(readOnly = true) - public ReviewSliceResponse getAllByEventId(Long eventId, Long oldLastId, Pageable pageable) { + public ReviewSliceResponse getAllByEventId(Long eventId, Pageable pageable, Long oldLastId) { Slice reviews = reviewRepository.findByEventIdOrderByReviewIdDesc(eventId, oldLastId, pageable); Long newLastId = getLastId(reviews, oldLastId); @@ -60,8 +60,10 @@ private Long getLastId(Slice reviews, Long oldLastId) { } @Transactional - public ReviewEventSliceResponse getUnreviewedEventsByMemberId(Long memberId, Pageable pageable, Long beforeLastId) { - Slice unreviewedEvents = reviewRepository.findUnreviewedEventsByMemberId(memberId, beforeLastId, pageable); + public ReviewEventSliceResponse getUnreviewedEventsByMemberId(Long memberId, Pageable pageable, + Long beforeLastId) { + Slice unreviewedEvents = reviewRepository.findUnreviewedEventsByMemberId(memberId, + beforeLastId, pageable); Long newLastId = EventService.getLastId(unreviewedEvents, beforeLastId); List responses = unreviewedEvents.stream() .map(ReviewEventResponse::from).toList(); diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java index 9024bb7b..3112a3ba 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java @@ -1,6 +1,8 @@ package org.ktc2.cokaen.wouldyouin._global.testdata; import org.ktc2.cokaen.wouldyouin._common.api.SliceInfo; +import org.ktc2.cokaen.wouldyouin._global.testdata.ReservationData.R.reservation1; +import org.ktc2.cokaen.wouldyouin._global.testdata.ReviewData.R.review1; public class CommonData { @@ -20,5 +22,25 @@ public static SliceInfo get() { .build(); } } + + public static class reservation { + + public static SliceInfo get() { + return SliceInfo.builder() + .sliceSize(10) + .lastId(reservation1.id) + .build(); + } + } + + public static class review { + + public static SliceInfo get() { + return SliceInfo.builder() + .sliceSize(10) + .lastId(review1.id) + .build(); + } + } } } \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/EventData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/EventData.java index c46c10d2..068d7988 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/EventData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/EventData.java @@ -2,7 +2,6 @@ import java.time.LocalDateTime; import java.util.List; -import org.ktc2.cokaen.wouldyouin.image.persist.EventImage; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; import org.ktc2.cokaen.wouldyouin._common.vo.Location; @@ -11,7 +10,9 @@ import org.ktc2.cokaen.wouldyouin.event.api.dto.EventResponse; import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.CurationEventResponse; import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.ReservationEventResponse; +import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.ReviewEventResponse; import org.ktc2.cokaen.wouldyouin.event.persist.Event; +import org.ktc2.cokaen.wouldyouin.image.persist.EventImage; import org.ktc2.cokaen.wouldyouin.member.persist.Host; import org.springframework.test.util.ReflectionTestUtils; @@ -20,16 +21,36 @@ public class EventData { public static class R { public static class event1 { + + public static final long id = 201L; + public static final String title = "행사 제목"; + public static final String content = "행사 내용입니다. 행사의 내용은 최소 20자 최대 1000자 입니다."; + public static final Area area = Area.전체; + public static final Location location = new Location(55.0, 43.0, "광주 북구 용봉로 77"); + public static final LocalDateTime startTime = LocalDateTime.now().plusDays(3) + .plusHours(11).plusMinutes(47); + public static final LocalDateTime endTime = startTime.plusWeeks(2); + public static final Integer price = 15000; + public static final Integer totalSeat = 100; + public static final Integer leftSeat = 10; + public static final Category category = Category.밴드; + public static final String thumbnailUrl = ImageData.getThumbnailUrl( + _Relation.images().getFirst()); + public static final LocalDateTime createdDate = LocalDateTime.now().minusDays(1); + public static class _Relation { + public static Host host() { return MemberData.host1.entity.get(); } + public static List images() { return List.of( ImageData.event1.entity.get(), ImageData.event2.entity.get(), ImageData.event3.entity.get()); } + public static List imageUrls() { return List.of( ImageData.R.event1.url, @@ -39,11 +60,14 @@ public static List imageUrls() { } public static class _Dto { + public static class editRequest1 { + public static final String title = "modifiedTitle"; - public static final String content = "modifiedContent 조홍식씨 최소글자 20자라고 해놓고 안 지켰어요. "; + public static final String content = "modifiedContent 조홍식씨 최소글자 20자라고 해놓고 안 지켰어요."; public static final Area area = Area.광주; - public static final Location location = new Location(45.0, 143.0, "광주 북구 용봉로 77"); + public static final Location location = new Location(45.0, 143.0, + "광주 북구 용봉로 77"); public static final LocalDateTime startTime = event1.startTime.plusDays(2); public static final LocalDateTime endTime = startTime.plusWeeks(3); public static final int price = 20000; @@ -55,33 +79,39 @@ public static class editRequest1 { ); } } + } - public static final long id = 201L; + public static class event2 { + + public static final long id = 202L; public static final String title = "행사 제목"; public static final String content = "행사 내용입니다. 행사의 내용은 최소 20자 최대 1000자 입니다."; public static final Area area = Area.전체; public static final Location location = new Location(55.0, 43.0, "광주 북구 용봉로 77"); - public static final LocalDateTime startTime = LocalDateTime.now().plusDays(3).plusHours(11).plusMinutes(47); + public static final LocalDateTime startTime = LocalDateTime.now().plusDays(3) + .plusHours(11).plusMinutes(47); public static final LocalDateTime endTime = startTime.plusWeeks(2); public static final Integer price = 15000; public static final Integer totalSeat = 100; public static final Integer leftSeat = 10; public static final Category category = Category.밴드; - public static final String thumbnailUrl = ImageData.getThumbnailUrl(_Relation.images().getFirst()); + public static final String thumbnailUrl = ImageData.getThumbnailUrl( + _Relation.images().getFirst()); public static final LocalDateTime createdDate = LocalDateTime.now().minusDays(1); - } - public static class event2 { public static class _Relation { + public static Host host() { return MemberData.host1.entity.get(); } + public static List images() { return List.of( ImageData.event1.entity.get(), ImageData.event2.entity.get(), ImageData.event3.entity.get()); } + public static List imageUrls() { return List.of( ImageData.R.event1.url, @@ -91,11 +121,14 @@ public static List imageUrls() { } public static class _Dto { + public static class editRequest1 { + public static final String title = "modifiedTitle"; public static final String content = "modifiedContent 조홍식씨 최소글자 20자라고 해놓고 안 지켰어요. "; public static final Area area = Area.광주; - public static final Location location = new Location(45.0, 143.0, "광주 북구 용봉로 77"); + public static final Location location = new Location(45.0, 143.0, + "광주 북구 용봉로 77"); public static final LocalDateTime startTime = event1.startTime.plusDays(2); public static final LocalDateTime endTime = startTime.plusWeeks(3); public static final int price = 20000; @@ -107,25 +140,13 @@ public static class editRequest1 { ); } } - - public static final long id = 202L; - public static final String title = "행사 제목"; - public static final String content = "행사 내용입니다. 행사의 내용은 최소 20자 최대 1000자 입니다."; - public static final Area area = Area.전체; - public static final Location location = new Location(55.0, 43.0, "광주 북구 용봉로 77"); - public static final LocalDateTime startTime = LocalDateTime.now().plusDays(3).plusHours(11).plusMinutes(47); - public static final LocalDateTime endTime = startTime.plusWeeks(2); - public static final Integer price = 15000; - public static final Integer totalSeat = 100; - public static final Integer leftSeat = 10; - public static final Category category = Category.밴드; - public static final String thumbnailUrl = ImageData.getThumbnailUrl(_Relation.images().getFirst()); - public static final LocalDateTime createdDate = LocalDateTime.now().minusDays(1); } } public static class event1 { + public static class entity { + public static Event get() { Event ret = Event.builder() .title(R.event1.title) @@ -149,7 +170,9 @@ public static Event get() { return ret; } } + public static class entityWithNoHost { + public static Event get() { Event ret = Event.builder() .title(R.event1.title) @@ -172,8 +195,11 @@ public static Event get() { return ret; } } + public static class request { + public static class create { + public static EventCreateRequest get() { return EventCreateRequest.builder() .title(R.event1.title) @@ -185,11 +211,14 @@ public static EventCreateRequest get() { .price(R.event1.price) .totalSeat(R.event1.totalSeat) .category(R.event1.category) - .imageIds(R.event1._Relation.images().stream().map(EventImage::getId).toList()) + .imageIds( + R.event1._Relation.images().stream().map(EventImage::getId).toList()) .build(); } } + public static class edit1 { + public static EventEditRequest get() { return EventEditRequest.builder() .title(R.event1._Dto.editRequest1.title) @@ -206,21 +235,34 @@ public static EventEditRequest get() { } } } + public static class response { + public static EventResponse get() { - return EventResponse.from(EventData.event1.entity.get(), R.event1._Relation.imageUrls()); + return EventResponse.from(EventData.event1.entity.get(), + R.event1._Relation.imageUrls()); } } } public static class response { + public static class reservationEvent { + public static ReservationEventResponse createValidReservationEventResponse() { return ReservationEventResponse.from(EventData.event1.entity.get()); } } + public static class reviewEvent { + + public static ReviewEventResponse createValidReviewEventResponse() { + return ReviewEventResponse.from(EventData.event1.entity.get()); + } + } + public static class curationEvent { + public static CurationEventResponse createValidCurationEventResponse() { return CurationEventResponse.from(EventData.event1.entity.get()); } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java index ab59ae1b..9c95335a 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java @@ -10,6 +10,7 @@ import org.ktc2.cokaen.wouldyouin.like.persist.CuratorLike; import org.ktc2.cokaen.wouldyouin.like.persist.HostLike; import org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse.CurationCuratorResponse; +import org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse.ReviewMemberResponse; import org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse.ReservationMemberResponse; import org.ktc2.cokaen.wouldyouin.member.persist.AccountType; import org.ktc2.cokaen.wouldyouin.member.persist.Curator; @@ -295,7 +296,11 @@ public static ReservationMemberResponse get() { return ReservationMemberResponse.from(normal1.entity.get()); } } - + public static class review1Member1 { + public static ReviewMemberResponse get(){ + return ReviewMemberResponse.from(normal1.entity.get()); + } + } public static class curation1Curator1 { public static CurationCuratorResponse get() { diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ReservationData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ReservationData.java index 1f6789a4..649fd88f 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ReservationData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ReservationData.java @@ -16,27 +16,33 @@ public class ReservationData { public static class R { + public static class reservation1 { + + public static final Long id = 1L; + public static final Integer price = _Relation.event().getPrice(); + public static final Integer quantity = 2; + public static final LocalDateTime reservationDate = LocalDateTime.of(2024, 3, 23, 0, 0); + public static final ReservationMemberResponse memberResponse = reservation1Member1.get(); + public static final ReservationEventResponse eventResponse = EventData.response.reservationEvent.createValidReservationEventResponse(); + public static class _Relation { + public static Member member() { return MemberData.normal1.entity.get(); } + public static Event event() { return EventData.event1.entity.get(); } } - public static final Long id = 1L; - public static final Integer price = _Relation.event().getPrice(); - public static final Integer quantity = 2; - public static final LocalDateTime reservationDate = LocalDateTime.of(2024, 3, 23, 0, 0); - - public static final ReservationMemberResponse memberResponse = reservation1Member1.get(); - public static final ReservationEventResponse eventResponse = EventData.response.reservationEvent.createValidReservationEventResponse(); } } public static class reservation1 { + public static class entity { + public static Reservation get() { Reservation ret = Reservation.builder() .member(R.reservation1._Relation.member()) @@ -45,11 +51,14 @@ public static Reservation get() { .quantity(R.reservation1.quantity) .build(); ReflectionTestUtils.setField(ret, "id", R.reservation1.id); - ReflectionTestUtils.setField(ret, "reservationDate", R.reservation1.reservationDate); + ReflectionTestUtils.setField(ret, "reservationDate", + R.reservation1.reservationDate); return ret; } } + public static class request { + public static ReservationRequest get() { return ReservationRequest.builder() .eventId(R.reservation1._Relation.event().getId()) @@ -57,21 +66,24 @@ public static ReservationRequest get() { .build(); } } + public static class response { + public static ReservationResponse get() { return ReservationResponse.from(reservation1.entity.get()); } } } + public static class sliceResponse { + public static ReservationSliceResponse get() { return ReservationSliceResponse.builder() .reservations(List.of( ReservationData.reservation1.response.get())) - .sliceInfo(CommonData.sliceInfo.curation.get()) + .sliceInfo(CommonData.sliceInfo.reservation.get()) .build(); } } - } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ReviewData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ReviewData.java new file mode 100644 index 00000000..26abee5e --- /dev/null +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ReviewData.java @@ -0,0 +1,109 @@ +package org.ktc2.cokaen.wouldyouin._global.testdata; + +import java.util.List; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.response.review1Member1; +import org.ktc2.cokaen.wouldyouin._global.testdata.ReviewData.R.review1._Dto.editRequest1; +import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.ReviewEventResponse; +import org.ktc2.cokaen.wouldyouin.event.persist.Event; +import org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse.ReviewMemberResponse; +import org.ktc2.cokaen.wouldyouin.member.persist.Member; +import org.ktc2.cokaen.wouldyouin.review.api.dto.ReviewCreateRequest; +import org.ktc2.cokaen.wouldyouin.review.api.dto.ReviewEditRequest; +import org.ktc2.cokaen.wouldyouin.review.api.dto.ReviewResponse; +import org.ktc2.cokaen.wouldyouin.review.api.dto.ReviewSliceResponse; +import org.ktc2.cokaen.wouldyouin.review.persist.Review; +import org.springframework.test.util.ReflectionTestUtils; + +public class ReviewData { + + public static class R { + + public static class review1 { + + public static final Long id = 1L; + public static final Integer score = 3; + public static final ReviewMemberResponse memberResponse = review1Member1.get(); + public static final ReviewEventResponse eventResponse = EventData.response.reviewEvent.createValidReviewEventResponse(); + private static final String content = "리뷰 내용입니다. 리뷰 내용은 5자 이상 50자 이하입니다"; + + public static class _Relation { + + public static Member member() { + return MemberData.normal1.entity.get(); + } + + public static Event event() { + return EventData.event1.entity.get(); + } + } + + public static class _Dto { + + public static class editRequest1 { + + public static final Integer score = 5; + public static final String content = "수정된 리뷰 내용입니다. 리뷰 내용은 5자 이상 50자 이하입니다"; + } + } + } + } + + public static class review1 { + + public static class entity { + + public static Review get() { + Review ret = Review.builder() + .member(R.review1._Relation.member()) + .event(R.review1._Relation.event()) + .score(R.review1.score) + .content(R.review1.content) + .build(); + ReflectionTestUtils.setField(ret, "id", R.review1.id); + return ret; + } + } + + public static class request { + + public static class create { + + public static ReviewCreateRequest get() { + return ReviewCreateRequest.builder() + .eventId(R.review1._Relation.event().getId()) + .score(R.review1.score) + .content(R.review1.content) + .build(); + } + } + + public static class edit1 { + + public static ReviewEditRequest get() { + return ReviewEditRequest.builder() + .score(editRequest1.score) + .content(editRequest1.content) + .build(); + } + } + } + + public static class response { + + public static ReviewResponse get() { + return ReviewResponse.from(review1.entity.get()); + } + } + } + + public static class sliceResponse { + + public static ReviewSliceResponse get() { + return ReviewSliceResponse.builder() + .reviews(List.of( + ReviewData.review1.response.get())) + .sliceInfo(CommonData.sliceInfo.review.get()) + .build(); + } + } +} diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java index d356afdc..c28db0c5 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java @@ -43,21 +43,17 @@ @WebMvcTest(ReservationController.class) class ReservationControllerUnitTest { + private static final long randomId = abs(new Random().nextLong()); @Autowired private ObjectMapper objectMapper; - @MockBean private ReservationService reservationService; - @MockBean private JwtAuthFilter jwtAuthFilter; - @Autowired private MockMvc mockMvc; - @Autowired private WebApplicationContext context; - private static final long randomId = abs(new Random().nextLong()); @BeforeEach public void setup() throws Exception { @@ -155,7 +151,8 @@ void getReservationByEventId2() throws Exception { // then then(reservationService).should(times(1)).getAllByEventId( - eq(host1.memberIdentifier), eq(randomId), eq(PageRequest.of(0, 10)), eq(Long.MAX_VALUE)); + eq(host1.memberIdentifier), eq(randomId), eq(PageRequest.of(0, 10)), + eq(Long.MAX_VALUE)); } @Test @@ -191,8 +188,7 @@ void getReservationByEventId4() throws Exception { @WithMockCurator1 void getReservationById1() throws Exception { // given, when - mockMvc.perform(get("/api/reservations/" + randomId)) - .andDo(print()) + mockMvc.perform(get("/api/reservations/" + randomId)).andDo(print()) .andExpect(status().isOk()); // then @@ -204,7 +200,8 @@ void getReservationById1() throws Exception { @WithMockMember1 void createReservation1() throws Exception { // given - ArgumentCaptor captor = ArgumentCaptor.forClass(ReservationRequest.class); + ArgumentCaptor captor = ArgumentCaptor.forClass( + ReservationRequest.class); ReservationRequest request = ReservationData.reservation1.request.get(); // when @@ -225,7 +222,8 @@ void createReservation1() throws Exception { @WithMockCurator1 void createReservation2() throws Exception { // given - ArgumentCaptor captor = ArgumentCaptor.forClass(ReservationRequest.class); + ArgumentCaptor captor = ArgumentCaptor.forClass( + ReservationRequest.class); ReservationRequest request = ReservationData.reservation1.request.get(); // when @@ -350,7 +348,7 @@ void deleteReservation2() throws Exception { } @Test - @DisplayName("Host 권한으로 예약 ID를 통해 예약을 삭제한다.") + @DisplayName("Host 권한으로 예약 ID를 통해 예약을 삭제할 수 없다.") @WithMockHost1 void deleteReservation3() throws Exception { // given, when diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/review/ReviewControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/review/ReviewControllerUnitTest.java new file mode 100644 index 00000000..d7fcf7e8 --- /dev/null +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/review/ReviewControllerUnitTest.java @@ -0,0 +1,571 @@ +package org.ktc2.cokaen.wouldyouin.review; + +import static java.lang.Math.abs; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.BDDMockito.then; +import static org.mockito.Mockito.times; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; +import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.Random; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockCurator1; +import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost1; +import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember1; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator1; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.normal1; +import org.ktc2.cokaen.wouldyouin._global.testdata.ReviewData; +import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; +import org.ktc2.cokaen.wouldyouin.review.api.ReviewController; +import org.ktc2.cokaen.wouldyouin.review.api.dto.ReviewCreateRequest; +import org.ktc2.cokaen.wouldyouin.review.api.dto.ReviewEditRequest; +import org.ktc2.cokaen.wouldyouin.review.application.ReviewService; +import org.mockito.ArgumentCaptor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.data.domain.PageRequest; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +@WebMvcTest(ReviewController.class) +public class ReviewControllerUnitTest { + + private static final long randomId = abs(new Random().nextLong()); + @Autowired + private ObjectMapper objectMapper; + @MockBean + private ReviewService reviewService; + @MockBean + private JwtAuthFilter jwtAuthFilter; + @Autowired + private MockMvc mockMvc; + @Autowired + private WebApplicationContext context; + + @BeforeEach + public void setup() throws Exception { + mockMvc = MockMvcBuilders + .webAppContextSetup(context) + .apply(springSecurity()) + .build(); + } + + @Test + @DisplayName("jwt 토큰 정보에 해당하는 member의 리뷰 목록을 조회한다.") + @WithMockMember1 + void getReviewsByMemberId1() throws Exception { + // given, when + mockMvc.perform(get("/api/reviews") + .param("page", "5") + .param("size", "20") + .param("lastId", "100")).andDo(print()) + .andExpect(status().isOk()); + + // then + then(reviewService).should(times(1)).getAllByMemberId( + eq(normal1.id), eq(PageRequest.of(5, 20)), eq(100L)); + } + + @Test + @DisplayName("RequestParam으로 페이지 정보가 주어지지 않으면 기본값으로 리뷰 목록을 조회한다.") + @WithMockMember1 + void getReviewsByMemberId2() throws Exception { + // given, when + mockMvc.perform(get("/api/reviews")).andDo(print()) + .andExpect(status().isOk()); + + // then + then(reviewService).should(times(1)).getAllByMemberId( + eq(normal1.id), eq(PageRequest.of(0, 10)), eq(Long.MAX_VALUE)); + } + + @Test + @DisplayName("PathVariable로 이벤트 ID를 받아 해당하는 리뷰 목록을 조회한다.") + @WithMockMember1 + void getReviewsByEventId() throws Exception { + // given, when + mockMvc.perform(get("/api/reviews/events/" + randomId) + .param("page", "5") + .param("size", "20") + .param("lastId", "100")).andDo(print()) + .andExpect(status().isOk()); + + // then + then(reviewService).should(times(1)).getAllByEventId( + eq(randomId), eq(PageRequest.of(5, 20)), eq(100L)); + } + + @Test + @DisplayName("RequestParam으로 페이지 정보가 주어지지 않으면 기본값으로 리뷰 목록을 조회한다.") + @WithMockMember1 + void getReviewsByEventId2() throws Exception { + // given, when + mockMvc.perform(get("/api/reviews/events/" + randomId)) + .andDo(print()) + .andExpect(status().isOk()); + + // then + then(reviewService).should(times(1)).getAllByEventId( + eq(randomId), eq(PageRequest.of(0, 10)), eq(Long.MAX_VALUE)); + } + + @Test + @DisplayName("리뷰 ID를 통해 리뷰를 조회한다.") + @WithMockMember1 + void getReviewByReviewId() throws Exception { + // given, when + mockMvc.perform(get("/api/reviews/" + randomId)).andDo(print()) + .andExpect(status().isOk()); + + // then + then(reviewService).should(times(1)).getById(randomId); + } + + @Test + @DisplayName("jwt 토큰 정보에 해당하는 member가 리뷰를 작성하지 않은 이벤트 목록을 조회한다.") + @WithMockMember1 + void getUnreviewedEventsByMemberId1() throws Exception { + // given, when + mockMvc.perform(get("/api/reviews/events") + .param("page", "5") + .param("size", "20") + .param("lastId", "100")).andDo(print()) + .andExpect(status().isOk()); + + // then + then(reviewService).should(times(1)).getUnreviewedEventsByMemberId( + eq(normal1.id), eq(PageRequest.of(5, 20)), eq(100L)); + } + + @Test + @DisplayName("Host의 권한으로 자신이 리뷰를 작성하지 않은 이벤트 목록을 조회할 수 없다.") + @WithMockHost1 + void getUnreviewedEventsByMemberId2() throws Exception { + // given, when + mockMvc.perform(get("/api/reviews/events") + .param("page", "5") + .param("size", "20") + .param("lastId", "100")).andDo(print()) + .andExpect(status().isUnauthorized()) + .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); + + // then + then(reviewService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("Member 권한으로 RequestBody를 통해 리뷰를 생성한다.") + @WithMockMember1 + void createReview1() throws Exception { + // given + ArgumentCaptor captor = ArgumentCaptor.forClass( + ReviewCreateRequest.class); + ReviewCreateRequest request = ReviewData.review1.request.create.get(); + + // when + mockMvc.perform(post("/api/reviews") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isCreated()); + + // then + then(reviewService).should(times(1)).create(eq(normal1.id), captor.capture()); + assertThat(captor.getValue()).isEqualTo(request); + } + + @Test + @DisplayName("Curator 권한으로 RequestBody를 통해 리뷰를 생성한다.") + @WithMockCurator1 + void createReview2() throws Exception { + // given + ArgumentCaptor captor = ArgumentCaptor.forClass( + ReviewCreateRequest.class); + ReviewCreateRequest request = ReviewData.review1.request.create.get(); + + // when + mockMvc.perform(post("/api/reviews") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isCreated()); + + // then + then(reviewService).should(times(1)).create(eq(curator1.id), captor.capture()); + assertThat(captor.getValue()).isEqualTo(request); + } + + @Test + @DisplayName("Host 권한으로 RequestBody를 통해 리뷰를 생성할 수 없다.") + @WithMockHost1 + void createReview3() throws Exception { + // given + ArgumentCaptor captor = ArgumentCaptor.forClass( + ReviewCreateRequest.class); + ReviewCreateRequest request = ReviewData.review1.request.create.get(); + + // when + mockMvc.perform(post("/api/reviews") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isUnauthorized()) + .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); + + // then + then(reviewService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("리뷰 생성 시 이벤트 ID는 빈 값이 될 수 없다.") + @WithMockMember1 + void createReview4() throws Exception { + // given + ReviewCreateRequest request = ReviewData.review1.request.create.get().toBuilder() + .eventId(null).build(); + + // when + mockMvc.perform(post("/api/reviews") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("이벤트 ID는 필수입니다.")); + + // then + then(reviewService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("리뷰 생성 시 별점은 빈 값이 될 수 없다.") + @WithMockMember1 + void createReview5() throws Exception { + // given + ReviewCreateRequest request = ReviewData.review1.request.create.get().toBuilder() + .score(null).build(); + + // when + mockMvc.perform(post("/api/reviews") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("별점은 필수입니다.")); + + // then + then(reviewService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("리뷰 생성 시 별점은 0점 이상이어야 한다.") + @WithMockMember1 + void createReview6() throws Exception { + // given + ReviewCreateRequest request = ReviewData.review1.request.create.get().toBuilder() + .score(-1).build(); + + // when + mockMvc.perform(post("/api/reviews") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("별점은 0점 이상입니다.")); + + // then + then(reviewService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("리뷰 생성 시 별점은 5점 이하이어야 한다.") + @WithMockMember1 + void createReview7() throws Exception { + // given + ReviewCreateRequest request = ReviewData.review1.request.create.get().toBuilder() + .score(8).build(); + + // when + mockMvc.perform(post("/api/reviews") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("별점은 5점 이하입니다.")); + + // then + then(reviewService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("리뷰 생성 시 내용은 빈 값이 될 수 없다.") + @WithMockMember1 + void createReview8() throws Exception { + // given + ReviewCreateRequest request = ReviewData.review1.request.create.get().toBuilder() + .content(null).build(); + + // when + mockMvc.perform(post("/api/reviews") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("내용은 필수입니다.")); + + // then + then(reviewService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("리뷰 생성 시 내용은 5자 이상 50자 이하입니다.") + @WithMockMember1 + void createReview9() throws Exception { + // given + ReviewCreateRequest request = ReviewData.review1.request.create.get().toBuilder() + .content("짧은내용").build(); + + // when + mockMvc.perform(post("/api/reviews") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("내용은 5자 이상 50자 이하입니다.")); + + // then + then(reviewService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("Member 권한으로 RequestBody를 통해 리뷰를 수정한다.") + @WithMockMember1 + void updateReview1() throws Exception { + // given + ArgumentCaptor captor = ArgumentCaptor.forClass( + ReviewEditRequest.class); + ReviewEditRequest request = ReviewData.review1.request.edit1.get(); + + // when + mockMvc.perform(put("/api/reviews/" + randomId) + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isOk()); + + // then + then(reviewService).should(times(1)).update(eq(normal1.id), eq(randomId), captor.capture()); + assertThat(captor.getValue()).isEqualTo(request); + } + + @Test + @DisplayName("Curator 권한으로 RequestBody를 통해 리뷰를 생성한다.") + @WithMockCurator1 + void updateReview2() throws Exception { + // given + ArgumentCaptor captor = ArgumentCaptor.forClass( + ReviewEditRequest.class); + ReviewEditRequest request = ReviewData.review1.request.edit1.get(); + + // when + mockMvc.perform(put("/api/reviews/" + randomId) + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isOk()); + + // then + then(reviewService).should(times(1)) + .update(eq(curator1.id), eq(randomId), captor.capture()); + assertThat(captor.getValue()).isEqualTo(request); + } + + @Test + @DisplayName("Host 권한으로 RequestBody를 통해 리뷰를 생성할 수 없다.") + @WithMockHost1 + void updateReview3() throws Exception { + // given, when + mockMvc.perform(put("/api/reviews/" + randomId) + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(ReviewData.review1.request.edit1.get()))) + .andDo(print()) + .andExpect(status().isUnauthorized()) + .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); + + // then + then(reviewService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("리뷰 수정 시, 별점은 빈 값이 될 수 없다. ") + @WithMockCurator1 + void updateReview4() throws Exception { + // given + ReviewEditRequest request = ReviewData.review1.request.edit1.get().toBuilder() + .score(null).build(); + + // when + mockMvc.perform(put("/api/reviews/" + randomId) + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("별점은 필수입니다.")); + + // then + then(reviewService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("리뷰 수정 시, 별점은 0점 이상이어야 한다.") + @WithMockCurator1 + void updateReview5() throws Exception { + // given + ReviewEditRequest request = ReviewData.review1.request.edit1.get().toBuilder() + .score(-1).build(); + + // when + mockMvc.perform(put("/api/reviews/" + randomId) + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("별점은 0점 이상입니다.")); + + // then + then(reviewService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("리뷰 수정 시, 별점은 5점 이하여야 한다.") + @WithMockCurator1 + void updateReview6() throws Exception { + // given + ReviewEditRequest request = ReviewData.review1.request.edit1.get().toBuilder() + .score(8).build(); + + // when + mockMvc.perform(put("/api/reviews/" + randomId) + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("별점은 5점 이하입니다.")); + + // then + then(reviewService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("리뷰 수정 시, 내용은 필수입니다.") + @WithMockCurator1 + void updateReview7() throws Exception { + // given + ReviewEditRequest request = ReviewData.review1.request.edit1.get().toBuilder() + .content(null).build(); + + // when + mockMvc.perform(put("/api/reviews/" + randomId) + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("내용은 필수입니다.")); + + // then + then(reviewService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("리뷰 수정 시, 내용은 5자 이상 50자 이하입니다.") + @WithMockCurator1 + void updateReview8() throws Exception { + // given + ReviewEditRequest request = ReviewData.review1.request.edit1.get().toBuilder() + .content("짧은내용").build(); + + // when + mockMvc.perform(put("/api/reviews/" + randomId) + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("내용은 5자 이상 50자 이하입니다.")); + + // then + then(reviewService).shouldHaveNoInteractions(); + } + + @Test + @DisplayName("Member 권한으로 리뷰 ID를 통해 리뷰를 삭제한다.") + @WithMockMember1 + void deleteReview1() throws Exception { + // given, when + mockMvc.perform(delete("/api/reviews/" + randomId) + .with(csrf())) + .andDo(print()) + .andExpect(status().isNoContent()); + + // then + then(reviewService).should(times(1)).delete(normal1.id, randomId); + } + + @Test + @DisplayName("Curator 권한으로 리뷰 ID를 통해 리뷰를 삭제한다.") + @WithMockCurator1 + void deleteReview2() throws Exception { + // given, when + mockMvc.perform(delete("/api/reviews/" + randomId) + .with(csrf())) + .andDo(print()) + .andExpect(status().isNoContent()); + + // then + then(reviewService).should(times(1)).delete(curator1.id, randomId); + } + + @Test + @DisplayName("Host 권한으로 리뷰 ID를 통해 리뷰를 삭제할 수 없다.") + @WithMockHost1 + void deleteReview3() throws Exception { + // given, when + mockMvc.perform(delete("/api/reviews/" + randomId) + .with(csrf())) + .andDo(print()) + .andExpect(status().isUnauthorized()) + .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); + + // then + then(reviewService).shouldHaveNoInteractions(); + } +} From 19808e3580fff549fda023274143eb19c941acf2 Mon Sep 17 00:00:00 2001 From: Jangan Lee Date: Fri, 15 Nov 2024 03:40:06 +0900 Subject: [PATCH 39/53] =?UTF-8?q?[Weekly/11/TestData/Like]=20likeData=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20(#138)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_global/testdata/CommonData.java | 14 +- .../wouldyouin/_global/testdata/LikeData.java | 164 ++++++++++++++++++ 2 files changed, 177 insertions(+), 1 deletion(-) create mode 100644 src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/LikeData.java diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java index 3112a3ba..08fcd4c1 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java @@ -1,6 +1,8 @@ package org.ktc2.cokaen.wouldyouin._global.testdata; import org.ktc2.cokaen.wouldyouin._common.api.SliceInfo; +import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.R.curation1; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator1; import org.ktc2.cokaen.wouldyouin._global.testdata.ReservationData.R.reservation1; import org.ktc2.cokaen.wouldyouin._global.testdata.ReviewData.R.review1; @@ -18,11 +20,21 @@ public static class curation { public static SliceInfo get() { return SliceInfo.builder() .sliceSize(10) - .lastId(301L) + .lastId(curation1.id) .build(); } } + public static class like { + + public static SliceInfo get() { + return SliceInfo.builder() + .sliceSize(2) + .lastId(curator1.id) + .build(); + } + } + public static class reservation { public static SliceInfo get() { diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/LikeData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/LikeData.java new file mode 100644 index 00000000..581a87f2 --- /dev/null +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/LikeData.java @@ -0,0 +1,164 @@ +package org.ktc2.cokaen.wouldyouin._global.testdata; + +import java.util.List; +import org.ktc2.cokaen.wouldyouin.like.api.dto.LikeResponse; +import org.ktc2.cokaen.wouldyouin.like.api.dto.LikeSliceResponse; +import org.ktc2.cokaen.wouldyouin.like.persist.CuratorLike; +import org.ktc2.cokaen.wouldyouin.like.persist.HostLike; +import org.ktc2.cokaen.wouldyouin.member.persist.Curator; +import org.ktc2.cokaen.wouldyouin.member.persist.Host; +import org.ktc2.cokaen.wouldyouin.member.persist.Member; + +public class LikeData { + + public static class R { + public static class likeHost1 { + public static class byNormal1 { + public static class _Relation { + public static Host targetMember() { + return MemberData.host1.entity.get(); + } + public static Member member() { + return MemberData.normal1.entity.get(); + } + } + public static class response { + public static final Long id = MemberData.R.host1.id; + public static final String nickname = MemberData.R.host1.nickname; + public static final String intro = MemberData.R.host1.intro; + public static final List hashtags = MemberData.R.host1.hashtags; + public static final String profileImageUrl = MemberData.R.host1.profileImageUrl; + } + } + public static class byCurator1 { + public static class _Relation { + public static Host targetMember() { + return MemberData.host1.entity.get(); + } + public static Curator member() { + return MemberData.curator1.entity.get(); + } + } + public static class response { + public static final Long id = MemberData.R.host1.id; + public static final String nickname = MemberData.R.host1.nickname; + public static final String intro = MemberData.R.host1.intro; + public static final List hashtags = MemberData.R.host1.hashtags; + public static final String profileImageUrl = MemberData.R.host1.profileImageUrl; + } + } + } + public static class likeCurator1 { + public static class byNormal1 { + public static class _Relation { + public static Curator targetMember() { + return MemberData.curator1.entity.get(); + } + public static Member member() { + return MemberData.normal1.entity.get(); + } + } + public static class response { + public static final Long id = MemberData.R.curator1.id; + public static final String nickname = MemberData.R.curator1.nickname; + public static final String intro = MemberData.R.curator1.intro; + public static final List hashtags = MemberData.R.curator1.hashtags; + public static final String profileImageUrl = MemberData.R.curator1.profileImageUrl; + } + } + } + } + + public static class likeHost1 { + public static class byNormal1 { + public static class entity { + public static HostLike get() { + return HostLike.builder() + .targetMember(R.likeHost1.byNormal1._Relation.targetMember()) + .member(R.likeHost1.byNormal1._Relation.member()) + .build(); + } + } + public static class response { + public static LikeResponse get() { + return LikeResponse.builder() + .memberId(R.likeHost1.byNormal1.response.id) + .nickname(R.likeHost1.byNormal1.response.nickname) + .intro(R.likeHost1.byNormal1.response.intro) + .hashtags(R.likeHost1.byNormal1.response.hashtags) + .profileImageUrl(R.likeHost1.byNormal1.response.profileImageUrl) + .build(); + } + } + } + public static class byCurator1 { + public static class entity { + public static HostLike get() { + return HostLike.builder() + .targetMember(R.likeHost1.byCurator1._Relation.targetMember()) + .member(R.likeHost1.byCurator1._Relation.member()) + .build(); + } + } + public static class response { + public static LikeResponse get() { + return LikeResponse.builder() + .memberId(R.likeHost1.byCurator1.response.id) + .nickname(R.likeHost1.byCurator1.response.nickname) + .intro(R.likeHost1.byCurator1.response.intro) + .hashtags(R.likeHost1.byCurator1.response.hashtags) + .profileImageUrl(R.likeHost1.byCurator1.response.profileImageUrl) + .build(); + } + } + } + } + + public static class likeCurator1 { + public static class byNormal1 { + public static class entity { + public static CuratorLike get() { + return CuratorLike.builder() + .targetMember(R.likeCurator1.byNormal1._Relation.targetMember()) + .member(R.likeCurator1.byNormal1._Relation.member()) + .build(); + } + } + public static class response { + public static LikeResponse get() { + return LikeResponse.builder() + .memberId(R.likeCurator1.byNormal1.response.id) + .nickname(R.likeCurator1.byNormal1.response.nickname) + .intro(R.likeCurator1.byNormal1.response.intro) + .hashtags(R.likeCurator1.byNormal1.response.hashtags) + .profileImageUrl(R.likeCurator1.byNormal1.response.profileImageUrl) + .build(); + } + } + } + } + + public static class normal1LikeSliceResponse { + public static LikeSliceResponse get() { + return LikeSliceResponse.builder() + .likes(List.of( + LikeResponse.builder() + .memberId(R.likeHost1.byNormal1.response.id) + .nickname(R.likeHost1.byNormal1.response.nickname) + .intro(R.likeHost1.byNormal1.response.intro) + .hashtags(R.likeHost1.byNormal1.response.hashtags) + .profileImageUrl(R.likeHost1.byNormal1.response.profileImageUrl) + .build(), + LikeResponse.builder() + .memberId(R.likeCurator1.byNormal1.response.id) + .nickname(R.likeCurator1.byNormal1.response.nickname) + .intro(R.likeCurator1.byNormal1.response.intro) + .hashtags(R.likeCurator1.byNormal1.response.hashtags) + .profileImageUrl(R.likeCurator1.byNormal1.response.profileImageUrl) + .build() + )) + .sliceInfo(CommonData.sliceInfo.like.get()) + .build(); + } + } +} From bdbe9b289072c84990982d4575f6e010518c5c85 Mon Sep 17 00:00:00 2001 From: Jangan Lee Date: Fri, 15 Nov 2024 07:28:07 +0900 Subject: [PATCH 40/53] =?UTF-8?q?[Weekly/11/Refactor/TokenResponse]=20toke?= =?UTF-8?q?n=20response=EC=97=90=20=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=95=84?= =?UTF-8?q?=EC=9D=B4=EB=94=94,=20=ED=83=80=EC=9E=85=20=EB=B0=98=ED=99=98?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B0=98=EC=98=81=20(#139)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_develop/api/TempCreateController.java | 3 ++- .../auth/api/dto/SocialTokenResponse.java | 3 ++- .../wouldyouin/auth/api/dto/TokenResponse.java | 7 +++++-- .../wouldyouin/auth/application/AuthService.java | 15 ++++++++++++--- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_develop/api/TempCreateController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_develop/api/TempCreateController.java index ef6b0557..4b0dc57b 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_develop/api/TempCreateController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_develop/api/TempCreateController.java @@ -75,6 +75,7 @@ public ResponseEntity> testCreateToken( } private TokenResponse createToken(MemberIdentifier identifier) { - return TokenResponse.from(jwtService.createAccessToken(identifier.id(), identifier.type())); + String accessToken = jwtService.createAccessToken(identifier.id(), identifier.type()); + return TokenResponse.of(accessToken, identifier.id(), identifier.type()); } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/SocialTokenResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/SocialTokenResponse.java index bfdb4f43..ad4af168 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/SocialTokenResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/SocialTokenResponse.java @@ -1,8 +1,9 @@ package org.ktc2.cokaen.wouldyouin.auth.api.dto; import lombok.Builder; +import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @Builder -public record SocialTokenResponse(Boolean isWelcomeMember, String token) { +public record SocialTokenResponse(Boolean isWelcomeMember, String token, Long memberId, MemberType memberType) { } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/TokenResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/TokenResponse.java index 0ebae147..c40ba589 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/TokenResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/api/dto/TokenResponse.java @@ -1,13 +1,16 @@ package org.ktc2.cokaen.wouldyouin.auth.api.dto; import lombok.Builder; +import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @Builder -public record TokenResponse(String token) { +public record TokenResponse(String token, Long memberId, MemberType memberType) { - public static TokenResponse from(String token) { + public static TokenResponse of(String token, Long memberId, MemberType memberType) { return TokenResponse.builder() .token(token) + .memberId(memberId) + .memberType(memberType) .build(); } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/AuthService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/AuthService.java index 39631274..817e4b65 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/AuthService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/AuthService.java @@ -33,12 +33,14 @@ public class AuthService { @Transactional public TokenResponse localSignup(LocalSignupRequest request) { baseMemberService.checkUniqueEmailOrThrow(request.getEmail()); - return TokenResponse.from(createToken(hostService.createHost(request))); + MemberResponse response = hostService.createHost(request); + return TokenResponse.of(createToken(response), response.getMemberId(), response.getMemberType()); } @Transactional(readOnly = true) public TokenResponse localLogin(LocalLoginRequest request) { - return TokenResponse.from(createToken(hostService.getMemberResponseBy(request))); + MemberResponse response = hostService.getMemberResponseBy(request); + return TokenResponse.of(createToken(response), response.getMemberId(), response.getMemberType()); } @Transactional @@ -55,6 +57,8 @@ public SocialTokenResponse socialLogin(AccountType accountType, String code) { return SocialTokenResponse.builder() .isWelcomeMember(false) .token(createToken(id)) + .memberId(id.id()) + .memberType(id.type()) .build(); } // 소셜 계정이지만 아직 추가 정보 기입이 되지 않은 경우 @@ -62,6 +66,8 @@ public SocialTokenResponse socialLogin(AccountType accountType, String code) { return SocialTokenResponse.builder() .isWelcomeMember(true) .token(createToken(id)) + .memberId(id.id()) + .memberType(id.type()) .build(); } } @@ -78,12 +84,15 @@ public SocialTokenResponse socialLogin(AccountType accountType, String code) { return SocialTokenResponse.builder() .isWelcomeMember(true) .token(createToken(welcomeMemberResponse)) + .memberId(welcomeMemberResponse.getMemberId()) + .memberType(welcomeMemberResponse.getMemberType()) .build(); } @Transactional public TokenResponse acceptAdditionalInfo(Long welcomeMemberId, MemberAdditionalInfoRequest request) { - return TokenResponse.from(createToken(memberService.updateWelcomeMember(welcomeMemberId, request))); + MemberResponse response = memberService.updateWelcomeMember(welcomeMemberId, request); + return TokenResponse.of(createToken(response), response.getMemberId(), response.getMemberType()); } private String createToken(MemberIdentifier identifier) { From 4252796c9a066fc193d6ee4915f592aca61c192f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=99=8D=EC=8B=9D?= <90020593+Daolove0323@users.noreply.github.com> Date: Fri, 15 Nov 2024 07:38:17 +0900 Subject: [PATCH 41/53] =?UTF-8?q?[Weekly/11/Reservation/test]=20Reservatio?= =?UTF-8?q?n=20=EC=9C=A0=EB=8B=9B=ED=85=8C=EC=8A=A4=ED=8A=B8=20(#140)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wouldyouin/_common/util/FileUtil.java | 14 + .../wouldyouin/_common/vo/Category.java | 2 +- .../api/AdvertisementController.java | 10 - .../application/AdvertisementService.java | 32 +- .../application/CurationCardService.java | 2 +- .../wouldyouin/image/api/ImageController.java | 6 +- .../AdvertisementImageService.java | 8 +- .../application/CurationImageService.java | 6 +- .../image/application/EventImageService.java | 9 +- .../image/application/ImageService.java | 33 +-- .../application/ImageStorageService.java | 18 +- .../image/application/MemberImageService.java | 9 +- .../CurationCuratorResponse.java | 2 + .../payment/application/PaymentService.java | 1 - .../api/ReservationController.java | 19 +- .../api/dto/KakaoPayReservationResponse.java | 24 ++ .../application/ReservationService.java | 64 ++-- .../persist/ReservationRepository.java | 7 +- src/main/resources/application.yml | 1 - .../_global/testdata/AdvertisementData.java | 5 + .../_global/testdata/CurationData.java | 35 ++- .../_global/testdata/ReservationData.java | 41 +++ .../curation/CurationCardServiceTest.java | 85 ++++++ .../curation/CurationServiceTest.java | 46 +-- .../image/CurationImageServiceTest.java | 66 +++++ .../wouldyouin/image/ImageControllerTest.java | 19 +- .../ReservationControllerUnitTest.java | 15 +- .../ReservationServiceUnitTest.java | 275 +++++++++++------- 28 files changed, 577 insertions(+), 277 deletions(-) create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/KakaoPayReservationResponse.java create mode 100644 src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/AdvertisementData.java create mode 100644 src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationCardServiceTest.java create mode 100644 src/test/java/org/ktc2/cokaen/wouldyouin/image/CurationImageServiceTest.java diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/FileUtil.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/FileUtil.java index e0970c02..c5987467 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/FileUtil.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/util/FileUtil.java @@ -1,9 +1,12 @@ package org.ktc2.cokaen.wouldyouin._common.util; +import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.UUID; +import net.coobird.thumbnailator.Thumbnails; import org.ktc2.cokaen.wouldyouin._common.exception.ExtensionParsingException; import org.ktc2.cokaen.wouldyouin._common.exception.FailToReadImageException; import org.ktc2.cokaen.wouldyouin._common.exception.FailedToUploadImageException; @@ -37,6 +40,17 @@ public static void saveFile(byte[] file, Path path) { } } + public static void createThumbnail(String originalPath, String originFileName, String thumbnailPath, int width, int height) { + try { + Files.createDirectories(Paths.get(thumbnailPath)); + Thumbnails.of(new File(originalPath)) + .size(height, width) + .toFile(new File(thumbnailPath, originFileName)); + } catch (IOException e) { + throw new FailedToUploadImageException("썸네일을 생성하는데 실패했습니다."); + } + } + public static void deleteFile(Path path) { try { Files.deleteIfExists(path); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/vo/Category.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/vo/Category.java index 55593840..1a796347 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/vo/Category.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/vo/Category.java @@ -4,8 +4,8 @@ public enum Category { 전체, 밴드, 연극, - 뮤지컬, 원데이클래스, + 뮤지컬, 전시회, 공예, 축제 diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/AdvertisementController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/AdvertisementController.java index 92487102..65f7ee62 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/AdvertisementController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/AdvertisementController.java @@ -49,16 +49,6 @@ public ResponseEntity> createAdvertisemen return ApiResponse.created(advertisementService.create(advertisementRequest, image)); } - @PutMapping(path = "/{adId}", consumes = {MediaType.APPLICATION_JSON_VALUE, - MediaType.MULTIPART_FORM_DATA_VALUE}) - public ResponseEntity> updateAdvertisement( - @PathVariable Long adId, - @Valid @RequestPart AdvertisementRequest advertisementRequest, - @RequestPart(required = false) MultipartFile image, - @Authorize(MemberType.admin) MemberIdentifier identifier) { - return ApiResponse.ok(advertisementService.update(identifier, adId, advertisementRequest, image)); - } - @DeleteMapping("/{adId}") public ResponseEntity> deleteAdvertisement( @PathVariable Long adId, diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java index e033ea58..3a7fca03 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/application/AdvertisementService.java @@ -23,12 +23,6 @@ public class AdvertisementService { private final AdvertisementRepository adRepository; private final AdvertisementImageService adImageService; - @Transactional - public Advertisement getByIdOrThrow(Long adId) { - return adRepository.findById(adId) - .orElseThrow(() -> new EntityNotFoundException("해당하는 광고를 찾을 수 없습니다.")); - } - @Transactional(readOnly = true) public AdvertisementResponse getById(Long adId) { return AdvertisementResponse.from(getByIdOrThrow(adId)); @@ -40,7 +34,6 @@ public List getAllActiveAdvertisements() { .map(AdvertisementResponse::from).toList(); } - // Todo: 롤백될 경우, 저장한 이미지 삭제 @Transactional public AdvertisementResponse create(AdvertisementRequest adRequest, MultipartFile image) { AdvertisementImage adImage = adImageService.saveImage(image); @@ -49,30 +42,15 @@ public AdvertisementResponse create(AdvertisementRequest adRequest, MultipartFil return AdvertisementResponse.from(ad); } - // Todo: 수정될 때 이미지가 null인 경우 기존 이미지로 대체하는 로직 프론트와 협의 - // Todo: 롤백될 경우, 저장한 이미지 삭제 - @Transactional - public AdvertisementResponse update(MemberIdentifier identifier, Long adId, AdvertisementRequest adRequest, MultipartFile multipartFile) { - Advertisement ad = getByIdOrThrow(adId); - Optional.ofNullable(multipartFile).ifPresentOrElse( - image -> { - adImageService.deleteImage(identifier, ad.getAdvertisementImage().getId()); - AdvertisementImage adImage = adImageService.saveImage(image); - ad.updateFrom(adRequest, adImage); - adImage.setAdvertisement(ad); - }, - () -> { - AdvertisementImage adImage = ad.getAdvertisementImage(); - ad.updateFrom(adRequest, adImage); - } - ); - return AdvertisementResponse.from(ad); - } - @Transactional public void delete(MemberIdentifier identifier, Long adId) { Advertisement ad = getByIdOrThrow(adId); adImageService.deleteImage(identifier, ad.getAdvertisementImage().getId()); adRepository.deleteById(adId); } + + private Advertisement getByIdOrThrow(Long adId) { + return adRepository.findById(adId) + .orElseThrow(() -> new EntityNotFoundException("해당하는 광고를 찾을 수 없습니다.")); + } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java index ea73311b..b4503b13 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java @@ -52,7 +52,7 @@ private CurationCard getByIdOrThrow(Long id) { return curationCardRepository.findById(id).orElseThrow(() -> new EntityNotFoundException("해당하는 큐레이션 카드를 찾을 수 없습니다.")); } - public List getImageUrls(CurationCard curationCard) { + private List getImageUrls(CurationCard curationCard) { return curationCard.getCurationImages().stream() .map(curationImageService::getImageUrl) .toList(); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/ImageController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/ImageController.java index bf02c6c5..587f710e 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/ImageController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/ImageController.java @@ -11,7 +11,6 @@ import org.ktc2.cokaen.wouldyouin.image.application.ImageServiceFactory; import org.ktc2.cokaen.wouldyouin.image.application.ImageStorageService; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; -import org.ktc2.cokaen.wouldyouin.payment.application.PaymentService; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -31,7 +30,6 @@ public class ImageController { private final ImageServiceFactory imageServiceFactory; private final ImageStorageService imageStorageService; - private final PaymentService paymentService; @GetMapping(value = "/{directory}/{file}", produces = {MediaType.IMAGE_PNG_VALUE, MediaType.IMAGE_JPEG_VALUE}) public ResponseEntity getImage(@PathVariable String directory, @PathVariable String file) { @@ -39,7 +37,8 @@ public ResponseEntity getImage(@PathVariable String directory, @PathVari } @GetMapping(value = "/{directory}/{thumbnail}/{file}", produces = {MediaType.IMAGE_PNG_VALUE, MediaType.IMAGE_JPEG_VALUE}) - public ResponseEntity getThumnailImage(@PathVariable String directory, @PathVariable String thumbnail, @PathVariable String file) { + public ResponseEntity getThumnailImage(@PathVariable String directory, @PathVariable String thumbnail, + @PathVariable String file) { return ResponseEntity.status(HttpStatus.OK).body(imageStorageService.readFromDirectory(Paths.get(directory, thumbnail, file))); } @@ -51,7 +50,6 @@ public ResponseEntity>> uploadImages( return ApiResponse.ok(imageServiceFactory.getImageService(imageDomain).saveImages(images)); } - // Todo: 삭제로직 수정필요 @DeleteMapping("/{imageId}") public ResponseEntity> deleteImage( @PathVariable Long imageId, diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/AdvertisementImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/AdvertisementImageService.java index ca3245e6..69531a6d 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/AdvertisementImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/AdvertisementImageService.java @@ -16,14 +16,17 @@ import org.springframework.web.multipart.MultipartFile; @Service -@RequiredArgsConstructor public class AdvertisementImageService extends ImageService { @Value("${image.upload.ad.child-path}") private String childPath; - private final ImageStorageService imageStorageService; private final AdvertisementImageRepository adImageRepository; + public AdvertisementImageService(ImageStorageService imageStorageService, AdvertisementImageRepository adImageRepository) { + this.imageStorageService = imageStorageService; + this.adImageRepository = adImageRepository; + } + @Override protected ImageRepository getImageRepository() { return adImageRepository; @@ -48,7 +51,6 @@ protected AdvertisementImage mapToEntityFrom(ImageRequest imageRequest) { .build(); } - // TODO : ad image 삭제 인가 @Override protected void validateMemberId(MemberIdentifier identifier, AdvertisementImage image) { if (!identifier.type().equals(MemberType.admin)) { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/CurationImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/CurationImageService.java index 07a82d20..03bf57cc 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/CurationImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/CurationImageService.java @@ -15,13 +15,17 @@ import org.springframework.transaction.annotation.Transactional; @Service -@RequiredArgsConstructor public class CurationImageService extends ImageService { @Value("${image.upload.curation.child-path}") private String childPath; private final CurationImageRepository curationImageRepository; + public CurationImageService(ImageStorageService imageStorageService, CurationImageRepository curationImageRepository) { + this.imageStorageService = imageStorageService; + this.curationImageRepository = curationImageRepository; + } + @Override public ImageRepository getImageRepository() { return curationImageRepository; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/EventImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/EventImageService.java index 1b5bc460..5a57e580 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/EventImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/EventImageService.java @@ -14,7 +14,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -@RequiredArgsConstructor @Service public class EventImageService extends ImageService { @@ -22,6 +21,11 @@ public class EventImageService extends ImageService { private String childPath; private final EventImageRepository eventImageRepository; + public EventImageService(ImageStorageService imageStorageService, EventImageRepository eventImageRepository) { + this.imageStorageService = imageStorageService; + this.eventImageRepository = eventImageRepository; + } + @Override public ImageRepository getImageRepository() { return eventImageRepository; @@ -48,7 +52,8 @@ protected EventImage mapToEntityFrom(ImageRequest imageRequest) { @Override protected void validateMemberId(MemberIdentifier identifier, EventImage image) { - if (!identifier.type().equals(MemberType.admin) && !identifier.id().equals(image.getEvent().getHost().getId())) { + if (!identifier.type().equals(MemberType.admin) && + !identifier.id().equals(image.getEvent().getHost().getId())) { throw new UnauthorizedException("해당 이벤트 이미지에 접근할 권한이 없습니다."); } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageService.java index 616f6ddc..bee01f80 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageService.java @@ -10,7 +10,6 @@ import org.ktc2.cokaen.wouldyouin.image.api.dto.ImageResponse; import org.ktc2.cokaen.wouldyouin.image.persist.Image; import org.ktc2.cokaen.wouldyouin.image.persist.ImageRepository; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -20,11 +19,10 @@ @RequiredArgsConstructor public abstract class ImageService { - @Autowired protected ImageStorageService imageStorageService; @Value("${image.api-url}") - private String parentPath; + private String imageApiHeader; protected abstract ImageRepository getImageRepository(); @@ -36,6 +34,12 @@ public abstract class ImageService { protected abstract void validateMemberId(MemberIdentifier identifier, T image); + @Transactional(readOnly = true) + public T getById(Long id) { + return getImageRepository().findById(id) + .orElseThrow(() -> new EntityNotFoundException(getImageDomain().name() + " 이미지를 찾을 수 없습니다.")); + } + @Transactional public List saveImages(List images) { return images.stream() @@ -43,23 +47,12 @@ public List saveImages(List images) { .toList(); } - // TODO: delete 이미지 바꿔야함 @Transactional public void deleteImage(MemberIdentifier identifier, Long imageId) { T image = getById(imageId); validateMemberId(identifier, image); delete(imageId); imageStorageService.delete(getChildPath(), image.getName()); - // ToDO : 썸네일도 지워라 - } - - public String createThumbnail(String fileName) { - return imageStorageService.createThumbnailImage(parentPath, getChildPath(), fileName); - } - - public T getById(Long id) { - return getImageRepository().findById(id) - .orElseThrow(() -> new EntityNotFoundException(getImageDomain().name() + " 이미지를 찾을 수 없습니다.")); } protected ImageResponse create(ImageRequest imageRequest) { @@ -67,12 +60,16 @@ protected ImageResponse create(ImageRequest imageRequest) { return ImageResponse.from(getImageRepository().save(image), getImageUrl(image)); } - public String getImageUrl(T image) { - return UriUtil.assembleFullUrl(parentPath, getChildPath(), image.getName()); - } - protected void delete(Long id) { getById(id); getImageRepository().deleteById(id); } + + public String createThumbnail(String fileName) { + return imageStorageService.createThumbnailImage(imageApiHeader, getChildPath(), fileName); + } + + public String getImageUrl(T image) { + return UriUtil.assembleFullUrl(imageApiHeader, getChildPath(), image.getName()); + } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageStorageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageStorageService.java index 52886c4b..425adf3e 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageStorageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/ImageStorageService.java @@ -34,9 +34,6 @@ public class ImageStorageService { @Value("${image.upload.thumbnail.width}") private Integer thumbnailWidth; - @Value("${image.upload.thumbnail.extension}") - private String thumbnailExtension; - private final RestClientUtil client; public byte[] readFromDirectory(Path childPath) { @@ -56,7 +53,6 @@ public ImageRequest saveToDirectory(String imageUrl, String childPath) { throw new FailedToUploadImageException("이미지 URL에 대한 요청을 실패하였습니다."); } ); - String contentType = Optional.ofNullable(response.getHeaders().getContentType()).orElseThrow( () -> new FailedToUploadImageException("응답 헤더에 콘텐츠 타입이 없어 이미지를 가져올 수 없습니다.") ).toString(); @@ -71,23 +67,15 @@ public ImageRequest saveToDirectory(String imageUrl, String childPath) { return ImageRequest.of(fileName, (long)body.length, extension); } - // TODO : 썸네일 생성 코드 리팩토링, 파일 유틸로 이동 public String createThumbnailImage(String apiHeader, String childPath, String originFileName) { - String fileName = originFileName; String originImagePath = Path.of(parentPath, childPath, originFileName).toString(); String thumbnailImagePath = Path.of(parentPath, childPath, thumbnailChildPath).toString(); - try { - Files.createDirectories(Paths.get(thumbnailImagePath)); - Thumbnails.of(new File(originImagePath)) - .size(thumbnailHeight, thumbnailWidth) - .toFile(new File(thumbnailImagePath, fileName)); - } catch (Exception e) { - throw new RuntimeException(e); - } - return UriUtil.assembleFullUrl(apiHeader,childPath, thumbnailChildPath, fileName); + FileUtil.createThumbnail(originImagePath, originFileName, thumbnailImagePath, thumbnailWidth, thumbnailHeight); + return UriUtil.assembleFullUrl(apiHeader,childPath, thumbnailChildPath, originFileName); } public void delete(String childPath, String fileName) { FileUtil.deleteFile(Path.of(parentPath, childPath, fileName)); + FileUtil.deleteFile(Path.of(parentPath, childPath, thumbnailChildPath, fileName)); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/MemberImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/MemberImageService.java index efb20a97..d2656222 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/MemberImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/MemberImageService.java @@ -15,13 +15,17 @@ import org.springframework.transaction.annotation.Transactional; @Service -@RequiredArgsConstructor public class MemberImageService extends ImageService { @Value("${image.upload.member.child-path}") private String childPath; private final MemberImageRepository memberImageRepository; + public MemberImageService(ImageStorageService imageStorageService, MemberImageRepository memberImageRepository) { + this.imageStorageService = imageStorageService; + this.memberImageRepository = memberImageRepository; + } + @Override public ImageRepository getImageRepository() { return memberImageRepository; @@ -48,7 +52,8 @@ protected MemberImage mapToEntityFrom(ImageRequest imageRequest) { @Override protected void validateMemberId(MemberIdentifier identifier, MemberImage image) { - if (!identifier.type().equals(MemberType.admin) && !identifier.id().equals(image.getBaseMember().getId())) { + if (!identifier.type().equals(MemberType.admin) && + !identifier.id().equals(image.getBaseMember().getId())) { throw new UnauthorizedException("해당 프로필 이미지에 접근할 권한이 없습니다."); } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/CurationCuratorResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/CurationCuratorResponse.java index 651d748c..4a678b35 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/CurationCuratorResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/CurationCuratorResponse.java @@ -13,6 +13,7 @@ @ToString public class CurationCuratorResponse { + private Long curatorId; private String nickname; private String email; private String phone; @@ -24,6 +25,7 @@ public class CurationCuratorResponse { public static CurationCuratorResponse from(Curator curator) { return CurationCuratorResponse.builder() + .curatorId(curator.getId()) .nickname(curator.getNickname()) .email(curator.getEmail()) .phone(curator.getPhone()) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/payment/application/PaymentService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/payment/application/PaymentService.java index 2649750e..8327adc4 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/payment/application/PaymentService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/payment/application/PaymentService.java @@ -38,5 +38,4 @@ public KakaoPayResponse createPayment(KakaoPayRequest kakaoPayRequest) { (req, rsp) -> { throw new FailedToPayException("카카오페이 API 요청을 실패하였습니다."); } ); } - // Todo: pay 취소 기능 추가 } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/ReservationController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/ReservationController.java index 256be9ef..462c9db4 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/ReservationController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/ReservationController.java @@ -9,6 +9,7 @@ import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.ktc2.cokaen.wouldyouin.payment.dto.KakaoPayResponse; +import org.ktc2.cokaen.wouldyouin.reservation.api.dto.KakaoPayReservationResponse; import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationRequest; import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationResponse; import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationSliceResponse; @@ -33,11 +34,11 @@ public class ReservationController { @GetMapping public ResponseEntity> getReservationsByMemberId( - @Authorize({MemberType.normal, MemberType.curator}) MemberIdentifier member, + @Authorize({MemberType.normal, MemberType.curator}) MemberIdentifier identifier, @RequestParam(defaultValue = ParamDefaults.PAGE) Integer page, @RequestParam(defaultValue = ParamDefaults.PAGE_SIZE) Integer size, @RequestParam(defaultValue = ParamDefaults.LAST_ID) Long lastId) { - return ApiResponse.ok(reservationService.getAllByMemberId(member.id(), PageRequest.of(page, size), lastId)); + return ApiResponse.ok(reservationService.getAllByMemberId(identifier, PageRequest.of(page, size), lastId)); } @GetMapping("/events/{eventId}") @@ -57,24 +58,24 @@ public ResponseEntity> getReservationById( } @PostMapping - public ResponseEntity> createReservation( + public ResponseEntity> createReservation( @Valid @RequestBody ReservationRequest reservationRequest, - @Authorize({MemberType.normal, MemberType.curator}) MemberIdentifier member) { - return ApiResponse.created(reservationService.create(member.id(), reservationRequest)); + @Authorize({MemberType.normal, MemberType.curator}) MemberIdentifier identifier) { + return ApiResponse.created(reservationService.create(identifier, reservationRequest)); } @PostMapping("/test") public ResponseEntity> createTestReservation( @Valid @RequestBody ReservationRequest reservationRequest, - @Authorize({MemberType.normal, MemberType.curator}) MemberIdentifier member) { - return ApiResponse.created(reservationService.createTest(member.id(), reservationRequest)); + @Authorize({MemberType.normal, MemberType.curator}) MemberIdentifier identifier) { + return ApiResponse.created(reservationService.createTest(identifier, reservationRequest)); } @DeleteMapping("/{reservationId}") public ResponseEntity> deleteReservation( @PathVariable Long reservationId, - @Authorize({MemberType.normal, MemberType.curator}) MemberIdentifier member) { - reservationService.delete(member.id(), reservationId); + @Authorize({MemberType.normal, MemberType.curator}) MemberIdentifier identifier) { + reservationService.delete(identifier, reservationId); return ApiResponse.noContent(); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/KakaoPayReservationResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/KakaoPayReservationResponse.java new file mode 100644 index 00000000..599368aa --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/api/dto/KakaoPayReservationResponse.java @@ -0,0 +1,24 @@ +package org.ktc2.cokaen.wouldyouin.reservation.api.dto; + +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import org.ktc2.cokaen.wouldyouin.payment.dto.KakaoPayResponse; + +@Builder +@Getter +@EqualsAndHashCode +@ToString +public class KakaoPayReservationResponse { + + private ReservationResponse reservationResponse; + private KakaoPayResponse kakaoPayResponse; + + public static KakaoPayReservationResponse from(ReservationResponse reservationResponse, KakaoPayResponse kakaoPayResponse) { + return KakaoPayReservationResponse.builder() + .reservationResponse(reservationResponse) + .kakaoPayResponse(kakaoPayResponse) + .build(); + } +} diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java index 85bbd555..30a79660 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java @@ -1,5 +1,6 @@ package org.ktc2.cokaen.wouldyouin.reservation.application; +import java.util.Optional; import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; import org.ktc2.cokaen.wouldyouin._common.exception.ReservationNotFoundForReviewException; @@ -10,6 +11,7 @@ import org.ktc2.cokaen.wouldyouin.payment.application.PaymentService; import org.ktc2.cokaen.wouldyouin.payment.dto.KakaoPayRequest; import org.ktc2.cokaen.wouldyouin.payment.dto.KakaoPayResponse; +import org.ktc2.cokaen.wouldyouin.reservation.api.dto.KakaoPayReservationResponse; import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationRequest; import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationResponse; import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationSliceResponse; @@ -29,27 +31,15 @@ public class ReservationService { private final MemberService memberService; private final EventService eventService; - @Transactional - public Reservation getByIdOrThrow(Long id) { - return reservationRepository.findById(id) - .orElseThrow(() -> new EntityNotFoundException("해당하는 예약을 찾을 수 없습니다.")); - } - @Transactional(readOnly = true) public ReservationResponse getById(Long id) { return ReservationResponse.from(getByIdOrThrow(id)); } - @Transactional - public void validateByMemberIdAndEventId(Long memberId, Long eventId) { - if (reservationRepository.findByMemberIdAndEventId(memberId, eventId) == null) { - throw new ReservationNotFoundForReviewException("해당 이벤트에 대한 리뷰를 작성할 자격이 없습니다."); - } - } - @Transactional(readOnly = true) - public ReservationSliceResponse getAllByMemberId(Long memberId, Pageable pageable, Long oldLastId) { - Slice reservations = reservationRepository.findByMemberIdOrderByReservationIdDesc(memberId, oldLastId, pageable); + public ReservationSliceResponse getAllByMemberId(MemberIdentifier identifier, Pageable pageable, Long oldLastId) { + Slice reservations = + reservationRepository.findByMemberIdOrderByReservationIdDesc(identifier.id(), oldLastId, pageable); Long newLastId = getLastId(reservations, oldLastId); return ReservationSliceResponse.from(reservations, reservations.getSize(), newLastId); } @@ -62,41 +52,55 @@ public ReservationSliceResponse getAllByEventId(MemberIdentifier identifier, Lon return ReservationSliceResponse.from(reservations, reservations.getSize(), newLastId); } - private Long getLastId(Slice reservations, Long oldLastId) { - if (reservations.hasContent()) { - return reservations.getContent().getLast().getId(); - } - return oldLastId; - } - @Transactional - public KakaoPayResponse create(Long memberId, ReservationRequest reservationRequest) { + public KakaoPayReservationResponse create(MemberIdentifier identifier, ReservationRequest reservationRequest) { Reservation reservation = reservationRepository.save(reservationRequest.toEntity( - memberService.getByIdOrThrow(memberId), + memberService.getByIdOrThrow(identifier.id()), eventService.getByIdOrThrow(reservationRequest.getEventId())) ); eventService.decreaseLeftSeat(reservation.getEvent().getId(), reservationRequest.getQuantity()); - return paymentService.createPayment(KakaoPayRequest.from(reservation)); + KakaoPayResponse kakaoPayResponse = paymentService.createPayment(KakaoPayRequest.from(reservation)); + ReservationResponse reservationResponse = ReservationResponse.from(reservation); + return KakaoPayReservationResponse.from(reservationResponse, kakaoPayResponse); } @Transactional - public ReservationResponse createTest(Long memberId, ReservationRequest reservationRequest) { + public ReservationResponse createTest(MemberIdentifier identifier, ReservationRequest reservationRequest) { Reservation reservation = reservationRepository.save(reservationRequest.toEntity( - memberService.getByIdOrThrow(memberId), + memberService.getByIdOrThrow(identifier.id()), eventService.getByIdOrThrow(reservationRequest.getEventId()))); eventService.decreaseLeftSeat(reservation.getEvent().getId(), reservationRequest.getQuantity()); return ReservationResponse.from(reservation); } @Transactional - public void delete(Long memberId, Long reservationId) { - validateMemberId(memberId, getByIdOrThrow(reservationId)); + public void delete(MemberIdentifier identifier, Long reservationId) { + validateMemberId(identifier.id(), getByIdOrThrow(reservationId)); reservationRepository.deleteById(reservationId); } + @Transactional(readOnly = true) + public void validateByMemberIdAndEventId(Long memberId, Long eventId) { + if (reservationRepository.findByMemberIdAndEventId(memberId, eventId).isEmpty()) { + throw new ReservationNotFoundForReviewException("해당 이벤트에 대한 리뷰를 작성할 수 없습니다."); + } + } + + private Reservation getByIdOrThrow(Long id) { + return reservationRepository.findById(id) + .orElseThrow(() -> new EntityNotFoundException("해당하는 예약을 찾을 수 없습니다.")); + } + + private Long getLastId(Slice reservations, Long oldLastId) { + if (reservations.hasContent()) { + return reservations.getContent().getLast().getId(); + } + return oldLastId; + } + private void validateMemberId(Long memberId, Reservation reservation) { if (!memberId.equals(reservation.getMember().getId())) { - throw new UnauthorizedException("member ID가 예약의 member ID와 일치하지 않습니다."); + throw new UnauthorizedException("사용자 ID가 예약한 사용자 ID와 일치하지 않습니다."); } } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/ReservationRepository.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/ReservationRepository.java index 5c7b726b..4739e588 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/ReservationRepository.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/ReservationRepository.java @@ -1,5 +1,6 @@ package org.ktc2.cokaen.wouldyouin.reservation.persist; +import java.util.List; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; import org.springframework.data.jpa.repository.JpaRepository; @@ -19,5 +20,9 @@ public interface ReservationRepository extends JpaRepository + "ORDER BY R.id DESC") Slice findByEventIdOrderByReservationIdDesc(Long eventId, Long lastId, Pageable pageable); - Reservation findByMemberIdAndEventId(Long memberId, Long eventId); + @Query("SELECT R FROM Reservation R JOIN FETCH R.member JOIN FETCH R.event " + + "WHERE R.member.id = :memberId " + + "AND R.event.id = :eventId " + + "AND R.event.endTime > CURRENT_TIMESTAMP") + List findByMemberIdAndEventId(Long memberId, Long eventId); } \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index fef18b26..258d67c9 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -56,7 +56,6 @@ image: child-path: thumbnail width: 130 height: 90 - extension: png # for jwt jwt: diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/AdvertisementData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/AdvertisementData.java new file mode 100644 index 00000000..7a7583d7 --- /dev/null +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/AdvertisementData.java @@ -0,0 +1,5 @@ +package org.ktc2.cokaen.wouldyouin._global.testdata; + +public class AdvertisementData { + +} diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java index 6f0e7f41..f084180f 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java @@ -5,6 +5,7 @@ import java.time.LocalDateTime; import java.util.List; import org.ktc2.cokaen.wouldyouin._common.vo.Area; +import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.curation1.entity; import org.ktc2.cokaen.wouldyouin._global.testdata.EventData.R.event1; import org.ktc2.cokaen.wouldyouin._global.testdata.EventData.R.event2; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCardRequest; @@ -32,7 +33,7 @@ public static class curationCard1 { public static final String subtitle = "큐레이션 카드 부제목1"; public static final String content = "큐레이션 카드 내용1 입니다. 큐레이션 카드의 내용은 최소 20자 최대 1000자 입니다."; public static final List images = List.of(ImageData.curation1.entity.get()); - public static final List imageIds = List.of(1301L); + public static final List imageIds = List.of(ImageData.R.curation1.id); public static final List imageUrls = List.of(ImageData.R.curation1.url); } @@ -41,7 +42,8 @@ public static class curationCard2 { public static final Long id = 352L; public static final String subtitle = "큐레이션 카드 부제목2"; public static final String content = "큐레이션 카드 내용2 입니다. 큐레이션 카드의 내용은 최소 20자 최대 1000자 입니다."; - public static final List imageIds = List.of(1302L); + public static final List images = List.of(ImageData.curation2.entity.get()); + public static final List imageIds = List.of(ImageData.R.curation2.id); public static final List imageUrls = List.of(ImageData.R.curation2.url); } @@ -86,8 +88,8 @@ public static class curation2 { CurationData.curationCard2.response.get() ); public static final int page = 0; - public static final int pageSize = 10; - public static final Long lastId = 100L; + public static final int pageSize = 20; + public static final Long lastId = 50L; public static final PageRequest pageable = PageRequest.of(0, 10); public static final Area area = Area.광주; public static final List hashtags = List.of("수정 해시태그"); @@ -114,6 +116,17 @@ public static CurationCard get() { } } + public static class entityWithNoId { + + public static CurationCard get() { + return CurationCard.builder() + .subtitle(R.curationCard1.subtitle) + .content(R.curationCard1.content) + .images(R.curationCard1.images) + .build(); + } + } + public static class entityWithNoCuration { public static CurationCard get() { @@ -223,13 +236,6 @@ public static Curation get() { } } - public static class CurationSlice { - - public static Slice get() { - return new SliceImpl<>(List.of(entity.get()), R.curation1.pageable, true); - } - } - public static class entityWithNoCurator { public static Curation get() { @@ -385,4 +391,11 @@ public static CurationResponse get() { } } } + + public static class CurationSlice { + + public static Slice get() { + return new SliceImpl<>(List.of(entity.get()), R.curation1.pageable, true); + } + } } \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ReservationData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ReservationData.java index 649fd88f..2933e1e9 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ReservationData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ReservationData.java @@ -2,21 +2,35 @@ import java.time.LocalDateTime; import java.util.List; +import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.R; +import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.curation1.entity; import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.response.reservation1Member1; +import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.ReservationEventResponse; import org.ktc2.cokaen.wouldyouin.event.persist.Event; import org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse.ReservationMemberResponse; import org.ktc2.cokaen.wouldyouin.member.persist.Member; +import org.ktc2.cokaen.wouldyouin.payment.dto.KakaoPayResponse; +import org.ktc2.cokaen.wouldyouin.reservation.api.dto.KakaoPayReservationResponse; import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationRequest; import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationResponse; import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationSliceResponse; import org.ktc2.cokaen.wouldyouin.reservation.persist.Reservation; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; +import org.springframework.data.domain.SliceImpl; import org.springframework.test.util.ReflectionTestUtils; public class ReservationData { public static class R { + public static final int page = 0; + public static final int pageSize = 10; + public static final Long lastId = 1L; + public static final Pageable pageable = PageRequest.of(0, 10); + public static class reservation1 { public static final Long id = 1L; @@ -74,6 +88,33 @@ public static ReservationResponse get() { } } + + public static class kakaoPayResponse { + + public static KakaoPayResponse get() { + return new KakaoPayResponse( + "10L", "nextRedirectAppUrl", "nextRedirectMobileUrl", + "nextRedirectPcUrl", "androidAppScheme", "ios_app_scheme", + LocalDateTime.of(2024, 3, 23, 0, 0)); + } + } + + public static class kakaoPayReservationResponse { + + public static ReservationResponse reservationResponse = ReservationResponse.from(reservation1.entity.get()); + public static KakaoPayResponse kakaoPayResponse = ReservationData.reservation1.kakaoPayResponse.get(); + + public static KakaoPayReservationResponse get() { + return KakaoPayReservationResponse.from(reservationResponse, kakaoPayResponse); + } + } + } + + public static class ReservationSlice { + + public static Slice get() { + return new SliceImpl<>(List.of(ReservationData.reservation1.entity.get()), PageRequest.of(0, 10), true); + } } public static class sliceResponse { diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationCardServiceTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationCardServiceTest.java new file mode 100644 index 00000000..8bd2efda --- /dev/null +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationCardServiceTest.java @@ -0,0 +1,85 @@ +package org.ktc2.cokaen.wouldyouin.curation; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; +import static org.mockito.Mockito.times; + +import java.util.Optional; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData; +import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.R.curationCard1; +import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData; +import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.R.curation1; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator1; +import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCardResponse; +import org.ktc2.cokaen.wouldyouin.curation.application.CurationCardService; +import org.ktc2.cokaen.wouldyouin.curation.persist.CurationCard; +import org.ktc2.cokaen.wouldyouin.curation.persist.CurationCardRepository; +import org.ktc2.cokaen.wouldyouin.image.application.CurationImageService; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +public class CurationCardServiceTest { + + private CurationCardService curationCardService; + + @Mock + private CurationCardRepository curationCardRepository; + + @Mock + private CurationImageService curationImageService; + + @BeforeEach + void setUp() { + curationCardService = new CurationCardService(curationCardRepository, curationImageService); + } + + @Test + @DisplayName("큐레이션 ID를 통해 해당 하는 큐레이션을 반환한다.") + void getById() { + // given + given(curationCardRepository.findById(curationCard1.id)).willReturn(Optional.of(CurationData.curationCard1.entity.get())); + given(curationImageService.getImageUrl(ImageData.curation1.entity.get())).willReturn(ImageData.R.curation1.url); + + // when + CurationCardResponse response = curationCardService.getById(curationCard1.id); + + // then + assertThat(response).isEqualTo(CurationData.curationCard1.response.get()); + } + + @Test + @DisplayName("큐레이션 카드 DTO를 통해 큐레이션 카드를 생성한다.") + void create() { + // given + given(curationImageService.getById(curation1.id)).willReturn(ImageData.curation1.entity.get()); + given(curationCardRepository.save(CurationData.curationCard1.entityWithNoId.get())) + .willReturn(CurationData.curationCard1.entity.get()); + + // when + CurationCard response = curationCardService.create(CurationData.curationCard1.request.get()); + + // then + assertThat(response).isEqualTo(CurationData.curationCard1.entity.get()); + } + + @Test + @DisplayName("큐레이션 카 ID를 통해 해당 하는 큐레이션 카드를 삭제한다.") + void delete() { + // given + given(curationCardRepository.findById(curationCard1.id)).willReturn(Optional.of(CurationData.curationCard1.entity.get())); + + // when + curationCardService.delete(curator1.memberIdentifier, curationCard1.id); + + // then + then(curationImageService).should(times(curationCard1.images.size())).deleteImage(any(), any()); + then(curationCardRepository).should(times(1)).deleteById(curationCard1.id); + } +} diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java index 739ad27f..5ddc8fc0 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java @@ -1,6 +1,5 @@ package org.ktc2.cokaen.wouldyouin.curation; -import static java.lang.Math.abs; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; @@ -10,7 +9,6 @@ import static org.mockito.Mockito.times; import java.util.Optional; -import java.util.Random; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -18,7 +16,6 @@ import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData; import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.R.curation1; -import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.curation1.entity; import org.ktc2.cokaen.wouldyouin._global.testdata.EventData; import org.ktc2.cokaen.wouldyouin._global.testdata.EventData.R.event2; import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData; @@ -34,7 +31,6 @@ import org.ktc2.cokaen.wouldyouin.curation.persist.CurationRepository; import org.ktc2.cokaen.wouldyouin.event.application.EventService; import org.ktc2.cokaen.wouldyouin.image.application.CurationImageService; -import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin.member.application.CuratorService; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.mockito.Mock; @@ -60,17 +56,6 @@ class CurationServiceTest { @Mock private CurationImageService curationImageService; - @Mock - private CurationResponse curationResponse; - - @Mock - private MemberImage memberImage; - - Curation validCuration = entity.get(); - CurationResponse validCurationResponse = CurationData.curation1.response.get(); - - private final long randomId = abs(new Random().nextLong()); - @BeforeEach void setUp() { curationService = new CurationService(curationRepository, curatorService, eventService, curationCardService, curationImageService); @@ -80,14 +65,14 @@ void setUp() { @DisplayName("큐레이션 ID를 통해 해당 하는 큐레이션을 반환한다.") void getById() { // given - given(curationRepository.findById(randomId)).willReturn(Optional.of(validCuration)); + given(curationRepository.findById(curation1.id)).willReturn(Optional.of(CurationData.curation1.entity.get())); given(curationImageService.getImageUrl(ImageData.curation1.entity.get())).willReturn(ImageData.R.curation1.url); // when - CurationResponse response = curationService.getById(randomId); + CurationResponse response = curationService.getById(curation1.id); // then - assertThat(response).isEqualTo(validCurationResponse); + assertThat(response).isEqualTo(CurationData.curation1.response.get()); } @Test @@ -95,7 +80,7 @@ void getById() { void getAllByAreaOrderByCreatedDateDesc() { // given given(curationRepository.findAllByAreaOrderByCreatedDateDesc(curation1.area, curation1.lastId, curation1.pageable)) - .willReturn(CurationData.curation1.CurationSlice.get()); + .willReturn(CurationData.CurationSlice.get()); given(curationImageService.getImageUrl(ImageData.curation1.entity.get())).willReturn(ImageData.R.curation1.url); // when @@ -111,7 +96,7 @@ void getAllByAreaOrderByCreatedDateDesc() { void getAllByCuratorIdOrderByCreatedDateDesc() { // given given(curationRepository.findAllByCuratorOrderByCreatedDateDesc(curator1.id, curation1.lastId, curation1.pageable)) - .willReturn(CurationData.curation1.CurationSlice.get()); + .willReturn(CurationData.CurationSlice.get()); given(curationImageService.getImageUrl(ImageData.curation1.entity.get())).willReturn(ImageData.R.curation1.url); // when @@ -123,7 +108,7 @@ void getAllByCuratorIdOrderByCreatedDateDesc() { } @Test - @DisplayName("CurationCreateReqeust를 통해 큐레이션을 생성한다.") + @DisplayName("큐레이션 생성 DTO를 통해 큐레이션을 생성한다.") void create() { // given given(curatorService.getByIdOrThrow(curator1.id)).willReturn(MemberData.curator1.entity.get()); @@ -163,13 +148,13 @@ void update1() { @DisplayName("멤버 ID가 다르면 큐레이션을 수정할 수 없다.") void update2() { // given - Long invalidCuratorId = 100L; + MemberIdentifier differentMember = new MemberIdentifier(100L, MemberType.curator); given(curationRepository.findById(curation1.id)).willReturn(Optional.of(CurationData.curation1.entity.get())); // when, then - assertThrows( - UnauthorizedException.class, () -> curationService.update( - new MemberIdentifier(invalidCuratorId, MemberType.curator), curation1.id, CurationData.curation1.request.edit.get())); + UnauthorizedException exception = assertThrows( + UnauthorizedException.class, () -> curationService.update(differentMember, curation1.id, CurationData.curation1.request.edit.get())); + assertThat(exception.getMessage()).isEqualTo("큐레이션에 접근할 권한이 없습니다."); } @Test @@ -210,21 +195,20 @@ void delete1() { @DisplayName("멤버 ID가 다르면 큐레이션을 삭제할 수 없다.") void delete2() { // given - Long invalidCuratorId = 100L; + MemberIdentifier differentMember = new MemberIdentifier(100L, MemberType.curator); given(curationRepository.findById(curation1.id)).willReturn(Optional.of(CurationData.curation1.entity.get())); // when, then - assertThrows( - UnauthorizedException.class, () -> curationService.delete( - new MemberIdentifier(invalidCuratorId, MemberType.curator), curation1.id)); + UnauthorizedException exception = assertThrows( + UnauthorizedException.class, () -> curationService.delete(differentMember, curation1.id)); + assertThat(exception.getMessage()).isEqualTo("큐레이션에 접근할 권한이 없습니다."); } @Test @DisplayName("멤버 ID가 달라도 ADMIN은 큐레이션을 삭제할 수 있다.") void delete3() { // given - Long invalidCuratorId = 100L; - MemberIdentifier admin = new MemberIdentifier(invalidCuratorId, MemberType.admin); + MemberIdentifier admin = new MemberIdentifier(100L, MemberType.admin); given(curationRepository.findById(curation1.id)).willReturn(Optional.of(CurationData.curation1.entity.get())); // when diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/image/CurationImageServiceTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/image/CurationImageServiceTest.java new file mode 100644 index 00000000..dde61a18 --- /dev/null +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/image/CurationImageServiceTest.java @@ -0,0 +1,66 @@ +package org.ktc2.cokaen.wouldyouin.image; + + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; +import static org.mockito.Mockito.times; + +import java.util.Optional; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData; +import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.R.curation1; +import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData; +import org.ktc2.cokaen.wouldyouin.image.application.AdvertisementImageService; +import org.ktc2.cokaen.wouldyouin.image.application.CurationImageService; +import org.ktc2.cokaen.wouldyouin.image.application.ImageStorageService; +import org.ktc2.cokaen.wouldyouin.image.persist.CurationImage; +import org.ktc2.cokaen.wouldyouin.image.persist.CurationImageRepository; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +public class CurationImageServiceTest { + + private CurationImageService curationImageService; + + @Mock + private ImageStorageService imageStorageService; + + @Mock + private CurationImageRepository curationImageRepository; + + @BeforeEach + void setUp() { + curationImageService = new CurationImageService(imageStorageService, curationImageRepository); + } + + @Test + @DisplayName("이미지 ID를 통해 큐레이션 이미지를 반환한다.") + void getById() { + // given + given(curationImageRepository.findById(curation1.id)).willReturn(Optional.of(ImageData.curation1.entity.get())); + + // when + CurationImage response = curationImageService.getById(curation1.id); + + // then + assertThat(response).isEqualTo(ImageData.curation1.entity.get()); + } + +// @Test +// @DisplayName("이미지 ID를 통해 해당 이미지를 삭제한다.") +// void deleteImage() { +// // given +// CurationImage image = ImageData.curation1.entity.get(); +// given(curationImageRepository.findById(curation1.id)).willReturn(Optional.of(image)); +// +// // when, then +// then(imageStorageService).should(times(1)).delete(eq(image.getName()), any()); +// } +} diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java index ae8e174e..7d467c4e 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java @@ -70,7 +70,6 @@ class ImageControllerTest { @BeforeEach public void setup() throws Exception { - mockMvc = MockMvcBuilders .webAppContextSetup(context) .apply(springSecurity()) @@ -94,6 +93,24 @@ void getImage() throws Exception { then(imageStorageService).should(times(1)).readFromDirectory(eq(Paths.get(directory, file))); } + @Test + @DisplayName("이미지 경로를 통해 썸네일 이미지를 조회한다.") + @WithMockMember1 + void getThumnailImage() throws Exception { + // given + String directory = "member"; + String thumbnail = "thumbnail"; + String file = "image.jpg"; + + // when + mockMvc.perform(get("/api/images/{directory}/{thumbnail}/{file}", directory, thumbnail, file)) + .andDo(print()) + .andExpect(status().isOk()); + + // then + then(imageStorageService).should(times(1)).readFromDirectory(eq(Paths.get(directory, thumbnail, file))); + } + @Test @DisplayName("RequestParam으로 이미지 도메인을 받아 첨부된 이미지를 업로드한다.") @WithMockCurator1 diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java index c28db0c5..7d1dcc09 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java @@ -22,6 +22,7 @@ import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockCurator1; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost1; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember1; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator1; import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host1; import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.normal1; @@ -76,7 +77,7 @@ void getReservationsByMemberId1() throws Exception { // then then(reservationService).should(times(1)).getAllByMemberId( - eq(normal1.id), eq(PageRequest.of(5, 20)), eq(100L)); + eq(normal1.memberIdentifier), eq(PageRequest.of(5, 20)), eq(100L)); } @Test @@ -89,7 +90,7 @@ void getReservationsByMemberId2() throws Exception { // then then(reservationService).should(times(1)).getAllByMemberId( - eq(normal1.id), eq(PageRequest.of(0, 10)), eq(Long.MAX_VALUE)); + eq(normal1.memberIdentifier), eq(PageRequest.of(0, 10)), eq(Long.MAX_VALUE)); } @Test @@ -105,7 +106,7 @@ void getReservationsByMemberId3() throws Exception { // then then(reservationService).should(times(1)).getAllByMemberId( - eq(curator1.id), eq(PageRequest.of(5, 20)), eq(100L)); + eq(curator1.memberIdentifier), eq(PageRequest.of(5, 20)), eq(100L)); } @Test @@ -213,7 +214,7 @@ void createReservation1() throws Exception { .andExpect(status().isCreated()); // then - then(reservationService).should(times(1)).create(eq(normal1.id), captor.capture()); + then(reservationService).should(times(1)).create(eq(normal1.memberIdentifier), captor.capture()); assertThat(captor.getValue()).isEqualTo(request); } @@ -235,7 +236,7 @@ void createReservation2() throws Exception { .andExpect(status().isCreated()); // then - then(reservationService).should(times(1)).create(eq(curator1.id), captor.capture()); + then(reservationService).should(times(1)).create(eq(curator1.memberIdentifier), captor.capture()); assertThat(captor.getValue()).isEqualTo(request); } @@ -330,7 +331,7 @@ void deleteReservation1() throws Exception { .andExpect(status().isNoContent()); // then - then(reservationService).should(times(1)).delete(normal1.id, randomId); + then(reservationService).should(times(1)).delete(normal1.memberIdentifier, randomId); } @Test @@ -344,7 +345,7 @@ void deleteReservation2() throws Exception { .andExpect(status().isNoContent()); // then - then(reservationService).should(times(1)).delete(curator1.id, randomId); + then(reservationService).should(times(1)).delete(curator1.memberIdentifier, randomId); } @Test diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationServiceUnitTest.java index 86fa090a..fc44cc7b 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationServiceUnitTest.java @@ -1,101 +1,174 @@ -//package org.ktc2.cokaen.wouldyouin.reservation; -// -//import static java.lang.Math.abs; -//import static org.junit.jupiter.api.Assertions.assertThrows; -//import static org.mockito.ArgumentMatchers.any; -//import static org.mockito.Mockito.times; -//import static org.mockito.Mockito.verify; -//import static org.mockito.Mockito.when; -// -//import java.util.List; -//import java.util.Optional; -//import java.util.Random; -//import org.junit.jupiter.api.BeforeEach; -//import org.junit.jupiter.api.DisplayName; -//import org.junit.jupiter.api.Test; -//import org.junit.jupiter.api.extension.ExtendWith; -//import org.ktc2.cokaen.wouldyouin.event.application.EventService; -//import org.ktc2.cokaen.wouldyouin.global.TestData; -//import org.ktc2.cokaen.wouldyouin.member.application.MemberService; -//import org.ktc2.cokaen.wouldyouin.payment.application.PaymentService; -//import org.ktc2.cokaen.wouldyouin.reservation.application.ReservationService; -//import org.ktc2.cokaen.wouldyouin.reservation.persist.ReservationRepository; -//import org.mockito.Mock; -//import org.mockito.junit.jupiter.MockitoExtension; -// -//@ExtendWith({MockitoExtension.class}) -//class ReservationServiceUnitTest { -// -// private ReservationService reservationService; -// -// @Mock -// private ReservationRepository reservationRepository; -// @Mock -// private MemberService memberService; -// @Mock -// private EventService eventService; -// @Mock -// private PaymentService paymentService; -// -// private Long id; -// -// @BeforeEach -// void setUp() { -// reservationService = new ReservationService(reservationRepository, paymentService, memberService, eventService); -// id = abs(new Random().nextLong()); -// } -// -// @Test -// @DisplayName("사용자 id를 통한 모든 예약 조회 - 성공") -// void getAllByMemberId() { -// when(reservationRepository.findByMemberIdOrderByReservationIdDesc(id)).thenReturn(List.of()); -// reservationService.getAllByMemberId(id); -// verify(reservationRepository, times(1)).findByMemberIdOrderByReservationIdDesc(id); -// } -// -// @Test -// @DisplayName("행사 id를 통한 모든 예약 조회 - 성공") -// void getAllByEventId() { -// when(reservationRepository.findByEventIdOrderByReservationIdDesc(id)).thenReturn(List.of()); -// reservationService.getAllByEventId(id); -// verify(reservationRepository, times(1)).findByEventIdOrderByReservationIdDesc(id); -// } -// -// @Test -// @DisplayName("예약 id를 통한 예약 조회 - 성공") -// void getById() { -// when(reservationRepository.findById(id)).thenReturn(Optional.of(TestData.validReservation)); -// reservationService.getById(id); -// verify(reservationRepository, times(1)).findById(id); -// } -// -// @Test -// @DisplayName("유효하지 않은 예약 id를 통한 모든 예약 조회 - 실패") -// void getByInvalidId() { -// when(reservationRepository.findById(id)).thenThrow(RuntimeException.class); -// assertThrows(RuntimeException.class, () -> reservationService.getById(id)); -// } -// -// @Test -// @DisplayName("예약 생성 - 성공") -// void create() { -// when(reservationRepository.save(any())).thenReturn(TestData.validReservation); -// reservationService.create(1L, TestData.validReservationRequest); -// verify(reservationRepository, times(1)).save(any()); -// } -// -// @Test -// @DisplayName("예약 삭제 - 성공") -// void delete() { -// when(reservationRepository.findById(id)).thenReturn(Optional.of(TestData.validReservation)); -// reservationService.delete(id); -// verify(reservationRepository, times(1)).findById(id); -// } -// -// @Test -// @DisplayName("예약 삭제 - 실패") -// void deleteByInvalidId() { -// when(reservationRepository.findById(id)).thenThrow(RuntimeException.class); -// assertThrows(RuntimeException.class, () -> reservationService.delete(id)); -// } -//} \ No newline at end of file +package org.ktc2.cokaen.wouldyouin.reservation; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; +import static org.mockito.Mockito.times; + +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.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.ktc2.cokaen.wouldyouin._common.exception.ReservationNotFoundForReviewException; +import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.normal1; +import org.ktc2.cokaen.wouldyouin._global.testdata.ReservationData; +import org.ktc2.cokaen.wouldyouin._global.testdata.ReservationData.R; +import org.ktc2.cokaen.wouldyouin._global.testdata.ReservationData.R.reservation1; +import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; +import org.ktc2.cokaen.wouldyouin.event.application.EventService; +import org.ktc2.cokaen.wouldyouin.member.application.MemberService; +import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; +import org.ktc2.cokaen.wouldyouin.payment.application.PaymentService; +import org.ktc2.cokaen.wouldyouin.reservation.api.dto.KakaoPayReservationResponse; +import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationResponse; +import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationSliceResponse; +import org.ktc2.cokaen.wouldyouin.reservation.application.ReservationService; +import org.ktc2.cokaen.wouldyouin.reservation.persist.ReservationRepository; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith({MockitoExtension.class}) +class ReservationServiceUnitTest { + + private ReservationService reservationService; + + @Mock + private ReservationRepository reservationRepository; + @Mock + private MemberService memberService; + @Mock + private EventService eventService; + @Mock + private PaymentService paymentService; + + @BeforeEach + void setUp() { + reservationService = new ReservationService(reservationRepository, paymentService, memberService, eventService); + } + + @Test + @DisplayName("예약 ID를 통한 해당 예약을 반환한다.") + void getById() { + // given + given(reservationRepository.findById(reservation1.id)).willReturn(Optional.of(ReservationData.reservation1.entity.get())); + + // when + ReservationResponse response = reservationService.getById(reservation1.id); + + // then + assertThat(response).isEqualTo(ReservationResponse.from(ReservationData.reservation1.entity.get())); + } + + @Test + @DisplayName("멤버 ID를 통해 자신의 모든 예약을 반환한다.") + void getAllByMemberId() { + // given + given(reservationRepository.findByMemberIdOrderByReservationIdDesc(normal1.id, R.lastId, ReservationData.R.pageable)) + .willReturn(ReservationData.ReservationSlice.get()); + + // when + ReservationSliceResponse response = + reservationService.getAllByMemberId(normal1.memberIdentifier, R.pageable, R.lastId); + + // then + assertThat(response).isEqualTo(ReservationData.sliceResponse.get()); + } + + @Test + @DisplayName("이벤트 ID를 통해 해당 행사의 모든 예약을 반환한다.") + void getAllByEventId() { + // given + given(eventService.getByIdOrThrow(R.reservation1._Relation.event().getId())).willReturn(R.reservation1._Relation.event()); + given(reservationRepository.findByEventIdOrderByReservationIdDesc(R.reservation1._Relation.event().getId(), R.lastId, R.pageable)) + .willReturn(ReservationData.ReservationSlice.get()); + + // when + ReservationSliceResponse response = + reservationService.getAllByEventId(normal1.memberIdentifier, R.reservation1._Relation.event().getId(), R.pageable, R.lastId); + + // then + assertThat(response).isEqualTo(ReservationData.sliceResponse.get()); + } + + @Test + @DisplayName("예약 생성 DTO를 통해 결제를 진행하고 예약을 생성한다.") + void create() { + // given + given(reservationRepository.save(any())).willReturn(ReservationData.reservation1.entity.get()); + given(eventService.getByIdOrThrow(R.reservation1._Relation.event().getId())).willReturn(R.reservation1._Relation.event()); + given(reservationRepository.save(any())).willReturn(ReservationData.reservation1.entity.get()); + given(paymentService.createPayment(any())).willReturn(ReservationData.reservation1.kakaoPayResponse.get()); + + // when + KakaoPayReservationResponse response = + reservationService.create(normal1.memberIdentifier, ReservationData.reservation1.request.get()); + + // then + assertThat(response).isEqualTo(ReservationData.reservation1.kakaoPayReservationResponse.get()); + } + + @Test + @DisplayName("예약 생성 DTO를 통해 예약을 생성한다.") + void createTest() { + // given + given(reservationRepository.save(any())).willReturn(ReservationData.reservation1.entity.get()); + given(eventService.getByIdOrThrow(R.reservation1._Relation.event().getId())).willReturn(R.reservation1._Relation.event()); + given(reservationRepository.save(any())).willReturn(ReservationData.reservation1.entity.get()); + + // when + ReservationResponse response = + reservationService.createTest(normal1.memberIdentifier, ReservationData.reservation1.request.get()); + + // then + assertThat(response).isEqualTo(ReservationData.reservation1.response.get()); + } + + @Test + @DisplayName("예약 ID를 통해 해당 예약을 삭제한다.") + void delete1() { + // given + given(reservationRepository.findById(reservation1.id)).willReturn(Optional.of(ReservationData.reservation1.entity.get())); + + // when + reservationService.delete(normal1.memberIdentifier, reservation1.id); + + // then + then(reservationRepository).should(times(1)).deleteById(reservation1.id); + } + + @Test + @DisplayName("멤버 ID와 예약의 멤버 ID가 일치하지 않으면 예약을 삭제할 수 없다.") + void delete2() { + // given + MemberIdentifier anotherMember = new MemberIdentifier(100L, MemberType.normal); + given(reservationRepository.findById(reservation1.id)).willReturn(Optional.of(ReservationData.reservation1.entity.get())); + + // when + UnauthorizedException exception = + assertThrows(UnauthorizedException.class, () -> reservationService.delete(anotherMember, reservation1.id)); + + // then + then(reservationRepository).should(times(0)).deleteById(reservation1.id); + assertThat(exception.getMessage()).isEqualTo("사용자 ID가 예약한 사용자 ID와 일치하지 않습니다."); + } + + @Test + @DisplayName("사용자는 해당 이벤트에 대한 예약이 없으면 리뷰를 작성할 수 없다.") + void validateByMemberIdAndEventId() { + // given + given(reservationRepository.findByMemberIdAndEventId(normal1.id, R.reservation1._Relation.event().getId())).willReturn(List.of()); + + // when + ReservationNotFoundForReviewException exception = + assertThrows(ReservationNotFoundForReviewException.class, + () -> reservationService.validateByMemberIdAndEventId(normal1.id, R.reservation1._Relation.event().getId())); + + // then + assertThat(exception.getMessage()).isEqualTo("해당 이벤트에 대한 리뷰를 작성할 수 없습니다."); + } +} \ No newline at end of file From 8d6da0c3759fbc769696ef1792e1ed87e703945d Mon Sep 17 00:00:00 2001 From: ariimo Date: Fri, 15 Nov 2024 08:34:01 +0900 Subject: [PATCH 42/53] =?UTF-8?q?[Weekly/11/Test/Like]=20LikeControllerUni?= =?UTF-8?q?tTest=20=EC=83=9D=EC=84=B1=20(#141)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * test: Event Unit Test 리팩터링 * feat: Like 리팩터링 * feat: LikeData 추가 * test: LikeControllerUnitTest 생성 --- .../wouldyouin/like/api/LikeController.java | 16 +- .../like/application/LikeService.java | 9 +- .../like/application/dto/LikeResponse.java | 31 ++ .../application/dto/LikeToggleResponse.java | 20 + .../_global/mockMember/WithMockCurator1.java | 2 +- .../_global/testdata/CommonData.java | 37 +- .../wouldyouin/_global/testdata/LikeData.java | 96 +++- .../event/EventServiceUnitTest.java | 448 +++++++++--------- .../wouldyouin/image/ImageControllerTest.java | 37 +- .../like/LikeControllerUnitTest.java | 285 ++++++++++- 10 files changed, 699 insertions(+), 282 deletions(-) create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/like/application/dto/LikeResponse.java create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/like/application/dto/LikeToggleResponse.java diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/LikeController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/LikeController.java index 1f1712a6..9a2d52f4 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/LikeController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/LikeController.java @@ -28,22 +28,28 @@ public class LikeController { @GetMapping public ResponseEntity> getLikes( - @Authorize(MemberType.normal) MemberIdentifier identifier, + @Authorize({MemberType.normal, MemberType.curator}) MemberIdentifier identifier, @RequestParam("type") MemberType memberType, @RequestParam(defaultValue = ParamDefaults.PAGE) Integer page, @RequestParam(defaultValue = ParamDefaults.PAGE_SIZE) Integer size, @RequestParam(defaultValue = ParamDefaults.LAST_ID) Long lastId ) { return ApiResponse.ok( - likeServiceFactory.getLikeServiceFrom(memberType) - .getLikes(identifier.id(), PageRequest.of(page, size), lastId)); + likeServiceFactory + .getLikeServiceFrom(memberType) + .getLikes(identifier, PageRequest.of(page, size), lastId)); } @PostMapping("/{targetMemberId}") public ResponseEntity> createOrDeleteLike( - @Authorize(MemberType.normal) MemberIdentifier identifier, + @Authorize({MemberType.normal, MemberType.curator}) MemberIdentifier identifier, + @RequestParam("type") MemberType memberType, @PathVariable("targetMemberId") Long targetId) { return ApiResponse.created( - likeServiceFactory.getLikeServiceFrom(targetId).toggleLike(identifier.id(), targetId)); + likeServiceFactory.getLikeServiceFrom(memberType) + .toggleLike(identifier, targetId)); } } + +// TODO: Like service에 Identifier 넘겨주기 +// TODO: Review service에 Identifier 넘겨주기 \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/LikeService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/LikeService.java index 0d8dfbb9..49e6d043 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/LikeService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/LikeService.java @@ -2,6 +2,7 @@ import java.util.List; import lombok.RequiredArgsConstructor; +import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.like.api.dto.LikeResponse; import org.ktc2.cokaen.wouldyouin.like.api.dto.LikeSliceResponse; import org.ktc2.cokaen.wouldyouin.like.api.dto.LikeToggleResponse; @@ -31,9 +32,9 @@ public abstract class LikeService likes = getLikeRepository().findAllByMember( - memberService.getByIdOrThrow(memberId), beforeLastId, pageable); + memberService.getByIdOrThrow(identifier.id()), beforeLastId, pageable); Long newLastId = getLastId(likes, beforeLastId); List responses = likes.stream() .map(like -> LikeResponse.from(like.getLikeableMember())).toList(); @@ -41,8 +42,8 @@ public LikeSliceResponse getLikes(Long memberId, Pageable pageable, Long beforeL } @Transactional - public LikeToggleResponse toggleLike(Long memberId, Long targetMemberId) { - Member member = memberService.getByIdOrThrow(memberId); + public LikeToggleResponse toggleLike(MemberIdentifier identifier, Long targetMemberId) { + Member member = memberService.getByIdOrThrow(identifier.id()); LikeableMember targetLikeableMember = getLikeableMemberByIdOrThrow(targetMemberId); return getLikeRepository().findByMemberAndLikeableMember(member, targetLikeableMember) .map(like -> { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/dto/LikeResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/dto/LikeResponse.java new file mode 100644 index 00000000..3dca9a88 --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/dto/LikeResponse.java @@ -0,0 +1,31 @@ + +package org.ktc2.cokaen.wouldyouin.like.api.dto; + +import java.util.List; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.ktc2.cokaen.wouldyouin.member.persist.LikeableMember; + +@Getter +@RequiredArgsConstructor(access = AccessLevel.PROTECTED) +@Builder +public class LikeResponse { + + private final Long memberId; + private final String nickname; + private final String intro; + private final List hashtags; + private final String profileImageUrl; + + public static LikeResponse from(LikeableMember member) { + return LikeResponse.builder() + .memberId(member.getId()) + .nickname(member.getNickname()) + .intro(member.getIntro()) + .hashtags(member.getHashtags()) + .profileImageUrl(member.getProfileImageUrl()) + .build(); + } +} diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/dto/LikeToggleResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/dto/LikeToggleResponse.java new file mode 100644 index 00000000..d5181d72 --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/dto/LikeToggleResponse.java @@ -0,0 +1,20 @@ +package org.ktc2.cokaen.wouldyouin.like.application.dto; + +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.ktc2.cokaen.wouldyouin.member.persist.LikeableMember; + +@Getter +@RequiredArgsConstructor(access = AccessLevel.PROTECTED) +@Builder +public class LikeToggleResponse { + private final boolean isLiked; + + public static LikeToggleResponse from(boolean state) { + return LikeToggleResponse.builder() + .isLiked(state) + .build(); + } +} diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockCurator1.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockCurator1.java index 877e3b20..0b1a6097 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockCurator1.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockCurator1.java @@ -8,5 +8,5 @@ @Retention(RetentionPolicy.RUNTIME) @WithMockCustomUser(memberId = curator1.id, memberType = MemberType.curator) public @interface WithMockCurator1 { - + // TODO: mockMember 패키지명 변경 } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java index 08fcd4c1..e956adae 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java @@ -2,7 +2,9 @@ import org.ktc2.cokaen.wouldyouin._common.api.SliceInfo; import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.R.curation1; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R; import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator1; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host1; import org.ktc2.cokaen.wouldyouin._global.testdata.ReservationData.R.reservation1; import org.ktc2.cokaen.wouldyouin._global.testdata.ReviewData.R.review1; @@ -26,13 +28,36 @@ public static SliceInfo get() { } public static class like { - - public static SliceInfo get() { - return SliceInfo.builder() - .sliceSize(2) - .lastId(curator1.id) - .build(); + public static class normal1 { + public static class hostLikes { + public static SliceInfo get() { + return SliceInfo.builder() + .sliceSize(1) + .lastId(host1.id) + .build(); + } + } + public static class curatorLikes { + public static SliceInfo get() { + return SliceInfo.builder() + .sliceSize(1) + .lastId(R.curator1.id) + .build(); + } + } + } + public static class curator1 { + public static class hostLikes { + public static SliceInfo get() { + return SliceInfo.builder() + .sliceSize(1) + .lastId(host1.id) + .build(); + } } + } + + } public static class reservation { diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/LikeData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/LikeData.java index 581a87f2..bc0a7664 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/LikeData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/LikeData.java @@ -1,8 +1,11 @@ package org.ktc2.cokaen.wouldyouin._global.testdata; import java.util.List; +import org.ktc2.cokaen.wouldyouin._global.testdata.LikeData.R.likeHost1.byNormal1; +import org.ktc2.cokaen.wouldyouin._global.testdata.LikeData.R.likeHost1.byNormal1.create; import org.ktc2.cokaen.wouldyouin.like.api.dto.LikeResponse; import org.ktc2.cokaen.wouldyouin.like.api.dto.LikeSliceResponse; +import org.ktc2.cokaen.wouldyouin.like.api.dto.LikeToggleResponse; import org.ktc2.cokaen.wouldyouin.like.persist.CuratorLike; import org.ktc2.cokaen.wouldyouin.like.persist.HostLike; import org.ktc2.cokaen.wouldyouin.member.persist.Curator; @@ -29,6 +32,10 @@ public static class response { public static final List hashtags = MemberData.R.host1.hashtags; public static final String profileImageUrl = MemberData.R.host1.profileImageUrl; } + public static class create{ + public static final Boolean created = true; + public static final Boolean deleted = false; + } } public static class byCurator1 { public static class _Relation { @@ -46,6 +53,10 @@ public static class response { public static final List hashtags = MemberData.R.host1.hashtags; public static final String profileImageUrl = MemberData.R.host1.profileImageUrl; } + public static class create{ + public static final Boolean created = true; + public static final Boolean deleted = false; + } } } public static class likeCurator1 { @@ -137,28 +148,71 @@ public static LikeResponse get() { } } } + public static class toggleResponse{ + public static class hostLikes { + public static class create { - public static class normal1LikeSliceResponse { - public static LikeSliceResponse get() { - return LikeSliceResponse.builder() - .likes(List.of( - LikeResponse.builder() - .memberId(R.likeHost1.byNormal1.response.id) - .nickname(R.likeHost1.byNormal1.response.nickname) - .intro(R.likeHost1.byNormal1.response.intro) - .hashtags(R.likeHost1.byNormal1.response.hashtags) - .profileImageUrl(R.likeHost1.byNormal1.response.profileImageUrl) - .build(), - LikeResponse.builder() - .memberId(R.likeCurator1.byNormal1.response.id) - .nickname(R.likeCurator1.byNormal1.response.nickname) - .intro(R.likeCurator1.byNormal1.response.intro) - .hashtags(R.likeCurator1.byNormal1.response.hashtags) - .profileImageUrl(R.likeCurator1.byNormal1.response.profileImageUrl) - .build() - )) - .sliceInfo(CommonData.sliceInfo.like.get()) - .build(); + public static LikeToggleResponse get() { + return LikeToggleResponse.builder().isLiked(byNormal1.create.created).build(); + } + } + public static class delete { + + public static LikeToggleResponse get() { + return LikeToggleResponse.builder().isLiked(byNormal1.create.deleted).build(); + } + } + } + } + public static class sliceResponse { + public static class normal1 { + public static class hostLikes { + public static LikeSliceResponse get() { + return LikeSliceResponse.builder() + .likes(List.of( + LikeResponse.builder() + .memberId(R.likeHost1.byNormal1.response.id) + .nickname(R.likeHost1.byNormal1.response.nickname) + .intro(R.likeHost1.byNormal1.response.intro) + .hashtags(R.likeHost1.byNormal1.response.hashtags) + .profileImageUrl(R.likeHost1.byNormal1.response.profileImageUrl) + .build())) + .sliceInfo(CommonData.sliceInfo.like.normal1.hostLikes.get()) + .build(); + } + } + public static class curatorLikes { + public static LikeSliceResponse get() { + return LikeSliceResponse.builder() + .likes(List.of( + LikeResponse.builder() + .memberId(R.likeCurator1.byNormal1.response.id) + .nickname(R.likeCurator1.byNormal1.response.nickname) + .intro(R.likeCurator1.byNormal1.response.intro) + .hashtags(R.likeCurator1.byNormal1.response.hashtags) + .profileImageUrl(R.likeCurator1.byNormal1.response.profileImageUrl) + .build())) + .sliceInfo(CommonData.sliceInfo.like.normal1.curatorLikes.get()) + .build(); + } + } + } + public static class curator1 { + public static class hostLikes { + public static LikeSliceResponse get() { + return LikeSliceResponse.builder() + .likes(List.of( + LikeResponse.builder() + .memberId(R.likeHost1.byCurator1.response.id) + .nickname(R.likeHost1.byCurator1.response.nickname) + .intro(R.likeHost1.byCurator1.response.intro) + .hashtags(R.likeHost1.byCurator1.response.hashtags) + .profileImageUrl(R.likeHost1.byCurator1.response.profileImageUrl) + .build())) + .sliceInfo(CommonData.sliceInfo.like.curator1.hostLikes.get()) + .build(); + } + } } } } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java index 8b7ee7de..e0f17cfa 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java @@ -1,224 +1,224 @@ -package org.ktc2.cokaen.wouldyouin.event; - -import static org.junit.jupiter.api.Assertions.assertAll; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.BDDMockito.given; -import static org.mockito.BDDMockito.then; -import static org.mockito.BDDMockito.willDoNothing; -import static org.mockito.Mockito.times; - -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.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.ktc2.cokaen.wouldyouin.image.application.EventImageService; -import org.ktc2.cokaen.wouldyouin.image.application.MemberImageService; -import org.ktc2.cokaen.wouldyouin._common.vo.Area; -import org.ktc2.cokaen.wouldyouin._common.vo.Category; -import org.ktc2.cokaen.wouldyouin._global.testdata.EventData; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host1; -import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; -import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationFilter; -import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; -import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; -import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationRequest; -import org.ktc2.cokaen.wouldyouin.event.application.EventService; -import org.ktc2.cokaen.wouldyouin.event.persist.Event; -import org.ktc2.cokaen.wouldyouin.event.persist.EventRepository; -import org.ktc2.cokaen.wouldyouin.member.application.HostService; -import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.SliceImpl; - -@ExtendWith(MockitoExtension.class) -class EventServiceUnitTest { - - private EventService eventService; - - @Mock - private EventRepository eventRepository; - - @Mock - private HostService hostService; - - @Mock - private EventImageService eventImageService; - - @Mock - private MemberImageService memberImageService; - - private Event validEvent; - - @BeforeEach - void setUp() { - eventService = new EventService(eventRepository, hostService, eventImageService, memberImageService); - validEvent = EventData.event1.entity.get(); - } - - @Test - @DisplayName("모든 행사 조회 - 성공") - void getAllByFilterOrderByDistanceAsc() { - // given - LocationFilter location = new LocationFilter(); - LocationRequest currentLocation = new LocationRequest(3.0, 2.0); - String title = "testTitle"; - Category category = Category.공예; - Area area = Area.광주; - int pageNumber = 1; - int pageSize = 10; - Pageable pageable = PageRequest.of(pageNumber, pageSize); - Long lastId = 1L; - given(eventRepository.findAllByFilterOrderByDistance(location.getStartLatitude(), - location.getStartLongitude(), - location.getEndLatitude(), location.getEndLongitude(), currentLocation.getLatitude(), - currentLocation.getLongitude(), title, category, area, pageable)).willReturn( - new SliceImpl<>(List.of())); - - // when - eventService.getAllByFilterOrderByDistanceAsc(location, currentLocation, title, category, - area, pageable, lastId); - - // then - then(eventRepository).should(times(1)) - .findAllByFilterOrderByDistance(any(Double.class), any(Double.class), any(Double.class), - any(Double.class), any(Double.class), any(Double.class), - any(String.class), any(Category.class), any(Area.class), any(Pageable.class)); - } - - @Test - @DisplayName("주최자 id를 통한 모든 행사 조회 - 성공") - void getAllByHostIdOrderByCreatedDateDesc() { - // given - Long hostId = validEvent.getHost().getId(); - int pageNumber = 1; - int pageSize = 10; - Pageable pageable = PageRequest.of(pageNumber, pageSize); - Long lastId = 1L; - given(eventRepository.findAllByHostIdOrderByEventIdDesc(hostId, lastId, pageable)) - .willReturn(new SliceImpl<>(List.of())); - - // when - eventService.getAllByHostIdOrderByCreatedDateDesc(hostId, pageable, lastId); - - // then - then(eventRepository).should(times(1)). - findAllByHostIdOrderByEventIdDesc(any(Long.class), any(Long.class), - any(Pageable.class)); - } - - @Test - @DisplayName("행사 id를 통한 행사 조회 - 성공") - void getById() { - // given - given(eventRepository.findById(validEvent.getId())).willReturn(Optional.of(validEvent)); - - // when - eventService.getById(validEvent.getId()); - - // then - then(eventRepository).should(times(1)).findById(validEvent.getId()); - } - - @Test - @DisplayName("유효하지 않은 행사 id를 통한 행사 조회 - 실패") - void getByInvalidId() { - // given - Long eventId = validEvent.getId(); - given(eventRepository.findById(eventId)).willThrow(RuntimeException.class); - - // when & then - assertThrows(RuntimeException.class, () -> eventService.getById(eventId)); - } - - @Test - @DisplayName("행사 생성 - 성공") - void create() { - // given - Long hostId = validEvent.getHost().getId(); - EventCreateRequest validEventCreateRequest = EventData.event1.request.create.get(); - given(eventRepository.save(any())).willReturn(validEvent); - - // when - eventService.create(host1.memberIdentifier, validEventCreateRequest); - - // then - then(eventRepository).should(times(1)).save(any(Event.class)); - } - - @Test - @DisplayName("행사 id를 통한 행사 수정 - 성공") - void update() { - // given - Long eventId = validEvent.getId(); - Long hostId = validEvent.getHost().getId(); - EventEditRequest validEventEditRequest = EventData.event1.request.edit1.get(); - given(eventRepository.findById(eventId)).willReturn(Optional.of(validEvent)); - - // when - eventService.update(host1.memberIdentifier, eventId, validEventEditRequest); - - // then - then(eventRepository).should(times(1)).findById(eventId); - assertAll( - () -> assertEquals(validEvent.getTitle(), validEventEditRequest.getTitle()), - () -> assertEquals(validEvent.getContent(), validEventEditRequest.getContent()), - () -> assertEquals(validEvent.getArea(), validEventEditRequest.getArea()), - () -> assertEquals(validEvent.getLocation(), validEventEditRequest.getLocation()), - () -> assertEquals(validEvent.getStartTime(), validEventEditRequest.getStartTime()), - () -> assertEquals(validEvent.getEndTime(), validEventEditRequest.getEndTime()), - () -> assertEquals(validEvent.getPrice(), validEventEditRequest.getPrice()), - () -> assertEquals(validEvent.getTotalSeat(), validEventEditRequest.getTotalSeat()), - () -> assertEquals(validEvent.getCategory(), validEventEditRequest.getCategory()) - ); - } - - @Test - @DisplayName("유효하지 않은 행사 id를 통한 행사 수정 - 실패") - void updateByInvalidId() { - // given - EventEditRequest request = EventData.event1.request.edit1.get(); - Long invalidHostId = 999L; - given(eventRepository.findById(invalidHostId)).willThrow(RuntimeException.class); - - // when & then - assertThrows(RuntimeException.class, - () -> eventService.update(new MemberIdentifier(invalidHostId, MemberType.host), validEvent.getId(), - EventData.event1.request.edit1.get())); - } - - @Test - @DisplayName("행사 삭제 - 성공") - void delete() { - // given - Long eventId = validEvent.getId(); - Long hostId = validEvent.getHost().getId(); - - // when - given(eventRepository.findById(eventId)).willReturn(Optional.of(validEvent)); - willDoNothing().given(eventRepository).deleteById(eventId); - eventService.delete(host1.memberIdentifier, eventId); - - // then - then(eventRepository).should(times(1)).findById(eventId); - then(eventRepository).should(times(1)).deleteById(eventId); - } - - @Test - @DisplayName("유효하지 않은 행사 id를 통한 행사 삭제 - 실패") - void deleteByInvalidId() { - // given - Long eventId = validEvent.getId(); - Long hostId = validEvent.getHost().getId(); - given(eventRepository.findById(eventId)).willThrow(RuntimeException.class); - - // when & then - assertThrows(RuntimeException.class, () -> eventService.delete(host1.memberIdentifier, eventId)); - } -} \ No newline at end of file +//package org.ktc2.cokaen.wouldyouin.event; +// +//import static org.junit.jupiter.api.Assertions.assertAll; +//import static org.junit.jupiter.api.Assertions.assertEquals; +//import static org.junit.jupiter.api.Assertions.assertThrows; +//import static org.mockito.ArgumentMatchers.any; +//import static org.mockito.BDDMockito.given; +//import static org.mockito.BDDMockito.then; +//import static org.mockito.BDDMockito.willDoNothing; +//import static org.mockito.Mockito.times; +// +//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.Test; +//import org.junit.jupiter.api.extension.ExtendWith; +//import org.ktc2.cokaen.wouldyouin.image.application.EventImageService; +//import org.ktc2.cokaen.wouldyouin.image.application.MemberImageService; +//import org.ktc2.cokaen.wouldyouin._common.vo.Area; +//import org.ktc2.cokaen.wouldyouin._common.vo.Category; +//import org.ktc2.cokaen.wouldyouin._global.testdata.EventData; +//import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host1; +//import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; +//import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationFilter; +//import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; +//import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; +//import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationRequest; +//import org.ktc2.cokaen.wouldyouin.event.application.EventService; +//import org.ktc2.cokaen.wouldyouin.event.persist.Event; +//import org.ktc2.cokaen.wouldyouin.event.persist.EventRepository; +//import org.ktc2.cokaen.wouldyouin.member.application.HostService; +//import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; +//import org.mockito.Mock; +//import org.mockito.junit.jupiter.MockitoExtension; +//import org.springframework.data.domain.PageRequest; +//import org.springframework.data.domain.Pageable; +//import org.springframework.data.domain.SliceImpl; +// +//@ExtendWith(MockitoExtension.class) +//class EventServiceUnitTest { +// +// private EventService eventService; +// +// @Mock +// private EventRepository eventRepository; +// +// @Mock +// private HostService hostService; +// +// @Mock +// private EventImageService eventImageService; +// +// @Mock +// private MemberImageService memberImageService; +// +// private Event validEvent; +// +// @BeforeEach +// void setUp() { +// eventService = new EventService(eventRepository, hostService, eventImageService, memberImageService); +// validEvent = EventData.event1.entity.get(); +// } +// +// @Test +// @DisplayName("모든 행사 조회 - 성공") +// void getAllByFilterOrderByDistanceAsc() { +// // given +// LocationFilter location = new LocationFilter(); +// LocationRequest currentLocation = new LocationRequest(3.0, 2.0); +// String title = "testTitle"; +// Category category = Category.공예; +// Area area = Area.광주; +// int pageNumber = 1; +// int pageSize = 10; +// Pageable pageable = PageRequest.of(pageNumber, pageSize); +// Long lastId = 1L; +// given(eventRepository.findAllByFilterOrderByDistance(location.getStartLatitude(), +// location.getStartLongitude(), +// location.getEndLatitude(), location.getEndLongitude(), currentLocation.getLatitude(), +// currentLocation.getLongitude(), title, category, area, pageable)).willReturn( +// new SliceImpl<>(List.of())); +// +// // when +// eventService.getAllByFilterOrderByDistanceAsc(location, currentLocation, title, category, +// area, pageable, lastId); +// +// // then +// then(eventRepository).should(times(1)) +// .findAllByFilterOrderByDistance(any(Double.class), any(Double.class), any(Double.class), +// any(Double.class), any(Double.class), any(Double.class), +// any(Category.class), any(Area.class), any(Pageable.class)); +// } +// +// @Test +// @DisplayName("주최자 id를 통한 모든 행사 조회 - 성공") +// void getAllByHostIdOrderByCreatedDateDesc() { +// // given +// Long hostId = validEvent.getHost().getId(); +// int pageNumber = 1; +// int pageSize = 10; +// Pageable pageable = PageRequest.of(pageNumber, pageSize); +// Long lastId = 1L; +// given(eventRepository.findAllByHostIdOrderByEventIdDesc(hostId, lastId, pageable)) +// .willReturn(new SliceImpl<>(List.of())); +// +// // when +// eventService.getAllByHostIdOrderByCreatedDateDesc(hostId, pageable, lastId); +// +// // then +// then(eventRepository).should(times(1)). +// findAllByHostIdOrderByEventIdDesc(any(Long.class), any(Long.class), +// any(Pageable.class)); +// } +// +// @Test +// @DisplayName("행사 id를 통한 행사 조회 - 성공") +// void getById() { +// // given +// given(eventRepository.findById(validEvent.getId())).willReturn(Optional.of(validEvent)); +// +// // when +// eventService.getById(validEvent.getId()); +// +// // then +// then(eventRepository).should(times(1)).findById(validEvent.getId()); +// } +// +// @Test +// @DisplayName("유효하지 않은 행사 id를 통한 행사 조회 - 실패") +// void getByInvalidId() { +// // given +// Long eventId = validEvent.getId(); +// given(eventRepository.findById(eventId)).willThrow(RuntimeException.class); +// +// // when & then +// assertThrows(RuntimeException.class, () -> eventService.getById(eventId)); +// } +// +// @Test +// @DisplayName("행사 생성 - 성공") +// void create() { +// // given +// Long hostId = validEvent.getHost().getId(); +// EventCreateRequest validEventCreateRequest = EventData.event1.request.create.get(); +// given(eventRepository.save(any())).willReturn(validEvent); +// +// // when +// eventService.create(host1.memberIdentifier, validEventCreateRequest); +// +// // then +// then(eventRepository).should(times(1)).save(any(Event.class)); +// } +// +// @Test +// @DisplayName("행사 id를 통한 행사 수정 - 성공") +// void update() { +// // given +// Long eventId = validEvent.getId(); +// Long hostId = validEvent.getHost().getId(); +// EventEditRequest validEventEditRequest = EventData.event1.request.edit1.get(); +// given(eventRepository.findById(eventId)).willReturn(Optional.of(validEvent)); +// +// // when +// eventService.update(host1.memberIdentifier, eventId, validEventEditRequest); +// +// // then +// then(eventRepository).should(times(1)).findById(eventId); +// assertAll( +// () -> assertEquals(validEvent.getTitle(), validEventEditRequest.getTitle()), +// () -> assertEquals(validEvent.getContent(), validEventEditRequest.getContent()), +// () -> assertEquals(validEvent.getArea(), validEventEditRequest.getArea()), +// () -> assertEquals(validEvent.getLocation(), validEventEditRequest.getLocation()), +// () -> assertEquals(validEvent.getStartTime(), validEventEditRequest.getStartTime()), +// () -> assertEquals(validEvent.getEndTime(), validEventEditRequest.getEndTime()), +// () -> assertEquals(validEvent.getPrice(), validEventEditRequest.getPrice()), +// () -> assertEquals(validEvent.getTotalSeat(), validEventEditRequest.getTotalSeat()), +// () -> assertEquals(validEvent.getCategory(), validEventEditRequest.getCategory()) +// ); +// } +// +// @Test +// @DisplayName("유효하지 않은 행사 id를 통한 행사 수정 - 실패") +// void updateByInvalidId() { +// // given +// EventEditRequest request = EventData.event1.request.edit1.get(); +// Long invalidHostId = 999L; +// given(eventRepository.findById(invalidHostId)).willThrow(RuntimeException.class); +// +// // when & then +// assertThrows(RuntimeException.class, +// () -> eventService.update(new MemberIdentifier(invalidHostId, MemberType.host), validEvent.getId(), +// EventData.event1.request.edit1.get())); +// } +// +// @Test +// @DisplayName("행사 삭제 - 성공") +// void delete() { +// // given +// Long eventId = validEvent.getId(); +// Long hostId = validEvent.getHost().getId(); +// +// // when +// given(eventRepository.findById(eventId)).willReturn(Optional.of(validEvent)); +// willDoNothing().given(eventRepository).deleteById(eventId); +// eventService.delete(host1.memberIdentifier, eventId); +// +// // then +// then(eventRepository).should(times(1)).findById(eventId); +// then(eventRepository).should(times(1)).deleteById(eventId); +// } +// +// @Test +// @DisplayName("유효하지 않은 행사 id를 통한 행사 삭제 - 실패") +// void deleteByInvalidId() { +// // given +// Long eventId = validEvent.getId(); +// Long hostId = validEvent.getHost().getId(); +// given(eventRepository.findById(eventId)).willThrow(RuntimeException.class); +// +// // when & then +// assertThrows(RuntimeException.class, () -> eventService.delete(host1.memberIdentifier, eventId)); +// } +//} \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java index 7d467c4e..c636128f 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java @@ -20,11 +20,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.ktc2.cokaen.wouldyouin.image.api.ImageController; -import org.ktc2.cokaen.wouldyouin.image.api.ImageDomain; -import org.ktc2.cokaen.wouldyouin.image.application.CurationImageService; -import org.ktc2.cokaen.wouldyouin.image.application.ImageServiceFactory; -import org.ktc2.cokaen.wouldyouin.image.application.ImageStorageService; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockCurator1; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember1; import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData; @@ -32,6 +27,11 @@ import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.mockMultipartFile2; import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator1; import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; +import org.ktc2.cokaen.wouldyouin.image.api.ImageController; +import org.ktc2.cokaen.wouldyouin.image.api.ImageDomain; +import org.ktc2.cokaen.wouldyouin.image.application.CurationImageService; +import org.ktc2.cokaen.wouldyouin.image.application.ImageServiceFactory; +import org.ktc2.cokaen.wouldyouin.image.application.ImageStorageService; import org.ktc2.cokaen.wouldyouin.payment.application.PaymentService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; @@ -45,29 +45,22 @@ @WebMvcTest(ImageController.class) class ImageControllerTest { + private final long randomId = abs(new Random().nextLong()); @Autowired private MockMvc mockMvc; - @Autowired private WebApplicationContext context; - @MockBean private ImageServiceFactory imageServiceFactory; - @MockBean private CurationImageService curationImageService; - @MockBean private ImageStorageService imageStorageService; - @MockBean private PaymentService paymentService; - @MockBean private JwtAuthFilter jwtAuthFilter; - private final long randomId = abs(new Random().nextLong()); - @BeforeEach public void setup() throws Exception { mockMvc = MockMvcBuilders @@ -90,7 +83,8 @@ void getImage() throws Exception { .andExpect(status().isOk()); // then - then(imageStorageService).should(times(1)).readFromDirectory(eq(Paths.get(directory, file))); + then(imageStorageService).should(times(1)) + .readFromDirectory(eq(Paths.get(directory, file))); } @Test @@ -118,9 +112,11 @@ void uploadImages1() throws Exception { // given MockMultipartFile image1 = mockMultipartFile1.get(); MockMultipartFile image2 = mockMultipartFile2.get(); - given((CurationImageService) imageServiceFactory.getImageService(ImageDomain.CURATION)).willReturn(curationImageService); + given((CurationImageService) imageServiceFactory.getImageService( + ImageDomain.CURATION)).willReturn(curationImageService); given(curationImageService.saveImages(List.of(image1, image2))) - .willReturn(List.of(ImageData.curation1.response.get(), ImageData.curation2.response.get())); + .willReturn( + List.of(ImageData.curation1.response.get(), ImageData.curation2.response.get())); // when mockMvc.perform(multipart("/api/images") @@ -166,7 +162,8 @@ void uploadImages2() throws Exception { @WithMockCurator1 void deleteImage1() throws Exception { // given - given((CurationImageService) imageServiceFactory.getImageService(ImageDomain.CURATION)).willReturn(curationImageService); + given((CurationImageService) imageServiceFactory.getImageService( + ImageDomain.CURATION)).willReturn(curationImageService); // when mockMvc.perform(delete("/api/images/" + randomId) @@ -177,7 +174,8 @@ void deleteImage1() throws Exception { // then then(imageServiceFactory).should(times(1)).getImageService(eq(ImageDomain.CURATION)); - then(curationImageService).should(times(1)).deleteImage(curator1.memberIdentifier, randomId); + then(curationImageService).should(times(1)) + .deleteImage(curator1.memberIdentifier, randomId); } @Test @@ -185,7 +183,8 @@ void deleteImage1() throws Exception { @WithMockCurator1 void deleteImage2() throws Exception { // given - given((CurationImageService) imageServiceFactory.getImageService(ImageDomain.CURATION)).willReturn(curationImageService); + given((CurationImageService) imageServiceFactory.getImageService( + ImageDomain.CURATION)).willReturn(curationImageService); // when mockMvc.perform(delete("/api/images/" + randomId) diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/like/LikeControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/like/LikeControllerUnitTest.java index f3777b3b..15acb4e3 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/like/LikeControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/like/LikeControllerUnitTest.java @@ -1,6 +1,287 @@ package org.ktc2.cokaen.wouldyouin.like; -public class LikeControllerUnitTest -{ +import static java.lang.Math.abs; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; +import static org.mockito.Mockito.times; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; +import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import java.util.Random; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockCurator1; +import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost1; +import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember1; +import org.ktc2.cokaen.wouldyouin._global.testdata.LikeData; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator1; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.normal1; +import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; +import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; +import org.ktc2.cokaen.wouldyouin.like.api.LikeController; +import org.ktc2.cokaen.wouldyouin.like.api.dto.LikeSliceResponse; +import org.ktc2.cokaen.wouldyouin.like.application.CuratorLikeService; +import org.ktc2.cokaen.wouldyouin.like.application.HostLikeService; +import org.ktc2.cokaen.wouldyouin.like.application.LikeServiceFactory; +import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +@WebMvcTest(LikeController.class) +public class LikeControllerUnitTest { + + private final long randomId = abs(new Random().nextLong()); + @Autowired + private MockMvc mockMvc; + @Autowired + private WebApplicationContext context; + @MockBean + private LikeServiceFactory likeServiceFactory; + @MockBean + private CuratorLikeService curatorLikeService; + @MockBean + private HostLikeService hostLikeService; + @MockBean + private JwtAuthFilter jwtAuthFilter; + + + @BeforeEach + public void setup() throws Exception { + mockMvc = MockMvcBuilders + .webAppContextSetup(context) + .apply(springSecurity()) + .build(); + } + + @Test + @DisplayName("jwt 토큰 정보에 해당하는 member의 Curator 좋아요 목록을 조회한다.") + @WithMockMember1 + void getLikes1() throws Exception { + // given + MemberIdentifier identifier = normal1.memberIdentifier; + MemberType targetMemberType = MemberType.curator; + LikeSliceResponse sliceResponse = LikeData.sliceResponse.normal1.curatorLikes.get(); + int pageNumber = 0; + int pageSize = 10; + Pageable pageable = PageRequest.of(pageNumber, pageSize); + Long beforeLastId = sliceResponse.getLikes().getLast().getMemberId(); + + given((CuratorLikeService) likeServiceFactory.getLikeServiceFrom(targetMemberType)) + .willReturn(curatorLikeService); + given(curatorLikeService.getLikes(eq(identifier), eq(pageable), eq(beforeLastId))) + .willReturn(sliceResponse); + + // when + mockMvc.perform(get("/api/likes") + .param("type", targetMemberType.name()) + .param("page", Integer.toString(pageNumber)) + .param("size", Integer.toString(pageSize)) + .param("lastId", beforeLastId.toString())) + .andDo(print()) + .andExpect(status().isOk()); + + // then + then(likeServiceFactory).should(times(1)).getLikeServiceFrom(eq(targetMemberType)); + then(curatorLikeService).should(times(1)) + .getLikes(eq(identifier), eq(pageable), eq(beforeLastId)); + } + + @Test + @DisplayName("jwt 토큰 정보에 해당하는 member의 Host 좋아요 목록을 조회한다.") + @WithMockMember1 + void getLikes2() throws Exception { + // given + MemberIdentifier identifier = normal1.memberIdentifier; + MemberType targetMemberType = MemberType.host; + LikeSliceResponse sliceResponse = LikeData.sliceResponse.normal1.hostLikes.get(); + int pageNumber = 0; + int pageSize = 10; + Pageable pageable = PageRequest.of(pageNumber, pageSize); + Long beforeLastId = sliceResponse.getLikes().getLast().getMemberId(); + + given((HostLikeService) likeServiceFactory.getLikeServiceFrom(targetMemberType)) + .willReturn(hostLikeService); + given(hostLikeService.getLikes(eq(identifier), eq(pageable), eq(beforeLastId))) + .willReturn(sliceResponse); + + // when + mockMvc.perform(get("/api/likes") + .param("type", targetMemberType.name()) + .param("page", Integer.toString(pageNumber)) + .param("size", Integer.toString(pageSize)) + .param("lastId", beforeLastId.toString())) + .andDo(print()) + .andExpect(status().isOk()); + + // then + then(likeServiceFactory).should(times(1)).getLikeServiceFrom(eq(targetMemberType)); + then(hostLikeService).should(times(1)) + .getLikes(eq(identifier), eq(pageable), eq(beforeLastId)); + } + + @Test + @DisplayName("jwt 토큰 정보에 해당하는 curator의 Host 좋아요 목록을 조회한다.") + @WithMockCurator1 + void getLikes3() throws Exception { + // given + MemberIdentifier identifier = curator1.memberIdentifier; + MemberType targetMemberType = MemberType.host; + LikeSliceResponse sliceResponse = LikeData.sliceResponse.curator1.hostLikes.get(); + int pageNumber = 0; + int pageSize = 10; + Pageable pageable = PageRequest.of(pageNumber, pageSize); + Long beforeLastId = sliceResponse.getLikes().getLast().getMemberId(); + + given((HostLikeService) likeServiceFactory.getLikeServiceFrom(targetMemberType)) + .willReturn(hostLikeService); + given(hostLikeService.getLikes(eq(identifier), eq(pageable), eq(beforeLastId))) + .willReturn(sliceResponse); + + // when + mockMvc.perform(get("/api/likes") + .param("type", targetMemberType.name()) + .param("page", Integer.toString(pageNumber)) + .param("size", Integer.toString(pageSize)) + .param("lastId", beforeLastId.toString())) + .andDo(print()) + .andExpect(status().isOk()); + + // then + then(likeServiceFactory).should(times(1)).getLikeServiceFrom(eq(targetMemberType)); + then(hostLikeService).should(times(1)) + .getLikes(eq(identifier), eq(pageable), eq(beforeLastId)); + } + + @Test + @DisplayName("Member 권한으로 Host ID를 통해 Host 좋아요를 생성한다.") + @WithMockMember1 + void createOrDeleteLike1() throws Exception { + // given + Long beforeLastId = LikeData.sliceResponse.normal1.hostLikes.get().getSliceInfo() + .getLastId(); + given((HostLikeService) likeServiceFactory.getLikeServiceFrom(MemberType.host)) + .willReturn(hostLikeService); + given(hostLikeService.toggleLike(eq(normal1.memberIdentifier), eq(beforeLastId))) + .willReturn(LikeData.toggleResponse.hostLikes.create.get()); + + // when + mockMvc.perform(post("/api/likes/" + randomId) + .param("type", MemberType.host.name()).with(csrf())) + .andDo(print()) + .andExpect(status().isCreated()); + + // then + then(likeServiceFactory).should(times(1)).getLikeServiceFrom(eq(MemberType.host)); + then(hostLikeService).should(times(1)) + .toggleLike(eq(normal1.memberIdentifier), eq(randomId)); + } + + @Test + @DisplayName("Member 권한으로 Host ID를 통해 Host 좋아요를 삭제한다.") + @WithMockMember1 + void createOrDeleteLike2() throws Exception { + // given + Long beforeLastId = LikeData.sliceResponse.normal1.hostLikes.get().getSliceInfo() + .getLastId(); + given((HostLikeService) likeServiceFactory.getLikeServiceFrom(MemberType.host)) + .willReturn(hostLikeService); + given(hostLikeService.toggleLike(eq(normal1.memberIdentifier), eq(beforeLastId))) + .willReturn(LikeData.toggleResponse.hostLikes.delete.get()); + + // when + mockMvc.perform(post("/api/likes/" + randomId) + .param("type", MemberType.host.name()).with(csrf())) + .andDo(print()) + .andExpect(status().isCreated()); + + // then + then(likeServiceFactory).should(times(1)).getLikeServiceFrom(eq(MemberType.host)); + then(hostLikeService).should(times(1)) + .toggleLike(eq(normal1.memberIdentifier), eq(randomId)); + } + + @Test + @DisplayName("Curator 권한으로 Host ID를 통해 Host 좋아요를 생성한다.") + @WithMockCurator1 + void createOrDeleteLike3() throws Exception { + // given + Long beforeLastId = LikeData.sliceResponse.normal1.hostLikes.get().getSliceInfo() + .getLastId(); + given((HostLikeService) likeServiceFactory.getLikeServiceFrom(MemberType.host)) + .willReturn(hostLikeService); + given(hostLikeService.toggleLike(eq(normal1.memberIdentifier), eq(beforeLastId))) + .willReturn(LikeData.toggleResponse.hostLikes.create.get()); + + // when + mockMvc.perform(post("/api/likes/" + randomId) + .param("type", MemberType.host.name()).with(csrf())) + .andDo(print()) + .andExpect(status().isCreated()); + + // then + then(likeServiceFactory).should(times(1)).getLikeServiceFrom(eq(MemberType.host)); + then(hostLikeService).should(times(1)) + .toggleLike(eq(curator1.memberIdentifier), eq(randomId)); + } + + @Test + @DisplayName("Curator 권한으로 Host ID를 통해 Host 좋아요를 삭제한다.") + @WithMockCurator1 + void createOrDeleteLike4() throws Exception { + // given + Long beforeLastId = LikeData.sliceResponse.normal1.hostLikes.get().getSliceInfo() + .getLastId(); + given((HostLikeService) likeServiceFactory.getLikeServiceFrom(MemberType.host)) + .willReturn(hostLikeService); + given(hostLikeService.toggleLike(eq(normal1.memberIdentifier), eq(beforeLastId))) + .willReturn(LikeData.toggleResponse.hostLikes.delete.get()); + + // when + mockMvc.perform(post("/api/likes/" + randomId) + .param("type", MemberType.host.name()).with(csrf())) + .andDo(print()) + .andExpect(status().isCreated()); + + // then + then(likeServiceFactory).should(times(1)).getLikeServiceFrom(eq(MemberType.host)); + then(hostLikeService).should(times(1)) + .toggleLike(eq(curator1.memberIdentifier), eq(randomId)); + } + + @Test + @DisplayName("Host 권한으로 좋아요할 수 없다.") + @WithMockHost1 + void createOrDeleteLike5() throws Exception { + // given + Long beforeLastId = LikeData.sliceResponse.normal1.hostLikes.get().getSliceInfo() + .getLastId(); + given((HostLikeService) likeServiceFactory.getLikeServiceFrom(MemberType.host)) + .willReturn(hostLikeService); + given(hostLikeService.toggleLike(eq(normal1.memberIdentifier), eq(beforeLastId))) + .willReturn(LikeData.toggleResponse.hostLikes.delete.get()); + + // when + mockMvc.perform(post("/api/likes/" + randomId) + .param("type", MemberType.host.name()).with(csrf())) + .andDo(print()) + .andExpect(status().isUnauthorized()) + .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); + + // then + then(likeServiceFactory).shouldHaveNoInteractions(); + then(hostLikeService).shouldHaveNoInteractions(); + } } From 4d31a5c37e9925e862f015897c2e7859bf59cd60 Mon Sep 17 00:00:00 2001 From: ariimo Date: Fri, 15 Nov 2024 09:34:59 +0900 Subject: [PATCH 43/53] =?UTF-8?q?[Weekly/11/Refactor/All]=20Transactional?= =?UTF-8?q?=20=EC=84=A4=EC=A0=95,=20=EC=A0=91=EA=B7=BC=EC=A0=9C=EC=96=B4?= =?UTF-8?q?=EC=9E=90=20=EC=84=A4=EC=A0=95=20(#142)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: Review Transactional 설정 * refactor: RequestDto 접근제어자 private으로 변경 --- .../advertisement/api/dto/AdvertisementRequest.java | 2 +- .../cokaen/wouldyouin/event/api/dto/EventCreateRequest.java | 4 ++-- .../cokaen/wouldyouin/event/api/dto/EventEditRequest.java | 4 ++-- .../cokaen/wouldyouin/review/application/ReviewService.java | 5 ++--- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/dto/AdvertisementRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/dto/AdvertisementRequest.java index 566ada93..27f58443 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/dto/AdvertisementRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/dto/AdvertisementRequest.java @@ -30,7 +30,7 @@ public class AdvertisementRequest { private LocalDateTime endTime; @AssertTrue(message = "종료 시간은 시작 시간 이후여야 합니다.") - public boolean isEndTimeAfterStartTime() { + private boolean isEndTimeAfterStartTime() { return endTime.isAfter(startTime); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java index 3d877b03..d236ed3d 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java @@ -66,7 +66,7 @@ public class EventCreateRequest { private List imageIds; @AssertTrue(message = "종료 시간은 시작 시간 이후여야 합니다.") - public boolean isEndTimeAfterStartTime() { + private boolean isEndTimeAfterStartTime() { if (startTime == null || endTime == null) { return true; } @@ -74,7 +74,7 @@ public boolean isEndTimeAfterStartTime() { } @AssertTrue(message = "이미지는 최대 5개까지 등록할 수 있습니다.") - public boolean isImageSizeValid() { + private boolean isImageSizeValid() { return imageIds.size() <= 5; } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventEditRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventEditRequest.java index afec07f6..f06e9eab 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventEditRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventEditRequest.java @@ -62,7 +62,7 @@ public class EventEditRequest { private List imageIds; @AssertTrue(message = "종료 시간은 시작 시간 이후여야 합니다.") - public boolean isEndTimeAfterStartTime() { + private boolean isEndTimeAfterStartTime() { if (startTime == null || endTime == null) { return true; } @@ -70,7 +70,7 @@ public boolean isEndTimeAfterStartTime() { } @AssertTrue(message = "이미지는 최대 5개까지 등록할 수 있습니다.") - public boolean isImageSizeValid() { + private boolean isImageSizeValid() { return imageIds.size() <= 5; } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/review/application/ReviewService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/review/application/ReviewService.java index c2178751..f542eced 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/review/application/ReviewService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/review/application/ReviewService.java @@ -59,7 +59,7 @@ private Long getLastId(Slice reviews, Long oldLastId) { return oldLastId; } - @Transactional + @Transactional(readOnly = true) public ReviewEventSliceResponse getUnreviewedEventsByMemberId(Long memberId, Pageable pageable, Long beforeLastId) { Slice unreviewedEvents = reviewRepository.findUnreviewedEventsByMemberId(memberId, @@ -95,8 +95,7 @@ public void delete(Long memberId, Long reviewId) { reviewRepository.deleteById(reviewId); } - @Transactional - public Review getByIdOrThrow(Long id) { + private Review getByIdOrThrow(Long id) { return reviewRepository.findById(id) .orElseThrow(() -> new EntityNotFoundException("해당하는 리뷰를 찾을 수 없습니다.")); } From b7ec6d01104455cd6af116933b4afea6f7143d31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=99=8D=EC=8B=9D?= <90020593+Daolove0323@users.noreply.github.com> Date: Fri, 15 Nov 2024 10:30:30 +0900 Subject: [PATCH 44/53] =?UTF-8?q?[Weekly/11]=20=20not=20null=20=EC=86=8D?= =?UTF-8?q?=EC=84=B1=20=EC=88=98=EC=A0=95=20(#143)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ktc2/cokaen/wouldyouin/event/api/dto/LocationRequest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationRequest.java index 08505767..5181a79c 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationRequest.java @@ -18,12 +18,10 @@ @ToString public class LocationRequest { - @NotNull(message = "위도는 필수값입니다.") @Min(value = -90, message = "위도는 -90 이상이어야 합니다.") @Max(value = 90, message = "위도는 90 이하여야 합니다.") private Double latitude; - @NotNull(message = "경도는 필수값입니다.") @Min(value = -180, message = "경도는 -180 이상이어야 합니다.") @Max(value = 180, message = "경도는 180 이하여야 합니다.") private Double longitude; From 63aa785ec0091703b4d1145334980491ff0fac0a Mon Sep 17 00:00:00 2001 From: Jangan Lee Date: Fri, 15 Nov 2024 10:47:46 +0900 Subject: [PATCH 45/53] =?UTF-8?q?[Weekly/11/Hotfix/brokenBuild]=20?= =?UTF-8?q?=EB=B9=8C=EB=93=9C=20=EC=8B=A4=ED=8C=A8=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20(#144)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../like/application/dto/LikeResponse.java | 31 ------------------- .../application/dto/LikeToggleResponse.java | 20 ------------ 2 files changed, 51 deletions(-) delete mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/like/application/dto/LikeResponse.java delete mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/like/application/dto/LikeToggleResponse.java diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/dto/LikeResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/dto/LikeResponse.java deleted file mode 100644 index 3dca9a88..00000000 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/dto/LikeResponse.java +++ /dev/null @@ -1,31 +0,0 @@ - -package org.ktc2.cokaen.wouldyouin.like.api.dto; - -import java.util.List; -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import org.ktc2.cokaen.wouldyouin.member.persist.LikeableMember; - -@Getter -@RequiredArgsConstructor(access = AccessLevel.PROTECTED) -@Builder -public class LikeResponse { - - private final Long memberId; - private final String nickname; - private final String intro; - private final List hashtags; - private final String profileImageUrl; - - public static LikeResponse from(LikeableMember member) { - return LikeResponse.builder() - .memberId(member.getId()) - .nickname(member.getNickname()) - .intro(member.getIntro()) - .hashtags(member.getHashtags()) - .profileImageUrl(member.getProfileImageUrl()) - .build(); - } -} diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/dto/LikeToggleResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/dto/LikeToggleResponse.java deleted file mode 100644 index d5181d72..00000000 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/dto/LikeToggleResponse.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.ktc2.cokaen.wouldyouin.like.application.dto; - -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import org.ktc2.cokaen.wouldyouin.member.persist.LikeableMember; - -@Getter -@RequiredArgsConstructor(access = AccessLevel.PROTECTED) -@Builder -public class LikeToggleResponse { - private final boolean isLiked; - - public static LikeToggleResponse from(boolean state) { - return LikeToggleResponse.builder() - .isLiked(state) - .build(); - } -} From fef728f6b5bb21e6f31ab826d2337b84a6e528a6 Mon Sep 17 00:00:00 2001 From: daolove0323 Date: Fri, 15 Nov 2024 11:17:50 +0900 Subject: [PATCH 46/53] =?UTF-8?q?[Weekly/11/Hotfix/Event]=20=EB=AA=A8?= =?UTF-8?q?=EB=93=A0=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ktc2/cokaen/wouldyouin/event/api/dto/LocationRequest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationRequest.java index 5181a79c..44ac37cc 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationRequest.java @@ -20,9 +20,9 @@ public class LocationRequest { @Min(value = -90, message = "위도는 -90 이상이어야 합니다.") @Max(value = 90, message = "위도는 90 이하여야 합니다.") - private Double latitude; + private Double latitude = 37.0; @Min(value = -180, message = "경도는 -180 이상이어야 합니다.") @Max(value = 180, message = "경도는 180 이하여야 합니다.") - private Double longitude; + private Double longitude = 127.1; } \ No newline at end of file From 4ca29d9186d809c8d5d405d77572d68de8875136 Mon Sep 17 00:00:00 2001 From: daolove0323 Date: Fri, 15 Nov 2024 11:43:24 +0900 Subject: [PATCH 47/53] =?UTF-8?q?[Weekly/11//Feacture/Event]=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=20=EB=A0=88=ED=8F=AC=EC=A7=80=ED=86=A0?= =?UTF-8?q?=EB=A6=AC=20JPQL=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ktc2/cokaen/wouldyouin/event/persist/EventRepository.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/EventRepository.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/EventRepository.java index 4a48d468..2aaa6fb2 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/EventRepository.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/EventRepository.java @@ -13,12 +13,12 @@ public interface EventRepository extends JpaRepository { @Query("SELECT E FROM Event E JOIN FETCH E.host " + "WHERE E.host.id = :hostId " - + "AND E.id > :lastId " + + "AND E.id < :lastId " + "ORDER BY E.id DESC") Slice findAllByHostIdOrderByEventIdDesc(Long hostId, Long lastId, Pageable pageable); @Query("SELECT E FROM Event E JOIN FETCH E.host " - + "WHERE E.id > :lastId " + + "WHERE E.id < :lastId " + "ORDER BY E.id DESC") Slice findAllByEventIdDesc(Long lastId, Pageable pageable); From 1b062d283a9e7549c811cf4f469e683e8206c130 Mon Sep 17 00:00:00 2001 From: daolove0323 Date: Fri, 15 Nov 2024 11:53:00 +0900 Subject: [PATCH 48/53] =?UTF-8?q?[Weekly/11/HotFix/Event]=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20=EB=B2=84=EA=B7=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/dto/relationResponse/EventHostResponse.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/EventHostResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/EventHostResponse.java index 1ed59606..a3d82ee0 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/EventHostResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/EventHostResponse.java @@ -1,10 +1,13 @@ package org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse; import java.util.List; +import java.util.Optional; import lombok.Builder; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; +import org.ktc2.cokaen.wouldyouin.image.persist.Image; +import org.ktc2.cokaen.wouldyouin.member.persist.BaseMember; import org.ktc2.cokaen.wouldyouin.member.persist.Host; @Builder @@ -28,7 +31,11 @@ public static EventHostResponse from(Host host) { .nickname(host.getNickname()) .email(host.getEmail()) .phone(host.getPhone()) - .profileImageUrl(host.getProfileImage().getName()) + .profileImageUrl(Optional.of(host) + .map(BaseMember::getProfileImage) + .map(Image::getName) + .orElse(null) + ) .intro(host.getIntro()) .likes(host.getLikes()) .hashtags(host.getHashtags()) From b330f8ad767b891010f94e4037e1b041a999ddf7 Mon Sep 17 00:00:00 2001 From: daolove0323 Date: Fri, 15 Nov 2024 12:15:54 +0900 Subject: [PATCH 49/53] =?UTF-8?q?[Weekly/11/Feature/curation]=20JPQL=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/dto/AdvertisementResponse.java | 8 ++++++- .../oauth/dto/OauthResourcesResponse.java | 12 ++-------- .../api/dto/CurationCardResponse.java | 2 ++ .../api/dto/CurationCreateRequest.java | 7 ++---- .../wouldyouin/curation/persist/Curation.java | 10 ++++---- .../curation/persist/CurationCard.java | 6 ++--- .../curation/persist/CurationRepository.java | 7 +++--- .../event/api/dto/EventCreateRequest.java | 3 +-- .../event/api/dto/EventEditRequest.java | 2 +- .../CurationEventResponse.java | 7 +++++- .../wouldyouin/event/persist/Event.java | 24 +++++++++---------- .../relationResponse/EventHostResponse.java | 2 +- .../persist/ReservationRepository.java | 4 ++-- .../review/persist/ReviewRepository.java | 4 ++-- 14 files changed, 48 insertions(+), 50 deletions(-) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/dto/AdvertisementResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/dto/AdvertisementResponse.java index 0eb32f70..5e9da066 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/dto/AdvertisementResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/advertisement/api/dto/AdvertisementResponse.java @@ -1,10 +1,13 @@ package org.ktc2.cokaen.wouldyouin.advertisement.api.dto; import java.time.LocalDateTime; +import java.util.Optional; import lombok.Builder; import lombok.EqualsAndHashCode; import lombok.ToString; import org.ktc2.cokaen.wouldyouin.advertisement.persist.Advertisement; +import org.ktc2.cokaen.wouldyouin.image.persist.AdvertisementImage; +import org.ktc2.cokaen.wouldyouin.image.persist.Image; @Builder @EqualsAndHashCode @@ -21,7 +24,10 @@ public static AdvertisementResponse from(Advertisement advertisement) { return AdvertisementResponse.builder() .id(advertisement.getId()) .title(advertisement.getTitle()) - .imageUrl(advertisement.getAdvertisementImage().getName()) + .imageUrl(Optional.of(advertisement) + .map((ad) -> advertisement.getAdvertisementImage()) + .map(Image::getName) + .orElse("")) .startTime(advertisement.getStartTime()) .endTime(advertisement.getEndTime()) .build(); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/dto/OauthResourcesResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/dto/OauthResourcesResponse.java index 8dcdf841..2489472d 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/dto/OauthResourcesResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/dto/OauthResourcesResponse.java @@ -3,24 +3,16 @@ import lombok.Builder; import lombok.Getter; import lombok.RequiredArgsConstructor; +import lombok.ToString; @Getter @RequiredArgsConstructor @Builder +@ToString public class OauthResourcesResponse { private final String nickname; private final String email; private final String socialId; private final String profileImageUrl; - - @Override - public String toString() { - return "OauthResourcesResponse{" + - "nickname='" + nickname + '\'' + - ", email='" + email + '\'' + - ", socialId='" + socialId + '\'' + - ", profileImageUrl='" + profileImageUrl + '\'' + - '}'; - } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCardResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCardResponse.java index 0248e77c..748631b4 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCardResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCardResponse.java @@ -3,12 +3,14 @@ import java.util.List; import lombok.Builder; import lombok.EqualsAndHashCode; +import lombok.Getter; import lombok.ToString; import org.ktc2.cokaen.wouldyouin.curation.persist.CurationCard; @Builder @EqualsAndHashCode @ToString +@Getter public class CurationCardResponse { private String subtitle; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCreateRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCreateRequest.java index 0fdf22d0..c21bdb79 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCreateRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCreateRequest.java @@ -41,11 +41,8 @@ public class CurationCreateRequest { private List eventIds; @AssertTrue(message = "큐레이션 카드의 개수는 1개 이상 10개 이하이어야 합니다.") - public boolean isCurationCardsSizeValid() { - if (this.curationCards == null) { - return false; - } - return 1 <= this.curationCards.size() && this.curationCards.size() <= 10; + private boolean isCurationCardsSizeValid() { + return curationCards != null && 1 <= this.curationCards.size() && this.curationCards.size() <= 10; } public Curation toEntity(Curator curator, List curationCards, diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java index f8ca329c..dab2245f 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java @@ -71,7 +71,7 @@ public class Curation { @Column(name = "area") private Area area; - @Column(name = "hashtag") + @Column(name = "hashtags") @Convert(converter = HashtagConverter.class) private List hashtags = new ArrayList<>(); @@ -98,11 +98,11 @@ public class Curation { public Curation(Curator curator, String title, String content, List curationCards, Area area, List hashtags, List events, String thumbnailUrl) { - this.curator = curator; - this.title = title; - this.content = content; + Optional.ofNullable(curator).ifPresent(this::setCurator); + Optional.ofNullable(title).ifPresent(this::setTitle); + Optional.ofNullable(content).ifPresent(this::setContent); Optional.ofNullable(curationCards).ifPresent(this::setCurationCards); - this.area = area; + Optional.ofNullable(area).ifPresent(this::setArea); Optional.ofNullable(hashtags).ifPresent(this::setHashtags); Optional.ofNullable(events).ifPresent(this::setEvents); Optional.ofNullable(thumbnailUrl).ifPresent(this::setThumbnailUrl); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCard.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCard.java index 21a28aab..9f875961 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCard.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCard.java @@ -50,9 +50,9 @@ public class CurationCard { @Builder public CurationCard(String subtitle, String content, Curation curation, List images) { - this.subtitle = subtitle; - this.content = content; - this.curation = curation; + Optional.ofNullable(subtitle).ifPresent(this::setSubtitle); + Optional.ofNullable(content).ifPresent(this::setContent); + Optional.ofNullable(curation).ifPresent(this::setCuration); Optional.ofNullable(images).ifPresent(this::setCurationImages); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationRepository.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationRepository.java index e2c3e940..a7165267 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationRepository.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationRepository.java @@ -12,13 +12,12 @@ public interface CurationRepository extends JpaRepository { @Query("SELECT C FROM Curation C JOIN FETCH C.curator " - + "WHERE C.area = :area AND C.id > :lastId " + + "WHERE C.area = :area AND C.id < :lastId " + "ORDER BY C.id DESC") Slice findAllByAreaOrderByCreatedDateDesc(Area area, Long lastId, Pageable pageable); @Query("SELECT C FROM Curation C JOIN FETCH C.curator " - + "WHERE C.curator.id = :curatorId AND C.id > :lastId " + + "WHERE C.curator.id = :curatorId AND C.id < :lastId " + "ORDER BY C.id DESC") - Slice findAllByCuratorOrderByCreatedDateDesc(Long curatorId, Long lastId, - Pageable pageable); + Slice findAllByCuratorOrderByCreatedDateDesc(Long curatorId, Long lastId, Pageable pageable); } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java index d236ed3d..75db1e48 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java @@ -62,7 +62,6 @@ public class EventCreateRequest { @NotNull(message = "카테고리는 필수입니다.") private Category category; - // TODO : 이미지 not null 고민, 큐레이션도! private List imageIds; @AssertTrue(message = "종료 시간은 시작 시간 이후여야 합니다.") @@ -75,7 +74,7 @@ private boolean isEndTimeAfterStartTime() { @AssertTrue(message = "이미지는 최대 5개까지 등록할 수 있습니다.") private boolean isImageSizeValid() { - return imageIds.size() <= 5; + return imageIds == null || imageIds.size() <= 5; } public Event toEntity(Host host, List images, String thumbnailUrl) { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventEditRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventEditRequest.java index f06e9eab..ffd67f77 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventEditRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventEditRequest.java @@ -71,6 +71,6 @@ private boolean isEndTimeAfterStartTime() { @AssertTrue(message = "이미지는 최대 5개까지 등록할 수 있습니다.") private boolean isImageSizeValid() { - return imageIds.size() <= 5; + return imageIds == null || imageIds.size() <= 5; } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/CurationEventResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/CurationEventResponse.java index 5999bc91..242e1235 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/CurationEventResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/relationResonse/CurationEventResponse.java @@ -1,12 +1,14 @@ package org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse; import java.time.LocalDateTime; +import java.util.Optional; import lombok.Builder; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; import org.ktc2.cokaen.wouldyouin._common.vo.Location; import org.ktc2.cokaen.wouldyouin.event.persist.Event; +import org.ktc2.cokaen.wouldyouin.member.persist.BaseMember; @Getter @Builder @@ -29,7 +31,10 @@ public static CurationEventResponse from(Event event) { .location(event.getLocation()) .startTime(event.getStartTime()) .thumbnailImageUrl(event.getThumbnailUrl()) - .hostProfileImageUrl(event.getHost().getProfileImageUrl()) + .hostProfileImageUrl(Optional.of(event) + .map(Event::getHost) + .map(BaseMember::getProfileImageUrl) + .orElse("")) .hostNickname(event.getHost().getNickname()) .build(); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java index d3e5686a..37e2301c 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java @@ -102,7 +102,6 @@ public class Event { @Enumerated(EnumType.STRING) private Category category; - // Todo: 이미지를 사용하는 모든 엔티티 thumnail 설정 @Column(name = "thumbnail_url") private String thumbnailUrl; @@ -118,22 +117,21 @@ public class Event { protected Event(String title, String content, Host host, Area area, Location location, LocalDateTime startTime, LocalDateTime endTime, Integer price, Integer totalSeat, Category category, List images, String thumbnailUrl) { - this.title = title; - this.content = content; - this.host = host; - this.area = area; - this.location = location; - this.startTime = startTime; - this.endTime = endTime; - this.price = price; - this.totalSeat = totalSeat; - this.leftSeat = totalSeat; - this.category = category; + Optional.ofNullable(title).ifPresent(this::setTitle); + Optional.ofNullable(content).ifPresent(this::setContent); + Optional.ofNullable(host).ifPresent(this::setHost); + Optional.ofNullable(area).ifPresent(this::setArea); + Optional.ofNullable(location).ifPresent(this::setLocation); + Optional.ofNullable(startTime).ifPresent(this::setStartTime); + Optional.ofNullable(endTime).ifPresent(this::setEndTime); + Optional.ofNullable(price).ifPresent(this::setPrice); + Optional.ofNullable(totalSeat).ifPresent(this::setTotalSeat); + Optional.ofNullable(leftSeat).ifPresent(this::setLeftSeat); + Optional.ofNullable(category).ifPresent(this::setCategory); Optional.ofNullable(images).ifPresent(this::setImages); Optional.of(thumbnailUrl).ifPresent(this::setThumbnailUrl); } - // Todo: oneToMany 연관관계에서 모든 null 처리 public void updateFrom(EventEditRequest eventEditRequest, List images, String thumbnailUrl) { Optional.ofNullable(eventEditRequest.getTitle()).ifPresent(this::setTitle); Optional.ofNullable(eventEditRequest.getContent()).ifPresent(this::setContent); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/EventHostResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/EventHostResponse.java index a3d82ee0..430a24f0 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/EventHostResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/EventHostResponse.java @@ -34,7 +34,7 @@ public static EventHostResponse from(Host host) { .profileImageUrl(Optional.of(host) .map(BaseMember::getProfileImage) .map(Image::getName) - .orElse(null) + .orElse("") ) .intro(host.getIntro()) .likes(host.getLikes()) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/ReservationRepository.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/ReservationRepository.java index 4739e588..810e248a 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/ReservationRepository.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/ReservationRepository.java @@ -11,12 +11,12 @@ public interface ReservationRepository extends JpaRepository { @Query("SELECT R FROM Reservation R JOIN FETCH R.member JOIN FETCH R.event " - + "WHERE R.member.id = :memberId AND R.id > :lastId " + + "WHERE R.member.id = :memberId AND R.id < :lastId " + "ORDER BY R.id DESC") Slice findByMemberIdOrderByReservationIdDesc(Long memberId, Long lastId, Pageable pageable); @Query("SELECT R FROM Reservation R JOIN FETCH R.member JOIN FETCH R.event " - + "WHERE R.event.id = :eventId AND R.id > :lastId " + + "WHERE R.event.id = :eventId AND R.id < :lastId " + "ORDER BY R.id DESC") Slice findByEventIdOrderByReservationIdDesc(Long eventId, Long lastId, Pageable pageable); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/review/persist/ReviewRepository.java b/src/main/java/org/ktc2/cokaen/wouldyouin/review/persist/ReviewRepository.java index 06eb296e..af631e54 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/review/persist/ReviewRepository.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/review/persist/ReviewRepository.java @@ -11,12 +11,12 @@ public interface ReviewRepository extends JpaRepository { @Query("SELECT R FROM Review R JOIN FETCH R.member JOIN FETCH R.event " - + "WHERE R.member.id = :memberId AND R.id > :lastId " + + "WHERE R.member.id = :memberId AND R.id < :lastId " + "ORDER BY R.id DESC") Slice findByMemberIdOrderByReviewIdDesc(Long memberId, Long lastId, Pageable pageable); @Query("SELECT R FROM Review R JOIN FETCH R.member JOIN FETCH R.event " - + "WHERE R.event.id = :eventId AND R.id > :lastId " + + "WHERE R.event.id = :eventId AND R.id < :lastId " + "ORDER BY R.id DESC") Slice findByEventIdOrderByReviewIdDesc(Long eventId, Long lastId, Pageable pageable); From f938260a2692342c7bcc8ed18dd7638d28bda53f Mon Sep 17 00:00:00 2001 From: Jangan Lee Date: Fri, 15 Nov 2024 14:48:02 +0900 Subject: [PATCH 50/53] =?UTF-8?q?[Weekly/11/Refactor/All]=20=EC=98=88?= =?UTF-8?q?=EC=99=B8,=20TODO=EC=A0=9C=EA=B1=B0,=20=EC=9D=B4=EB=A6=84?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EC=99=B8=20=EB=8B=A4=EC=88=98=20(#145)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: exception 생성 * feat: exception 핸들링 * refactor: CurationImage -> CurationCardImage 이름변경 * refactor: mockmember 패키지명 변경 --- .../wouldyouin/_common/api/ApiResponse.java | 6 +- .../_common/config/SecurityConfig.java | 2 +- .../wouldyouin/_common/error/ErrorCode.java | 46 ------------- .../_common/exception/BusinessException.java | 1 - .../exception/EntityNotFoundException.java | 2 - .../_common/exception/ErrorCode.java | 65 +++++++++++++++++++ .../exception/ExtensionParsingException.java | 2 - .../exception/FailToReadImageException.java | 2 - .../FailedToDeleteImageException.java | 10 --- .../exception/FailedToPayException.java | 10 --- .../FailedToUploadImageException.java | 2 - .../GlobalExceptionHandler.java | 3 +- .../exception/NoLeftSeatException.java | 10 --- .../exception/UnauthorizedException.java | 2 - .../_develop/api/TempCreateController.java | 4 +- .../auth/AuthorizeArgumentResolver.java | 6 +- .../CustomAccessDeniedHandler.java | 13 ++-- .../CustomAuthenticationEntryPoint.java | 13 ++-- .../application/CustomUserDetailsService.java | 5 +- .../auth/application/JwtService.java | 13 ++-- .../oauth/GoogleRequestService.java | 8 +-- .../oauth/KakaoRequestService.java | 10 ++- .../AuthenticationEmptyException.java | 12 ++++ .../FailAccessTokenGetException.java | 12 ++++ .../exception/FailSocialDataGetException.java | 12 ++++ .../InvalidAuthorizationHeaderException.java | 12 ++++ .../auth/exception/JwtTokenException.java | 11 ++++ .../curation/api/dto/CurationCardRequest.java | 4 +- .../application/CurationCardService.java | 8 +-- .../curation/application/CurationService.java | 8 +-- .../curation/persist/CurationCard.java | 8 +-- .../event/application/EventService.java | 2 +- .../event/exception/NoLeftSeatException.java | 11 ++++ .../wouldyouin/image/api/ImageController.java | 3 +- .../application/CurationImageService.java | 25 ++++--- ...ationImage.java => CurationCardImage.java} | 4 +- ....java => CurationCardImageRepository.java} | 2 +- .../like/application/LikeServiceFactory.java | 3 +- .../like/persist/LikeRepository.java | 2 +- .../member/api/MemberController.java | 4 +- .../member/application/BaseMemberService.java | 14 ++-- .../member/application/CuratorService.java | 4 +- .../member/application/HostService.java | 9 ++- .../member/application/MemberService.java | 10 +-- .../AdditionalInfoIllegalAccessException.java | 10 +++ .../EmailAlreadyExistsException.java | 11 ++++ .../exception/LoginFailedException.java | 11 ++++ .../exception/NotLikeableMemberException.java | 11 ++++ .../wouldyouin/member/persist/BaseMember.java | 10 +-- .../wouldyouin/member/persist/Curator.java | 6 +- .../wouldyouin/member/persist/Host.java | 8 +-- .../wouldyouin/member/persist/Member.java | 11 ++-- .../payment/application/PaymentService.java | 2 +- .../exception/FailedToPayException.java | 11 ++++ .../application/ReservationService.java | 3 +- ...ReservationNotFoundForReviewException.java | 5 +- .../WithMockCurator1.java | 2 +- .../WithMockCustomUser.java | 2 +- ...hMockCustomUserSecurityContextFactory.java | 2 +- .../WithMockHost1.java | 2 +- .../WithMockMember1.java | 2 +- .../WithMockWelcomeMember1.java | 2 +- .../_global/testdata/CurationData.java | 6 +- .../_global/testdata/ImageData.java | 36 +++++----- .../curation/CurationControllerUnitTest.java | 6 +- .../event/EventControllerUnitTest.java | 6 +- ...java => CurationCardImageServiceTest.java} | 23 +++---- .../wouldyouin/image/ImageControllerTest.java | 4 +- .../like/LikeControllerUnitTest.java | 6 +- .../BaseMemberServiceUnitTest.java | 4 +- .../application/MemberServiceUnitTest.java | 4 +- .../ReservationControllerUnitTest.java | 7 +- .../ReservationServiceUnitTest.java | 2 +- .../review/ReviewControllerUnitTest.java | 6 +- 74 files changed, 369 insertions(+), 267 deletions(-) delete mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/ErrorCode.java create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/ErrorCode.java delete mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailedToDeleteImageException.java delete mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailedToPayException.java rename src/main/java/org/ktc2/cokaen/wouldyouin/_common/{error => exception}/GlobalExceptionHandler.java (94%) delete mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/NoLeftSeatException.java create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/auth/exception/AuthenticationEmptyException.java create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/auth/exception/FailAccessTokenGetException.java create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/auth/exception/FailSocialDataGetException.java create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/auth/exception/InvalidAuthorizationHeaderException.java create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/auth/exception/JwtTokenException.java create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/event/exception/NoLeftSeatException.java rename src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/{CurationImage.java => CurationCardImage.java} (85%) rename src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/{CurationImageRepository.java => CurationCardImageRepository.java} (56%) create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/member/exception/AdditionalInfoIllegalAccessException.java create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/member/exception/EmailAlreadyExistsException.java create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/member/exception/LoginFailedException.java create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/member/exception/NotLikeableMemberException.java create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/payment/exception/FailedToPayException.java rename src/main/java/org/ktc2/cokaen/wouldyouin/{_common => reservation}/exception/ReservationNotFoundForReviewException.java (53%) rename src/test/java/org/ktc2/cokaen/wouldyouin/_global/{mockMember => mockmember}/WithMockCurator1.java (88%) rename src/test/java/org/ktc2/cokaen/wouldyouin/_global/{mockMember => mockmember}/WithMockCustomUser.java (88%) rename src/test/java/org/ktc2/cokaen/wouldyouin/_global/{mockMember => mockmember}/WithMockCustomUserSecurityContextFactory.java (95%) rename src/test/java/org/ktc2/cokaen/wouldyouin/_global/{mockMember => mockmember}/WithMockHost1.java (86%) rename src/test/java/org/ktc2/cokaen/wouldyouin/_global/{mockMember => mockmember}/WithMockMember1.java (87%) rename src/test/java/org/ktc2/cokaen/wouldyouin/_global/{mockMember => mockmember}/WithMockWelcomeMember1.java (87%) rename src/test/java/org/ktc2/cokaen/wouldyouin/image/{CurationImageServiceTest.java => CurationCardImageServiceTest.java} (64%) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/api/ApiResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/api/ApiResponse.java index f3872780..adec2578 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/api/ApiResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/api/ApiResponse.java @@ -1,6 +1,6 @@ package org.ktc2.cokaen.wouldyouin._common.api; -import org.ktc2.cokaen.wouldyouin._common.error.ErrorCode; +import org.ktc2.cokaen.wouldyouin._common.exception.ErrorCode; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -18,10 +18,6 @@ public static ResponseEntity> noContent() { return ResponseEntity.status(HttpStatus.NO_CONTENT).body(new ApiResponseBody<>(true, null)); } - public static ResponseEntity> error(ErrorCode errorCode) { - return ResponseEntity.status(errorCode.getStatus()).body(new ApiResponseBody<>(false, errorCode.getCode(), errorCode.getMessage())); - } - public static ResponseEntity> error(ErrorCode errorCode, String errorMessage) { return ResponseEntity.status(errorCode.getStatus()).body(new ApiResponseBody<>(false, errorCode.getCode(), errorMessage)); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/config/SecurityConfig.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/config/SecurityConfig.java index 139b214a..f3aff276 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/config/SecurityConfig.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/config/SecurityConfig.java @@ -32,7 +32,7 @@ public class SecurityConfig { private final CustomAuthenticationEntryPoint authenticationEntryPoint; private static final String[] AUTH_WHITELIST = { - "/**", //임시 설정, 나중에 제거필요 + "/**", "/h2-console/**", "/swagger-ui/**", "/swagger-ui/index.html", diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/ErrorCode.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/ErrorCode.java deleted file mode 100644 index 1eedf58d..00000000 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/ErrorCode.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.ktc2.cokaen.wouldyouin._common.error; - -import lombok.Getter; -import org.springframework.http.HttpStatus; - -@Getter -public enum ErrorCode { - - // TODO: status,code, message 수정 - - UNEXPECTED(HttpStatus.BAD_REQUEST.value(), "-1", "예상치 못한 오류가 발생했습니다."), - - ENTITY_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "-10404", "엔티티를 찾을 수 없습니다."), - - NO_LEFT_SEAT(HttpStatus.BAD_REQUEST.value(), "-10400", "남은 좌석이 부족합니다."), - - RESERVATION_NOT_FOUND_FOR_REVIEW(HttpStatus.NOT_FOUND.value(), "14044", "리뷰를 작성할 자격이 없습니다."), - - INVALID_INPUT_VALUE(HttpStatus.BAD_REQUEST.value(), "-20400", "Invalid Input Value"), - - FAIL_TO_READ_IMAGE(HttpStatus.CONFLICT.value(), "-20400", "Fail to read image"), - - FAIL_TO_PAY(HttpStatus.CONFLICT.value(), "-20400", "Fail to %s"), - - UNAUTHORIZED(HttpStatus.UNAUTHORIZED.value(), "-20400", "Unauthorized, %s."), - - FAIL_TO_UPLOAD_IMAGE(HttpStatus.CONFLICT.value(), "-20400", "Fail to upload image"), - - FAIL_TO_DELETE_IMAGE(HttpStatus.CONFLICT.value(), "-20400", "Fail to delete image"), - - URL_PARSING_FAILED(HttpStatus.BAD_REQUEST.value(), "-20400", "URL 파싱에 실패했습니다."), - - INVALID_IMAGE_DOMAIN(HttpStatus.BAD_REQUEST.value(), "-20400", "해당 이미지 도메인에 대한 서비스가 존재하지 않습니다."), - - CURRENT_LOCATION_EMPTY(HttpStatus.BAD_REQUEST.value(), "-20400", "현재 위치 정보를 찾을 수 없습니다."); - - private final Integer status; - private final String code; - private final String message; - - ErrorCode(int status, String code, String message) { - this.status = status; - this.code = code; - this.message = message; - } -} diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/BusinessException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/BusinessException.java index b9eaff4d..b2776adf 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/BusinessException.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/BusinessException.java @@ -2,7 +2,6 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; -import org.ktc2.cokaen.wouldyouin._common.error.ErrorCode; @Getter @RequiredArgsConstructor diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/EntityNotFoundException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/EntityNotFoundException.java index 3399f1f4..1368a736 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/EntityNotFoundException.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/EntityNotFoundException.java @@ -1,7 +1,5 @@ package org.ktc2.cokaen.wouldyouin._common.exception; -import org.ktc2.cokaen.wouldyouin._common.error.ErrorCode; - public class EntityNotFoundException extends BusinessException { public EntityNotFoundException(String message) { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/ErrorCode.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/ErrorCode.java new file mode 100644 index 00000000..3ebf85fa --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/ErrorCode.java @@ -0,0 +1,65 @@ +package org.ktc2.cokaen.wouldyouin._common.exception; + +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +// TODO: code 수정 필요 +public enum ErrorCode { + + FAIL_SOCIAL_DATA_GET(HttpStatus.UNAUTHORIZED.value(), "-20400"), + + FAIL_ACCESS_TOKEN_GET(HttpStatus.UNAUTHORIZED.value(), "-20400"), + + AUTHENTICATION_EMPTY(HttpStatus.UNAUTHORIZED.value(), "-20400"), + + JWT_TOKEN_EXCEPTION(HttpStatus.UNAUTHORIZED.value(), "-20400"), + + INVALID_AUTHORIZATION_HEADER(HttpStatus.BAD_REQUEST.value(), "-20400"), + + SECURITY_FILTER_AUTHORIZATION_REQUIRED(HttpStatus.FORBIDDEN.value(), "-20400"), + + SECURITY_FILTER_FORBIDDEN_ACCESS(HttpStatus.BAD_REQUEST.value(), "-20400"), + + NOT_LIKEABLE_MEMBER_TYPE(HttpStatus.BAD_REQUEST.value(), "-20400"), + + ADDITIONAL_INFO_ILLEGAL_ACCESS(HttpStatus.UNAUTHORIZED.value(), "-20400"), + + LOGIN_FAILED(HttpStatus.UNAUTHORIZED.value(), "-20400"), + + EMAIL_ALREADY_EXISTS(HttpStatus.CONFLICT.value(), "-10400"), + + CURRENT_LOCATION_EMPTY(HttpStatus.BAD_REQUEST.value(), "-20400"), + + INVALID_IMAGE_DOMAIN(HttpStatus.BAD_REQUEST.value(), "-20400"), + + FAIL_TO_DELETE_IMAGE(HttpStatus.CONFLICT.value(), "-20400"), + + FAIL_TO_UPLOAD_IMAGE(HttpStatus.CONFLICT.value(), "-20400"), + + FAIL_TO_PAY(HttpStatus.CONFLICT.value(), "-20400"), + + FAIL_TO_READ_IMAGE(HttpStatus.CONFLICT.value(), "-20400"), + + RESERVATION_NOT_FOUND_FOR_REVIEW(HttpStatus.NOT_FOUND.value(), "14044"), + + NO_LEFT_SEAT(HttpStatus.BAD_REQUEST.value(), "-10400"), + + URL_PARSING_FAILED(HttpStatus.BAD_REQUEST.value(), "-20400"), + + INVALID_INPUT_VALUE(HttpStatus.BAD_REQUEST.value(), "-20400"), + + UNAUTHORIZED(HttpStatus.UNAUTHORIZED.value(), "-20400"), + + ENTITY_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "-10404"), + + UNEXPECTED(HttpStatus.BAD_REQUEST.value(), "-1"); + + private final Integer status; + private final String code; + + ErrorCode(int status, String code) { + this.status = status; + this.code = code; + } +} diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/ExtensionParsingException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/ExtensionParsingException.java index b07099b7..e6ad2b85 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/ExtensionParsingException.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/ExtensionParsingException.java @@ -1,7 +1,5 @@ package org.ktc2.cokaen.wouldyouin._common.exception; -import org.ktc2.cokaen.wouldyouin._common.error.ErrorCode; - public class ExtensionParsingException extends BusinessException { public ExtensionParsingException(String message) { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailToReadImageException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailToReadImageException.java index 69e4acd4..71f4414b 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailToReadImageException.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailToReadImageException.java @@ -1,7 +1,5 @@ package org.ktc2.cokaen.wouldyouin._common.exception; -import org.ktc2.cokaen.wouldyouin._common.error.ErrorCode; - public class FailToReadImageException extends BusinessException { public FailToReadImageException(String message) { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailedToDeleteImageException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailedToDeleteImageException.java deleted file mode 100644 index 1989d4ee..00000000 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailedToDeleteImageException.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.ktc2.cokaen.wouldyouin._common.exception; - -import org.ktc2.cokaen.wouldyouin._common.error.ErrorCode; - -public class FailedToDeleteImageException extends BusinessException { - - public FailedToDeleteImageException(String message) { - super(message, ErrorCode.FAIL_TO_DELETE_IMAGE); - } -} \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailedToPayException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailedToPayException.java deleted file mode 100644 index 11307f78..00000000 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailedToPayException.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.ktc2.cokaen.wouldyouin._common.exception; - -import org.ktc2.cokaen.wouldyouin._common.error.ErrorCode; - -public class FailedToPayException extends BusinessException { - - public FailedToPayException(String message) { - super(message, ErrorCode.FAIL_TO_PAY); - } -} \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailedToUploadImageException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailedToUploadImageException.java index 53314a64..8bb6f4dd 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailedToUploadImageException.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/FailedToUploadImageException.java @@ -1,7 +1,5 @@ package org.ktc2.cokaen.wouldyouin._common.exception; -import org.ktc2.cokaen.wouldyouin._common.error.ErrorCode; - public class FailedToUploadImageException extends BusinessException { public FailedToUploadImageException(String message) { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/GlobalExceptionHandler.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/GlobalExceptionHandler.java similarity index 94% rename from src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/GlobalExceptionHandler.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/GlobalExceptionHandler.java index 34bc5653..a08a2b98 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/GlobalExceptionHandler.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/GlobalExceptionHandler.java @@ -1,10 +1,9 @@ -package org.ktc2.cokaen.wouldyouin._common.error; +package org.ktc2.cokaen.wouldyouin._common.exception; import java.util.stream.Collectors; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponse; import org.ktc2.cokaen.wouldyouin._common.api.ApiResponseBody; -import org.ktc2.cokaen.wouldyouin._common.exception.BusinessException; import org.ktc2.cokaen.wouldyouin.image.api.ImageDomain; import org.springframework.context.support.DefaultMessageSourceResolvable; import org.springframework.http.ResponseEntity; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/NoLeftSeatException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/NoLeftSeatException.java deleted file mode 100644 index e2690850..00000000 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/NoLeftSeatException.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.ktc2.cokaen.wouldyouin._common.exception; - -import org.ktc2.cokaen.wouldyouin._common.error.ErrorCode; - -public class NoLeftSeatException extends BusinessException { - - public NoLeftSeatException(String message) { - super(message, ErrorCode.NO_LEFT_SEAT); - } -} \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/UnauthorizedException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/UnauthorizedException.java index 7a17c69f..e03ba9fd 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/UnauthorizedException.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/UnauthorizedException.java @@ -1,7 +1,5 @@ package org.ktc2.cokaen.wouldyouin._common.exception; -import org.ktc2.cokaen.wouldyouin._common.error.ErrorCode; - public class UnauthorizedException extends BusinessException { public UnauthorizedException(String message) { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_develop/api/TempCreateController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_develop/api/TempCreateController.java index 4b0dc57b..5e5cc0ca 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_develop/api/TempCreateController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_develop/api/TempCreateController.java @@ -63,9 +63,9 @@ public ResponseEntity>> testCreateCurator(@R // 테스트: 사용자 삭제 @DeleteMapping("/delete/{memberId}") - public void testDeleteMember(@PathVariable("memberId") Long id) { - // TODO: 204 NO CONTENT 반환하게 수정필요 + public ResponseEntity> testDeleteMember(@PathVariable("memberId") Long id) { baseMemberService.deleteById(id); + return ApiResponse.noContent(); } @GetMapping("create/token") diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/AuthorizeArgumentResolver.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/AuthorizeArgumentResolver.java index cef846b8..c6e8afa7 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/AuthorizeArgumentResolver.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/AuthorizeArgumentResolver.java @@ -4,6 +4,7 @@ import java.util.Objects; import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; +import org.ktc2.cokaen.wouldyouin.auth.exception.AuthenticationEmptyException; import org.ktc2.cokaen.wouldyouin.auth.persist.CustomUserDetails; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.springframework.core.MethodParameter; @@ -17,7 +18,6 @@ @Component @RequiredArgsConstructor -//TODO: 커스텀 예외 추가 필요 public class AuthorizeArgumentResolver implements HandlerMethodArgumentResolver { @Override @@ -37,12 +37,12 @@ public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer m // 토큰으로 인증된 사용자 정보 얻기 private MemberIdentifier getAuthorizedMemberIdFrom(Authentication authentication) { if (authentication == null) { - throw new RuntimeException("No authentication found"); + throw new AuthenticationEmptyException("시큐리티 컨텍스트 내 인증 정보가 없습니다."); } if (authentication.getPrincipal() instanceof CustomUserDetails userDetails) { return userDetails.getIdentifier(); } - throw new RuntimeException("No CustomUserDetails found"); + throw new RuntimeException("No CustomUserDetails found"); // 절대 도달하지 않음 } // @Authorize 애너테이션이 요구한 멤버 타입 추출 diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/CustomAccessDeniedHandler.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/CustomAccessDeniedHandler.java index 1430f3dd..7ea85f5e 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/CustomAccessDeniedHandler.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/CustomAccessDeniedHandler.java @@ -6,8 +6,8 @@ import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import lombok.RequiredArgsConstructor; -import org.ktc2.cokaen.wouldyouin._common.api.ApiResponseBody; -import org.springframework.http.HttpStatus; +import org.ktc2.cokaen.wouldyouin._common.api.ApiResponse; +import org.ktc2.cokaen.wouldyouin._common.exception.ErrorCode; import org.springframework.http.MediaType; import org.springframework.security.access.AccessDeniedException; import org.springframework.security.web.access.AccessDeniedHandler; @@ -22,13 +22,12 @@ public class CustomAccessDeniedHandler implements AccessDeniedHandler { @Override public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException { - - // TODO: Fail ApiResponse로 변경필요 - ApiResponseBody body = new ApiResponseBody<>(false, "No Authorities(response by CustomAccessDeniedHandler.Class)"); - String responseBody = objectMapper.writeValueAsString(body); + String responseBody = objectMapper.writeValueAsString(ApiResponse.error(ErrorCode.SECURITY_FILTER_FORBIDDEN_ACCESS, + "권한이 부족하여 접근이 거부되었습니다.") + .getBody()); response.setContentType(MediaType.APPLICATION_JSON_VALUE); - response.setStatus(HttpStatus.FORBIDDEN.value()); + response.setStatus(ErrorCode.SECURITY_FILTER_FORBIDDEN_ACCESS.getStatus()); response.setCharacterEncoding("UTF-8"); response.getWriter().write(responseBody); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/CustomAuthenticationEntryPoint.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/CustomAuthenticationEntryPoint.java index 3df329ea..8e1e004d 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/CustomAuthenticationEntryPoint.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/CustomAuthenticationEntryPoint.java @@ -6,8 +6,8 @@ import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import lombok.RequiredArgsConstructor; -import org.ktc2.cokaen.wouldyouin._common.api.ApiResponseBody; -import org.springframework.http.HttpStatus; +import org.ktc2.cokaen.wouldyouin._common.api.ApiResponse; +import org.ktc2.cokaen.wouldyouin._common.exception.ErrorCode; import org.springframework.http.MediaType; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.AuthenticationEntryPoint; @@ -21,13 +21,12 @@ public class CustomAuthenticationEntryPoint implements AuthenticationEntryPoint @Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { - - // TODO: Fail ApiResponse로 변경필요 - ApiResponseBody body = new ApiResponseBody<>(false, "Not Authenticated Request(response by CustomAuthenticationEntryPoint.Class)"); - String responseBody = objectMapper.writeValueAsString(body); + String responseBody = objectMapper.writeValueAsString(ApiResponse.error(ErrorCode.SECURITY_FILTER_AUTHORIZATION_REQUIRED, + "요청시 인증이 필요합니다. Authorization Token을 확인해주세요.") + .getBody()); response.setContentType(MediaType.APPLICATION_JSON_VALUE); - response.setStatus(HttpStatus.UNAUTHORIZED.value()); + response.setStatus(ErrorCode.SECURITY_FILTER_AUTHORIZATION_REQUIRED.getStatus()); response.setCharacterEncoding("UTF-8"); response.getWriter().write(responseBody); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/CustomUserDetailsService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/CustomUserDetailsService.java index 71cf280c..85cbe21c 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/CustomUserDetailsService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/CustomUserDetailsService.java @@ -1,6 +1,7 @@ package org.ktc2.cokaen.wouldyouin.auth.application; import lombok.RequiredArgsConstructor; +import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.auth.persist.CustomUserDetails; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMember; @@ -20,8 +21,8 @@ public class CustomUserDetailsService implements UserDetailsService { @Override public UserDetails loadUserByUsername(String id) throws UsernameNotFoundException { - // TODO: 커스텀 예외 필요 - BaseMember member = baseMemberRepository.findById(Long.parseLong(id)).orElseThrow(RuntimeException::new); + BaseMember member = baseMemberRepository.findById(Long.parseLong(id)).orElseThrow(() -> + new EntityNotFoundException("아이디에 해당하는 사용자를 찾을 수 없습니다.")); return new CustomUserDetails(new MemberIdentifier(member.getId(), member.getMemberType())); } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/JwtService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/JwtService.java index c169acad..5da2c445 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/JwtService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/JwtService.java @@ -14,12 +14,13 @@ import java.time.ZoneOffset; import java.util.Date; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; +import org.ktc2.cokaen.wouldyouin.auth.exception.InvalidAuthorizationHeaderException; +import org.ktc2.cokaen.wouldyouin.auth.exception.JwtTokenException; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @Service -//TODO: 커스텀 예외 필요 public class JwtService { @Value("${jwt.access.expiration}") @@ -76,7 +77,7 @@ public boolean hasPrefix(String authorizationHeader) { // 토큰 접두사 제거 private String removePrefixFrom(String authorizationHeader) { if (!hasPrefix(authorizationHeader)) { - throw new RuntimeException("Authorization header is missing or invalid"); + throw new InvalidAuthorizationHeaderException("Authorization header is missing or invalid"); } // 'Bearer ' 제거 후 실제 JWT 토큰만 추출 및 토큰 검증 @@ -88,13 +89,13 @@ private void validateToken(String token) { try { Jwts.parserBuilder().setSigningKey(key).build().parseClaimsJws(token); } catch (io.jsonwebtoken.security.SecurityException | MalformedJwtException e) { - throw new RuntimeException("Invalid JWT Token"); + throw new JwtTokenException("Invalid JWT Token"); } catch (ExpiredJwtException e) { - throw new RuntimeException("Expired JWT Token"); + throw new JwtTokenException("Expired JWT Token"); } catch (UnsupportedJwtException e) { - throw new RuntimeException("Unsupported JWT Token"); + throw new JwtTokenException("Unsupported JWT Token"); } catch (IllegalArgumentException e) { - throw new RuntimeException("JWT claims string is empty."); + throw new JwtTokenException("JWT claims string is empty."); } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/GoogleRequestService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/GoogleRequestService.java index d5a46366..da691399 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/GoogleRequestService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/GoogleRequestService.java @@ -11,6 +11,8 @@ import org.ktc2.cokaen.wouldyouin.auth.application.oauth.dto.AccessTokenResponse; import org.ktc2.cokaen.wouldyouin.auth.application.oauth.dto.OauthRequest; import org.ktc2.cokaen.wouldyouin.auth.application.oauth.dto.OauthResourcesResponse; +import org.ktc2.cokaen.wouldyouin.auth.exception.FailAccessTokenGetException; +import org.ktc2.cokaen.wouldyouin.auth.exception.FailSocialDataGetException; import org.ktc2.cokaen.wouldyouin.member.persist.AccountType; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpHeaders; @@ -84,14 +86,12 @@ protected OauthResourcesResponse requestLoginAndAccessResources(OauthRequest req AccessTokenResponse authenticationResponse = client.post( AccessTokenResponse.class, loginRequestUri, loginRequestHeaders, request, - // TODO: 커스텀 예외 추가 - (req, response) -> { throw new RuntimeException("에러"); }); + (req, response) -> { throw new FailAccessTokenGetException("구글 액세스 토큰을 가져오는데 실패했습니다."); }); Objects.requireNonNull(authenticationResponse); GoogleAccessRequestResponse result = client.get( GoogleAccessRequestResponse.class, accessRequestUri, getAccessRequestHeaders(authenticationResponse), - // TODO: 커스텀 예외 추가 - (req, rsp) -> { throw new RuntimeException("에러"); }); + (req, rsp) -> { throw new FailSocialDataGetException("구글 소셜 계정 정보를 가져오는데 실패했습니다."); }); log.debug("#### GoogleAccessRequestResponse result = {}", result); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/KakaoRequestService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/KakaoRequestService.java index 20d618fa..3b443200 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/KakaoRequestService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/KakaoRequestService.java @@ -13,6 +13,8 @@ import org.ktc2.cokaen.wouldyouin.auth.application.oauth.dto.AccessTokenResponse; import org.ktc2.cokaen.wouldyouin.auth.application.oauth.dto.OauthRequest; import org.ktc2.cokaen.wouldyouin.auth.application.oauth.dto.OauthResourcesResponse; +import org.ktc2.cokaen.wouldyouin.auth.exception.FailAccessTokenGetException; +import org.ktc2.cokaen.wouldyouin.auth.exception.FailSocialDataGetException; import org.ktc2.cokaen.wouldyouin.member.persist.AccountType; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpHeaders; @@ -92,16 +94,12 @@ protected OauthRequest getOauthRequestBase() { protected OauthResourcesResponse requestLoginAndAccessResources(OauthRequest request) { AccessTokenResponse authenticationResponse = client.post( AccessTokenResponse.class, getLoginRequestUri(request), loginRequestHeaders, - // TODO: 커스텀 예외 추가 - (req, rsp) -> { - throw new RuntimeException("에러"); - }); + (req, rsp) -> { throw new FailAccessTokenGetException("카카오 액세스 토큰을 가져오는데 실패했습니다."); }); Objects.requireNonNull(authenticationResponse); KakaoAccessRequestResponse result = client.get( KakaoAccessRequestResponse.class, accessRequestUri, getAccessRequestHeaders(authenticationResponse), - // TODO: 커스텀 예외 추가 - (req, rsp) -> { throw new RuntimeException("에러"); }); + (req, rsp) -> { throw new FailSocialDataGetException("카카오 소셜 계정 정보를 가져오는데 실패했습니다."); }); log.debug("#### KakaoAccessRequestResponse result = {}", result); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/exception/AuthenticationEmptyException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/exception/AuthenticationEmptyException.java new file mode 100644 index 00000000..86d24128 --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/exception/AuthenticationEmptyException.java @@ -0,0 +1,12 @@ +package org.ktc2.cokaen.wouldyouin.auth.exception; + +import org.ktc2.cokaen.wouldyouin._common.exception.BusinessException; +import org.ktc2.cokaen.wouldyouin._common.exception.ErrorCode; + +public class AuthenticationEmptyException extends BusinessException { + + public AuthenticationEmptyException(String message) { + super(message, ErrorCode.AUTHENTICATION_EMPTY); + } + +} diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/exception/FailAccessTokenGetException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/exception/FailAccessTokenGetException.java new file mode 100644 index 00000000..480a7a4d --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/exception/FailAccessTokenGetException.java @@ -0,0 +1,12 @@ +package org.ktc2.cokaen.wouldyouin.auth.exception; + +import org.ktc2.cokaen.wouldyouin._common.exception.BusinessException; +import org.ktc2.cokaen.wouldyouin._common.exception.ErrorCode; + +public class FailAccessTokenGetException extends BusinessException { + + public FailAccessTokenGetException(String message) { + super(message, ErrorCode.FAIL_ACCESS_TOKEN_GET); + } + +} diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/exception/FailSocialDataGetException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/exception/FailSocialDataGetException.java new file mode 100644 index 00000000..a583984c --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/exception/FailSocialDataGetException.java @@ -0,0 +1,12 @@ +package org.ktc2.cokaen.wouldyouin.auth.exception; + +import org.ktc2.cokaen.wouldyouin._common.exception.BusinessException; +import org.ktc2.cokaen.wouldyouin._common.exception.ErrorCode; + +public class FailSocialDataGetException extends BusinessException { + + public FailSocialDataGetException(String message) { + super(message, ErrorCode.FAIL_SOCIAL_DATA_GET); + } + +} diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/exception/InvalidAuthorizationHeaderException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/exception/InvalidAuthorizationHeaderException.java new file mode 100644 index 00000000..f76717ae --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/exception/InvalidAuthorizationHeaderException.java @@ -0,0 +1,12 @@ +package org.ktc2.cokaen.wouldyouin.auth.exception; + +import org.ktc2.cokaen.wouldyouin._common.exception.BusinessException; +import org.ktc2.cokaen.wouldyouin._common.exception.ErrorCode; + +public class InvalidAuthorizationHeaderException extends BusinessException { + + public InvalidAuthorizationHeaderException(String message) { + super(message, ErrorCode.INVALID_AUTHORIZATION_HEADER); + } + +} diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/exception/JwtTokenException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/exception/JwtTokenException.java new file mode 100644 index 00000000..7e5ccf28 --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/exception/JwtTokenException.java @@ -0,0 +1,11 @@ +package org.ktc2.cokaen.wouldyouin.auth.exception; + +import org.ktc2.cokaen.wouldyouin._common.exception.BusinessException; +import org.ktc2.cokaen.wouldyouin._common.exception.ErrorCode; + +public class JwtTokenException extends BusinessException { + + public JwtTokenException(String message) { + super(message, ErrorCode.JWT_TOKEN_EXCEPTION); + } +} diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCardRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCardRequest.java index 52fe3df8..960fa524 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCardRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCardRequest.java @@ -10,7 +10,7 @@ import lombok.Getter; import lombok.ToString; import org.ktc2.cokaen.wouldyouin.curation.persist.CurationCard; -import org.ktc2.cokaen.wouldyouin.image.persist.CurationImage; +import org.ktc2.cokaen.wouldyouin.image.persist.CurationCardImage; @Getter @Builder(toBuilder = true) @@ -32,7 +32,7 @@ public boolean isImageSizeValid() { return imageIds == null || imageIds.size() <= 5; } - public CurationCard toEntity(List images) { + public CurationCard toEntity(List images) { return CurationCard.builder() .subtitle(this.subtitle) .content(this.content) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java index b4503b13..3817177f 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationCardService.java @@ -10,7 +10,7 @@ import org.ktc2.cokaen.wouldyouin.curation.persist.CurationCard; import org.ktc2.cokaen.wouldyouin.curation.persist.CurationCardRepository; import org.ktc2.cokaen.wouldyouin.image.application.CurationImageService; -import org.ktc2.cokaen.wouldyouin.image.persist.CurationImage; +import org.ktc2.cokaen.wouldyouin.image.persist.CurationCardImage; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -29,7 +29,7 @@ public CurationCardResponse getById(Long id) { @Transactional public CurationCard create(CurationCardRequest request) { - List images = request.getImageIds().stream() + List images = request.getImageIds().stream() .map(curationImageService::getById).toList(); CurationCard curationCard = curationCardRepository.save(request.toEntity(images)); images.forEach(image -> curationImageService.setCuration(image, curationCard)); @@ -39,7 +39,7 @@ public CurationCard create(CurationCardRequest request) { @Transactional public void delete(MemberIdentifier identifier, Long id) { CurationCard target = getByIdOrThrow(id); - target.getCurationImages().forEach(image -> curationImageService.deleteImage(identifier, image.getId())); + target.getCurationCardImages().forEach(image -> curationImageService.deleteImage(identifier, image.getId())); curationCardRepository.deleteById(id); } @@ -53,7 +53,7 @@ private CurationCard getByIdOrThrow(Long id) { } private List getImageUrls(CurationCard curationCard) { - return curationCard.getCurationImages().stream() + return curationCard.getCurationCardImages().stream() .map(curationImageService::getImageUrl) .toList(); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationService.java index e4e94c96..9d35dff6 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/application/CurationService.java @@ -18,7 +18,7 @@ import org.ktc2.cokaen.wouldyouin.event.application.EventService; import org.ktc2.cokaen.wouldyouin.event.persist.Event; import org.ktc2.cokaen.wouldyouin.image.application.CurationImageService; -import org.ktc2.cokaen.wouldyouin.image.persist.CurationImage; +import org.ktc2.cokaen.wouldyouin.image.persist.CurationCardImage; import org.ktc2.cokaen.wouldyouin.member.application.CuratorService; import org.ktc2.cokaen.wouldyouin.member.persist.Curator; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @@ -122,7 +122,7 @@ private List getCurationResponses(Slice curations) { private List getCurationCardResponses(Curation curation) { return curation.getCurationCards().stream() .map(curationCard -> CurationCardResponse.from( - curationCard, curationCard.getCurationImages().stream() + curationCard, curationCard.getCurationCardImages().stream() .map(curationImageService::getImageUrl).toList())) .toList(); } @@ -130,9 +130,9 @@ private List getCurationCardResponses(Curation curation) { private String getThumbnailUrl(List curationCards) { return Optional.ofNullable(curationCards) .map(List::getFirst) - .map(CurationCard::getCurationImages) + .map(CurationCard::getCurationCardImages) .map(List::getFirst) - .map(CurationImage::getName) + .map(CurationCardImage::getName) .map(curationImageService::createThumbnail) .orElse(""); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCard.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCard.java index 9f875961..257f8bda 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCard.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCard.java @@ -19,7 +19,7 @@ import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; -import org.ktc2.cokaen.wouldyouin.image.persist.CurationImage; +import org.ktc2.cokaen.wouldyouin.image.persist.CurationCardImage; @Getter @Setter @@ -46,13 +46,13 @@ public class CurationCard { private Curation curation; @OneToMany(mappedBy = "curationCard", fetch = FetchType.LAZY) - private List curationImages = new ArrayList<>(); + private List curationCardImages = new ArrayList<>(); @Builder - public CurationCard(String subtitle, String content, Curation curation, List images) { + public CurationCard(String subtitle, String content, Curation curation, List images) { Optional.ofNullable(subtitle).ifPresent(this::setSubtitle); Optional.ofNullable(content).ifPresent(this::setContent); Optional.ofNullable(curation).ifPresent(this::setCuration); - Optional.ofNullable(images).ifPresent(this::setCurationImages); + Optional.ofNullable(images).ifPresent(this::setCurationCardImages); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java index 5ed92e94..3d077085 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java @@ -4,7 +4,7 @@ import java.util.Optional; import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; -import org.ktc2.cokaen.wouldyouin._common.exception.NoLeftSeatException; +import org.ktc2.cokaen.wouldyouin.event.exception.NoLeftSeatException; import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/exception/NoLeftSeatException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/exception/NoLeftSeatException.java new file mode 100644 index 00000000..ce133983 --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/exception/NoLeftSeatException.java @@ -0,0 +1,11 @@ +package org.ktc2.cokaen.wouldyouin.event.exception; + +import org.ktc2.cokaen.wouldyouin._common.exception.BusinessException; +import org.ktc2.cokaen.wouldyouin._common.exception.ErrorCode; + +public class NoLeftSeatException extends BusinessException { + + public NoLeftSeatException(String message) { + super(message, ErrorCode.NO_LEFT_SEAT); + } +} \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/ImageController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/ImageController.java index 587f710e..3c4b4f79 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/ImageController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/api/ImageController.java @@ -45,8 +45,7 @@ public ResponseEntity getThumnailImage(@PathVariable String directory, @ @PostMapping public ResponseEntity>> uploadImages( @RequestParam List images, - @RequestParam(value = "type") ImageDomain imageDomain, - @Authorize({MemberType.normal, MemberType.curator, MemberType.host}) MemberIdentifier identifier) { + @RequestParam(value = "type") ImageDomain imageDomain) { return ApiResponse.ok(imageServiceFactory.getImageService(imageDomain).saveImages(images)); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/CurationImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/CurationImageService.java index 03bf57cc..ae946a1f 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/CurationImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/application/CurationImageService.java @@ -1,13 +1,12 @@ package org.ktc2.cokaen.wouldyouin.image.application; -import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.curation.persist.CurationCard; import org.ktc2.cokaen.wouldyouin.image.api.ImageDomain; import org.ktc2.cokaen.wouldyouin.image.api.dto.ImageRequest; -import org.ktc2.cokaen.wouldyouin.image.persist.CurationImage; -import org.ktc2.cokaen.wouldyouin.image.persist.CurationImageRepository; +import org.ktc2.cokaen.wouldyouin.image.persist.CurationCardImage; +import org.ktc2.cokaen.wouldyouin.image.persist.CurationCardImageRepository; import org.ktc2.cokaen.wouldyouin.image.persist.ImageRepository; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.springframework.beans.factory.annotation.Value; @@ -15,20 +14,20 @@ import org.springframework.transaction.annotation.Transactional; @Service -public class CurationImageService extends ImageService { +public class CurationImageService extends ImageService { @Value("${image.upload.curation.child-path}") private String childPath; - private final CurationImageRepository curationImageRepository; + private final CurationCardImageRepository curationCardImageRepository; - public CurationImageService(ImageStorageService imageStorageService, CurationImageRepository curationImageRepository) { + public CurationImageService(ImageStorageService imageStorageService, CurationCardImageRepository curationCardImageRepository) { this.imageStorageService = imageStorageService; - this.curationImageRepository = curationImageRepository; + this.curationCardImageRepository = curationCardImageRepository; } @Override - public ImageRepository getImageRepository() { - return curationImageRepository; + public ImageRepository getImageRepository() { + return curationCardImageRepository; } @Override @@ -42,8 +41,8 @@ protected String getChildPath() { } @Override - protected CurationImage mapToEntityFrom(ImageRequest imageRequest) { - return CurationImage.builder() + protected CurationCardImage mapToEntityFrom(ImageRequest imageRequest) { + return CurationCardImage.builder() .name(imageRequest.getName()) .size(imageRequest.getSize()) .extension(imageRequest.getExtension()) @@ -51,7 +50,7 @@ protected CurationImage mapToEntityFrom(ImageRequest imageRequest) { } @Override - protected void validateMemberId(MemberIdentifier identifier, CurationImage image) { + protected void validateMemberId(MemberIdentifier identifier, CurationCardImage image) { if (!identifier.type().equals(MemberType.admin) && !identifier.id().equals(image.getCurationCard().getCuration().getCurator().getId())) { throw new UnauthorizedException("해당 큐레이션 이미지에 접근할 권한이 없습니다."); @@ -59,7 +58,7 @@ protected void validateMemberId(MemberIdentifier identifier, CurationImage image } @Transactional - public void setCuration(CurationImage image, CurationCard curationCard) { + public void setCuration(CurationCardImage image, CurationCard curationCard) { image.setCurationCard(curationCard); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/CurationImage.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/CurationCardImage.java similarity index 85% rename from src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/CurationImage.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/CurationCardImage.java index a4406b8b..48eec470 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/CurationImage.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/CurationCardImage.java @@ -18,14 +18,14 @@ @EqualsAndHashCode(callSuper = true) @ToString @NoArgsConstructor -public class CurationImage extends Image { +public class CurationCardImage extends Image { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "curation_card_id") private CurationCard curationCard; @Builder - public CurationImage(String name, Long size, String extension) { + public CurationCardImage(String name, Long size, String extension) { super(name, size, extension); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/CurationImageRepository.java b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/CurationCardImageRepository.java similarity index 56% rename from src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/CurationImageRepository.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/CurationCardImageRepository.java index f18770b8..bbe22bd1 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/CurationImageRepository.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/image/persist/CurationCardImageRepository.java @@ -3,6 +3,6 @@ import org.springframework.stereotype.Repository; @Repository -public interface CurationImageRepository extends ImageRepository { +public interface CurationCardImageRepository extends ImageRepository { } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/LikeServiceFactory.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/LikeServiceFactory.java index dd4bb176..85d2bf73 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/LikeServiceFactory.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/like/application/LikeServiceFactory.java @@ -6,6 +6,7 @@ import java.util.stream.Collectors; import org.ktc2.cokaen.wouldyouin.like.persist.Like; import org.ktc2.cokaen.wouldyouin.member.application.BaseMemberService; +import org.ktc2.cokaen.wouldyouin.member.exception.NotLikeableMemberException; import org.ktc2.cokaen.wouldyouin.member.persist.LikeableMember; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.springframework.beans.factory.annotation.Autowired; @@ -28,7 +29,7 @@ public LikeServiceFactory( public LikeService> getLikeServiceFrom(MemberType targetLikeableMemberType) { if (!LikeableMember.getLikeableMemberTypes().contains(targetLikeableMemberType)) { - throw new RuntimeException("해당 사용자는 좋아요할 수 없는 사용자 유형입니다."); + throw new NotLikeableMemberException("해당 사용자는 좋아요할 수 없는 사용자 유형입니다."); } return map.get(targetLikeableMemberType); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/LikeRepository.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/LikeRepository.java index c1ef6628..2bfe6c14 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/LikeRepository.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/LikeRepository.java @@ -17,7 +17,7 @@ public interface LikeRepository @Query("SELECT l FROM #{#entityName} l " + "JOIN FETCH l.member m " + "JOIN FETCH l.likeableMember lm " + - "WHERE l.member.id = :member " + + "WHERE l.member = :member " + "AND l.id < :lastId " + "ORDER BY l.id DESC") Slice findAllByMember(Member member, Long lastId, Pageable pageable); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/MemberController.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/MemberController.java index 22532fe7..77702fcb 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/MemberController.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/MemberController.java @@ -41,8 +41,8 @@ public ResponseEntity> findMember(@PathVariable( // 사용자 삭제 @DeleteMapping - public void deleteMember(@Authorize({MemberType.normal, MemberType.host, MemberType.curator}) MemberIdentifier identifier) { - // TODO: 204 NO CONTENT 반환하게 수정필요 + public ResponseEntity> deleteMember(@Authorize({MemberType.normal, MemberType.host, MemberType.curator}) MemberIdentifier identifier) { baseMemberService.deleteById(identifier.id()); + return ApiResponse.noContent(); } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberService.java index 154c2d11..ec5c7191 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberService.java @@ -1,7 +1,9 @@ package org.ktc2.cokaen.wouldyouin.member.application; import lombok.RequiredArgsConstructor; +import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; import org.ktc2.cokaen.wouldyouin.member.api.dto.MemberResponse; +import org.ktc2.cokaen.wouldyouin.member.exception.EmailAlreadyExistsException; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMember; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMemberRepository; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @@ -15,13 +17,14 @@ public class BaseMemberService { private final BaseMemberRepository baseMemberRepository; private final DerivedMemberServiceFactory derivedMemberServiceFactory; - public BaseMember getByIdOrThrow(Long id) throws RuntimeException { - // TODO: 커스텀 예외 작성필요 - return baseMemberRepository.findById(id).orElseThrow(RuntimeException::new); + public BaseMember getByIdOrThrow(Long id) throws EntityNotFoundException { + return baseMemberRepository.findById(id).orElseThrow(() -> + new EntityNotFoundException("아이디에 해당하는 사용자를 찾을 수 없습니다.") + ); } @Transactional(readOnly = true) - public MemberType getMemberType(Long id) throws RuntimeException { + public MemberType getMemberType(Long id) throws EntityNotFoundException { return getByIdOrThrow(id).getMemberType(); } @@ -32,9 +35,8 @@ public MemberResponse findById(Long id) { @Transactional(readOnly = true) public void checkUniqueEmailOrThrow(String email) { - // TODO: 커스텀 예외 추가필요 baseMemberRepository.findByEmail(email).ifPresent(p -> { - throw new RuntimeException("Email already exists"); + throw new EmailAlreadyExistsException("이미 사용중인 이메일입니다."); }); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java index d157f0cf..36493e07 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java @@ -66,14 +66,16 @@ public MemberResponse createCurator(Long normalMemberId) { .build(); Long toDeleteId = member.getId(); + memberImageService.setBaseMember(member.getProfileImage(), null); memberRepository.deleteById(toDeleteId); baseMemberRepository.deleteById(toDeleteId); //삭제 후 플러시를 사용해 즉시 데이터베이스에 반영 - memberRepository.flush(); baseMemberRepository.flush(); + memberRepository.flush(); curatorRepository.save(curator); + memberImageService.setBaseMember(curator.getProfileImage(), curator); return MemberResponse.from(curator, memberImageService.getImageUrl(curator.getProfileImage())); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java index 345f03fb..e1e32343 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java @@ -2,12 +2,14 @@ import java.util.Optional; import lombok.RequiredArgsConstructor; +import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; import org.ktc2.cokaen.wouldyouin.auth.api.dto.LocalLoginRequest; import org.ktc2.cokaen.wouldyouin.image.application.MemberImageService; import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin.member.api.dto.MemberResponse; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.create.HostCreateRequest; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit.HostEditRequest; +import org.ktc2.cokaen.wouldyouin.member.exception.LoginFailedException; import org.ktc2.cokaen.wouldyouin.member.persist.Host; import org.ktc2.cokaen.wouldyouin.member.persist.HostRepository; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @@ -68,14 +70,15 @@ public MemberResponse getMemberResponseById(Long id) { @Transactional(readOnly = true) public MemberResponse getMemberResponseBy(LocalLoginRequest loginRequest) { Host host = hostRepository.findByEmailAndHashedPassword(loginRequest.email(), passwordEncoder.encode(loginRequest.password())) - .orElseThrow(RuntimeException::new); + .orElseThrow(() -> new LoginFailedException("이메일 또는 비밀번호가 일치하지 않습니다.")); return MemberResponse.from(host, memberImageService.getImageUrl(host.getProfileImage())); } @Transactional(readOnly = true) public Host getByIdOrThrow(Long id) { - //TODO: 커스텀 예외 필요 - return hostRepository.findById(id).orElseThrow(RuntimeException::new); + return hostRepository.findById(id).orElseThrow(() -> + new EntityNotFoundException("사용자가 주최자가 아니거나 없습니다.") + ); } @Override diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/MemberService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/MemberService.java index 5aada5b9..92a64656 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/MemberService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/MemberService.java @@ -2,6 +2,7 @@ import java.util.Optional; import lombok.RequiredArgsConstructor; +import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.image.application.MemberImageService; import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; @@ -9,6 +10,7 @@ import org.ktc2.cokaen.wouldyouin.member.api.dto.request.MemberAdditionalInfoRequest; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.create.MemberCreateRequest; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit.MemberEditRequest; +import org.ktc2.cokaen.wouldyouin.member.exception.AdditionalInfoIllegalAccessException; import org.ktc2.cokaen.wouldyouin.member.persist.Member; import org.ktc2.cokaen.wouldyouin.member.persist.MemberRepository; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @@ -53,8 +55,7 @@ public MemberResponse updateWelcomeMember(Long welcomeMemberId, MemberAdditional Member member = getByIdOrThrow(welcomeMemberId); // TODO : validate if (member.getMemberType() != MemberType.welcome) { - // TODO: 커스텀 예외 필요 - throw new RuntimeException("Welcome Member가 아닙니다."); + throw new AdditionalInfoIllegalAccessException("최초 소셜로그인 후 추가정보를 기입하지 않은 사용자만 접근 가능합니다."); } member.updateFrom(additionalInfoRequest); return MemberResponse.from(member, memberImageService.getImageUrl(member.getProfileImage())); @@ -75,8 +76,9 @@ public MemberResponse getMemberResponseById(Long id) { @Transactional(readOnly = true) public Member getByIdOrThrow(Long id) { - //TODO: 커스텀 예외 필요 - return memberRepository.findById(id).orElseThrow(RuntimeException::new); + return memberRepository.findById(id).orElseThrow(() -> + new EntityNotFoundException("해당 사용자를 찾을 수 없습니다.") + ); } @Transactional(readOnly = true) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/exception/AdditionalInfoIllegalAccessException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/exception/AdditionalInfoIllegalAccessException.java new file mode 100644 index 00000000..1358bef4 --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/exception/AdditionalInfoIllegalAccessException.java @@ -0,0 +1,10 @@ +package org.ktc2.cokaen.wouldyouin.member.exception; + +import org.ktc2.cokaen.wouldyouin._common.exception.BusinessException; +import org.ktc2.cokaen.wouldyouin._common.exception.ErrorCode; + +public class AdditionalInfoIllegalAccessException extends BusinessException { + public AdditionalInfoIllegalAccessException(String message) { + super(message, ErrorCode.ADDITIONAL_INFO_ILLEGAL_ACCESS); + } +} diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/exception/EmailAlreadyExistsException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/exception/EmailAlreadyExistsException.java new file mode 100644 index 00000000..1f010c0d --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/exception/EmailAlreadyExistsException.java @@ -0,0 +1,11 @@ +package org.ktc2.cokaen.wouldyouin.member.exception; + +import org.ktc2.cokaen.wouldyouin._common.exception.BusinessException; +import org.ktc2.cokaen.wouldyouin._common.exception.ErrorCode; + +public class EmailAlreadyExistsException extends BusinessException { + + public EmailAlreadyExistsException(String message) { + super(message, ErrorCode.EMAIL_ALREADY_EXISTS); + } +} diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/exception/LoginFailedException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/exception/LoginFailedException.java new file mode 100644 index 00000000..b7d9608f --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/exception/LoginFailedException.java @@ -0,0 +1,11 @@ +package org.ktc2.cokaen.wouldyouin.member.exception; + +import org.ktc2.cokaen.wouldyouin._common.exception.BusinessException; +import org.ktc2.cokaen.wouldyouin._common.exception.ErrorCode; + +public class LoginFailedException extends BusinessException { + public LoginFailedException(String message) { + super(message, ErrorCode.LOGIN_FAILED); + } + +} diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/exception/NotLikeableMemberException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/exception/NotLikeableMemberException.java new file mode 100644 index 00000000..28225cb2 --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/exception/NotLikeableMemberException.java @@ -0,0 +1,11 @@ +package org.ktc2.cokaen.wouldyouin.member.exception; + +import org.ktc2.cokaen.wouldyouin._common.exception.BusinessException; +import org.ktc2.cokaen.wouldyouin._common.exception.ErrorCode; + +public class NotLikeableMemberException extends BusinessException { + public NotLikeableMemberException(String message) { + super(message, ErrorCode.NOT_LIKEABLE_MEMBER_TYPE); + } + +} diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java index b77db0e2..f89cc912 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java @@ -34,21 +34,21 @@ public abstract class BaseMember { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Column(nullable = false) + @Column(nullable = false, name = "account_type") @Enumerated(EnumType.STRING) private AccountType accountType; - @Column(nullable = false) + @Column(nullable = false, name = "member_type") @Enumerated(EnumType.STRING) private MemberType memberType; - @Column(nullable = false, unique = true) + @Column(nullable = false, unique = true, name = "email") private String email; - @Column(nullable = false, unique = true) + @Column(nullable = false, unique = true, name = "nickname") private String nickname; - @Column(nullable = false) + @Column(nullable = false, name = "phone") private String phone; @OneToOne(mappedBy = "baseMember") diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java index fba78fa3..cae6326a 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java @@ -31,13 +31,13 @@ @Entity public class Curator extends Member implements LikeableMember { - @Column(nullable = false) + @Column(nullable = false, name = "intro") private String intro; - @Column(nullable = false) + @Column(nullable = false, name = "likes") private Integer likes; - @Column(nullable = false) + @Column(nullable = false, name = "hashtags") @Convert(converter = HashtagConverter.class) private List hashtags; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java index 05f48f6a..fcabec34 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java @@ -28,16 +28,16 @@ @Entity public class Host extends BaseMember implements LikeableMember { - @Column(nullable = false) + @Column(nullable = false, name = "hashed_password") private String hashedPassword; - @Column(nullable = false) + @Column(nullable = false, name = "intro") private String intro; - @Column(nullable = false) + @Column(nullable = false, name = "likes") private Integer likes; - @Column(nullable = false) + @Column(nullable = false, name = "hashtags") @Convert(converter = HashtagConverter.class) private List hashtags; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java index a9eab86e..560ae232 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java @@ -3,6 +3,8 @@ import jakarta.persistence.Column; import jakarta.persistence.DiscriminatorValue; import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; import jakarta.persistence.FetchType; import jakarta.persistence.OneToMany; import java.util.ArrayList; @@ -31,17 +33,18 @@ @Entity public class Member extends BaseMember { - @Column(nullable = false) + @Column(nullable = false, name = "area") + @Enumerated(EnumType.STRING) private Area area; - @Column(nullable = false) + @Column(nullable = false, name = "gender") private String gender; - @Column + @Column(name = "social_id") private String socialId; //소셜 타입 식별자 값 //for JWT refresh token - @Column(length = 1000) + @Column(length = 1000, name = "refresh_token") private String refreshToken; @OneToMany(mappedBy = "member", fetch = FetchType.LAZY) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/payment/application/PaymentService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/payment/application/PaymentService.java index 8327adc4..0de71a1f 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/payment/application/PaymentService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/payment/application/PaymentService.java @@ -1,7 +1,7 @@ package org.ktc2.cokaen.wouldyouin.payment.application; import lombok.RequiredArgsConstructor; -import org.ktc2.cokaen.wouldyouin._common.exception.FailedToPayException; +import org.ktc2.cokaen.wouldyouin.payment.exception.FailedToPayException; import org.ktc2.cokaen.wouldyouin._common.util.KakaoPayUtil; import org.ktc2.cokaen.wouldyouin._common.util.RestClientUtil; import org.ktc2.cokaen.wouldyouin._common.util.UriUtil; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/payment/exception/FailedToPayException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/payment/exception/FailedToPayException.java new file mode 100644 index 00000000..351612aa --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/payment/exception/FailedToPayException.java @@ -0,0 +1,11 @@ +package org.ktc2.cokaen.wouldyouin.payment.exception; + +import org.ktc2.cokaen.wouldyouin._common.exception.BusinessException; +import org.ktc2.cokaen.wouldyouin._common.exception.ErrorCode; + +public class FailedToPayException extends BusinessException { + + public FailedToPayException(String message) { + super(message, ErrorCode.FAIL_TO_PAY); + } +} \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java index 30a79660..391e9ac8 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java @@ -1,9 +1,8 @@ package org.ktc2.cokaen.wouldyouin.reservation.application; -import java.util.Optional; import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; -import org.ktc2.cokaen.wouldyouin._common.exception.ReservationNotFoundForReviewException; +import org.ktc2.cokaen.wouldyouin.reservation.exception.ReservationNotFoundForReviewException; import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.event.application.EventService; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/ReservationNotFoundForReviewException.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/exception/ReservationNotFoundForReviewException.java similarity index 53% rename from src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/ReservationNotFoundForReviewException.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/reservation/exception/ReservationNotFoundForReviewException.java index af17d83d..a4cb9d16 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/ReservationNotFoundForReviewException.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/exception/ReservationNotFoundForReviewException.java @@ -1,6 +1,7 @@ -package org.ktc2.cokaen.wouldyouin._common.exception; +package org.ktc2.cokaen.wouldyouin.reservation.exception; -import org.ktc2.cokaen.wouldyouin._common.error.ErrorCode; +import org.ktc2.cokaen.wouldyouin._common.exception.BusinessException; +import org.ktc2.cokaen.wouldyouin._common.exception.ErrorCode; public class ReservationNotFoundForReviewException extends BusinessException { public ReservationNotFoundForReviewException(String message) { diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockCurator1.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockmember/WithMockCurator1.java similarity index 88% rename from src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockCurator1.java rename to src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockmember/WithMockCurator1.java index 0b1a6097..b1ee3cc4 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockCurator1.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockmember/WithMockCurator1.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin._global.mockMember; +package org.ktc2.cokaen.wouldyouin._global.mockmember; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockCustomUser.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockmember/WithMockCustomUser.java similarity index 88% rename from src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockCustomUser.java rename to src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockmember/WithMockCustomUser.java index 742a7324..ae26e6e5 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockCustomUser.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockmember/WithMockCustomUser.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin._global.mockMember; +package org.ktc2.cokaen.wouldyouin._global.mockmember; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockCustomUserSecurityContextFactory.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockmember/WithMockCustomUserSecurityContextFactory.java similarity index 95% rename from src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockCustomUserSecurityContextFactory.java rename to src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockmember/WithMockCustomUserSecurityContextFactory.java index 4c164a2b..0e7e0773 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockCustomUserSecurityContextFactory.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockmember/WithMockCustomUserSecurityContextFactory.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin._global.mockMember; +package org.ktc2.cokaen.wouldyouin._global.mockmember; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.auth.persist.CustomUserDetails; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockHost1.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockmember/WithMockHost1.java similarity index 86% rename from src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockHost1.java rename to src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockmember/WithMockHost1.java index 41dcf575..783da542 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockHost1.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockmember/WithMockHost1.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin._global.mockMember; +package org.ktc2.cokaen.wouldyouin._global.mockmember; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockMember1.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockmember/WithMockMember1.java similarity index 87% rename from src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockMember1.java rename to src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockmember/WithMockMember1.java index c533cb6e..62c0957b 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockMember1.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockmember/WithMockMember1.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin._global.mockMember; +package org.ktc2.cokaen.wouldyouin._global.mockmember; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockWelcomeMember1.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockmember/WithMockWelcomeMember1.java similarity index 87% rename from src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockWelcomeMember1.java rename to src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockmember/WithMockWelcomeMember1.java index e3717250..ec241e3f 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockWelcomeMember1.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockmember/WithMockWelcomeMember1.java @@ -1,4 +1,4 @@ -package org.ktc2.cokaen.wouldyouin._global.mockMember; +package org.ktc2.cokaen.wouldyouin._global.mockmember; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java index f084180f..99fa3240 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java @@ -17,7 +17,7 @@ import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; import org.ktc2.cokaen.wouldyouin.curation.persist.CurationCard; import org.ktc2.cokaen.wouldyouin.event.persist.Event; -import org.ktc2.cokaen.wouldyouin.image.persist.CurationImage; +import org.ktc2.cokaen.wouldyouin.image.persist.CurationCardImage; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Slice; import org.springframework.data.domain.SliceImpl; @@ -32,7 +32,7 @@ public static class curationCard1 { public static final Long id = 351L; public static final String subtitle = "큐레이션 카드 부제목1"; public static final String content = "큐레이션 카드 내용1 입니다. 큐레이션 카드의 내용은 최소 20자 최대 1000자 입니다."; - public static final List images = List.of(ImageData.curation1.entity.get()); + public static final List images = List.of(ImageData.curation1.entity.get()); public static final List imageIds = List.of(ImageData.R.curation1.id); public static final List imageUrls = List.of(ImageData.R.curation1.url); } @@ -42,7 +42,7 @@ public static class curationCard2 { public static final Long id = 352L; public static final String subtitle = "큐레이션 카드 부제목2"; public static final String content = "큐레이션 카드 내용2 입니다. 큐레이션 카드의 내용은 최소 20자 최대 1000자 입니다."; - public static final List images = List.of(ImageData.curation2.entity.get()); + public static final List images = List.of(ImageData.curation2.entity.get()); public static final List imageIds = List.of(ImageData.R.curation2.id); public static final List imageUrls = List.of(ImageData.R.curation2.url); } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ImageData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ImageData.java index b2d79d41..3cf0e590 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ImageData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ImageData.java @@ -4,7 +4,7 @@ import org.ktc2.cokaen.wouldyouin.image.api.dto.ImageRequest; import org.ktc2.cokaen.wouldyouin.image.api.dto.ImageResponse; import org.ktc2.cokaen.wouldyouin.image.persist.AdvertisementImage; -import org.ktc2.cokaen.wouldyouin.image.persist.CurationImage; +import org.ktc2.cokaen.wouldyouin.image.persist.CurationCardImage; import org.ktc2.cokaen.wouldyouin.image.persist.EventImage; import org.ktc2.cokaen.wouldyouin.image.persist.Image; import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; @@ -29,7 +29,7 @@ public static class childPath { public static String getThumbnailUrl(AdvertisementImage image) { return CommonData.path.domainUrl + childPath.advertisement + "/thumbnails/" + image.getName(); } - public static String getThumbnailUrl(CurationImage image) { + public static String getThumbnailUrl(CurationCardImage image) { return CommonData.path.domainUrl + childPath.curation + "/thumbnails/" + image.getName(); } public static String getThumbnailUrl(EventImage image) { @@ -423,8 +423,8 @@ public static class response { public static class curation1 { public static class entity { - public static CurationImage get() { - CurationImage ret = CurationImage.builder() + public static CurationCardImage get() { + CurationCardImage ret = CurationCardImage.builder() .name(R.curation1.name) .size(R.curation1.size) .extension(R.curation1.extension) @@ -457,8 +457,8 @@ public static ImageResponse get() { } public static class curation2 { public static class entity { - public static CurationImage get() { - CurationImage ret = CurationImage.builder() + public static CurationCardImage get() { + CurationCardImage ret = CurationCardImage.builder() .name(R.curation2.name) .size(R.curation2.size) .extension(R.curation2.extension) @@ -491,8 +491,8 @@ public static ImageResponse get() { } public static class curation3 { public static class entity { - public static CurationImage get() { - CurationImage ret = CurationImage.builder() + public static CurationCardImage get() { + CurationCardImage ret = CurationCardImage.builder() .name(R.curation3.name) .size(R.curation3.size) .extension(R.curation3.extension) @@ -525,8 +525,8 @@ public static ImageResponse get() { } public static class curation4 { public static class entity { - public static CurationImage get() { - CurationImage ret = CurationImage.builder() + public static CurationCardImage get() { + CurationCardImage ret = CurationCardImage.builder() .name(R.curation4.name) .size(R.curation4.size) .extension(R.curation4.extension) @@ -559,8 +559,8 @@ public static ImageResponse get() { } public static class curation5 { public static class entity { - public static CurationImage get() { - CurationImage ret = CurationImage.builder() + public static CurationCardImage get() { + CurationCardImage ret = CurationCardImage.builder() .name(R.curation5.name) .size(R.curation5.size) .extension(R.curation5.extension) @@ -593,8 +593,8 @@ public static ImageResponse get() { } public static class curation6 { public static class entity { - public static CurationImage get() { - CurationImage ret = CurationImage.builder() + public static CurationCardImage get() { + CurationCardImage ret = CurationCardImage.builder() .name(R.curation6.name) .size(R.curation6.size) .extension(R.curation6.extension) @@ -627,8 +627,8 @@ public static ImageResponse get() { } public static class curation7 { public static class entity { - public static CurationImage get() { - CurationImage ret = CurationImage.builder() + public static CurationCardImage get() { + CurationCardImage ret = CurationCardImage.builder() .name(R.curation7.name) .size(R.curation7.size) .extension(R.curation7.extension) @@ -661,8 +661,8 @@ public static ImageResponse get() { } public static class curation8 { public static class entity { - public static CurationImage get() { - CurationImage ret = CurationImage.builder() + public static CurationCardImage get() { + CurationCardImage ret = CurationCardImage.builder() .name(R.curation8.name) .size(R.curation8.size) .extension(R.curation8.extension) diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java index 172396da..1343a924 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java @@ -22,9 +22,9 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.ktc2.cokaen.wouldyouin._common.vo.Area; -import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockCurator1; -import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost1; -import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember1; +import org.ktc2.cokaen.wouldyouin._global.mockmember.WithMockCurator1; +import org.ktc2.cokaen.wouldyouin._global.mockmember.WithMockHost1; +import org.ktc2.cokaen.wouldyouin._global.mockmember.WithMockMember1; import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData; import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.curation1; import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator1; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java index 2e3aa9e1..1727dead 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java @@ -24,9 +24,9 @@ import org.junit.jupiter.api.Test; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; -import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockCurator1; -import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost1; -import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember1; +import org.ktc2.cokaen.wouldyouin._global.mockmember.WithMockCurator1; +import org.ktc2.cokaen.wouldyouin._global.mockmember.WithMockHost1; +import org.ktc2.cokaen.wouldyouin._global.mockmember.WithMockMember1; import org.ktc2.cokaen.wouldyouin._global.testdata.EventData; import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host1; import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/image/CurationImageServiceTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/image/CurationCardImageServiceTest.java similarity index 64% rename from src/test/java/org/ktc2/cokaen/wouldyouin/image/CurationImageServiceTest.java rename to src/test/java/org/ktc2/cokaen/wouldyouin/image/CurationCardImageServiceTest.java index dde61a18..5d57121a 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/image/CurationImageServiceTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/image/CurationCardImageServiceTest.java @@ -5,27 +5,23 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; -import static org.mockito.BDDMockito.then; -import static org.mockito.Mockito.times; import java.util.Optional; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData; import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.R.curation1; import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData; -import org.ktc2.cokaen.wouldyouin.image.application.AdvertisementImageService; import org.ktc2.cokaen.wouldyouin.image.application.CurationImageService; import org.ktc2.cokaen.wouldyouin.image.application.ImageStorageService; -import org.ktc2.cokaen.wouldyouin.image.persist.CurationImage; -import org.ktc2.cokaen.wouldyouin.image.persist.CurationImageRepository; +import org.ktc2.cokaen.wouldyouin.image.persist.CurationCardImage; +import org.ktc2.cokaen.wouldyouin.image.persist.CurationCardImageRepository; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -public class CurationImageServiceTest { +public class CurationCardImageServiceTest { private CurationImageService curationImageService; @@ -33,21 +29,22 @@ public class CurationImageServiceTest { private ImageStorageService imageStorageService; @Mock - private CurationImageRepository curationImageRepository; + private CurationCardImageRepository curationCardImageRepository; @BeforeEach void setUp() { - curationImageService = new CurationImageService(imageStorageService, curationImageRepository); + curationImageService = new CurationImageService(imageStorageService, + curationCardImageRepository); } @Test @DisplayName("이미지 ID를 통해 큐레이션 이미지를 반환한다.") void getById() { // given - given(curationImageRepository.findById(curation1.id)).willReturn(Optional.of(ImageData.curation1.entity.get())); + given(curationCardImageRepository.findById(curation1.id)).willReturn(Optional.of(ImageData.curation1.entity.get())); // when - CurationImage response = curationImageService.getById(curation1.id); + CurationCardImage response = curationImageService.getById(curation1.id); // then assertThat(response).isEqualTo(ImageData.curation1.entity.get()); @@ -57,8 +54,8 @@ void getById() { // @DisplayName("이미지 ID를 통해 해당 이미지를 삭제한다.") // void deleteImage() { // // given -// CurationImage image = ImageData.curation1.entity.get(); -// given(curationImageRepository.findById(curation1.id)).willReturn(Optional.of(image)); +// CurationCardImage image = ImageData.curation1.entity.get(); +// given(curationCardImageRepository.findById(curation1.id)).willReturn(Optional.of(image)); // // // when, then // then(imageStorageService).should(times(1)).delete(eq(image.getName()), any()); diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java index c636128f..4b381670 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java @@ -20,8 +20,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockCurator1; -import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember1; +import org.ktc2.cokaen.wouldyouin._global.mockmember.WithMockCurator1; +import org.ktc2.cokaen.wouldyouin._global.mockmember.WithMockMember1; import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData; import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.mockMultipartFile1; import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.mockMultipartFile2; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/like/LikeControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/like/LikeControllerUnitTest.java index 15acb4e3..ad2a69d1 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/like/LikeControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/like/LikeControllerUnitTest.java @@ -17,9 +17,9 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockCurator1; -import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost1; -import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember1; +import org.ktc2.cokaen.wouldyouin._global.mockmember.WithMockCurator1; +import org.ktc2.cokaen.wouldyouin._global.mockmember.WithMockHost1; +import org.ktc2.cokaen.wouldyouin._global.mockmember.WithMockMember1; import org.ktc2.cokaen.wouldyouin._global.testdata.LikeData; import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator1; import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.normal1; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberServiceUnitTest.java index e42f0318..395c428e 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberServiceUnitTest.java @@ -23,6 +23,7 @@ import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.normal1; import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.welcome1; import org.ktc2.cokaen.wouldyouin.member.api.dto.MemberResponse; +import org.ktc2.cokaen.wouldyouin.member.exception.EmailAlreadyExistsException; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMember; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMemberRepository; import org.ktc2.cokaen.wouldyouin.member.persist.Curator; @@ -146,8 +147,7 @@ void checkUniqueEmailOrThrow(long id) { given(baseMemberRepository.findByEmail(email)).willReturn(optionalMember); // when & then - // TODO: 커스텀 예외 처리 필요 - assertThrows(RuntimeException.class, () -> baseMemberService.checkUniqueEmailOrThrow(email)); + assertThrows(EmailAlreadyExistsException.class, () -> baseMemberService.checkUniqueEmailOrThrow(email)); then(baseMemberRepository).should(times(1)).findByEmail(email); } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java index 1a22a91f..de970f6f 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java @@ -20,6 +20,7 @@ import org.ktc2.cokaen.wouldyouin.member.api.dto.request.MemberAdditionalInfoRequest; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.create.MemberCreateRequest; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit.MemberEditRequest; +import org.ktc2.cokaen.wouldyouin.member.exception.AdditionalInfoIllegalAccessException; import org.ktc2.cokaen.wouldyouin.member.persist.Member; import org.ktc2.cokaen.wouldyouin.member.persist.MemberRepository; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @@ -123,8 +124,7 @@ void updateWelcomeMember_NormalMemberUsage() { given(memberRepository.findById(validMember.getId())).willReturn(Optional.of(validMember)); // when & then - // TODO: 커스텀 예외 필요 - assertThrows(RuntimeException.class, () -> + assertThrows(AdditionalInfoIllegalAccessException.class, () -> memberService.updateWelcomeMember(validMember.getId(), memberAdditionalInfoRequest)); // then diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java index 7d1dcc09..3fd6996f 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java @@ -19,10 +19,9 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockCurator1; -import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost1; -import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember1; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; +import org.ktc2.cokaen.wouldyouin._global.mockmember.WithMockCurator1; +import org.ktc2.cokaen.wouldyouin._global.mockmember.WithMockHost1; +import org.ktc2.cokaen.wouldyouin._global.mockmember.WithMockMember1; import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator1; import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host1; import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.normal1; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationServiceUnitTest.java index fc44cc7b..d58454e1 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationServiceUnitTest.java @@ -13,7 +13,7 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.ktc2.cokaen.wouldyouin._common.exception.ReservationNotFoundForReviewException; +import org.ktc2.cokaen.wouldyouin.reservation.exception.ReservationNotFoundForReviewException; import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.normal1; import org.ktc2.cokaen.wouldyouin._global.testdata.ReservationData; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/review/ReviewControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/review/ReviewControllerUnitTest.java index d7fcf7e8..d34f7790 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/review/ReviewControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/review/ReviewControllerUnitTest.java @@ -20,9 +20,9 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockCurator1; -import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost1; -import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember1; +import org.ktc2.cokaen.wouldyouin._global.mockmember.WithMockCurator1; +import org.ktc2.cokaen.wouldyouin._global.mockmember.WithMockHost1; +import org.ktc2.cokaen.wouldyouin._global.mockmember.WithMockMember1; import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator1; import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.normal1; import org.ktc2.cokaen.wouldyouin._global.testdata.ReviewData; From 5b8986727e36a5932de0c5358eddfb65b5679bf5 Mon Sep 17 00:00:00 2001 From: ariimo Date: Fri, 15 Nov 2024 15:57:55 +0900 Subject: [PATCH 51/53] =?UTF-8?q?[Weekly/11/Test/Event]=20EventServiceUnit?= =?UTF-8?q?Test=20=EC=9E=91=EC=84=B1=20(#146)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Weekly/10/Test/CurationController] curationControllerUnitTest 2 (#90) * feat: EventServiceUnitTest 작성 --- .../event/application/EventService.java | 5 +- .../_global/testdata/CommonData.java | 9 + .../_global/testdata/EventData.java | 86 +++- .../event/EventServiceUnitTest.java | 463 +++++++++--------- 4 files changed, 335 insertions(+), 228 deletions(-) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java index 3d077085..2d0c25d4 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java @@ -110,8 +110,9 @@ public EventResponse update(MemberIdentifier identifier, Long eventId, EventEdit @Transactional public void delete(MemberIdentifier identifier, Long eventId) { - validateHostId(identifier, getByIdOrThrow(eventId)); - eventImageService.deleteImage(identifier, eventId); + Event event = getByIdOrThrow(eventId); + validateHostId(identifier, event); + event.getImages().forEach(eventImage -> eventImageService.deleteImage(identifier, eventImage.getId())); eventRepository.deleteById(eventId); } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java index e956adae..7698524b 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java @@ -2,6 +2,7 @@ import org.ktc2.cokaen.wouldyouin._common.api.SliceInfo; import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.R.curation1; +import org.ktc2.cokaen.wouldyouin._global.testdata.EventData.R.event1; import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R; import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator1; import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host1; @@ -16,6 +17,14 @@ public static class path { } public static class sliceInfo { + public static class event{ + public static SliceInfo get(){ + return SliceInfo.builder() + .sliceSize(10) + .lastId(event1.id) + .build(); + } + } public static class curation { diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/EventData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/EventData.java index 068d7988..cd689051 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/EventData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/EventData.java @@ -5,15 +5,25 @@ import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; import org.ktc2.cokaen.wouldyouin._common.vo.Location; +import org.ktc2.cokaen.wouldyouin._global.testdata.EventData.R.event1; +import org.ktc2.cokaen.wouldyouin._global.testdata.EventData.R.event1._Dto.editRequest1; +import org.ktc2.cokaen.wouldyouin._global.testdata.EventData.R.event1._Relation; +import org.ktc2.cokaen.wouldyouin._global.testdata.EventData.R.updatedEvent1; +import org.ktc2.cokaen.wouldyouin._global.testdata.EventData.event1.entity; +import org.ktc2.cokaen.wouldyouin._global.testdata.EventData.event1.response; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventResponse; +import org.ktc2.cokaen.wouldyouin.event.api.dto.EventSliceResponse; import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.CurationEventResponse; import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.ReservationEventResponse; import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.ReviewEventResponse; import org.ktc2.cokaen.wouldyouin.event.persist.Event; import org.ktc2.cokaen.wouldyouin.image.persist.EventImage; import org.ktc2.cokaen.wouldyouin.member.persist.Host; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Slice; +import org.springframework.data.domain.SliceImpl; import org.springframework.test.util.ReflectionTestUtils; public class EventData { @@ -34,6 +44,8 @@ public static class event1 { public static final Integer totalSeat = 100; public static final Integer leftSeat = 10; public static final Category category = Category.밴드; + public static final Long lastId = 100L; + public static final PageRequest pageable = PageRequest.of(0, 10); public static final String thumbnailUrl = ImageData.getThumbnailUrl( _Relation.images().getFirst()); public static final LocalDateTime createdDate = LocalDateTime.now().minusDays(1); @@ -81,6 +93,25 @@ public static class editRequest1 { } } + public static class updatedEvent1{ + public static final long id = event1.id; + public static final String title = editRequest1.title; + public static final String content = editRequest1.content; + public static final Area area = editRequest1.area; + public static final Location location = editRequest1.location; + public static final LocalDateTime startTime = editRequest1.startTime; + public static final LocalDateTime endTime = editRequest1.endTime; + public static final Integer price = editRequest1.price; + public static final Integer totalSeat = editRequest1.totalSeat; + public static final Integer leftSeat = 10; + public static final Category category = editRequest1.category; + public static final Long lastId = 100L; + public static final List images = List.of(ImageData.event4.entity.get(), ImageData.event5.entity.get()); + public static final String thumbnailUrl = ImageData.getThumbnailUrl( + images.getFirst()); + public static final LocalDateTime createdDate = LocalDateTime.now().minusDays(1); + } + public static class event2 { public static final long id = 202L; @@ -165,8 +196,6 @@ public static Event get() { ReflectionTestUtils.setField(ret, "id", R.event1.id); ReflectionTestUtils.setField(ret, "leftSeat", R.event1.leftSeat); - ret.getHost().setEvents(List.of(ret)); - ret.getImages().forEach(image -> image.setEvent(ret)); return ret; } } @@ -242,6 +271,52 @@ public static EventResponse get() { return EventResponse.from(EventData.event1.entity.get(), R.event1._Relation.imageUrls()); } + + public static class slice{ + public static EventSliceResponse get(){ + return EventSliceResponse.builder() + .events(List.of(response.get())) + .sliceInfo(CommonData.sliceInfo.event.get()) + .build(); + } + } + } + } + + public static class updatedEvent1{ + public static class entity { + + public static Event get() { + Event ret = Event.builder() + .title(R.updatedEvent1.title) + .content(R.updatedEvent1.content) + .host(R.event1._Relation.host()) + .area(R.updatedEvent1.area) + .location(R.updatedEvent1.location) + .startTime(R.updatedEvent1.startTime) + .endTime(R.updatedEvent1.endTime) + .price(R.updatedEvent1.price) + .totalSeat(R.updatedEvent1.totalSeat) + .category(R.updatedEvent1.category) + .images(R.updatedEvent1.images) + .thumbnailUrl(R.updatedEvent1.thumbnailUrl) + .build(); + + ReflectionTestUtils.setField(ret, "id", R.updatedEvent1.id); + ReflectionTestUtils.setField(ret, "leftSeat", R.updatedEvent1.leftSeat); + return ret; + } + } + public static class response { + + public static EventResponse get() { + List imageUrls= List.of( + ImageData.R.event4.url, + ImageData.R.event5.url); + + return EventResponse.from(EventData.updatedEvent1.entity.get(), + imageUrls); + } } } @@ -268,4 +343,11 @@ public static CurationEventResponse createValidCurationEventResponse() { } } } + + public static class EventSlice{ + + public static Slice get(){ + return new SliceImpl<>(List.of(entity.get()), R.event1.pageable, true); + } + } } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java index e0f17cfa..72cc7420 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java @@ -1,224 +1,239 @@ -//package org.ktc2.cokaen.wouldyouin.event; -// -//import static org.junit.jupiter.api.Assertions.assertAll; -//import static org.junit.jupiter.api.Assertions.assertEquals; -//import static org.junit.jupiter.api.Assertions.assertThrows; -//import static org.mockito.ArgumentMatchers.any; -//import static org.mockito.BDDMockito.given; -//import static org.mockito.BDDMockito.then; -//import static org.mockito.BDDMockito.willDoNothing; -//import static org.mockito.Mockito.times; -// -//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.Test; -//import org.junit.jupiter.api.extension.ExtendWith; -//import org.ktc2.cokaen.wouldyouin.image.application.EventImageService; -//import org.ktc2.cokaen.wouldyouin.image.application.MemberImageService; -//import org.ktc2.cokaen.wouldyouin._common.vo.Area; -//import org.ktc2.cokaen.wouldyouin._common.vo.Category; -//import org.ktc2.cokaen.wouldyouin._global.testdata.EventData; -//import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host1; -//import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; -//import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationFilter; -//import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; -//import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; -//import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationRequest; -//import org.ktc2.cokaen.wouldyouin.event.application.EventService; -//import org.ktc2.cokaen.wouldyouin.event.persist.Event; -//import org.ktc2.cokaen.wouldyouin.event.persist.EventRepository; -//import org.ktc2.cokaen.wouldyouin.member.application.HostService; -//import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; -//import org.mockito.Mock; -//import org.mockito.junit.jupiter.MockitoExtension; -//import org.springframework.data.domain.PageRequest; -//import org.springframework.data.domain.Pageable; -//import org.springframework.data.domain.SliceImpl; -// -//@ExtendWith(MockitoExtension.class) -//class EventServiceUnitTest { -// -// private EventService eventService; -// -// @Mock -// private EventRepository eventRepository; -// -// @Mock -// private HostService hostService; -// -// @Mock -// private EventImageService eventImageService; -// -// @Mock -// private MemberImageService memberImageService; -// -// private Event validEvent; -// -// @BeforeEach -// void setUp() { -// eventService = new EventService(eventRepository, hostService, eventImageService, memberImageService); -// validEvent = EventData.event1.entity.get(); -// } -// -// @Test -// @DisplayName("모든 행사 조회 - 성공") -// void getAllByFilterOrderByDistanceAsc() { -// // given -// LocationFilter location = new LocationFilter(); -// LocationRequest currentLocation = new LocationRequest(3.0, 2.0); -// String title = "testTitle"; -// Category category = Category.공예; -// Area area = Area.광주; -// int pageNumber = 1; -// int pageSize = 10; -// Pageable pageable = PageRequest.of(pageNumber, pageSize); -// Long lastId = 1L; -// given(eventRepository.findAllByFilterOrderByDistance(location.getStartLatitude(), -// location.getStartLongitude(), -// location.getEndLatitude(), location.getEndLongitude(), currentLocation.getLatitude(), -// currentLocation.getLongitude(), title, category, area, pageable)).willReturn( -// new SliceImpl<>(List.of())); -// -// // when -// eventService.getAllByFilterOrderByDistanceAsc(location, currentLocation, title, category, -// area, pageable, lastId); -// -// // then -// then(eventRepository).should(times(1)) -// .findAllByFilterOrderByDistance(any(Double.class), any(Double.class), any(Double.class), -// any(Double.class), any(Double.class), any(Double.class), -// any(Category.class), any(Area.class), any(Pageable.class)); -// } -// -// @Test -// @DisplayName("주최자 id를 통한 모든 행사 조회 - 성공") -// void getAllByHostIdOrderByCreatedDateDesc() { -// // given -// Long hostId = validEvent.getHost().getId(); -// int pageNumber = 1; -// int pageSize = 10; -// Pageable pageable = PageRequest.of(pageNumber, pageSize); -// Long lastId = 1L; -// given(eventRepository.findAllByHostIdOrderByEventIdDesc(hostId, lastId, pageable)) -// .willReturn(new SliceImpl<>(List.of())); -// -// // when -// eventService.getAllByHostIdOrderByCreatedDateDesc(hostId, pageable, lastId); -// -// // then -// then(eventRepository).should(times(1)). -// findAllByHostIdOrderByEventIdDesc(any(Long.class), any(Long.class), -// any(Pageable.class)); -// } -// -// @Test -// @DisplayName("행사 id를 통한 행사 조회 - 성공") -// void getById() { -// // given -// given(eventRepository.findById(validEvent.getId())).willReturn(Optional.of(validEvent)); -// -// // when -// eventService.getById(validEvent.getId()); -// -// // then -// then(eventRepository).should(times(1)).findById(validEvent.getId()); -// } -// -// @Test -// @DisplayName("유효하지 않은 행사 id를 통한 행사 조회 - 실패") -// void getByInvalidId() { -// // given -// Long eventId = validEvent.getId(); -// given(eventRepository.findById(eventId)).willThrow(RuntimeException.class); -// -// // when & then -// assertThrows(RuntimeException.class, () -> eventService.getById(eventId)); -// } -// -// @Test -// @DisplayName("행사 생성 - 성공") -// void create() { -// // given -// Long hostId = validEvent.getHost().getId(); -// EventCreateRequest validEventCreateRequest = EventData.event1.request.create.get(); -// given(eventRepository.save(any())).willReturn(validEvent); -// -// // when -// eventService.create(host1.memberIdentifier, validEventCreateRequest); -// -// // then -// then(eventRepository).should(times(1)).save(any(Event.class)); -// } -// -// @Test -// @DisplayName("행사 id를 통한 행사 수정 - 성공") -// void update() { -// // given -// Long eventId = validEvent.getId(); -// Long hostId = validEvent.getHost().getId(); -// EventEditRequest validEventEditRequest = EventData.event1.request.edit1.get(); -// given(eventRepository.findById(eventId)).willReturn(Optional.of(validEvent)); -// -// // when -// eventService.update(host1.memberIdentifier, eventId, validEventEditRequest); -// -// // then -// then(eventRepository).should(times(1)).findById(eventId); -// assertAll( -// () -> assertEquals(validEvent.getTitle(), validEventEditRequest.getTitle()), -// () -> assertEquals(validEvent.getContent(), validEventEditRequest.getContent()), -// () -> assertEquals(validEvent.getArea(), validEventEditRequest.getArea()), -// () -> assertEquals(validEvent.getLocation(), validEventEditRequest.getLocation()), -// () -> assertEquals(validEvent.getStartTime(), validEventEditRequest.getStartTime()), -// () -> assertEquals(validEvent.getEndTime(), validEventEditRequest.getEndTime()), -// () -> assertEquals(validEvent.getPrice(), validEventEditRequest.getPrice()), -// () -> assertEquals(validEvent.getTotalSeat(), validEventEditRequest.getTotalSeat()), -// () -> assertEquals(validEvent.getCategory(), validEventEditRequest.getCategory()) -// ); -// } -// -// @Test -// @DisplayName("유효하지 않은 행사 id를 통한 행사 수정 - 실패") -// void updateByInvalidId() { -// // given -// EventEditRequest request = EventData.event1.request.edit1.get(); -// Long invalidHostId = 999L; -// given(eventRepository.findById(invalidHostId)).willThrow(RuntimeException.class); -// -// // when & then -// assertThrows(RuntimeException.class, -// () -> eventService.update(new MemberIdentifier(invalidHostId, MemberType.host), validEvent.getId(), -// EventData.event1.request.edit1.get())); -// } -// -// @Test -// @DisplayName("행사 삭제 - 성공") -// void delete() { -// // given -// Long eventId = validEvent.getId(); -// Long hostId = validEvent.getHost().getId(); -// -// // when -// given(eventRepository.findById(eventId)).willReturn(Optional.of(validEvent)); -// willDoNothing().given(eventRepository).deleteById(eventId); -// eventService.delete(host1.memberIdentifier, eventId); -// -// // then -// then(eventRepository).should(times(1)).findById(eventId); -// then(eventRepository).should(times(1)).deleteById(eventId); -// } -// -// @Test -// @DisplayName("유효하지 않은 행사 id를 통한 행사 삭제 - 실패") -// void deleteByInvalidId() { -// // given -// Long eventId = validEvent.getId(); -// Long hostId = validEvent.getHost().getId(); -// given(eventRepository.findById(eventId)).willThrow(RuntimeException.class); -// -// // when & then -// assertThrows(RuntimeException.class, () -> eventService.delete(host1.memberIdentifier, eventId)); -// } -//} \ No newline at end of file +package org.ktc2.cokaen.wouldyouin.event; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; +import static org.mockito.Mockito.times; + +import java.util.Optional; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; +import org.ktc2.cokaen.wouldyouin._common.vo.Area; +import org.ktc2.cokaen.wouldyouin._common.vo.Category; +import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData; +import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.R.curation1; +import org.ktc2.cokaen.wouldyouin._global.testdata.EventData; +import org.ktc2.cokaen.wouldyouin._global.testdata.EventData.EventSlice; +import org.ktc2.cokaen.wouldyouin._global.testdata.EventData.R.event1; +import org.ktc2.cokaen.wouldyouin._global.testdata.EventData.R.updatedEvent1; +import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData; +import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.R; +import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.R.event4; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host1; +import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; +import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; +import org.ktc2.cokaen.wouldyouin.event.api.dto.EventResponse; +import org.ktc2.cokaen.wouldyouin.event.api.dto.EventSliceResponse; +import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationFilter; +import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationRequest; +import org.ktc2.cokaen.wouldyouin.event.application.EventService; +import org.ktc2.cokaen.wouldyouin.event.persist.Event; +import org.ktc2.cokaen.wouldyouin.event.persist.EventRepository; +import org.ktc2.cokaen.wouldyouin.image.application.EventImageService; +import org.ktc2.cokaen.wouldyouin.image.application.MemberImageService; +import org.ktc2.cokaen.wouldyouin.image.persist.EventImage; +import org.ktc2.cokaen.wouldyouin.member.application.HostService; +import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.data.domain.PageRequest; + +@ExtendWith(MockitoExtension.class) +class EventServiceUnitTest { + + private EventService eventService; + + @Mock + private EventRepository eventRepository; + + @Mock + private HostService hostService; + + @Mock + private EventImageService eventImageService; + + @Mock + private MemberImageService memberImageService; + + @BeforeEach + void setUp() { + eventService = new EventService(eventRepository, hostService, eventImageService, + memberImageService); + } + + @Test + @DisplayName("행사 ID를 통해 해당하는 행사를 반환한다.") + void getById() { + // given + given(eventRepository.findById(event1.id)).willReturn( + Optional.of(EventData.event1.entity.get())); + EventImage eventImage1 = EventData.event1.entity.get().getImages().get(0); + EventImage eventImage2 = EventData.event1.entity.get().getImages().get(1); + EventImage eventImage3 = EventData.event1.entity.get().getImages().get(2); + given(eventImageService.getImageUrl(eventImage1)).willReturn(R.event1.url); + given(eventImageService.getImageUrl(eventImage2)).willReturn(R.event2.url); + given(eventImageService.getImageUrl(eventImage3)).willReturn(R.event3.url); + // when + EventResponse response = eventService.getById(event1.id); + + // then + assertThat(response).isEqualTo(EventData.event1.response.get()); + } + + @Test + @DisplayName("거리에 따른 이벤트들을 반환한다. ") + void getAllByFilterOrderByDistanceAsc() { + // given + LocationFilter location = new LocationFilter(0.0, 0.0, 10.0, 10.0); + LocationRequest currentLocation = new LocationRequest(3.0, 2.0); + given(eventRepository.findAllByFilterOrderByDistance( + location.getStartLatitude(), location.getStartLongitude(), + location.getEndLatitude(), location.getEndLongitude(), + currentLocation.getLatitude(), currentLocation.getLongitude(), + event1.title, event1.category, event1.area, event1.pageable)) + .willReturn(EventData.EventSlice.get()); + EventImage eventImage1 = EventData.event1.entity.get().getImages().get(0); + EventImage eventImage2 = EventData.event1.entity.get().getImages().get(1); + EventImage eventImage3 = EventData.event1.entity.get().getImages().get(2); + given(eventImageService.getImageUrl(eventImage1)).willReturn(R.event1.url); + given(eventImageService.getImageUrl(eventImage2)).willReturn(R.event2.url); + given(eventImageService.getImageUrl(eventImage3)).willReturn(R.event3.url); + + // when + EventSliceResponse responses = eventService.getAllByFilterOrderByDistanceAsc( + location, currentLocation, event1.title, event1.category, event1.area, event1.pageable, event1.lastId); + + // then + assertThat(responses).isEqualTo(EventData.event1.response.slice.get()); + } + + @Test + @DisplayName("Host ID를 통해 해당하는 모든 이벤트를 반환한다.") + void getAllByHostIdOrderByCreatedDateDesc() { + // given + given(eventRepository.findAllByHostIdOrderByEventIdDesc(host1.id, event1.lastId, event1.pageable)) + .willReturn(EventData.EventSlice.get()); + EventImage eventImage1 = EventData.event1.entity.get().getImages().get(0); + EventImage eventImage2 = EventData.event1.entity.get().getImages().get(1); + EventImage eventImage3 = EventData.event1.entity.get().getImages().get(2); + given(eventImageService.getImageUrl(eventImage1)).willReturn(R.event1.url); + given(eventImageService.getImageUrl(eventImage2)).willReturn(R.event2.url); + given(eventImageService.getImageUrl(eventImage3)).willReturn(R.event3.url); + + // when + EventSliceResponse responses = eventService.getAllByHostIdOrderByCreatedDateDesc(host1.id, event1.pageable, event1.lastId); + + // then + assertThat(responses).isEqualTo(EventData.event1.response.slice.get()); + } + + @Test + @DisplayName("모든 이벤트를 반환한다.") + void getAllByCreatedDateDesc() { + // given + given(eventRepository.findAllByEventIdDesc(event1.lastId, event1.pageable)) + .willReturn(EventData.EventSlice.get()); + EventImage eventImage1 = EventData.event1.entity.get().getImages().get(0); + EventImage eventImage2 = EventData.event1.entity.get().getImages().get(1); + EventImage eventImage3 = EventData.event1.entity.get().getImages().get(2); + given(eventImageService.getImageUrl(eventImage1)).willReturn(R.event1.url); + given(eventImageService.getImageUrl(eventImage2)).willReturn(R.event2.url); + given(eventImageService.getImageUrl(eventImage3)).willReturn(R.event3.url); + + // when + EventSliceResponse responses = eventService.getAllByCreatedDateDesc(event1.pageable, event1.lastId); + + // then + assertThat(responses).isEqualTo(EventData.event1.response.slice.get()); + } + @Test + @DisplayName("EventCreateRequest를 통해 이벤트를 생성한다.") + void create() { + // given + given(hostService.getByIdOrThrow(host1.id)).willReturn(MemberData.host1.entity.get()); + given(eventImageService.getById(R.event1.id)).willReturn(ImageData.event1.entity.get()); + given(eventImageService.getById(R.event2.id)).willReturn(ImageData.event2.entity.get()); + given(eventImageService.getById(R.event3.id)).willReturn(ImageData.event3.entity.get()); + EventImage eventImage1 = EventData.event1.entity.get().getImages().get(0); + EventImage eventImage2 = EventData.event1.entity.get().getImages().get(1); + EventImage eventImage3 = EventData.event1.entity.get().getImages().get(2); + given(eventImageService.getImageUrl(eventImage1)).willReturn(R.event1.url); + given(eventImageService.getImageUrl(eventImage2)).willReturn(R.event2.url); + given(eventImageService.getImageUrl(eventImage3)).willReturn(R.event3.url); + given(eventRepository.save(any(Event.class))).willReturn(EventData.event1.entity.get()); + + // when + EventResponse response = eventService.create(host1.memberIdentifier, EventData.event1.request.create.get()); + + // then + assertThat(response).isEqualTo(EventData.event1.response.get()); + } + + @Test + @DisplayName("EventEditRequest를 통해 이벤트를 수정한다.") + void update1() { + // given + given(eventRepository.findById(event1.id)).willReturn(Optional.of(EventData.event1.entity.get())); + given(eventImageService.getById(R.event4.id)).willReturn(ImageData.event4.entity.get()); + given(eventImageService.getById(R.event5.id)).willReturn(ImageData.event5.entity.get()); + given(eventImageService.createThumbnail(event4.name)).willReturn(updatedEvent1.thumbnailUrl); + EventImage eventImage4 = EventData.updatedEvent1.entity.get().getImages().get(0); + EventImage eventImage5 = EventData.updatedEvent1.entity.get().getImages().get(1); + given(eventImageService.getImageUrl(eventImage4)).willReturn(R.event4.url); + given(eventImageService.getImageUrl(eventImage5)).willReturn(R.event5.url); + + // when + EventResponse response = eventService.update(host1.memberIdentifier, event1.id, + EventData.event1.request.edit1.get()); + + // then + then(eventImageService).should(times(3)).deleteImage(any(MemberIdentifier.class), any(Long.class)); + assertThat(response).isEqualTo(EventData.updatedEvent1.response.get()); + } + + @Test + @DisplayName("Host ID가 다르면 큐레이션을 수정할 수 없다.") + void update2() { + // given + MemberIdentifier differentMember = new MemberIdentifier(100L, MemberType.host); + given(eventRepository.findById(event1.id)).willReturn(Optional.of(EventData.event1.entity.get())); + + // when, then + UnauthorizedException exception = assertThrows( + UnauthorizedException.class, () -> eventService.update(differentMember, event1.id, EventData.event1.request.edit1.get())); + assertThat(exception.getMessage()).isEqualTo("해당 이벤트에 접근할 권한이 없습니다."); + } + + @Test + @DisplayName("이벤트 ID를 통해 해당하는 이벤트를 삭제한다.") + void delete() { + // given + given(eventRepository.findById(event1.id)).willReturn(Optional.of(EventData.event1.entity.get())); + + // when + eventService.delete(host1.memberIdentifier, event1.id); + + // then + then(eventImageService).should(times(3)).deleteImage(any(MemberIdentifier.class), any(Long.class)); + then(eventRepository).should(times(1)).deleteById(event1.id); + } + + @Test + @DisplayName("Host ID가 다르면 큐레이션을 삭제할 수 없다.") + void deleteByInvalidId() { + // given + MemberIdentifier differentMember = new MemberIdentifier(100L, MemberType.host); + given(eventRepository.findById(event1.id)).willReturn(Optional.of(EventData.event1.entity.get())); + + // when, then + UnauthorizedException exception = assertThrows( + UnauthorizedException.class, () -> eventService.delete(differentMember, event1.id)); + assertThat(exception.getMessage()).isEqualTo("해당 이벤트에 접근할 권한이 없습니다."); + } +} \ No newline at end of file From d9b4d3a6553f1a2577dd8a3ee762819a86b2a9b5 Mon Sep 17 00:00:00 2001 From: ariimo Date: Fri, 15 Nov 2024 16:38:52 +0900 Subject: [PATCH 52/53] =?UTF-8?q?[Weekly/11/Refactor/ErrorCode]=20ErrorCod?= =?UTF-8?q?e=20=EC=88=98=EC=A0=95=20(#147)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_common/exception/ErrorCode.java | 76 +++++++------------ .../event/EventServiceUnitTest.java | 47 +++++++----- 2 files changed, 55 insertions(+), 68 deletions(-) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/ErrorCode.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/ErrorCode.java index 3ebf85fa..80eaa3d8 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/ErrorCode.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/ErrorCode.java @@ -4,56 +4,36 @@ import org.springframework.http.HttpStatus; @Getter -// TODO: code 수정 필요 public enum ErrorCode { - FAIL_SOCIAL_DATA_GET(HttpStatus.UNAUTHORIZED.value(), "-20400"), - - FAIL_ACCESS_TOKEN_GET(HttpStatus.UNAUTHORIZED.value(), "-20400"), - - AUTHENTICATION_EMPTY(HttpStatus.UNAUTHORIZED.value(), "-20400"), - - JWT_TOKEN_EXCEPTION(HttpStatus.UNAUTHORIZED.value(), "-20400"), - - INVALID_AUTHORIZATION_HEADER(HttpStatus.BAD_REQUEST.value(), "-20400"), - - SECURITY_FILTER_AUTHORIZATION_REQUIRED(HttpStatus.FORBIDDEN.value(), "-20400"), - - SECURITY_FILTER_FORBIDDEN_ACCESS(HttpStatus.BAD_REQUEST.value(), "-20400"), - - NOT_LIKEABLE_MEMBER_TYPE(HttpStatus.BAD_REQUEST.value(), "-20400"), - - ADDITIONAL_INFO_ILLEGAL_ACCESS(HttpStatus.UNAUTHORIZED.value(), "-20400"), - - LOGIN_FAILED(HttpStatus.UNAUTHORIZED.value(), "-20400"), - - EMAIL_ALREADY_EXISTS(HttpStatus.CONFLICT.value(), "-10400"), - - CURRENT_LOCATION_EMPTY(HttpStatus.BAD_REQUEST.value(), "-20400"), - - INVALID_IMAGE_DOMAIN(HttpStatus.BAD_REQUEST.value(), "-20400"), - - FAIL_TO_DELETE_IMAGE(HttpStatus.CONFLICT.value(), "-20400"), - - FAIL_TO_UPLOAD_IMAGE(HttpStatus.CONFLICT.value(), "-20400"), - - FAIL_TO_PAY(HttpStatus.CONFLICT.value(), "-20400"), - - FAIL_TO_READ_IMAGE(HttpStatus.CONFLICT.value(), "-20400"), - - RESERVATION_NOT_FOUND_FOR_REVIEW(HttpStatus.NOT_FOUND.value(), "14044"), - - NO_LEFT_SEAT(HttpStatus.BAD_REQUEST.value(), "-10400"), - - URL_PARSING_FAILED(HttpStatus.BAD_REQUEST.value(), "-20400"), - - INVALID_INPUT_VALUE(HttpStatus.BAD_REQUEST.value(), "-20400"), - - UNAUTHORIZED(HttpStatus.UNAUTHORIZED.value(), "-20400"), - - ENTITY_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "-10404"), - - UNEXPECTED(HttpStatus.BAD_REQUEST.value(), "-1"); + EMAIL_ALREADY_EXISTS(HttpStatus.CONFLICT.value(), "-40904"), + FAIL_TO_DELETE_IMAGE(HttpStatus.CONFLICT.value(), "-40903"), + FAIL_TO_UPLOAD_IMAGE(HttpStatus.CONFLICT.value(), "-40902"), + FAIL_TO_PAY(HttpStatus.CONFLICT.value(), "-40901"), + FAIL_TO_READ_IMAGE(HttpStatus.CONFLICT.value(), "-40900"), + + RESERVATION_NOT_FOUND_FOR_REVIEW(HttpStatus.NOT_FOUND.value(), "40401"), + ENTITY_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "-40400"), + + SECURITY_FILTER_AUTHORIZATION_REQUIRED(HttpStatus.FORBIDDEN.value(), "-40300"), + + FAIL_SOCIAL_DATA_GET(HttpStatus.UNAUTHORIZED.value(), "-40106"), + FAIL_ACCESS_TOKEN_GET(HttpStatus.UNAUTHORIZED.value(), "-40105"), + AUTHENTICATION_EMPTY(HttpStatus.UNAUTHORIZED.value(), "-40104"), + JWT_TOKEN_EXCEPTION(HttpStatus.UNAUTHORIZED.value(), "-40103"), + ADDITIONAL_INFO_ILLEGAL_ACCESS(HttpStatus.UNAUTHORIZED.value(), "-40102"), + LOGIN_FAILED(HttpStatus.UNAUTHORIZED.value(), "-40101"), + UNAUTHORIZED(HttpStatus.UNAUTHORIZED.value(), "-40100"), + + INVALID_AUTHORIZATION_HEADER(HttpStatus.BAD_REQUEST.value(), "-40008"), + SECURITY_FILTER_FORBIDDEN_ACCESS(HttpStatus.BAD_REQUEST.value(), "-40007"), + NOT_LIKEABLE_MEMBER_TYPE(HttpStatus.BAD_REQUEST.value(), "-40006"), + CURRENT_LOCATION_EMPTY(HttpStatus.BAD_REQUEST.value(), "-40005"), + INVALID_IMAGE_DOMAIN(HttpStatus.BAD_REQUEST.value(), "-40004"), + NO_LEFT_SEAT(HttpStatus.BAD_REQUEST.value(), "-40003"), + URL_PARSING_FAILED(HttpStatus.BAD_REQUEST.value(), "-40002"), + INVALID_INPUT_VALUE(HttpStatus.BAD_REQUEST.value(), "-40001"), + UNEXPECTED(HttpStatus.BAD_REQUEST.value(), "-40000"); private final Integer status; private final String code; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java index 72cc7420..87c554b0 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java @@ -13,12 +13,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; -import org.ktc2.cokaen.wouldyouin._common.vo.Area; -import org.ktc2.cokaen.wouldyouin._common.vo.Category; -import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData; -import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.R.curation1; import org.ktc2.cokaen.wouldyouin._global.testdata.EventData; -import org.ktc2.cokaen.wouldyouin._global.testdata.EventData.EventSlice; import org.ktc2.cokaen.wouldyouin._global.testdata.EventData.R.event1; import org.ktc2.cokaen.wouldyouin._global.testdata.EventData.R.updatedEvent1; import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData; @@ -27,7 +22,6 @@ import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host1; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; -import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventResponse; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventSliceResponse; import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationFilter; @@ -42,7 +36,6 @@ import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.data.domain.PageRequest; @ExtendWith(MockitoExtension.class) class EventServiceUnitTest { @@ -107,7 +100,8 @@ void getAllByFilterOrderByDistanceAsc() { // when EventSliceResponse responses = eventService.getAllByFilterOrderByDistanceAsc( - location, currentLocation, event1.title, event1.category, event1.area, event1.pageable, event1.lastId); + location, currentLocation, event1.title, event1.category, event1.area, event1.pageable, + event1.lastId); // then assertThat(responses).isEqualTo(EventData.event1.response.slice.get()); @@ -117,7 +111,8 @@ void getAllByFilterOrderByDistanceAsc() { @DisplayName("Host ID를 통해 해당하는 모든 이벤트를 반환한다.") void getAllByHostIdOrderByCreatedDateDesc() { // given - given(eventRepository.findAllByHostIdOrderByEventIdDesc(host1.id, event1.lastId, event1.pageable)) + given(eventRepository.findAllByHostIdOrderByEventIdDesc(host1.id, event1.lastId, + event1.pageable)) .willReturn(EventData.EventSlice.get()); EventImage eventImage1 = EventData.event1.entity.get().getImages().get(0); EventImage eventImage2 = EventData.event1.entity.get().getImages().get(1); @@ -127,7 +122,8 @@ void getAllByHostIdOrderByCreatedDateDesc() { given(eventImageService.getImageUrl(eventImage3)).willReturn(R.event3.url); // when - EventSliceResponse responses = eventService.getAllByHostIdOrderByCreatedDateDesc(host1.id, event1.pageable, event1.lastId); + EventSliceResponse responses = eventService.getAllByHostIdOrderByCreatedDateDesc(host1.id, + event1.pageable, event1.lastId); // then assertThat(responses).isEqualTo(EventData.event1.response.slice.get()); @@ -147,11 +143,13 @@ void getAllByCreatedDateDesc() { given(eventImageService.getImageUrl(eventImage3)).willReturn(R.event3.url); // when - EventSliceResponse responses = eventService.getAllByCreatedDateDesc(event1.pageable, event1.lastId); + EventSliceResponse responses = eventService.getAllByCreatedDateDesc(event1.pageable, + event1.lastId); // then assertThat(responses).isEqualTo(EventData.event1.response.slice.get()); } + @Test @DisplayName("EventCreateRequest를 통해 이벤트를 생성한다.") void create() { @@ -169,7 +167,8 @@ void create() { given(eventRepository.save(any(Event.class))).willReturn(EventData.event1.entity.get()); // when - EventResponse response = eventService.create(host1.memberIdentifier, EventData.event1.request.create.get()); + EventResponse response = eventService.create(host1.memberIdentifier, + EventData.event1.request.create.get()); // then assertThat(response).isEqualTo(EventData.event1.response.get()); @@ -179,10 +178,12 @@ void create() { @DisplayName("EventEditRequest를 통해 이벤트를 수정한다.") void update1() { // given - given(eventRepository.findById(event1.id)).willReturn(Optional.of(EventData.event1.entity.get())); + given(eventRepository.findById(event1.id)).willReturn( + Optional.of(EventData.event1.entity.get())); given(eventImageService.getById(R.event4.id)).willReturn(ImageData.event4.entity.get()); given(eventImageService.getById(R.event5.id)).willReturn(ImageData.event5.entity.get()); - given(eventImageService.createThumbnail(event4.name)).willReturn(updatedEvent1.thumbnailUrl); + given(eventImageService.createThumbnail(event4.name)).willReturn( + updatedEvent1.thumbnailUrl); EventImage eventImage4 = EventData.updatedEvent1.entity.get().getImages().get(0); EventImage eventImage5 = EventData.updatedEvent1.entity.get().getImages().get(1); given(eventImageService.getImageUrl(eventImage4)).willReturn(R.event4.url); @@ -193,7 +194,8 @@ void update1() { EventData.event1.request.edit1.get()); // then - then(eventImageService).should(times(3)).deleteImage(any(MemberIdentifier.class), any(Long.class)); + then(eventImageService).should(times(3)) + .deleteImage(any(MemberIdentifier.class), any(Long.class)); assertThat(response).isEqualTo(EventData.updatedEvent1.response.get()); } @@ -202,11 +204,13 @@ void update1() { void update2() { // given MemberIdentifier differentMember = new MemberIdentifier(100L, MemberType.host); - given(eventRepository.findById(event1.id)).willReturn(Optional.of(EventData.event1.entity.get())); + given(eventRepository.findById(event1.id)).willReturn( + Optional.of(EventData.event1.entity.get())); // when, then UnauthorizedException exception = assertThrows( - UnauthorizedException.class, () -> eventService.update(differentMember, event1.id, EventData.event1.request.edit1.get())); + UnauthorizedException.class, () -> eventService.update(differentMember, event1.id, + EventData.event1.request.edit1.get())); assertThat(exception.getMessage()).isEqualTo("해당 이벤트에 접근할 권한이 없습니다."); } @@ -214,13 +218,15 @@ void update2() { @DisplayName("이벤트 ID를 통해 해당하는 이벤트를 삭제한다.") void delete() { // given - given(eventRepository.findById(event1.id)).willReturn(Optional.of(EventData.event1.entity.get())); + given(eventRepository.findById(event1.id)).willReturn( + Optional.of(EventData.event1.entity.get())); // when eventService.delete(host1.memberIdentifier, event1.id); // then - then(eventImageService).should(times(3)).deleteImage(any(MemberIdentifier.class), any(Long.class)); + then(eventImageService).should(times(3)) + .deleteImage(any(MemberIdentifier.class), any(Long.class)); then(eventRepository).should(times(1)).deleteById(event1.id); } @@ -229,7 +235,8 @@ void delete() { void deleteByInvalidId() { // given MemberIdentifier differentMember = new MemberIdentifier(100L, MemberType.host); - given(eventRepository.findById(event1.id)).willReturn(Optional.of(EventData.event1.entity.get())); + given(eventRepository.findById(event1.id)).willReturn( + Optional.of(EventData.event1.entity.get())); // when, then UnauthorizedException exception = assertThrows( From 725dbf7b49e01f5ebfbbfabd39c70098f29de810 Mon Sep 17 00:00:00 2001 From: Jangan Lee Date: Fri, 15 Nov 2024 16:48:36 +0900 Subject: [PATCH 53/53] =?UTF-8?q?[Weekly/11/Refactor/all]=20=EC=86=8C?= =?UTF-8?q?=EC=85=9C=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20(#148)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: gender enum으로 수정 * hotfix: 소셜로그인 오류 수정 --- .../application/oauth/GoogleRequestService.java | 7 ++++--- .../application/oauth/KakaoRequestService.java | 8 +++++--- .../application/oauth/OauthRequestService.java | 15 +-------------- .../auth/application/oauth/dto/OauthRequest.java | 2 +- .../ktc2/cokaen/wouldyouin/like/persist/Like.java | 3 +++ .../wouldyouin/member/api/dto/MemberResponse.java | 3 ++- .../ReservationMemberResponse.java | 3 ++- .../dto/request/MemberAdditionalInfoRequest.java | 3 ++- .../dto/request/create/MemberCreateRequest.java | 3 ++- .../cokaen/wouldyouin/member/persist/Curator.java | 2 +- .../cokaen/wouldyouin/member/persist/Gender.java | 8 ++++++++ .../cokaen/wouldyouin/member/persist/Host.java | 2 +- .../cokaen/wouldyouin/member/persist/Member.java | 7 ++++--- .../wouldyouin/_global/testdata/MemberData.java | 7 ++++--- 14 files changed, 40 insertions(+), 33 deletions(-) create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Gender.java diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/GoogleRequestService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/GoogleRequestService.java index da691399..bade50ee 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/GoogleRequestService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/GoogleRequestService.java @@ -72,13 +72,14 @@ protected AccountType getAccountType() { } @Override - protected OauthRequest getOauthRequestBase() { - return OauthRequest.builder() + public OauthResourcesResponse getOauthMemberResources(String code) { + return requestLoginAndAccessResources(OauthRequest.builder() .grantType("authorization_code") .clientId(clientId) .clientSecret(clientSecret) .redirectUri(redirectUri) - .build(); + .code(code) + .build()); } @Override diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/KakaoRequestService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/KakaoRequestService.java index 3b443200..f92a690d 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/KakaoRequestService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/KakaoRequestService.java @@ -81,15 +81,17 @@ protected HttpHeaders getAccessRequestHeaders(AccessTokenResponse authentication } @Override - protected OauthRequest getOauthRequestBase() { - return OauthRequest.builder() + public OauthResourcesResponse getOauthMemberResources(String code) { + return requestLoginAndAccessResources(OauthRequest.builder() .grantType("authorization_code") .clientId(clientId) .clientSecret(clientSecret) .redirectUri(redirectUri) - .build(); + .code(code) + .build()); } + @Override protected OauthResourcesResponse requestLoginAndAccessResources(OauthRequest request) { AccessTokenResponse authenticationResponse = client.post( diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/OauthRequestService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/OauthRequestService.java index 6e96036d..7b40e42a 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/OauthRequestService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/OauthRequestService.java @@ -9,22 +9,9 @@ @Service public abstract class OauthRequestService { - private OauthRequest oauthRequestBase; - protected abstract AccountType getAccountType(); - protected abstract OauthRequest getOauthRequestBase(); - protected abstract OauthResourcesResponse requestLoginAndAccessResources(OauthRequest oauthRequest); - @PostConstruct - private void init() { - oauthRequestBase = getOauthRequestBase(); - } - - final public OauthResourcesResponse getOauthMemberResources(String code) { - return requestLoginAndAccessResources(oauthRequestBase.toBuilder() - .code(code) - .build()); - } + public abstract OauthResourcesResponse getOauthMemberResources(String code); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/dto/OauthRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/dto/OauthRequest.java index ffcc3405..52cd236d 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/dto/OauthRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/auth/application/oauth/dto/OauthRequest.java @@ -9,7 +9,7 @@ @Getter @RequiredArgsConstructor(access = AccessLevel.PROTECTED) -@Builder(toBuilder = true) +@Builder @JsonNaming(SnakeCaseStrategy.class) public class OauthRequest { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/Like.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/Like.java index 48840190..9e1afcb4 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/Like.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/like/persist/Like.java @@ -1,6 +1,8 @@ package org.ktc2.cokaen.wouldyouin.like.persist; import jakarta.persistence.Column; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; @@ -39,6 +41,7 @@ public abstract class Like { @NotNull @Column + @Enumerated(EnumType.STRING) private MemberType likeableMemberType; @NotNull diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/MemberResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/MemberResponse.java index 3d350d8f..e64715b4 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/MemberResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/MemberResponse.java @@ -8,6 +8,7 @@ import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMember; import org.ktc2.cokaen.wouldyouin.member.persist.Curator; +import org.ktc2.cokaen.wouldyouin.member.persist.Gender; import org.ktc2.cokaen.wouldyouin.member.persist.Host; import org.ktc2.cokaen.wouldyouin.member.persist.Member; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @@ -26,7 +27,7 @@ public class MemberResponse { private MemberType memberType; private Area area; - private String gender; + private Gender gender; private String intro; private Integer likes; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/ReservationMemberResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/ReservationMemberResponse.java index eec96917..5e495ba4 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/ReservationMemberResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/ReservationMemberResponse.java @@ -4,6 +4,7 @@ import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; +import org.ktc2.cokaen.wouldyouin.member.persist.Gender; import org.ktc2.cokaen.wouldyouin.member.persist.Member; @Getter @@ -16,7 +17,7 @@ public class ReservationMemberResponse { private String email; private String nickname; private String phone; - private String gender; + private Gender gender; public static ReservationMemberResponse from(Member member) { return ReservationMemberResponse.builder() diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/MemberAdditionalInfoRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/MemberAdditionalInfoRequest.java index b1eda017..ec1c4b17 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/MemberAdditionalInfoRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/MemberAdditionalInfoRequest.java @@ -5,6 +5,7 @@ import lombok.RequiredArgsConstructor; import lombok.ToString; import org.ktc2.cokaen.wouldyouin._common.vo.Area; +import org.ktc2.cokaen.wouldyouin.member.persist.Gender; @Getter @EqualsAndHashCode @@ -14,5 +15,5 @@ public class MemberAdditionalInfoRequest { private String phone; private Area area; - private String gender; + private Gender gender; } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/MemberCreateRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/MemberCreateRequest.java index 0d3661a3..2d3c6a71 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/MemberCreateRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/create/MemberCreateRequest.java @@ -8,6 +8,7 @@ import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin.image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin.member.persist.AccountType; +import org.ktc2.cokaen.wouldyouin.member.persist.Gender; import org.ktc2.cokaen.wouldyouin.member.persist.Member; @Getter @@ -36,7 +37,7 @@ public Member toEntity(MemberImage profileImage, String thumbnailImageUrl) { .accountType(this.accountType) .socialId(this.socialId) .area(Area.서울) - .gender("") + .gender(Gender.MAN) .profileImage(profileImage) .profileImageThumbnailUrl(thumbnailImageUrl) .build(); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java index cae6326a..3db77301 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java @@ -45,7 +45,7 @@ public class Curator extends Member implements LikeableMember { private List curations = new ArrayList<>(); @Builder(builderMethodName = "curatorBuilder") - public Curator(AccountType accountType, String email, String nickname, String phone, MemberImage profileImage, String profileImageThumbnailUrl, Area area, String gender, + public Curator(AccountType accountType, String email, String nickname, String phone, MemberImage profileImage, String profileImageThumbnailUrl, Area area, Gender gender, String socialId) { super(accountType, MemberType.curator, email, nickname, phone, profileImage, profileImageThumbnailUrl, area, gender, socialId); this.intro = ""; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Gender.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Gender.java new file mode 100644 index 00000000..311b1652 --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Gender.java @@ -0,0 +1,8 @@ +package org.ktc2.cokaen.wouldyouin.member.persist; + +import lombok.Getter; + +@Getter +public enum Gender { + MAN, WOMAN +} diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java index fcabec34..4ff93ba2 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java @@ -24,7 +24,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @DiscriminatorValue("Host") @EqualsAndHashCode(callSuper = true) -@ToString() +@ToString @Entity public class Host extends BaseMember implements LikeableMember { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java index 560ae232..1c4f8345 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java @@ -38,7 +38,8 @@ public class Member extends BaseMember { private Area area; @Column(nullable = false, name = "gender") - private String gender; + @Enumerated(EnumType.STRING) + private Gender gender; @Column(name = "social_id") private String socialId; //소셜 타입 식별자 값 @@ -60,7 +61,7 @@ public class Member extends BaseMember { private List reviews = new ArrayList<>(); // for Curator - protected Member(AccountType accountType, MemberType memberType, String email, String nickname, String phone, MemberImage profileImage, String profileImageThumbNailUrl, Area area, String gender, String socialId) { + protected Member(AccountType accountType, MemberType memberType, String email, String nickname, String phone, MemberImage profileImage, String profileImageThumbNailUrl, Area area, Gender gender, String socialId) { super(accountType, memberType, email, nickname, phone, profileImage, profileImageThumbNailUrl); this.area = area; this.gender = gender; @@ -69,7 +70,7 @@ protected Member(AccountType accountType, MemberType memberType, String email, S @Builder // for public builder - protected Member(AccountType accountType, String email, String nickname, String phone, MemberImage profileImage, String profileImageThumbnailUrl, Area area, String gender, String socialId) { + protected Member(AccountType accountType, String email, String nickname, String phone, MemberImage profileImage, String profileImageThumbnailUrl, Area area, Gender gender, String socialId) { this(accountType, MemberType.welcome, email, nickname, phone, profileImage, profileImageThumbnailUrl, area, gender, socialId); } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java index 9c95335a..e9418187 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java @@ -14,6 +14,7 @@ import org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse.ReservationMemberResponse; import org.ktc2.cokaen.wouldyouin.member.persist.AccountType; import org.ktc2.cokaen.wouldyouin.member.persist.Curator; +import org.ktc2.cokaen.wouldyouin.member.persist.Gender; import org.ktc2.cokaen.wouldyouin.member.persist.Host; import org.ktc2.cokaen.wouldyouin.member.persist.Member; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @@ -56,7 +57,7 @@ public static List reviews() { public static final String profileImageUrl = ImageData.R.member.normal.url; public static final String profileImageThumbnailUrl = ImageData.getThumbnailUrl(profileImage); public static final Area area = Area.광주; - public static final String gender = "Men"; + public static final Gender gender = Gender.MAN; public static final String socialId = "100100100100100"; public static final MemberType memberType = MemberType.normal; } @@ -81,7 +82,7 @@ public static List curations() { public static final String profileImageUrl = ImageData.R.member.curator.url; public static final String profileImageThumbnailUrl = ImageData.getThumbnailUrl(profileImage); public static final Area area = Area.광주; - public static final String gender = "Women"; + public static final Gender gender = Gender.WOMAN; public static final String socialId = "200200200200200"; public static final String intro = "큐레이터 자기소개입니다."; public static final List hashtags = List.of("#큐레이터", "#해시태그", "#입니다"); @@ -122,7 +123,7 @@ public static class welcome1 { public static final String profileImageUrl = ImageData.R.member.welcome.url; public static final String profileImageThumbnailUrl = ImageData.getThumbnailUrl(profileImage); public static final Area area = Area.서울; - public static final String gender = "Men"; + public static final Gender gender = Gender.MAN; public static final String socialId = "456456456456"; }