Skip to content

Commit

Permalink
feat: 관심 공연 (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
devmizz authored Aug 15, 2024
1 parent 559ed4b commit 75cac87
Show file tree
Hide file tree
Showing 29 changed files with 446 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
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.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.ShowInterestPaginationApiResponse;
import com.example.show.controller.dto.response.ShowPaginationApiParam;
import com.example.show.service.ShowService;
import com.example.show.service.dto.request.ShowInterestServiceRequest;
import com.example.show.service.dto.response.ShowPaginationServiceResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.example.dto.response.PaginationApiResponse;
Expand Down Expand Up @@ -68,20 +70,40 @@ public ResponseEntity<PaginationApiResponse<ShowPaginationApiParam>> getShows(
@PostMapping("/{showId}/interest")
@Operation(summary = "공연 관심 등록 / 취소")
public ResponseEntity<ShowInterestApiResponse> interest(
@PathVariable("showId") UUID showId
@PathVariable("showId") UUID showId,
@AuthenticationPrincipal AuthenticatedUser user
) {
return ResponseEntity.ok(
new ShowInterestApiResponse(true)
ShowInterestApiResponse.from(
showService.interest(
ShowInterestServiceRequest.builder()
.showId(showId)
.userId(user.userId())
.build()
)
)
);
}

@GetMapping("/interests")
@Operation(summary = "공연 관심 목록 조회")
public ResponseEntity<ShowInterestPaginationApiResponse> getInterests(
@RequestParam(required = false) ShowInterestPaginationApiRequest param
public ResponseEntity<PaginationApiResponse<InterestShowPaginationApiResponse>> getInterests(
@ParameterObject ShowInterestPaginationApiRequest request,
@AuthenticationPrincipal AuthenticatedUser user
) {
var serviceResponse = showService.findInterestShows(
request.toServiceRequest(user.userId())
);

List<InterestShowPaginationApiResponse> response = serviceResponse.data().stream()
.map(InterestShowPaginationApiResponse::from)
.toList();

return ResponseEntity.ok(
ShowInterestPaginationApiResponse.builder().build()
PaginationApiResponse.<InterestShowPaginationApiResponse>builder()
.data(response)
.hasNext(serviceResponse.hasNext())
.build()
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package com.example.show.controller.dto.request;

import com.example.show.service.dto.request.InterestShowPaginationServiceRequest;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.UUID;
import org.example.pagination.vo.SortDirection;

public record ShowInterestPaginationApiRequest(

@Schema(description = "정렬 방향")
SortDirection sortDirection,

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

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

import com.example.show.service.dto.response.InterestShowPaginationServiceResponse;
import java.util.UUID;
import lombok.Builder;
import org.example.util.DateTimeUtil;

@Builder
public record InterestShowPaginationApiResponse(
UUID id,
String title,
String startAt,
String endAt,
String location,
String posterImageURL,
String interestedAt
) {

public static InterestShowPaginationApiResponse from(InterestShowPaginationServiceResponse response) {
return InterestShowPaginationApiResponse.builder()
.id(response.showId())
.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
@@ -1,10 +1,14 @@
package com.example.show.controller.dto.response;

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

public record ShowInterestApiResponse(
@Schema(description = "관심 여부 (T: 관심 있음, F: 관심 없음)")
boolean hasInterest
) {

public static ShowInterestApiResponse from(ShowInterestServiceResponse response) {
return new ShowInterestApiResponse(response.hasInterest());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public record ShowTicketingTimeApiResponse(
public static ShowTicketingTimeApiResponse from(ShowTicketingTimeServiceResponse response) {
return ShowTicketingTimeApiResponse.builder()
.ticketingApiType(response.ticketingApiType())
.ticketingAt(DateTimeUtil.formatLocalDateTime(response.ticketingAt()))
.ticketingAt(DateTimeUtil.formatDateTime(response.ticketingAt()))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public record ShowTicketingTimePaginationApiParam(
public static ShowTicketingTimePaginationApiParam from(ShowTicketingTimeServiceParam response) {
return ShowTicketingTimePaginationApiParam.builder()
.ticketingType(response.ticketingType())
.ticketingAt(DateTimeUtil.formatLocalDateTime(response.ticketingAt()))
.ticketingAt(DateTimeUtil.formatDateTime(response.ticketingAt()))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,26 @@

import com.example.show.error.ShowError;
import com.example.show.service.dto.param.ShowSearchPaginationServiceParam;
import com.example.show.service.dto.request.InterestShowPaginationServiceRequest;
import com.example.show.service.dto.request.ShowInterestServiceRequest;
import com.example.show.service.dto.request.ShowPaginationServiceRequest;
import com.example.show.service.dto.request.ShowSearchPaginationServiceRequest;
import com.example.show.service.dto.response.InterestShowPaginationServiceResponse;
import com.example.show.service.dto.response.ShowDetailServiceResponse;
import com.example.show.service.dto.response.ShowInterestServiceResponse;
import com.example.show.service.dto.response.ShowPaginationServiceResponse;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.UUID;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.example.dto.response.PaginationServiceResponse;
import org.example.dto.show.response.ShowDetailDomainResponse;
import org.example.entity.InterestShow;
import org.example.entity.show.Show;
import org.example.exception.BusinessException;
import org.example.usecase.UserShowUseCase;
import org.example.usecase.show.ShowUseCase;
import org.springframework.stereotype.Service;

Expand All @@ -21,6 +30,7 @@
public class ShowService {

private final ShowUseCase showUseCase;
private final UserShowUseCase userShowUseCase;

public ShowDetailServiceResponse getShow(UUID id) {
ShowDetailDomainResponse showDetail;
Expand Down Expand Up @@ -57,7 +67,32 @@ public PaginationServiceResponse<ShowPaginationServiceResponse> findShows(ShowPa
);
}

public PaginationServiceResponse<InterestShowPaginationServiceResponse> findInterestShows(
InterestShowPaginationServiceRequest request
) {
var interestShows = userShowUseCase.findInterestShows(request.toDomainRequest());
List<UUID> showIds = interestShows.data().stream().map(InterestShow::getShowId).toList();
Map<UUID, Show> showById = showUseCase.findShowsInIds(showIds).stream()
.collect(Collectors.toMap(Show::getId, s -> s));

return PaginationServiceResponse.of(
interestShows.data().stream()
.map(interestShow -> InterestShowPaginationServiceResponse.from(
showById.get(interestShow.getShowId()),
interestShow
))
.toList(),
interestShows.hasNext()
);
}

public void view(UUID showId) {
showUseCase.view(showId);
}

public ShowInterestServiceResponse interest(ShowInterestServiceRequest request) {
return ShowInterestServiceResponse.from(
userShowUseCase.interest(request.toDomainRequest())
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.example.show.service.dto.request;

import java.util.UUID;
import lombok.Builder;
import org.example.dto.request.InterestShowPaginationDomainRequest;

@Builder
public record InterestShowPaginationServiceRequest(
UUID userId,
int size,
UUID cursorId
) {

public InterestShowPaginationDomainRequest toDomainRequest() {
return InterestShowPaginationDomainRequest.builder()
.userId(userId)
.size(size)
.cursorId(cursorId)
.build();
}
}
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.request.InterestShowDomainRequest;

@Builder
public record ShowInterestServiceRequest(
UUID showId,
UUID userId
) {

public InterestShowDomainRequest toDomainRequest() {
return InterestShowDomainRequest.builder()
.showId(showId())
.userId(userId())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.example.show.service.dto.response;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.UUID;
import lombok.Builder;
import org.example.entity.InterestShow;
import org.example.entity.show.Show;

@Builder
public record InterestShowPaginationServiceResponse(
UUID showId,
LocalDateTime interestedAt,
String title,
String location,
String posterImageURL,
LocalDate startAt,
LocalDate endAt
) {

public static InterestShowPaginationServiceResponse from(
Show show,
InterestShow interestShow
) {
return InterestShowPaginationServiceResponse.builder()
.showId(show.getId())
.interestedAt(interestShow.getUpdatedAt())
.title(show.getTitle())
.location(show.getTitle())
.posterImageURL(show.getImage())
.startAt(show.getStartDate())
.endAt(show.getEndDate())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.show.service.dto.response;

import org.example.entity.InterestShow;

public record ShowInterestServiceResponse(
boolean hasInterest
) {

public static ShowInterestServiceResponse from(InterestShow interestShow) {
return new ShowInterestServiceResponse(interestShow.hasInterest());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static ShowPaginationServiceResponse from(ShowDetailDomainResponse respon
.findFirst();

String reservationAt = optShowTicketingTime.map(
showTicketingTime -> DateTimeUtil.formatLocalDateTime(showTicketingTime.ticketingAt())
showTicketingTime -> DateTimeUtil.formatDateTime(showTicketingTime.ticketingAt())
).orElseGet(() -> "");

return ShowPaginationServiceResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ArtistRequestDtoFixture {
"image",
"test_image.jpg",
"image/jpeg",
"test image content".getBytes()
"test posterImageURL content".getBytes()
);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.example.show.service.ShowService;
import org.assertj.core.api.SoftAssertions;
import org.example.usecase.UserShowUseCase;
import org.example.usecase.show.ShowUseCase;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand All @@ -14,7 +15,8 @@
class ShowServiceTest {

private final ShowUseCase showUseCase = mock(ShowUseCase.class);
private final ShowService showService = new ShowService(showUseCase);
private final UserShowUseCase userShowUseCase = mock(UserShowUseCase.class);
private final ShowService showService = new ShowService(showUseCase, userShowUseCase);

@Test
@DisplayName("페이지네이션을 이용해 공연을 검색 할 수 있다.")
Expand Down
Loading

0 comments on commit 75cac87

Please sign in to comment.