From ca06aba64ff5d48f092a01fc4b3a86eb9f750188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=AF=BC=EC=B0=AC=EA=B8=B0?= Date: Mon, 16 Sep 2024 16:17:59 +0900 Subject: [PATCH] =?UTF-8?q?=08fix:=20=EA=B3=B5=EC=97=B0=20=EA=B4=80?= =?UTF-8?q?=EC=8B=AC=20=EB=93=B1=EB=A1=9D=20API=20=EB=B6=84=EB=A6=AC=20(#1?= =?UTF-8?q?66)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/example/config/SecurityConfig.java | 1 + .../show/controller/ShowController.java | 1 - .../show/controller/UserShowController.java | 36 ++++++++++++------ .../dto/response/ShowInterestApiResponse.java | 14 ------- .../example/show/service/UserShowService.java | 12 +++--- .../ShowUninterestedServiceRequest.java | 19 ++++++++++ .../UninterestedShowDomainRequest.java | 12 ++++++ .../example/entity/usershow/InterestShow.java | 7 ++-- .../example/usecase/InterestShowUseCase.java | 37 ++++++++++--------- 9 files changed, 85 insertions(+), 54 deletions(-) delete mode 100644 app/api/show-api/src/main/java/com/example/show/controller/dto/response/ShowInterestApiResponse.java create mode 100644 app/api/show-api/src/main/java/com/example/show/service/dto/request/ShowUninterestedServiceRequest.java create mode 100644 app/domain/show-domain/src/main/java/org/example/dto/show/request/UninterestedShowDomainRequest.java diff --git a/app/api/common-api/src/main/java/org/example/config/SecurityConfig.java b/app/api/common-api/src/main/java/org/example/config/SecurityConfig.java index 2c4f1259..2135f7f4 100644 --- a/app/api/common-api/src/main/java/org/example/config/SecurityConfig.java +++ b/app/api/common-api/src/main/java/org/example/config/SecurityConfig.java @@ -96,6 +96,7 @@ private RequestMatcher getMatcherForUserAndAdmin() { antMatcher(HttpMethod.GET, "/api/v1/shows/interests"), antMatcher(HttpMethod.GET, "/api/v1/users/shows/interests/count"), antMatcher(HttpMethod.POST, "/api/v1/shows/{showId}/interests"), + antMatcher(HttpMethod.POST, "/api/v1/shows/{showId}/uninterested"), antMatcher(HttpMethod.POST, "/api/v1/shows/{showId}/alert"), antMatcher(HttpMethod.GET, "/api/v1/shows/alerts"), antMatcher(HttpMethod.GET, "/api/v1/shows/{showId}/alert/reservations"), diff --git a/app/api/show-api/src/main/java/com/example/show/controller/ShowController.java b/app/api/show-api/src/main/java/com/example/show/controller/ShowController.java index 5841b019..055dd4ca 100644 --- a/app/api/show-api/src/main/java/com/example/show/controller/ShowController.java +++ b/app/api/show-api/src/main/java/com/example/show/controller/ShowController.java @@ -47,7 +47,6 @@ public ResponseEntity> getShows( .hasNext(response.hasNext()) .build() ); - } @GetMapping("/{showId}") diff --git a/app/api/show-api/src/main/java/com/example/show/controller/UserShowController.java b/app/api/show-api/src/main/java/com/example/show/controller/UserShowController.java index d23e34e4..d7517433 100644 --- a/app/api/show-api/src/main/java/com/example/show/controller/UserShowController.java +++ b/app/api/show-api/src/main/java/com/example/show/controller/UserShowController.java @@ -5,7 +5,6 @@ import com.example.show.controller.dto.request.ShowInterestPaginationApiRequest; import com.example.show.controller.dto.request.TicketingAlertReservationApiRequest; import com.example.show.controller.dto.response.InterestShowPaginationApiResponse; -import com.example.show.controller.dto.response.ShowInterestApiResponse; import com.example.show.controller.dto.response.TerminatedTicketingShowCountApiResponse; import com.example.show.controller.dto.response.TicketingAlertReservationApiResponse; import com.example.show.controller.dto.usershow.response.NumberOfInterestShowApiResponse; @@ -13,6 +12,7 @@ import com.example.show.controller.vo.TicketingApiType; import com.example.show.service.UserShowService; import com.example.show.service.dto.request.ShowInterestServiceRequest; +import com.example.show.service.dto.request.ShowUninterestedServiceRequest; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; @@ -42,21 +42,33 @@ public class UserShowController { private final UserShowService userShowService; @PostMapping("/{showId}/interests") - @Operation(summary = "공연 관심 등록 / 취소") - public ResponseEntity interest( + @Operation(summary = "공연 관심 등록") + public ResponseEntity interest( @PathVariable("showId") UUID showId, @AuthenticationPrincipal AuthenticatedInfo info ) { - return ResponseEntity.ok( - ShowInterestApiResponse.from( - userShowService.interest( - ShowInterestServiceRequest.builder() - .showId(showId) - .userId(info.userId()) - .build() - ) - ) + userShowService.interest( + ShowInterestServiceRequest.builder() + .showId(showId) + .userId(info.userId()) + .build() + ); + return ResponseEntity.noContent().build(); + } + + @PostMapping("/{showId}/uninterested") + @Operation(summary = "공연 관심 취소") + public ResponseEntity uninterested( + @PathVariable("showId") UUID showId, + @AuthenticationPrincipal AuthenticatedInfo info + ) { + userShowService.notInterest( + ShowUninterestedServiceRequest.builder() + .showId(showId) + .userId(info.userId()) + .build() ); + return ResponseEntity.noContent().build(); } @GetMapping("/interests") diff --git a/app/api/show-api/src/main/java/com/example/show/controller/dto/response/ShowInterestApiResponse.java b/app/api/show-api/src/main/java/com/example/show/controller/dto/response/ShowInterestApiResponse.java deleted file mode 100644 index 08d6ea9a..00000000 --- a/app/api/show-api/src/main/java/com/example/show/controller/dto/response/ShowInterestApiResponse.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.example.show.controller.dto.response; - -import com.example.show.service.dto.response.ShowInterestServiceResponse; -import io.swagger.v3.oas.annotations.media.Schema; - -public record ShowInterestApiResponse( - @Schema(description = "관심 여부 (T: 관심 있음, F: 관심 없음)") - boolean hasInterest -) { - - public static ShowInterestApiResponse from(ShowInterestServiceResponse response) { - return new ShowInterestApiResponse(response.hasInterest()); - } -} diff --git a/app/api/show-api/src/main/java/com/example/show/service/UserShowService.java b/app/api/show-api/src/main/java/com/example/show/service/UserShowService.java index b5bf602b..489ed79b 100644 --- a/app/api/show-api/src/main/java/com/example/show/service/UserShowService.java +++ b/app/api/show-api/src/main/java/com/example/show/service/UserShowService.java @@ -8,9 +8,9 @@ import com.example.show.service.dto.request.InterestShowPaginationServiceRequest; import com.example.show.service.dto.request.ShowAlertPaginationServiceRequest; import com.example.show.service.dto.request.ShowInterestServiceRequest; +import com.example.show.service.dto.request.ShowUninterestedServiceRequest; import com.example.show.service.dto.request.TicketingAlertReservationServiceRequest; import com.example.show.service.dto.response.InterestShowPaginationServiceResponse; -import com.example.show.service.dto.response.ShowInterestServiceResponse; import com.example.show.service.dto.response.TerminatedTicketingShowCountServiceResponse; import com.example.show.service.dto.response.TicketingAlertReservationServiceResponse; import com.example.show.service.dto.usershow.response.NumberOfInterestShowServiceResponse; @@ -44,12 +44,14 @@ public class UserShowService { private final InterestShowUseCase interestShowUseCase; private final MessagePublisher messagePublisher; - public ShowInterestServiceResponse interest(ShowInterestServiceRequest request) { + public void interest(ShowInterestServiceRequest request) { Show show = showUseCase.findShowOrThrowNoSuchElementException(request.showId()); + interestShowUseCase.interest(request.toDomainRequest(show.getId())); + } - return ShowInterestServiceResponse.from( - interestShowUseCase.interest(request.toDomainRequest(show.getId())) - ); + public void notInterest(ShowUninterestedServiceRequest request) { + Show show = showUseCase.findShowOrThrowNoSuchElementException(request.showId()); + interestShowUseCase.notInterest(request.toDomainRequest(show.getId())); } public PaginationServiceResponse findInterestShows( diff --git a/app/api/show-api/src/main/java/com/example/show/service/dto/request/ShowUninterestedServiceRequest.java b/app/api/show-api/src/main/java/com/example/show/service/dto/request/ShowUninterestedServiceRequest.java new file mode 100644 index 00000000..7b3931c8 --- /dev/null +++ b/app/api/show-api/src/main/java/com/example/show/service/dto/request/ShowUninterestedServiceRequest.java @@ -0,0 +1,19 @@ +package com.example.show.service.dto.request; + +import java.util.UUID; +import lombok.Builder; +import org.example.dto.show.request.UninterestedShowDomainRequest; + +@Builder +public record ShowUninterestedServiceRequest( + UUID showId, + UUID userId +) { + + public UninterestedShowDomainRequest toDomainRequest(UUID showId) { + return UninterestedShowDomainRequest.builder() + .showId(showId) + .userId(userId()) + .build(); + } +} diff --git a/app/domain/show-domain/src/main/java/org/example/dto/show/request/UninterestedShowDomainRequest.java b/app/domain/show-domain/src/main/java/org/example/dto/show/request/UninterestedShowDomainRequest.java new file mode 100644 index 00000000..a527f7cf --- /dev/null +++ b/app/domain/show-domain/src/main/java/org/example/dto/show/request/UninterestedShowDomainRequest.java @@ -0,0 +1,12 @@ +package org.example.dto.show.request; + +import java.util.UUID; +import lombok.Builder; + +@Builder +public record UninterestedShowDomainRequest( + UUID showId, + UUID userId +) { + +} diff --git a/app/domain/show-domain/src/main/java/org/example/entity/usershow/InterestShow.java b/app/domain/show-domain/src/main/java/org/example/entity/usershow/InterestShow.java index 83061cb2..ca81dcc4 100644 --- a/app/domain/show-domain/src/main/java/org/example/entity/usershow/InterestShow.java +++ b/app/domain/show-domain/src/main/java/org/example/entity/usershow/InterestShow.java @@ -29,11 +29,10 @@ private InterestShow(UUID userId, UUID showId) { } public void interest() { - if (this.getIsDeleted()) { - this.revive(); - return; - } + this.revive(); + } + public void uninterested() { this.softDelete(); } diff --git a/app/domain/show-domain/src/main/java/org/example/usecase/InterestShowUseCase.java b/app/domain/show-domain/src/main/java/org/example/usecase/InterestShowUseCase.java index 336e02f7..c6a6c42b 100644 --- a/app/domain/show-domain/src/main/java/org/example/usecase/InterestShowUseCase.java +++ b/app/domain/show-domain/src/main/java/org/example/usecase/InterestShowUseCase.java @@ -3,6 +3,7 @@ import java.util.Optional; import java.util.UUID; import lombok.RequiredArgsConstructor; +import org.example.dto.show.request.UninterestedShowDomainRequest; import org.example.dto.usershow.request.InterestShowDomainRequest; import org.example.dto.usershow.request.InterestShowPaginationDomainRequest; import org.example.dto.usershow.response.InterestShowPaginationDomainResponse; @@ -18,25 +19,25 @@ public class InterestShowUseCase { private final InterestShowRepository interestShowRepository; @Transactional - public InterestShow interest(InterestShowDomainRequest request) { - Optional optInterestShow = findInterestShowByShowIdAndUserId( - request.showId(), - request.userId() - ); - - if (optInterestShow.isEmpty()) { - return interestShowRepository.save( - InterestShow.builder() - .showId(request.showId()) - .userId(request.userId()) - .build() + public void interest(InterestShowDomainRequest request) { + findOptionalInterestShowByShowIdAndUserId(request.showId(), request.userId()) + .ifPresentOrElse( + InterestShow::interest, + () -> interestShowRepository.save( + InterestShow.builder() + .showId(request.showId()) + .userId(request.userId()) + .build() + ) ); - } - - InterestShow interestShow = optInterestShow.get(); - interestShow.interest(); + } - return interestShow; + @Transactional + public void notInterest(UninterestedShowDomainRequest request) { + findOptionalInterestShowByShowIdAndUserId( + request.showId(), + request.userId() + ).ifPresent(InterestShow::uninterested); } public Optional findInterestShow(UUID showId, UUID userId) { @@ -57,7 +58,7 @@ public void deleteAllByUserId(UUID userId) { interestShowRepository.deleteAllByUserId(userId); } - private Optional findInterestShowByShowIdAndUserId(UUID showId, UUID userId) { + private Optional findOptionalInterestShowByShowIdAndUserId(UUID showId, UUID userId) { return interestShowRepository.findByShowIdAndUserId(showId, userId); } }