Skip to content

Commit

Permalink
�feat: 공연 알림 목록 조회 구현 (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
GaBaljaintheroom authored Aug 18, 2024
1 parent d2dbeab commit 01801e3
Show file tree
Hide file tree
Showing 39 changed files with 561 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,13 @@ private RequestMatcher getMatcherForAnyone() {

private RequestMatcher getMatcherForUserAndAdmin() {
return RequestMatchers.anyOf(
antMatcher(HttpMethod.GET, "/api/v1/shows/interests"),
antMatcher(HttpMethod.POST, "/api/v1/users/logout"),
antMatcher(HttpMethod.POST, "/api/v1/users/withdrawal"),
antMatcher(HttpMethod.GET, "/api/v1/users/profile"),
antMatcher(HttpMethod.POST, "/api/v1/shows/**/interest"),
antMatcher(HttpMethod.GET, "/api/v1/shows/interests"),
antMatcher(HttpMethod.POST, "/api/v1/shows/{showId}/alert"),
antMatcher(HttpMethod.GET, "/api/v1/shows/alerts"),
antMatcher(HttpMethod.GET, "/api/v1/shows/{showId}/alert/reservations"),
antMatcher(HttpMethod.POST, "/api/v1/genres/subscribe"),
antMatcher(HttpMethod.POST, "/api/v1/genres/unsubscribe"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public record TicketingAlertsToReserveServiceMessage(
String userFcmToken,
String name,
UUID showId,
List<LocalDateTime> reserveAts
List<LocalDateTime> addAts,
List<LocalDateTime> deleteAts
) {

public static TicketingAlertsToReserveServiceMessage from(
Expand All @@ -21,7 +22,8 @@ public static TicketingAlertsToReserveServiceMessage from(
.userFcmToken(responses.userFcmToken())
.name(responses.name())
.showId(responses.showId())
.reserveAts(responses.reservedAts())
.addAts(responses.addAts())
.deleteAts(responses.deleteAts())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package com.example.show.controller;

import com.example.show.controller.dto.param.ShowAlertPaginationApiParam;
import com.example.show.controller.dto.param.ShowSearchPaginationApiParam;
import com.example.show.controller.dto.request.ShowAlertPaginationApiRequest;
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.param.ShowAlertPaginationServiceParam;
import com.example.show.service.dto.request.ShowInterestServiceRequest;
import com.example.show.service.dto.response.ShowPaginationServiceResponse;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -153,18 +155,28 @@ public ResponseEntity<Void> alert(

@GetMapping("/alerts")
@Operation(summary = "공연 알림 목록 조회")
public ResponseEntity<ShowAlertPaginationApiResponse> getAlerts(
@RequestParam(required = false) ShowInterestPaginationApiRequest param
public ResponseEntity<PaginationApiResponse<ShowAlertPaginationApiParam>> getAlerts(
@AuthenticationPrincipal AuthenticatedUser user,
@ParameterObject ShowAlertPaginationApiRequest request
) {
PaginationServiceResponse<ShowAlertPaginationServiceParam> alertShows = showService.findAlertShows(
request.toServiceRequest(user.userId()));

var showAlertPaginationApiParams = alertShows.data().stream()
.map(ShowAlertPaginationApiParam::from)
.toList();

return ResponseEntity.ok(
ShowAlertPaginationApiResponse.builder().build()
PaginationApiResponse.<ShowAlertPaginationApiParam>builder()
.data(showAlertPaginationApiParams)
.hasNext(alertShows.hasNext())
.build()
);
}

@GetMapping("/search")
@Operation(summary = "검색하기")
public ResponseEntity<PaginationApiResponse<ShowSearchPaginationApiParam>> search(
@AuthenticationPrincipal AuthenticatedUser user,
@ParameterObject ShowSearchPaginationApiRequest request
) {
var response = showService.searchShow(request.toServiceRequest());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.example.show.controller.dto.param;

import com.example.show.service.dto.param.ShowAlertPaginationServiceParam;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;
import java.util.UUID;
import org.example.util.DateTimeUtil;

public record ShowAlertPaginationApiParam(
@Schema(description = "공연 ID")
UUID id,

@Schema(description = "공연 제목")
String title,

@Schema(description = "공연 시작 날짜")
String startAt,

@Schema(description = "공연 마지막 날짜")
String endAt,

@Schema(description = "공연 장소")
String location,

@Schema(description = "공연 이미지")
String image,

@Schema(description = "cursorValue로서 공연 티켓팅 날짜")
LocalDateTime ticketingAt
) {

public static ShowAlertPaginationApiParam from(ShowAlertPaginationServiceParam serviceParam) {
return new ShowAlertPaginationApiParam(
serviceParam.id(),
serviceParam.title(),
DateTimeUtil.formatDate(serviceParam.startAt()),
DateTimeUtil.formatDate(serviceParam.endAt()),
serviceParam.location(),
serviceParam.image(),
serviceParam.ticketingAt()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.example.show.service.dto.param.ShowSearchPaginationServiceParam;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDate;
import java.util.UUID;
import org.example.util.DateTimeUtil;

public record ShowSearchPaginationApiParam(
@Schema(description = "공연 ID")
Expand All @@ -12,8 +12,11 @@ public record ShowSearchPaginationApiParam(
@Schema(description = "공연 제목")
String title,

@Schema(description = "공연 날짜")
LocalDate date,
@Schema(description = "공연 시작 날짜")
String startAt,

@Schema(description = "공연 마지막 날짜")
String endAt,

@Schema(description = "공연 장소")
String location,
Expand All @@ -26,7 +29,8 @@ public static ShowSearchPaginationApiParam from(ShowSearchPaginationServiceParam
return new ShowSearchPaginationApiParam(
serviceParam.id(),
serviceParam.title(),
serviceParam.date(),
DateTimeUtil.formatDate(serviceParam.startAt()),
DateTimeUtil.formatDate(serviceParam.endAt()),
serviceParam.location(),
serviceParam.image()
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.example.show.controller.dto.request;

import com.example.show.service.dto.request.ShowAlertPaginationServiceRequest;
import io.swagger.v3.oas.annotations.Parameter;
import java.time.LocalDateTime;
import java.util.UUID;

public record ShowAlertPaginationApiRequest(

@Parameter(description = "페이지네이션 데이터 개수", required = true)
int size,
@Parameter(description = "이전 페이지네이션 마지막 데이터의 ID / 최초 조회라면 null")
UUID cursorId,

@Parameter(description = "이전 페이지네이션 마지막 데이터의 ticketingAt / 최초 조회라면 null")
LocalDateTime curSorValue
) {

public ShowAlertPaginationServiceRequest toServiceRequest(UUID userId) {
return ShowAlertPaginationServiceRequest.builder()
.userId(userId)
.size(size)
.cursorId(cursorId)
.cursorValue(curSorValue)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@

import com.example.show.service.dto.request.InterestShowPaginationServiceRequest;
import io.swagger.v3.oas.annotations.Parameter;
import java.time.LocalDateTime;
import java.util.UUID;

public record ShowInterestPaginationApiRequest(

@Parameter(description = "페이지네이션 데이터 개수")
@Parameter(description = "페이지네이션 데이터 개수", required = true)
int size,
@Parameter(description = "이전 페이지네이션 마지막 데이터의 ID / 최초 조회라면 null")
UUID cursorId
@Parameter(description = "이전 페이지네이션 마지막 데이터의 interestShowId / 최초 조회라면 null")
UUID cursorId,

@Parameter(description = "이전 페이지네이션 마지막 데이터의 interestedAt / 최초 조회라면 null")
LocalDateTime cursorValue
) {

public InterestShowPaginationServiceRequest toServiceRequest(UUID userId) {
return InterestShowPaginationServiceRequest.builder()
.userId(userId)
.size(size)
.cursorId(cursorId)
.cursorValue(cursorValue)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,51 @@
package com.example.show.controller.dto.response;

import com.example.show.service.dto.response.InterestShowPaginationServiceResponse;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;
import java.util.UUID;
import lombok.Builder;
import org.example.util.DateTimeUtil;

@Builder
public record InterestShowPaginationApiResponse(
@Schema(description = "공연 ID")
UUID id,

@Schema(description = "cursorID로서 관심 공연 ID")
UUID interestShowId,

@Schema(description = "cursorValue로서 관심 공연 지정 시간")
LocalDateTime interestedAt,

@Schema(description = "공연 이름")
String title,

@Schema(description = "공연 시작 날짜")
String startAt,

@Schema(description = "공연 종료 날짜")
String endAt,

@Schema(description = "공연 장소")
String location,
String posterImageURL,
String interestedAt

@Schema(description = "공연 포스터 이미지 주소")
String posterImageURL
) {

public static InterestShowPaginationApiResponse from(InterestShowPaginationServiceResponse response) {
public static InterestShowPaginationApiResponse from(
InterestShowPaginationServiceResponse response
) {
return InterestShowPaginationApiResponse.builder()
.id(response.showId())
.interestShowId(response.interestShowId())
.interestedAt(response.interestedAt())
.title(response.title())
.startAt(DateTimeUtil.formatDate(response.startAt()))
.endAt(DateTimeUtil.formatDate(response.endAt()))
.location(response.location())
.posterImageURL(response.posterImageURL())
.interestedAt(DateTimeUtil.formatDateTime(response.interestedAt()))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;
import java.util.UUID;
import lombok.Builder;
import org.example.util.DateTimeUtil;

@Builder
public record ShowDetailApiResponse(
Expand Down Expand Up @@ -44,8 +45,8 @@ public static ShowDetailApiResponse from(ShowDetailServiceResponse show) {
return ShowDetailApiResponse.builder()
.id(show.id())
.name(show.title())
.startDate(show.startDate().toString())
.endDate(show.endDate().toString())
.startDate(DateTimeUtil.formatDate(show.startDate()))
.endDate(DateTimeUtil.formatDate(show.endDate()))
.posterImageURL(show.posterImageURL())
.artists(
show.artists().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,19 @@ public TicketingAlertTime toDomainType() {
};
}

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

return ALL_ALERT_TIMES.stream()
return alertTimes.stream()
.filter(alertTime -> {
return switch (alertTime) {
case BEFORE_24 -> hoursDifference >= 24;
case BEFORE_6 -> hoursDifference >= 6;
case BEFORE_1 -> hoursDifference >= 1;
case BEFORE_24, BEFORE_6, BEFORE_1 -> hoursDifference >= alertTime.time;
};
})
.map(TicketingAlertTimeApiType::toDomainType)
.toList();
}

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

}
Loading

0 comments on commit 01801e3

Please sign in to comment.