Skip to content

Commit

Permalink
fix: 알림 설정한 공연 개수 쿼리 위치 이동
Browse files Browse the repository at this point in the history
  • Loading branch information
GaBaljaintheroom committed Sep 12, 2024
1 parent 0dffe24 commit 53ccee2
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public TicketingAlertReservationServiceResponse findAlertsReservations(
}

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

return NumberOfTicketingAlertServiceResponse.from(numberOfTicketingAlert);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
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);
InterestShowPaginationDomainResponse findInterestShowList(
InterestShowPaginationDomainRequest request
);
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
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 @@ -42,21 +39,9 @@ public InterestShowPaginationDomainResponse findInterestShowList(
.build();
}

@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) {
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
@@ -1,5 +1,9 @@
package org.example.repository.ticketing;

import java.time.LocalDateTime;
import java.util.UUID;

public interface TicketingAlertQuerydslRepository {

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

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

import com.querydsl.jpa.impl.JPAQueryFactory;
import java.time.LocalDateTime;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

Expand All @@ -10,4 +14,17 @@ public class TicketingAlertQuerydslRepositoryImpl implements TicketingAlertQuery

private final JPAQueryFactory jpaQueryFactory;

@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;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.example.usecase.interest;

import java.time.LocalDateTime;
import java.util.Optional;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
Expand All @@ -20,7 +19,10 @@ public class InterestShowUseCase {

@Transactional
public InterestShow interest(InterestShowDomainRequest request) {
Optional<InterestShow> optInterestShow = findInterestShowByShowIdAndUserId(request.showId(), request.userId());
Optional<InterestShow> optInterestShow = findInterestShowByShowIdAndUserId(
request.showId(),
request.userId()
);

if (optInterestShow.isEmpty()) {
return interestShowRepository.save(
Expand All @@ -46,10 +48,6 @@ public InterestShowPaginationDomainResponse findInterestShows(
return interestShowRepository.findInterestShowList(request);
}

public long countAlertShows(UUID userId, LocalDateTime now) {
return interestShowRepository.countValidTicketingAlerts(userId, now);
}

public long countInterestShows(UUID userId) {
Long result = interestShowRepository.countInterestShowByUserIdAndIsDeletedFalse(userId);
return result == null ? 0 : result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public List<TicketingAlert> findTicketingAlertsByUserId(UUID userId) {
return ticketingAlertRepository.findAllByUserIdAndIsDeletedFalse(userId);
}

public long countAlertShows(UUID userId, LocalDateTime now) {
return ticketingAlertRepository.countValidTicketingAlerts(userId, now);
}

@Transactional
public TicketingAlertsDomainResponse alertReservation(
TicketingAlertReservationDomainRequest ticketingAlertReservation
Expand Down

0 comments on commit 53ccee2

Please sign in to comment.