-
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 #27 from vanderleik/PPI-27-Adicionar-QueryDSL
feat: PPI-27 - adicionando QueryDsl ao projeto
- Loading branch information
Showing
10 changed files
with
126 additions
and
1 deletion.
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/com/produtopedidoitens/api/adapters/config/QueryDslConfiguration.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 com.produtopedidoitens.api.adapters.config; | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.PersistenceContext; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class QueryDslConfiguration { | ||
|
||
@PersistenceContext | ||
private EntityManager em; | ||
|
||
@Bean | ||
public JPAQueryFactory jpaQueryFactory() { | ||
return new JPAQueryFactory(em); | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
...m/produtopedidoitens/api/adapters/persistence/repositories/OrderItemRepositoryCustom.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,11 @@ | ||
package com.produtopedidoitens.api.adapters.persistence.repositories; | ||
|
||
import com.produtopedidoitens.api.adapters.web.projections.OrderByOrderNumber; | ||
|
||
import java.util.List; | ||
|
||
public interface OrderItemRepositoryCustom { | ||
|
||
List<OrderByOrderNumber> findOrdersByOrderNumber(String orderNumber); | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
...odutopedidoitens/api/adapters/persistence/repositories/OrderItemRepositoryCustomImpl.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,42 @@ | ||
package com.produtopedidoitens.api.adapters.persistence.repositories; | ||
|
||
import com.produtopedidoitens.api.adapters.web.projections.OrderByOrderNumber; | ||
import com.produtopedidoitens.api.application.domain.entities.QOrderEntity; | ||
import com.produtopedidoitens.api.application.domain.entities.QOrderItemEntity; | ||
import com.produtopedidoitens.api.application.domain.entities.QProductEntity; | ||
import com.querydsl.core.types.Projections; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.PersistenceContext; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
public class OrderItemRepositoryCustomImpl implements OrderItemRepositoryCustom { | ||
|
||
@PersistenceContext | ||
private EntityManager entityManager; | ||
|
||
@Override | ||
public List<OrderByOrderNumber> findOrdersByOrderNumber(String orderNumber) { | ||
JPAQueryFactory queryFactory = new JPAQueryFactory(entityManager); | ||
QOrderEntity order = QOrderEntity.orderEntity; | ||
QOrderItemEntity orderItem = QOrderItemEntity.orderItemEntity; | ||
QProductEntity product = QProductEntity.productEntity; | ||
|
||
return queryFactory | ||
.select(Projections.constructor(OrderByOrderNumber.class, | ||
product.productName, | ||
order.orderNumber, | ||
order.status.stringValue(), | ||
orderItem.quantity, | ||
product.price)) | ||
.from(orderItem) | ||
.innerJoin(orderItem.product, product) | ||
.innerJoin(orderItem.order, order) | ||
.where(order.orderNumber.eq(orderNumber)) | ||
.fetch(); | ||
} | ||
|
||
} |
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
16 changes: 16 additions & 0 deletions
16
src/main/java/com/produtopedidoitens/api/adapters/web/projections/OrderByOrderNumber.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,16 @@ | ||
package com.produtopedidoitens.api.adapters.web.projections; | ||
|
||
import lombok.Builder; | ||
|
||
import java.math.BigDecimal; | ||
|
||
@Builder | ||
public record OrderByOrderNumber ( | ||
|
||
String productName, | ||
String orderNumber, | ||
String status, | ||
Integer quantity, | ||
BigDecimal price | ||
){ | ||
} |
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
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