Skip to content

Commit

Permalink
fix: 알림 구독 시간 형태 수정 (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
GaBaljaintheroom authored Dec 5, 2024
1 parent 912aac0 commit 2420039
Show file tree
Hide file tree
Showing 40 changed files with 167 additions and 338 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public ArtistSubscriptionServiceResponse subscribe(ArtistSubscriptionServiceRequ
.map(Artist::getId)
.toList();

var userFcmToken = userUseCase.findUserFcmTokensByUserId(request.userId());

var subscribedArtistIds = artistSubscriptionUseCase
.subscribe(requestArtistIds, request.userId()).stream()
.map(ArtistSubscription::getArtistId)
Expand All @@ -81,7 +83,7 @@ public ArtistSubscriptionServiceResponse subscribe(ArtistSubscriptionServiceRequ
.filter(artist -> subscribedArtistIds.contains(artist.getId()))
.map(ArtistServiceMessage::from)
.toList();
var userFcmToken = userUseCase.findUserFcmTokensByUserId(request.userId());


messagePublisher.publishArtistSubscription(
"artistSubscription",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public ArtistGenreDomainRequest toDomainRequest() {
.map(ArtistGenreType::findByGenreClassificationName)
.filter(Objects::nonNull)
.findFirst()
.orElse(genres.get(0))
.orElseGet(ArtistGenreType.POP::name)
.toLowerCase();

return ArtistGenreDomainRequest.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.pub.message;

import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;
import lombok.Builder;
Expand All @@ -10,21 +11,22 @@ public record TicketingAlertsToReserveServiceMessage(
String userFcmToken,
String name,
UUID showId,
List<TicketingTimeServiceMessage> addAts,
List<TicketingTimeServiceMessage> deleteAts
LocalDateTime ticketingAt,
List<LocalDateTime> addAts,
List<LocalDateTime> deleteAts
) {

public static TicketingAlertsToReserveServiceMessage of(
TicketingAlertsDomainResponse responses,
TicketingAlertsDomainResponse response,
String userFcmToken
) {
return TicketingAlertsToReserveServiceMessage.builder()
.userFcmToken(userFcmToken)
.name(responses.name())
.showId(responses.showId())
.addAts(responses.addAts().stream().map(TicketingTimeServiceMessage::from).toList())
.deleteAts(
responses.deleteAts().stream().map(TicketingTimeServiceMessage::from).toList())
.name(response.name())
.showId(response.showId())
.ticketingAt(response.ticketingAt())
.addAts(response.addAts())
.deleteAts(response.deleteAts())
.build();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,9 @@ public SuccessResponse<TicketingAlertReservationApiResponse> getAlertsReservatio
@PathVariable("showId") UUID showId,
@RequestParam("ticketingApiType") TicketingApiType type
) {
var now = LocalDateTime.now();
return SuccessResponse.ok(
TicketingAlertReservationApiResponse.from(
userShowService.findAlertsReservations(info.userId(), showId, type, now)
userShowService.findAlertsReservations(info.userId(), showId, type)
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static TicketingAlertReservationTimeApiParam from(
TicketingAlertReservationTimeServiceParam param
) {
return TicketingAlertReservationTimeApiParam.builder()
.beforeMinutes(param.time().getMinutes())
.beforeMinutes(param.beforeMinutes())
.isReserved(param.isReserved())
.canReserve(param.canReserve())
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.example.show.controller.dto.request;

import com.example.show.controller.vo.TicketingAlertTimeApiType;
import com.example.show.controller.vo.TicketingApiType;
import com.example.show.service.dto.request.TicketingAlertReservationServiceRequest;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;
import org.example.util.ValidateStatus;

public record TicketingAlertReservationApiRequest(

@Schema(description = "공연 티켓팅 알림 시간 선택")
List<TicketingAlertTimeApiType> alertTimes
@Schema(description = "공연 티켓팅 알림 시간 선택", example = "yyyy-MM-dd'T'HH:mm")
List<LocalDateTime> alertTimes
) {

public TicketingAlertReservationServiceRequest toServiceRequest(
Expand All @@ -23,7 +23,7 @@ public TicketingAlertReservationServiceRequest toServiceRequest(
.userId(userId)
.showId(showId)
.type(type)
.alertTimes(ValidateStatus.checkNullOrEmpty(alertTimes))
.alertAts(ValidateStatus.checkNullOrEmpty(alertTimes))
.build();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public List<ShowInfoServiceResponse> findShowDetailWithTicketingTimes() {
var artistNameWithShowIdDomainResponses = artistUseCase.findArtistNamesWithShowId();
var genreNameWithShowIdDomainResponses = genreUseCase.findGenreNamesWithShowId();

return ShowInfoServiceResponse.as(
return ShowInfoServiceResponse.of(
showWithTicketingTimesDomainResponses,
artistNameWithShowIdDomainResponses,
genreNameWithShowIdDomainResponses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,14 @@ public void alertReservation(
throw new BusinessException(ShowError.TICKETING_ALERT_RESERVED_ERROR);
}

String userFcmToken = userUseCase.findUserFcmTokensByUserId(request.userId());
var domainResponse = ticketingAlertUseCase.alertReservation(
request.toDomainRequest(
showTicketingTime.getShow().getTitle(),
showTicketingTime.getTicketingAt()
)
);

String userFcmToken = userUseCase.findUserFcmTokensByUserId(request.userId());

messagePublisher.publishTicketingReservation(
"ticketingAlert",
TicketingAlertsToReserveServiceMessage.of(domainResponse, userFcmToken)
Expand Down Expand Up @@ -129,16 +128,14 @@ public PaginationServiceResponse<ShowAlertPaginationServiceParam> findAlertShows
public TicketingAlertReservationServiceResponse findAlertsReservations(
UUID userId,
UUID showId,
TicketingApiType type,
LocalDateTime now
TicketingApiType type
) {
ShowTicketingTime ticketingTime = showUseCase.findTicketingAlertReservation(showId, type.toDomainType());
List<TicketingAlert> ticketingAlerts = ticketingAlertUseCase.findTicketingAlerts(userId, showId);

return TicketingAlertReservationServiceResponse.as(
return TicketingAlertReservationServiceResponse.of(
ticketingTime.getTicketingAt(),
ticketingAlerts,
now
ticketingAlerts
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.example.show.service.dto.param;

import com.example.show.controller.vo.TicketingAlertTimeApiType;
import lombok.Builder;

@Builder
public record TicketingAlertReservationTimeServiceParam(
TicketingAlertTimeApiType time,
int beforeMinutes,
boolean isReserved,
boolean canReserve
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.example.show.service.dto.request;

import com.example.show.controller.vo.TicketingAlertTimeApiType;
import com.example.show.controller.vo.TicketingApiType;
import java.time.LocalDateTime;
import java.util.List;
Expand All @@ -14,7 +13,7 @@ public record TicketingAlertReservationServiceRequest(
UUID userId,
UUID showId,
TicketingApiType type,
List<TicketingAlertTimeApiType> alertTimes
List<LocalDateTime> alertAts
) {

public TicketingAlertReservationDomainRequest toDomainRequest(
Expand All @@ -27,7 +26,13 @@ public TicketingAlertReservationDomainRequest toDomainRequest(
.type(type.toDomainType())
.name(name)
.ticketingAt(ticketingAt)
.alertTimes(TicketingAlertTimeApiType.availableReserveTimeToDomainType(ticketingAt, alertTimes))
.alertAts(getAlertAts(ticketingAt))
.build();
}

private List<LocalDateTime> getAlertAts(LocalDateTime ticketingAt) {
return alertAts.stream()
.filter(alertTime -> alertTime.isBefore(ticketingAt))
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public ShowInfoServiceResponse(ShowInfoDomainResponse showInfo) {
);
}

public static List<ShowInfoServiceResponse> as(
public static List<ShowInfoServiceResponse> of(
List<ShowWithTicketingTimesDomainParam> showWithTicketingTimes,
List<ArtistNamesWithShowIdDomainParam> artistNamesWithShowId,
List<GenreNamesWithShowIdDomainParam> genreNamesWithShowId
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package com.example.show.service.dto.response;

import com.example.show.controller.vo.TicketingAlertTimeApiType;
import com.example.show.service.dto.param.TicketingAlertReservationTimeServiceParam;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.Builder;
import org.example.entity.usershow.TicketingAlert;

Expand All @@ -16,37 +12,26 @@ public record TicketingAlertReservationServiceResponse(
List<TicketingAlertReservationTimeServiceParam> times
) {

public static TicketingAlertReservationServiceResponse as(
public static TicketingAlertReservationServiceResponse of(
LocalDateTime ticketingAt,
List<TicketingAlert> reservedAlerts,
LocalDateTime now
List<TicketingAlert> reservedAlerts
) {
Set<TicketingAlertTimeApiType> distinctAlertTimes = reservedAlerts.stream()
List<TicketingAlertReservationTimeServiceParam> times = reservedAlerts.stream()
.map(alert -> {
int minutesGap = (int) Duration.between(alert.getAlertTime(), ticketingAt).toMinutes();
return TicketingAlertTimeApiType.getTicketingAlertTimeByMinutesGap(minutesGap);
}).collect(Collectors.toSet());
int beforeMinutes = Long.valueOf(Duration.between(alert.getAlertTime(), ticketingAt)
.toMinutes()).intValue();

return new TicketingAlertReservationServiceResponse(
Arrays.stream(TicketingAlertTimeApiType.values())
.map(alertTimeType -> {
LocalDateTime alertTime = ticketingAt.minusMinutes(alertTimeType.getMinutes());
boolean canReserve = alert.getAlertTime().isAfter(LocalDateTime.now());
return TicketingAlertReservationTimeServiceParam.builder()
.beforeMinutes(beforeMinutes)
.isReserved(true)
.canReserve(canReserve)
.build();
})
.toList();

if (alertTime.isBefore(now)) {
return TicketingAlertReservationTimeServiceParam.builder()
.time(alertTimeType)
.isReserved(false)
.canReserve(false)
.build();
}

return TicketingAlertReservationTimeServiceParam.builder()
.time(alertTimeType)
.isReserved(distinctAlertTimes.contains(alertTimeType))
.canReserve(true)
.build();
}
).toList()
);
return TicketingAlertReservationServiceResponse.builder()
.times(times)
.build();
}
}
Binary file not shown.
Loading

0 comments on commit 2420039

Please sign in to comment.