Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat : 공연 티켓팅 알림 등록 및 조회 #107

Merged
merged 12 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ private RequestMatcher getMatcherForUserAndAdmin() {
antMatcher(HttpMethod.POST, "/api/v1/users/withdrawal"),
antMatcher(HttpMethod.GET, "/api/v1/users/profile"),
antMatcher(HttpMethod.POST, "/api/v1/shows/**/interest"),
antMatcher(HttpMethod.POST, "/api/v1/shows/**/alert"),
antMatcher(HttpMethod.POST, "/api/v1/shows/{showId}/alert"),
antMatcher(HttpMethod.GET, "/api/v1/shows/{showId}/alert/reservations"),
antMatcher(HttpMethod.POST, "/api/v1/genres/subscribe"),
antMatcher(HttpMethod.POST, "/api/v1/genres/unsubscribe"),
antMatcher(HttpMethod.GET, "/api/v1/genres/subscriptions"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.example.publish.message.ArtistSubscriptionServiceMessage;
import com.example.publish.message.GenreSubscriptionServiceMessage;
import com.example.publish.message.ShowRelationArtistAndGenreServiceMessage;
import com.example.publish.message.TicketingReservationServiceMessage;
import com.example.publish.message.TicketingAlertsToReserveServiceMessage;

public interface MessagePublisher {

Expand All @@ -13,5 +13,5 @@ public interface MessagePublisher {

void publishGenreSubscription(String topic, GenreSubscriptionServiceMessage message);

void publishTicketingReservation(String topic, TicketingReservationServiceMessage message);
void publishTicketingReservation(String topic, TicketingAlertsToReserveServiceMessage message);
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.example.publish.message;

import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;
import lombok.Builder;
import org.example.dto.response.TicketingAlertsDomainResponse;

@Builder
public record TicketingAlertsToReserveServiceMessage(
String userFcmToken,
String name,
UUID showId,
List<LocalDateTime> reserveAts
) {

public static TicketingAlertsToReserveServiceMessage from(
TicketingAlertsDomainResponse responses
) {
return TicketingAlertsToReserveServiceMessage.builder()
.userFcmToken(responses.userFcmToken())
.name(responses.name())
.showId(responses.showId())
.reserveAts(responses.reservedAts())
.build();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package com.example.show.controller;

import com.example.show.controller.dto.param.ShowSearchPaginationApiParam;
import com.example.show.controller.dto.request.ShowAlertRegistrationApiRequest;
import com.example.show.controller.dto.request.ShowInterestPaginationApiRequest;
import com.example.show.controller.dto.request.ShowPaginationApiRequest;
import com.example.show.controller.dto.request.ShowSearchPaginationApiRequest;
import com.example.show.controller.dto.request.TicketingAlertReservationApiRequest;
import com.example.show.controller.dto.response.InterestShowPaginationApiResponse;
import com.example.show.controller.dto.response.ShowAlertPaginationApiResponse;
import com.example.show.controller.dto.response.ShowDetailApiResponse;
import com.example.show.controller.dto.response.ShowInterestApiResponse;
import com.example.show.controller.dto.response.ShowPaginationApiParam;
import com.example.show.controller.dto.response.TicketingAlertReservationApiResponse;
import com.example.show.controller.vo.TicketingApiType;
import com.example.show.service.ShowService;
import com.example.show.service.dto.request.ShowInterestServiceRequest;
import com.example.show.service.dto.response.ShowPaginationServiceResponse;
Expand Down Expand Up @@ -117,15 +119,35 @@ public ResponseEntity<ShowDetailApiResponse> getShow(
);
}

@GetMapping("/{showId}/alert/reservations")
@Operation(summary = "공연 티켓팅 알림 예약 조회")
public ResponseEntity<TicketingAlertReservationApiResponse> getAlertsReservations(
@AuthenticationPrincipal AuthenticatedUser user,
@PathVariable("showId") UUID showId,
@RequestParam("ticketingApiType") TicketingApiType type
) {
return ResponseEntity.ok(
TicketingAlertReservationApiResponse.from(
showService.findAlertsReservations(user.userId(), showId, type)
)
);
}

@PostMapping("/{showId}/alert")
@Operation(
summary = "공연 알림 등록 / 취소",
summary = "공연 티켓팅 알림 등록 / 취소",
description = "요청한 알람 시간으로 기존 내용을 덮어쓴다."
)
public ResponseEntity<Void> alert(
@AuthenticationPrincipal AuthenticatedUser user,
@PathVariable("showId") UUID showId,
@Valid @RequestBody ShowAlertRegistrationApiRequest request
@RequestParam("ticketingApiType") TicketingApiType type,
@Valid @RequestBody TicketingAlertReservationApiRequest ticketingAlertReservationRequest
) {
showService.alertReservation(
ticketingAlertReservationRequest.toServiceRequest(user.userId(), showId, type)
);

return ResponseEntity.noContent().build();
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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.util.List;
import java.util.UUID;
import org.example.util.ValidateStatus;

public record TicketingAlertReservationApiRequest(

@Schema(description = "공연 티켓팅 알림 시간 선택")
List<TicketingAlertTimeApiType> alertTimes
) {

public TicketingAlertReservationServiceRequest toServiceRequest(
UUID userId,
UUID showId,
TicketingApiType type
) {
return TicketingAlertReservationServiceRequest.builder()
.userId(userId)
.showId(showId)
.type(type)
.alertTimes(ValidateStatus.checkNullOrEmpty(alertTimes))
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.show.controller.dto.response;

import com.example.show.service.dto.response.TicketingAlertReservationServiceResponse;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;

@Builder
public record TicketingAlertReservationApiResponse(
@Schema(description = "공연 알림 예약 상태")
TicketingAlertReservationStatusApiResponse alertReservationStatus,

@Schema(description = "공연 알림 예약 가능 여부")
TicketingAlertReservationAvailabilityApiResponse alertReservationAvailability
) {
public static TicketingAlertReservationApiResponse from(
TicketingAlertReservationServiceResponse response
) {
var alertReservationStatus = TicketingAlertReservationStatusApiResponse.from(
response.alertReservationStatus()
);
var alertReservationAvailability = TicketingAlertReservationAvailabilityApiResponse.from(
response.alertReservationAvailability()
);

return TicketingAlertReservationApiResponse.builder()
.alertReservationStatus(alertReservationStatus)
.alertReservationAvailability(alertReservationAvailability)
.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.example.show.controller.dto.response;

import com.example.show.service.dto.response.TicketingAlertReservationAvailabilityServiceResponse;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;

@Builder
public record TicketingAlertReservationAvailabilityApiResponse(
@Schema(description = "공연 티켓팅 24 시간 전")
boolean canReserve24,

@Schema(description = "공연 티켓팅 6 시간 전")
boolean canReserve6,

@Schema(description = "공연 티켓팅 1 시간 전")
boolean canReserve1
) {

public static TicketingAlertReservationAvailabilityApiResponse from(
TicketingAlertReservationAvailabilityServiceResponse response
) {
return TicketingAlertReservationAvailabilityApiResponse.builder()
.canReserve24(response.canReserve24())
.canReserve6(response.canReserve6())
.canReserve1(response.canReserve1())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.example.show.controller.dto.response;

import com.example.show.service.dto.response.TicketingAlertReservationStatusServiceResponse;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;

@Builder
public record TicketingAlertReservationStatusApiResponse(

@Schema(description = "공연 티켓팅 24 시간 전")
boolean before24,

@Schema(description = "공연 티켓팅 6 시간 전")
boolean before6,

@Schema(description = "공연 티켓팅 1 시간 전")
boolean before1
) {

public static TicketingAlertReservationStatusApiResponse from(
TicketingAlertReservationStatusServiceResponse response
) {
return TicketingAlertReservationStatusApiResponse.builder()
.before24(response.before24())
.before6(response.before6())
.before1(response.before1())
.build();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.example.show.controller.vo;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.List;
import org.example.vo.TicketingAlertTime;

public enum TicketingAlertTimeApiType {
BEFORE_24(24),
BEFORE_6(6),
BEFORE_1(1);

private final int time;

TicketingAlertTimeApiType(int time) {
this.time = time;
}

public TicketingAlertTime toDomainType() {
return switch (this) {
case BEFORE_24 -> TicketingAlertTime.BEFORE_24;
case BEFORE_6 -> TicketingAlertTime.BEFORE_6;
case BEFORE_1 -> TicketingAlertTime.BEFORE_1;
};
}

public static List<TicketingAlertTime> availableReserveTimeToDomainType(LocalDateTime ticketingAt) {
long hoursDifference = Duration.between(LocalDateTime.now(), ticketingAt).toHours();

return ALL_ALERT_TIMES.stream()
.filter(alertTime -> {
return switch (alertTime) {
case BEFORE_24 -> hoursDifference >= 24;
case BEFORE_6 -> hoursDifference >= 6;
case BEFORE_1 -> hoursDifference >= 1;
};
})
.toList();
}

private static final List<TicketingAlertTime> ALL_ALERT_TIMES = List.of(
TicketingAlertTime.BEFORE_24,
TicketingAlertTime.BEFORE_6,
TicketingAlertTime.BEFORE_1
);

}
Loading
Loading