Skip to content

Commit

Permalink
Merge pull request kahluaband#50 from woogieon8on/admin-ticket
Browse files Browse the repository at this point in the history
kahluaband#21 Feat: add find all order by status method on ticket
  • Loading branch information
woogieon8on authored Aug 7, 2024
2 parents 0c5c48b + 3056867 commit 75ea617
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 16 deletions.
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ dependencies {
//redis
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'org.springframework.session:spring-session-data-redis'

//QueryDsl
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
annotationProcessor "com.querydsl:querydsl-apt:5.0.0:jakarta"
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
annotationProcessor "jakarta.persistence:jakarta.persistence-api"
}

tasks.named('test') {
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/kahlua/KahluaProject/config/QueryDslConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package kahlua.KahluaProject.config;

import com.querydsl.jpa.impl.JPAQueryFactory;
import jakarta.persistence.EntityManager;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@RequiredArgsConstructor
public class QueryDslConfig {

private final EntityManager entityManager;

@Bean
public JPAQueryFactory jpaQueryFactory() {
return new JPAQueryFactory(entityManager);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,26 @@ public class AdminTicketController {
private final TicketService ticketService;

@GetMapping
@Operation(summary = "전체 티켓 리스트 조회", description = "sort-by에 정의된 티켓 속성 기준으로 정렬된 전체 티켓 리스트를 조회합니다 </br> sort-by를 쿼리에 포함시키지 않은 경우 최신순으로 정렬합니다")
@Operation(summary = "전체 티켓 리스트 조회", description = "sort-by에 정의된 티켓 속성 기준으로 정렬된 전체 티켓 리스트를 조회합니다 " +
"</br> sort-by를 쿼리에 포함시키지 않은 경우 (환불 요청 -> 결제 대기 -> 결제 왼료 -> 환불 완료) 순서로, 같은 결제 상태에 대해서는 최신순으로 정렬합니다")
public ApiResponse<TicketListResponse> getTicketList(@AuthenticationPrincipal AuthDetails authDetails,
@RequestParam(name = "sort-by", required = false) String sortBy) {
TicketListResponse ticketListResponse = ticketService.getTicketList(authDetails.user(), sortBy);
return ApiResponse.onSuccess(ticketListResponse);
}

@GetMapping("/general")
@Operation(summary = "일반 티켓 리스트 조회", description = "sort-by에 정의된 티켓 속성 기준으로 정렬된 일반 티켓 리스트를 조회합니다 </br> sort-by를 쿼리에 포함시키지 않은 경우 최신순으로 정렬합니다")
@Operation(summary = "일반 티켓 리스트 조회", description = "sort-by에 정의된 티켓 속성 기준으로 정렬된 일반 티켓 리스트를 조회합니다 " +
"</br> sort-by를 쿼리에 포함시키지 않은 경우 (환불 요청 -> 결제 대기 -> 결제 왼료 -> 환불 완료) 순서로, 같은 결제 상태에 대해서는 최신순으로 정렬합니다")
public ApiResponse<TicketListResponse> getGeneralTicketList(@AuthenticationPrincipal AuthDetails authDetails,
@RequestParam(name = "sort-by", required = false) String sortBy) {
TicketListResponse ticketListResponse = ticketService.getGeneralTicketList(authDetails.user(), sortBy);
return ApiResponse.onSuccess(ticketListResponse);
}

@GetMapping("/freshman")
@Operation(summary = "신입생 티켓 리스트 조회", description = "sort-by에 정의된 티켓 속성 기준으로 정렬된 신입생 티켓 리스트를 조회합니다 </br> sort-by를 쿼리에 포함시키지 않은 경우 최신순으로 정렬합니다")
@Operation(summary = "신입생 티켓 리스트 조회", description = "sort-by에 정의된 티켓 속성 기준으로 정렬된 신입생 티켓 리스트를 조회합니다 " +
"</br> sort-by를 쿼리에 포함시키지 않은 경우 (환불 요청 -> 결제 대기 -> 결제 왼료 -> 환불 완료) 순서로, 같은 결제 상태에 대해서는 최신순으로 정렬합니다")
public ApiResponse<TicketListResponse> getFreshmanTicketList(@AuthenticationPrincipal AuthDetails authDetails,
@RequestParam(name = "sort-by", required = false) String sortBy) {
TicketListResponse ticketListResponse = ticketService.getFreshmanTicketList(authDetails.user(), sortBy);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package kahlua.KahluaProject.repository.ticket;

import kahlua.KahluaProject.domain.ticket.Ticket;

import java.util.List;

public interface TicketCustomRepository {

List<Ticket> findAllOrderByStatus();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package kahlua.KahluaProject.repository.ticket;


import com.querydsl.core.types.dsl.CaseBuilder;
import com.querydsl.core.types.dsl.NumberExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import kahlua.KahluaProject.domain.ticket.Status;
import kahlua.KahluaProject.domain.ticket.Ticket;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import java.util.List;

import static kahlua.KahluaProject.domain.ticket.QTicket.ticket;

@Repository
@RequiredArgsConstructor
public class TicketCustomRepositoryImpl implements TicketCustomRepository{

private final JPAQueryFactory jpaQueryFactory;


@Override
public List<Ticket> findAllOrderByStatus() {
NumberExpression<Integer> order = new CaseBuilder()
.when(ticket.status.eq(Status.CANCEL_REQUEST)).then(0)
.when(ticket.status.eq(Status.WAIT)).then(1)
.when(ticket.status.eq(Status.FINISH_PAYMENT)).then(2)
.when(ticket.status.eq(Status.CANCEL_COMPLETE)).then(3)
.otherwise(4);

return jpaQueryFactory
.selectFrom(ticket)
.orderBy(order.asc(), ticket.id.desc())
.fetch();
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package kahlua.KahluaProject.repository;
package kahlua.KahluaProject.repository.ticket;

import kahlua.KahluaProject.domain.ticket.Ticket;
import kahlua.KahluaProject.domain.ticket.Type;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.http.converter.json.GsonBuilderUtils;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

//데이터베이스와의 상호작용을 담당. 데이터 저장, 조회, 수정, 삭제와 같은 작업을 처리
public interface TicketRepository extends JpaRepository<Ticket, Long> {
public interface TicketRepository extends JpaRepository<Ticket, Long>, TicketCustomRepository {

boolean existsByReservationId(String reservationId);
List<Ticket> findAllByOrderByIdDesc();
List<Ticket> findAllByTypeOrderByIdDesc(Type type);
// List<Ticket> findAllByOrderByIdDesc();
// List<Ticket> findAllByTypeOrderByIdDesc(Type type);
Optional<Ticket> findByReservationId(String reservationId);
List<Ticket> findAllByOrderByBuyerAscIdDesc();
List<Ticket> findAllByTypeOrderByBuyerAscIdDesc(Type type);
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/kahlua/KahluaProject/service/TicketService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import kahlua.KahluaProject.dto.ticket.response.*;
import kahlua.KahluaProject.exception.GeneralException;
import kahlua.KahluaProject.repository.ParticipantsRepository;
import kahlua.KahluaProject.repository.TicketRepository;
import kahlua.KahluaProject.repository.ticket.TicketRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -138,9 +138,9 @@ public TicketListResponse getTicketList(User user, String sortBy) {
default -> throw new GeneralException(ErrorStatus.TICKET_COLUMN_INVALID);
};
}
// sortBy 값이 없다면 최신순 정렬
// sortBy 값이 없다면 결제 상태에 따라, 최신순으로 정렬
else {
tickets = ticketRepository.findAllByOrderByIdDesc();
tickets = ticketRepository.findAllOrderByStatus();
}

List<TicketItemResponse> ticketItemResponses = new ArrayList<>();
Expand Down Expand Up @@ -212,9 +212,9 @@ public TicketListResponse getGeneralTicketList(User user, String sortBy) {
default -> throw new GeneralException(ErrorStatus.TICKET_COLUMN_INVALID);
};
}
// sortBy 값이 없다면 최신순 정렬
// sortBy 값이 없다면 결제 상태에 따라, 최신순으로 정렬
else {
tickets = ticketRepository.findAllByTypeOrderByIdDesc(Type.GENERAL);
tickets = ticketRepository.findAllOrderByStatus();
}

List<TicketItemResponse> ticketItemResponses = new ArrayList<>();
Expand Down Expand Up @@ -266,9 +266,9 @@ public TicketListResponse getFreshmanTicketList(User user, String sortBy) {
default -> throw new GeneralException(ErrorStatus.TICKET_COLUMN_INVALID);
};
}
// sortBy 값이 없다면 최신순 정렬
// sortBy 값이 없다면 결제 상태에 따라, 최신순으로 정렬
else {
tickets = ticketRepository.findAllByTypeOrderByIdDesc(Type.FRESHMAN);
tickets = ticketRepository.findAllOrderByStatus();
}

List<TicketItemResponse> ticketItemResponses = new ArrayList<>();
Expand Down

0 comments on commit 75ea617

Please sign in to comment.