forked from kahluaband/Homepage_BE_SpringBoot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kahluaband#50 from woogieon8on/admin-ticket
kahluaband#21 Feat: add find all order by status method on ticket
- Loading branch information
Showing
7 changed files
with
89 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/kahlua/KahluaProject/config/QueryDslConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/kahlua/KahluaProject/repository/ticket/TicketCustomRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/kahlua/KahluaProject/repository/ticket/TicketCustomRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
10 changes: 4 additions & 6 deletions
10
...aProject/repository/TicketRepository.java → ...t/repository/ticket/TicketRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters