Skip to content

Commit

Permalink
feat: 개수 조회 API (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
devmizz authored Aug 19, 2024
1 parent 01801e3 commit 58302ce
Show file tree
Hide file tree
Showing 21 changed files with 285 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ private RequestMatcher getMatcherForUserAndAdmin() {
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/users/shows/alerts/count"),
antMatcher(HttpMethod.GET, "/api/v1/users/artists/subscriptions/count"),
antMatcher(HttpMethod.GET, "/api/v1/users/genres/subscriptions/count"),
antMatcher(HttpMethod.GET, "/api/v1/shows/interests"),
antMatcher(HttpMethod.GET, "/api/v1/users/shows/interests/count"),
antMatcher(HttpMethod.POST, "/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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public ResponseEntity<PaginationApiResponse<ShowPaginationApiParam>> getShows(

}

@PostMapping("/{showId}/interest")
@PostMapping("/{showId}/interests")
@Operation(summary = "공연 관심 등록 / 취소")
public ResponseEntity<ShowInterestApiResponse> interest(
@PathVariable("showId") UUID showId,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package org.example.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.time.LocalDateTime;
import lombok.RequiredArgsConstructor;
import org.example.controller.dto.response.NumberOfInterestShowApiResponse;
import org.example.controller.dto.response.NumberOfSubscribedArtistApiResponse;
import org.example.controller.dto.response.NumberOfSubscribedGenreApiResponse;
import org.example.controller.dto.response.NumberOfTicketingAlertApiResponse;
import org.example.security.dto.AuthenticatedUser;
import org.example.service.UserShowService;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/users")
@Tag(name = "유저 공연")
public class UserShowController {

private final UserShowService userShowService;

@GetMapping("/shows/alerts/count")
@Operation(summary = "알림 설정한 공연 개수")
public ResponseEntity<NumberOfTicketingAlertApiResponse> getNumberOfAlertShow(
@AuthenticationPrincipal AuthenticatedUser user
) {
LocalDateTime now = LocalDateTime.now();
return ResponseEntity.ok(
NumberOfTicketingAlertApiResponse.from(
userShowService.countAlertShows(user.userId(), now)
)
);
}

@GetMapping("/artists/subscriptions/count")
@Operation(summary = "구독한 아티스트 수")
public ResponseEntity<NumberOfSubscribedArtistApiResponse> getNumberOfSubscribedArtist(
@AuthenticationPrincipal AuthenticatedUser user
) {
return ResponseEntity.ok(
NumberOfSubscribedArtistApiResponse.from(
userShowService.countSubscribedArtists(user.userId())
)
);
}

@GetMapping("/genres/subscriptions/count")
@Operation(summary = "구독한 장르 수")
public ResponseEntity<NumberOfSubscribedGenreApiResponse> getNumberOfSubscribedGenre(
@AuthenticationPrincipal AuthenticatedUser user
) {
return ResponseEntity.ok(
NumberOfSubscribedGenreApiResponse.from(
userShowService.countSubscribedGenres(user.userId())
)
);
}

@GetMapping("/shows/interests/count")
@Operation(summary = "관심 공연 개수")
public ResponseEntity<NumberOfInterestShowApiResponse> getNumberOfInterestShow(
@AuthenticationPrincipal AuthenticatedUser user
) {
return ResponseEntity.ok(
NumberOfInterestShowApiResponse.from(
userShowService.countInterestShows(user.userId())
)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.example.controller.dto.response;

import org.example.service.dto.response.NumberOfInterestShowServiceResponse;

public record NumberOfInterestShowApiResponse(
long count
) {

public static NumberOfInterestShowApiResponse from(NumberOfInterestShowServiceResponse response) {
return new NumberOfInterestShowApiResponse(response.count());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.example.controller.dto.response;

import org.example.service.dto.response.NumberOfSubscribedArtistServiceResponse;

public record NumberOfSubscribedArtistApiResponse(
long count
) {

public static NumberOfSubscribedArtistApiResponse from(NumberOfSubscribedArtistServiceResponse response) {
return new NumberOfSubscribedArtistApiResponse(response.count());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.example.controller.dto.response;

import org.example.service.dto.response.NumberOfSubscribedGenreServiceResponse;

public record NumberOfSubscribedGenreApiResponse(
long count
) {

public static NumberOfSubscribedGenreApiResponse from(NumberOfSubscribedGenreServiceResponse response) {
return new NumberOfSubscribedGenreApiResponse(response.count());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.example.controller.dto.response;

import org.example.service.dto.response.NumberOfTicketingAlertServiceResponse;

public record NumberOfTicketingAlertApiResponse(
long count
) {

public static NumberOfTicketingAlertApiResponse from(NumberOfTicketingAlertServiceResponse response) {
return new NumberOfTicketingAlertApiResponse(response.count());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.example.service;

import java.time.LocalDateTime;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.example.service.dto.response.NumberOfInterestShowServiceResponse;
import org.example.service.dto.response.NumberOfSubscribedArtistServiceResponse;
import org.example.service.dto.response.NumberOfSubscribedGenreServiceResponse;
import org.example.service.dto.response.NumberOfTicketingAlertServiceResponse;
import org.example.usecase.UserShowUseCase;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class UserShowService {

private final UserShowUseCase userShowUseCase;

public NumberOfTicketingAlertServiceResponse countAlertShows(UUID userId, LocalDateTime now) {
long numberOfTicketingAlert = userShowUseCase.countAlertShows(userId, now);

return NumberOfTicketingAlertServiceResponse.from(numberOfTicketingAlert);
}

public NumberOfSubscribedArtistServiceResponse countSubscribedArtists(UUID userId) {
return NumberOfSubscribedArtistServiceResponse.from(
userShowUseCase.countSubscribedArtists(userId)
);
}

public NumberOfSubscribedGenreServiceResponse countSubscribedGenres(UUID uuid) {
return NumberOfSubscribedGenreServiceResponse.from(
userShowUseCase.countSubscribedGenres(uuid)
);
}

public NumberOfInterestShowServiceResponse countInterestShows(UUID uuid) {
return NumberOfInterestShowServiceResponse.from(
userShowUseCase.countInterestShows(uuid)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.example.service.dto.response;

public record NumberOfInterestShowServiceResponse(
long count
) {

public static NumberOfInterestShowServiceResponse from(long count) {
return new NumberOfInterestShowServiceResponse(count);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.example.service.dto.response;

public record NumberOfSubscribedArtistServiceResponse(
long count
) {

public static NumberOfSubscribedArtistServiceResponse from(long count) {
return new NumberOfSubscribedArtistServiceResponse(count);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.example.service.dto.response;

public record NumberOfSubscribedGenreServiceResponse(
long count
) {

public static NumberOfSubscribedGenreServiceResponse from(long count) {
return new NumberOfSubscribedGenreServiceResponse(count);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.example.service.dto.response;

public record NumberOfTicketingAlertServiceResponse(
long count
) {

public static NumberOfTicketingAlertServiceResponse from(long count) {
return new NumberOfTicketingAlertServiceResponse(count);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.example.repository.show;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
Expand All @@ -8,6 +9,7 @@
import org.example.dto.show.response.ShowInfoDomainResponse;
import org.example.dto.show.response.ShowPaginationDomainResponse;
import org.example.dto.show.response.ShowWithTicketingTimesDomainResponse;
import org.example.entity.show.Show;

public interface ShowQuerydslRepository {

Expand All @@ -18,4 +20,6 @@ public interface ShowQuerydslRepository {
ShowPaginationDomainResponse findShows(ShowPaginationDomainRequest request);

Optional<ShowInfoDomainResponse> findShowInfoById(UUID id);

List<Show> findNotFinishedShowsIn(List<UUID> showIds, LocalDateTime now);
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ public ShowPaginationDomainResponse findShows(ShowPaginationDomainRequest reques
.build();
}

@Override
public List<Show> findNotFinishedShowsIn(List<UUID> showIds, LocalDateTime now) {
return jpaQueryFactory
.selectFrom(show)
.where(
show.isDeleted.isFalse()
.and(show.id.in(showIds))
.and(show.lastTicketingAt.after(now))
)
.fetch();
}

private List<ShowDetailDomainResponse> findShowsByPopularity(ShowPaginationDomainRequest request) {
BooleanExpression whereExpression = show.isDeleted.isFalse();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.example.usecase.show;

import java.time.LocalDateTime;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.UUID;
Expand Down Expand Up @@ -233,6 +234,10 @@ public ShowTicketingTime findTicketingTimeWithShow(
.orElseThrow(NoSuchElementException::new);
}

public List<Show> findNotFinishedTicketingShows(List<UUID> showIds, LocalDateTime now) {
return showRepository.findNotFinishedShowsIn(showIds, now);
}

private Show findShowOrThrowNoSuchElementException(UUID id) {
return showRepository.findById(id).orElseThrow(NoSuchElementException::new);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package org.example.repository.interest;

import java.time.LocalDateTime;
import java.util.UUID;
import org.example.dto.request.InterestShowPaginationDomainRequest;
import org.example.dto.response.InterestShowPaginationDomainResponse;

public interface InterestShowQuerydslRepository {

InterestShowPaginationDomainResponse findInterestShowList(InterestShowPaginationDomainRequest request);

long countValidTicketingAlerts(UUID userId, LocalDateTime now);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package org.example.repository.interest;

import static org.example.entity.QInterestShow.interestShow;
import static org.example.entity.QTicketingAlert.ticketingAlert;

import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.time.LocalDateTime;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.example.dto.request.InterestShowPaginationDomainRequest;
import org.example.dto.response.InterestShowPaginationDomainResponse;
Expand Down Expand Up @@ -39,9 +42,21 @@ public InterestShowPaginationDomainResponse findInterestShowList(
.build();
}

private BooleanExpression getInterestShowPaginationConditions(
InterestShowPaginationDomainRequest request
) {
@Override
public long countValidTicketingAlerts(UUID userId, LocalDateTime now) {
Long result = jpaQueryFactory.select(ticketingAlert.showId.countDistinct())
.from(ticketingAlert)
.where(
ticketingAlert.isDeleted.isFalse()
.and(ticketingAlert.userId.eq(userId))
.and(ticketingAlert.alertTime.gt(now))
)
.fetchOne();

return result == null ? 0 : result;
}

private BooleanExpression getInterestShowPaginationConditions(InterestShowPaginationDomainRequest request) {
BooleanExpression whereConditions = interestShow.userId.eq(request.userId())
.and(interestShow.isDeleted.isFalse());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
public interface InterestShowRepository extends JpaRepository<InterestShow, UUID>, InterestShowQuerydslRepository {

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

Long countInterestShowByUserIdAndIsDeletedFalse(UUID userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ public interface ArtistSubscriptionRepository
extends JpaRepository<ArtistSubscription, UUID>, ArtistSubscriptionQuerydslRepository {

List<ArtistSubscription> findAllByUserId(UUID userId);

Long countByUserIdAndIsDeletedFalse(UUID userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface GenreSubscriptionRepository extends JpaRepository<GenreSubscrip
List<GenreSubscription> findAllByUserId(UUID userId);

List<GenreSubscription> findByUserIdAndIsDeletedFalse(UUID userId);

Long countByUserIdAndIsDeletedFalse(UUID uuid);
}
Loading

0 comments on commit 58302ce

Please sign in to comment.