Skip to content

Commit

Permalink
�fix: 공연 관심 등록 API 분리 (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
devmizz authored Sep 16, 2024
1 parent 745097d commit ca06aba
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public ResponseEntity<PaginationApiResponse<ShowPaginationApiParam>> getShows(
.hasNext(response.hasNext())
.build()
);

}

@GetMapping("/{showId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
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;
import com.example.show.controller.dto.usershow.response.NumberOfTicketingAlertApiResponse;
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;
Expand Down Expand Up @@ -42,21 +42,33 @@ public class UserShowController {
private final UserShowService userShowService;

@PostMapping("/{showId}/interests")
@Operation(summary = "공연 관심 등록 / 취소")
public ResponseEntity<ShowInterestApiResponse> interest(
@Operation(summary = "공연 관심 등록")
public ResponseEntity<Void> 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<Void> uninterested(
@PathVariable("showId") UUID showId,
@AuthenticationPrincipal AuthenticatedInfo info
) {
userShowService.notInterest(
ShowUninterestedServiceRequest.builder()
.showId(showId)
.userId(info.userId())
.build()
);
return ResponseEntity.noContent().build();
}

@GetMapping("/interests")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<InterestShowPaginationServiceResponse> findInterestShows(
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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
) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,25 +19,25 @@ public class InterestShowUseCase {
private final InterestShowRepository interestShowRepository;

@Transactional
public InterestShow interest(InterestShowDomainRequest request) {
Optional<InterestShow> 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<InterestShow> findInterestShow(UUID showId, UUID userId) {
Expand All @@ -57,7 +58,7 @@ public void deleteAllByUserId(UUID userId) {
interestShowRepository.deleteAllByUserId(userId);
}

private Optional<InterestShow> findInterestShowByShowIdAndUserId(UUID showId, UUID userId) {
private Optional<InterestShow> findOptionalInterestShowByShowIdAndUserId(UUID showId, UUID userId) {
return interestShowRepository.findByShowIdAndUserId(showId, userId);
}
}

0 comments on commit ca06aba

Please sign in to comment.