From 279175dd92ffaf49e79cfb9430402473cef74444 Mon Sep 17 00:00:00 2001 From: JiinHong Date: Fri, 8 Nov 2024 05:59:31 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=ED=8F=AC=ED=86=A0=EB=B6=80?= =?UTF-8?q?=EC=8A=A4=20=EC=B0=9C=20=EC=97=AC=EB=B6=80=20=ED=99=95=EC=9D=B8?= =?UTF-8?q?=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../photobooth/PhotoBoothCheckLikePort.java | 9 ++++++++ .../service/photobooth/PhotoBoothService.java | 12 +++++++--- .../PhotoBoothCheckLikeUseCase.java | 7 ++++++ .../presentation/PhotoBoothController.java | 10 ++++++++ .../adapter/PhotoBoothCheckLikeAdapter.java | 23 +++++++++++++++++++ .../repository/photobooth/LikeRepository.java | 3 +++ 6 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 domain/src/main/java/com/pocket/domain/port/photobooth/PhotoBoothCheckLikePort.java create mode 100644 domain/src/main/java/com/pocket/domain/usecase/photobooth/PhotoBoothCheckLikeUseCase.java create mode 100644 outbound/src/main/java/com/pocket/outbound/adapter/photobooth/adapter/PhotoBoothCheckLikeAdapter.java diff --git a/domain/src/main/java/com/pocket/domain/port/photobooth/PhotoBoothCheckLikePort.java b/domain/src/main/java/com/pocket/domain/port/photobooth/PhotoBoothCheckLikePort.java new file mode 100644 index 0000000..7fe564a --- /dev/null +++ b/domain/src/main/java/com/pocket/domain/port/photobooth/PhotoBoothCheckLikePort.java @@ -0,0 +1,9 @@ +package com.pocket.domain.port.photobooth; + +import com.pocket.domain.entity.photobooth.PhotoBooth; + +public interface PhotoBoothCheckLikePort { + + Boolean checkLike(Long photoBoothId, String userEmail); + +} diff --git a/domain/src/main/java/com/pocket/domain/service/photobooth/PhotoBoothService.java b/domain/src/main/java/com/pocket/domain/service/photobooth/PhotoBoothService.java index 9d30787..37d4f7a 100644 --- a/domain/src/main/java/com/pocket/domain/service/photobooth/PhotoBoothService.java +++ b/domain/src/main/java/com/pocket/domain/service/photobooth/PhotoBoothService.java @@ -13,7 +13,7 @@ @Service @RequiredArgsConstructor -public class PhotoBoothService implements PhotoBoothFindUseCase, PhotoBoothGetNameUseCase, PhotoBoothGetRatingUseCase, PhotoBoothSearchUseCase, PhotoBoothGetModalUseCase, PhotoBoothVisitedUseCase, PhotoBoothLikeUseCase, PhotoBoothGetLikeUseCase +public class PhotoBoothService implements PhotoBoothFindUseCase, PhotoBoothGetNameUseCase, PhotoBoothGetRatingUseCase, PhotoBoothSearchUseCase, PhotoBoothGetModalUseCase, PhotoBoothVisitedUseCase, PhotoBoothLikeUseCase, PhotoBoothGetLikeUseCase, PhotoBoothCheckLikeUseCase { private final PhotoBoothFindPort photoBoothFindPort; @@ -24,6 +24,7 @@ public class PhotoBoothService implements PhotoBoothFindUseCase, PhotoBoothGetNa private final PhotoBoothVisitedPort photoBoothVisitedPort; private final PhotoBoothLikePort photoBoothLikePort; private final PhotoBoothGetLikePort photoBoothGetLikePort; + private final PhotoBoothCheckLikePort photoBoothCheckLikePort; public PhotoBoothFindResponseDto findPhotoBoothResponse(Long id) { return photoBoothFindPort.findById(id); @@ -55,12 +56,17 @@ public List getVisitedPhotoBooths(String userEmail) { } @Override - public void photoBoothLike(Long photoId, String userEmail) { - photoBoothLikePort.photoBoothLike(photoId, userEmail); + public void photoBoothLike(Long photoboothId, String userEmail) { + photoBoothLikePort.photoBoothLike(photoboothId, userEmail); } @Override public List getLikedPhotos(String userEmail) { return photoBoothGetLikePort.getLikedPhotos(userEmail); } + + @Override + public Boolean checkLike(Long photoBoothId, String userEmail) { + return photoBoothCheckLikePort.checkLike(photoBoothId, userEmail); + } } diff --git a/domain/src/main/java/com/pocket/domain/usecase/photobooth/PhotoBoothCheckLikeUseCase.java b/domain/src/main/java/com/pocket/domain/usecase/photobooth/PhotoBoothCheckLikeUseCase.java new file mode 100644 index 0000000..b0cd3e8 --- /dev/null +++ b/domain/src/main/java/com/pocket/domain/usecase/photobooth/PhotoBoothCheckLikeUseCase.java @@ -0,0 +1,7 @@ +package com.pocket.domain.usecase.photobooth; + +public interface PhotoBoothCheckLikeUseCase { + + Boolean checkLike(Long photoBoothId, String userEmail); + +} diff --git a/inbounds/src/main/java/com/pocket/inbounds/photobooth/presentation/PhotoBoothController.java b/inbounds/src/main/java/com/pocket/inbounds/photobooth/presentation/PhotoBoothController.java index f8bfb2e..bce0832 100644 --- a/inbounds/src/main/java/com/pocket/inbounds/photobooth/presentation/PhotoBoothController.java +++ b/inbounds/src/main/java/com/pocket/inbounds/photobooth/presentation/PhotoBoothController.java @@ -25,6 +25,7 @@ public class PhotoBoothController implements PhotoBoothControllerDocs { private final PhotoBoothVisitedUseCase photoBoothVisitedUseCase; private final PhotoBoothLikeUseCase photoBoothLikeUseCase; private final PhotoBoothGetLikeUseCase photoBoothGetLikeUseCase; + private final PhotoBoothCheckLikeUseCase photoBoothCheckLikeUseCase; @GetMapping("{id}") public ApplicationResponse getPhotoBoothById(@PathVariable("id") Long id) { @@ -92,4 +93,13 @@ public ApplicationResponse> getPhotoBoothLike( List response = photoBoothGetLikeUseCase.getLikedPhotos(user.email()); return ApplicationResponse.ok(response); } + + @GetMapping("/like/check/{id}") + public ApplicationResponse likePhotoBoothCheck( + @PathVariable("id") Long id, + @AuthenticationPrincipal UserInfoDTO user + ) { + Boolean response = photoBoothCheckLikeUseCase.checkLike(id, user.email()); + return ApplicationResponse.ok(response); + } } diff --git a/outbound/src/main/java/com/pocket/outbound/adapter/photobooth/adapter/PhotoBoothCheckLikeAdapter.java b/outbound/src/main/java/com/pocket/outbound/adapter/photobooth/adapter/PhotoBoothCheckLikeAdapter.java new file mode 100644 index 0000000..c5be165 --- /dev/null +++ b/outbound/src/main/java/com/pocket/outbound/adapter/photobooth/adapter/PhotoBoothCheckLikeAdapter.java @@ -0,0 +1,23 @@ +package com.pocket.outbound.adapter.photobooth.adapter; + +import com.pocket.core.aop.annotation.AdapterService; +import com.pocket.domain.port.photobooth.PhotoBoothCheckLikePort; +import com.pocket.outbound.entity.photobooth.JpaLike; +import com.pocket.outbound.repository.photobooth.LikeRepository; +import lombok.RequiredArgsConstructor; + +import java.util.Optional; + + +@AdapterService +@RequiredArgsConstructor +public class PhotoBoothCheckLikeAdapter implements PhotoBoothCheckLikePort { + + private final LikeRepository likeRepository; + + @Override + public Boolean checkLike(Long photoBoothId, String userEmail) { + return likeRepository.findByUser_UserEmailAndPhotoBooth_Id(userEmail, photoBoothId).isPresent(); + } + +} diff --git a/outbound/src/main/java/com/pocket/outbound/repository/photobooth/LikeRepository.java b/outbound/src/main/java/com/pocket/outbound/repository/photobooth/LikeRepository.java index 227998c..5ee8a86 100644 --- a/outbound/src/main/java/com/pocket/outbound/repository/photobooth/LikeRepository.java +++ b/outbound/src/main/java/com/pocket/outbound/repository/photobooth/LikeRepository.java @@ -4,9 +4,12 @@ import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; +import java.util.Optional; public interface LikeRepository extends JpaRepository { List findByUser_UserEmail(String userEmail); + Optional findByUser_UserEmailAndPhotoBooth_Id(String userEmail, Long photoBoothId); + } From 671c94e530a838632b3b895a52a8acb8e16ae758 Mon Sep 17 00:00:00 2001 From: JiinHong Date: Fri, 8 Nov 2024 06:16:20 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=ED=8F=AC=ED=86=A0=EB=B6=80?= =?UTF-8?q?=EC=8A=A4=20=EC=B0=9C=20=EC=82=AD=EC=A0=9C=20API=20&=20?= =?UTF-8?q?=ED=8F=AC=ED=86=A0=EB=B6=80=EC=8A=A4=20=EC=B0=9C=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../photobooth/PhotoBoothErrorCode.java | 4 ++- .../photobooth/PhotoBoothDeleteLikePort.java | 9 ++++++ .../service/photobooth/PhotoBoothService.java | 8 ++++- .../PhotoBoothDeleteLikeUseCase.java | 7 +++++ .../presentation/PhotoBoothController.java | 10 +++++++ .../adapter/PhotoBoothDeleteLikeAdapter.java | 30 +++++++++++++++++++ .../adapter/PhotoBoothLikeAdapter.java | 8 +++++ 7 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 domain/src/main/java/com/pocket/domain/port/photobooth/PhotoBoothDeleteLikePort.java create mode 100644 domain/src/main/java/com/pocket/domain/usecase/photobooth/PhotoBoothDeleteLikeUseCase.java create mode 100644 outbound/src/main/java/com/pocket/outbound/adapter/photobooth/adapter/PhotoBoothDeleteLikeAdapter.java diff --git a/core/src/main/java/com/pocket/core/exception/photobooth/PhotoBoothErrorCode.java b/core/src/main/java/com/pocket/core/exception/photobooth/PhotoBoothErrorCode.java index af51bfe..a4385ed 100644 --- a/core/src/main/java/com/pocket/core/exception/photobooth/PhotoBoothErrorCode.java +++ b/core/src/main/java/com/pocket/core/exception/photobooth/PhotoBoothErrorCode.java @@ -10,7 +10,9 @@ @AllArgsConstructor public enum PhotoBoothErrorCode implements BaseErrorCode { PHOTOBOOTH_NOT_FOUND(HttpStatus.BAD_REQUEST, "400", "해당 포토부스가 존재하지 않습니다."), - PHOTOBOOTHBRAND_NOT_FOUND(HttpStatus.BAD_REQUEST, "400", "해당 포토부스 브랜드가 존재하지 않습니다."); + PHOTOBOOTHBRAND_NOT_FOUND(HttpStatus.BAD_REQUEST, "400", "해당 포토부스 브랜드가 존재하지 않습니다."), + PHOTOBOOTHLIKE_NOT_FOUND(HttpStatus.BAD_REQUEST, "400", "찜한 포토부스가 아닙니다."), + PHOTOBOOTHLIKE_FOUND(HttpStatus.BAD_REQUEST, "400", "이미 찜한 포토부스 입니다."); private final HttpStatus httpStatus; private final String code; diff --git a/domain/src/main/java/com/pocket/domain/port/photobooth/PhotoBoothDeleteLikePort.java b/domain/src/main/java/com/pocket/domain/port/photobooth/PhotoBoothDeleteLikePort.java new file mode 100644 index 0000000..be5c4d4 --- /dev/null +++ b/domain/src/main/java/com/pocket/domain/port/photobooth/PhotoBoothDeleteLikePort.java @@ -0,0 +1,9 @@ +package com.pocket.domain.port.photobooth; + +import com.pocket.domain.entity.photobooth.PhotoBooth; + +public interface PhotoBoothDeleteLikePort { + + void deleteLike(Long photoBoothId, String userEmail); + +} diff --git a/domain/src/main/java/com/pocket/domain/service/photobooth/PhotoBoothService.java b/domain/src/main/java/com/pocket/domain/service/photobooth/PhotoBoothService.java index 37d4f7a..5f61326 100644 --- a/domain/src/main/java/com/pocket/domain/service/photobooth/PhotoBoothService.java +++ b/domain/src/main/java/com/pocket/domain/service/photobooth/PhotoBoothService.java @@ -13,7 +13,7 @@ @Service @RequiredArgsConstructor -public class PhotoBoothService implements PhotoBoothFindUseCase, PhotoBoothGetNameUseCase, PhotoBoothGetRatingUseCase, PhotoBoothSearchUseCase, PhotoBoothGetModalUseCase, PhotoBoothVisitedUseCase, PhotoBoothLikeUseCase, PhotoBoothGetLikeUseCase, PhotoBoothCheckLikeUseCase +public class PhotoBoothService implements PhotoBoothFindUseCase, PhotoBoothGetNameUseCase, PhotoBoothGetRatingUseCase, PhotoBoothSearchUseCase, PhotoBoothGetModalUseCase, PhotoBoothVisitedUseCase, PhotoBoothLikeUseCase, PhotoBoothGetLikeUseCase, PhotoBoothCheckLikeUseCase, PhotoBoothDeleteLikeUseCase { private final PhotoBoothFindPort photoBoothFindPort; @@ -25,6 +25,7 @@ public class PhotoBoothService implements PhotoBoothFindUseCase, PhotoBoothGetNa private final PhotoBoothLikePort photoBoothLikePort; private final PhotoBoothGetLikePort photoBoothGetLikePort; private final PhotoBoothCheckLikePort photoBoothCheckLikePort; + private final PhotoBoothDeleteLikePort photoBoothDeleteLikePort; public PhotoBoothFindResponseDto findPhotoBoothResponse(Long id) { return photoBoothFindPort.findById(id); @@ -69,4 +70,9 @@ public List getLikedPhotos(String userEmail) { public Boolean checkLike(Long photoBoothId, String userEmail) { return photoBoothCheckLikePort.checkLike(photoBoothId, userEmail); } + + @Override + public void deleteLike(Long photoBoothId, String userEmail) { + photoBoothDeleteLikePort.deleteLike(photoBoothId, userEmail); + } } diff --git a/domain/src/main/java/com/pocket/domain/usecase/photobooth/PhotoBoothDeleteLikeUseCase.java b/domain/src/main/java/com/pocket/domain/usecase/photobooth/PhotoBoothDeleteLikeUseCase.java new file mode 100644 index 0000000..65ff889 --- /dev/null +++ b/domain/src/main/java/com/pocket/domain/usecase/photobooth/PhotoBoothDeleteLikeUseCase.java @@ -0,0 +1,7 @@ +package com.pocket.domain.usecase.photobooth; + +public interface PhotoBoothDeleteLikeUseCase { + + void deleteLike(Long photoBoothId, String userEmail); + +} diff --git a/inbounds/src/main/java/com/pocket/inbounds/photobooth/presentation/PhotoBoothController.java b/inbounds/src/main/java/com/pocket/inbounds/photobooth/presentation/PhotoBoothController.java index bce0832..55fbe85 100644 --- a/inbounds/src/main/java/com/pocket/inbounds/photobooth/presentation/PhotoBoothController.java +++ b/inbounds/src/main/java/com/pocket/inbounds/photobooth/presentation/PhotoBoothController.java @@ -26,6 +26,7 @@ public class PhotoBoothController implements PhotoBoothControllerDocs { private final PhotoBoothLikeUseCase photoBoothLikeUseCase; private final PhotoBoothGetLikeUseCase photoBoothGetLikeUseCase; private final PhotoBoothCheckLikeUseCase photoBoothCheckLikeUseCase; + private final PhotoBoothDeleteLikeUseCase photoBoothDeleteLikeUseCase; @GetMapping("{id}") public ApplicationResponse getPhotoBoothById(@PathVariable("id") Long id) { @@ -102,4 +103,13 @@ public ApplicationResponse likePhotoBoothCheck( Boolean response = photoBoothCheckLikeUseCase.checkLike(id, user.email()); return ApplicationResponse.ok(response); } + + @DeleteMapping("/like/{id}") + public ApplicationResponse deletePhotoBoothLike( + @PathVariable("id") Long id, + @AuthenticationPrincipal UserInfoDTO user + ) { + photoBoothDeleteLikeUseCase.deleteLike(id, user.email()); + return ApplicationResponse.ok("success"); + } } diff --git a/outbound/src/main/java/com/pocket/outbound/adapter/photobooth/adapter/PhotoBoothDeleteLikeAdapter.java b/outbound/src/main/java/com/pocket/outbound/adapter/photobooth/adapter/PhotoBoothDeleteLikeAdapter.java new file mode 100644 index 0000000..96d9e86 --- /dev/null +++ b/outbound/src/main/java/com/pocket/outbound/adapter/photobooth/adapter/PhotoBoothDeleteLikeAdapter.java @@ -0,0 +1,30 @@ +package com.pocket.outbound.adapter.photobooth.adapter; + +import com.pocket.core.aop.annotation.AdapterService; +import com.pocket.core.exception.photobooth.PhotoBoothCustomException; +import com.pocket.core.exception.photobooth.PhotoBoothErrorCode; +import com.pocket.domain.port.photobooth.PhotoBoothDeleteLikePort; +import com.pocket.outbound.entity.photobooth.JpaLike; +import com.pocket.outbound.repository.photobooth.LikeRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Optional; + +@AdapterService +@RequiredArgsConstructor +public class PhotoBoothDeleteLikeAdapter implements PhotoBoothDeleteLikePort { + + private final LikeRepository likeRepository; + + @Override + @Transactional + public void deleteLike(Long photoBoothId, String userEmail) { + Optional entity = likeRepository.findByUser_UserEmailAndPhotoBooth_Id(userEmail, photoBoothId); + if (entity.isPresent()) { + likeRepository.delete(entity.get()); + } else { + throw new PhotoBoothCustomException(PhotoBoothErrorCode.PHOTOBOOTHLIKE_NOT_FOUND); + } + } +} diff --git a/outbound/src/main/java/com/pocket/outbound/adapter/photobooth/adapter/PhotoBoothLikeAdapter.java b/outbound/src/main/java/com/pocket/outbound/adapter/photobooth/adapter/PhotoBoothLikeAdapter.java index faf5145..c3f4fa7 100644 --- a/outbound/src/main/java/com/pocket/outbound/adapter/photobooth/adapter/PhotoBoothLikeAdapter.java +++ b/outbound/src/main/java/com/pocket/outbound/adapter/photobooth/adapter/PhotoBoothLikeAdapter.java @@ -15,6 +15,8 @@ import com.pocket.outbound.repository.photobooth.PhotoBoothRepository; import lombok.RequiredArgsConstructor; +import java.util.Optional; + @AdapterService @RequiredArgsConstructor public class PhotoBoothLikeAdapter implements PhotoBoothLikePort { @@ -25,6 +27,11 @@ public class PhotoBoothLikeAdapter implements PhotoBoothLikePort { @Override public void photoBoothLike(Long photoBoothId, String userEmail) { + + Optional entity = likeRepository.findByUser_UserEmailAndPhotoBooth_Id(userEmail, photoBoothId); + if (entity.isPresent()) { + throw new PhotoBoothCustomException(PhotoBoothErrorCode.PHOTOBOOTHLIKE_FOUND); + } JpaUser jpaUser = userRepository.findByUserEmail(userEmail) .orElseThrow(() -> new UserCustomException(UserErrorCode.NO_USER_INFO)); @@ -32,6 +39,7 @@ public void photoBoothLike(Long photoBoothId, String userEmail) { .orElseThrow(() -> new PhotoBoothCustomException((PhotoBoothErrorCode.PHOTOBOOTH_NOT_FOUND))); JpaLike jpaLike = JpaLike.createLike(jpaUser, jpaPhotoBooth); + likeRepository.save(jpaLike); } } From dc906745e973dd663be62475fe141b9c9e289142 Mon Sep 17 00:00:00 2001 From: JiinHong Date: Fri, 8 Nov 2024 06:20:20 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20swagger=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PhotoBoothControllerDocs.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/inbounds/src/main/java/com/pocket/inbounds/photobooth/presentation/PhotoBoothControllerDocs.java b/inbounds/src/main/java/com/pocket/inbounds/photobooth/presentation/PhotoBoothControllerDocs.java index 42782a1..cbbec19 100644 --- a/inbounds/src/main/java/com/pocket/inbounds/photobooth/presentation/PhotoBoothControllerDocs.java +++ b/inbounds/src/main/java/com/pocket/inbounds/photobooth/presentation/PhotoBoothControllerDocs.java @@ -130,4 +130,30 @@ ApplicationResponse> getPhotoBoothLike( @AuthenticationPrincipal UserInfoDTO user ); + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "400", description = "BAD REQUEST", + content = {@Content(schema = @Schema(implementation = ErrorResponse.class))}), + @ApiResponse(responseCode = "500", description = "INTERNAL SERVER ERROR", + content = {@Content(schema = @Schema(implementation = ErrorResponse.class))}) + }) + @Operation(summary = "포토부스 찜 여부 확인", description = "찜한 포토부스인지 확인하는 API") + ApplicationResponse likePhotoBoothCheck( + @PathVariable("id") Long id, + @AuthenticationPrincipal UserInfoDTO user + ); + + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "400", description = "BAD REQUEST", + content = {@Content(schema = @Schema(implementation = ErrorResponse.class))}), + @ApiResponse(responseCode = "500", description = "INTERNAL SERVER ERROR", + content = {@Content(schema = @Schema(implementation = ErrorResponse.class))}) + }) + @Operation(summary = "포토부스 찜 삭제", description = "포토부스 찜 삭제하는 API") + ApplicationResponse deletePhotoBoothLike( + @PathVariable("id") Long id, + @AuthenticationPrincipal UserInfoDTO user + ); + }