Skip to content

Commit

Permalink
fix: 공연 티켓팅 알림, 관심 등록 예외 처리 추가 (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
GaBaljaintheroom authored Sep 3, 2024
1 parent a18a2af commit 3c9c645
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

public enum ShowError implements BusinessError {

ENTITY_NOT_FOUND {
TICKETING_ALERT_RESERVED_ERROR {
@Override
public int getHttpStatus() {
return 404;
return 400;
}

@Override
Expand All @@ -17,12 +17,12 @@ public String getErrorCode() {

@Override
public String getClientMessage() {
return "해당 공연을 찾을 수 없습니다.";
return "해당 공연의 티켓팅 알림을 설정할 수 없습니다.";
}

@Override
public String getLogMessage() {
return "공연 ID에 매칭되는 정보를 찾을 수 없습니다.";
return "해당 공연의 티켓팅 시간에 설정할 수 있는 알림 시간이 없습니다.";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.example.publish.MessagePublisher;
import com.example.publish.message.TicketingAlertsToReserveServiceMessage;
import com.example.show.controller.vo.TicketingApiType;
import com.example.show.error.ShowError;
import com.example.show.service.dto.param.ShowAlertPaginationServiceParam;
import com.example.show.service.dto.param.ShowSearchPaginationServiceParam;
import com.example.show.service.dto.request.InterestShowPaginationServiceRequest;
Expand Down Expand Up @@ -33,6 +34,7 @@
import org.example.entity.TicketingAlert;
import org.example.entity.show.Show;
import org.example.entity.show.ShowTicketingTime;
import org.example.exception.BusinessException;
import org.example.usecase.TicketingAlertUseCase;
import org.example.usecase.UserShowUseCase;
import org.example.usecase.show.ShowUseCase;
Expand All @@ -52,7 +54,7 @@ public ShowDetailServiceResponse getShow(UUID userId, UUID showId, String viewId
ShowDetailDomainResponse showDetail = showUseCase.findShowDetail(showId);

boolean isInterested =
userId != null && userShowUseCase.findByShowIdAndUserId(showId, userId).isPresent();
userId != null && userShowUseCase.findInterestShow(showId, userId).isPresent();

if (viewCountComponent.validateViewCount(showId, viewIdentifier)) {
showUseCase.view(showId);
Expand Down Expand Up @@ -111,8 +113,10 @@ public PaginationServiceResponse<InterestShowPaginationServiceResponse> findInte
}

public ShowInterestServiceResponse interest(ShowInterestServiceRequest request) {
Show show = showUseCase.findShowOrThrowNoSuchElementException(request.showId());

return ShowInterestServiceResponse.from(
userShowUseCase.interest(request.toDomainRequest())
userShowUseCase.interest(request.toDomainRequest(show.getId()))
);
}

Expand Down Expand Up @@ -147,13 +151,16 @@ public void alertReservation(
ticketingAlertReservationRequest.type().toDomainType()
);

var domainResponse = ticketingAlertUseCase.alertReservation(
ticketingAlertReservationRequest.toDomainRequest(
showTicketingTime.getShow().getTitle(),
showTicketingTime.getTicketingAt()
)
var request = ticketingAlertReservationRequest.toDomainRequest(
showTicketingTime.getShow().getTitle(),
showTicketingTime.getTicketingAt()
);

if (request.alertTimes().isEmpty()) {
throw new BusinessException(ShowError.TICKETING_ALERT_RESERVED_ERROR);
}

var domainResponse = ticketingAlertUseCase.alertReservation(request);
messagePublisher.publishTicketingReservation(
"ticketingAlert",
TicketingAlertsToReserveServiceMessage.from(domainResponse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public record ShowInterestServiceRequest(
UUID userId
) {

public InterestShowDomainRequest toDomainRequest() {
public InterestShowDomainRequest toDomainRequest(UUID showId) {
return InterestShowDomainRequest.builder()
.showId(showId())
.showId(showId)
.userId(userId())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static InterestShowPaginationServiceResponse from(
.interestShowId(interestShow.getId())
.interestedAt(interestShow.getUpdatedAt())
.title(show.getTitle())
.location(show.getTitle())
.location(show.getLocation())
.posterImageURL(show.getImage())
.startAt(show.getStartDate())
.endAt(show.getEndDate())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.example.repository.show;

import java.util.List;
import java.util.Optional;
import java.util.UUID;
import org.example.entity.show.Show;
import org.springframework.data.jpa.repository.JpaRepository;

public interface ShowRepository extends JpaRepository<Show, UUID>, ShowQuerydslRepository {

List<Show> findShowsByIdIn(List<UUID> showIds);

Optional<Show> findByIdAndIsDeletedFalse(UUID showId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public long findTerminatedTicketingShowsCount(List<UUID> showIds, LocalDateTime
return showRepository.findTerminatedTicketingShowsCount(showIds, now);
}

private Show findShowOrThrowNoSuchElementException(UUID id) {
return showRepository.findById(id).orElseThrow(NoSuchElementException::new);
public Show findShowOrThrowNoSuchElementException(UUID id) {
return showRepository.findByIdAndIsDeletedFalse(id).orElseThrow(NoSuchElementException::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ public interface InterestShowRepository extends JpaRepository<InterestShow, UUID

Optional<InterestShow> findByShowIdAndUserId(UUID showId, UUID userId);

Optional<InterestShow> findByShowIdAndUserIdAndIsDeletedFalse(UUID showId, UUID userId);

Long countInterestShowByUserIdAndIsDeletedFalse(UUID userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class UserShowUseCase {

@Transactional
public InterestShow interest(InterestShowDomainRequest request) {
Optional<InterestShow> optInterestShow = findByShowIdAndUserId(request.showId(), request.userId());
Optional<InterestShow> optInterestShow = findInterestShowByShowIdAndUserId(request.showId(), request.userId());

if (optInterestShow.isEmpty()) {
return interestShowRepository.save(
Expand All @@ -43,8 +43,8 @@ public InterestShow interest(InterestShowDomainRequest request) {
return interestShow;
}

public Optional<InterestShow> findByShowIdAndUserId(UUID showId, UUID userId) {
return interestShowRepository.findByShowIdAndUserId(showId, userId);
public Optional<InterestShow> findInterestShow(UUID showId, UUID userId) {
return interestShowRepository.findByShowIdAndUserIdAndIsDeletedFalse(showId, userId);
}

public List<ArtistSubscription> findArtistSubscriptionByUserId(UUID userId) {
Expand Down Expand Up @@ -73,4 +73,8 @@ public long countInterestShows(UUID userId) {
Long result = interestShowRepository.countInterestShowByUserIdAndIsDeletedFalse(userId);
return result == null ? 0 : result;
}

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

0 comments on commit 3c9c645

Please sign in to comment.