Skip to content

Commit

Permalink
feat: Added Querydsl Tests and resulting changes to the production codes
Browse files Browse the repository at this point in the history
  • Loading branch information
koreanMike513 committed Jan 31, 2025
1 parent 657f441 commit adf1583
Show file tree
Hide file tree
Showing 5 changed files with 324 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public class OrderSearchCondition {

//TODO Java Bean Validation 추가

private BigDecimal minCost = BigDecimal.ZERO; // Default value
private BigDecimal minCost = BigDecimal.ZERO;
private BigDecimal maxCost;
private String status = "ALL";
private String status;
private LocalDateTime startDate = LocalDateTime.of(2024, Month.JANUARY, 1, 0, 0);
private LocalDateTime endDate;
private List<String> sortBy = List.of("DATE_NEW");
private int page = 0; // Default page
private int size = 10; // Default page size
private int page = 0;
private int size = 10;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.f_lab.joyeuse_planete.orders.dto.response;

import com.f_lab.joyeuse_planete.core.domain.*;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.querydsl.core.annotations.QueryProjection;
import jakarta.persistence.JoinColumn;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -13,7 +11,6 @@


@Getter
@Builder
@NoArgsConstructor
public class OrderDTO {

Expand All @@ -38,15 +35,19 @@ public class OrderDTO {
@JsonProperty("status")
private String status;

@JoinColumn(name = "payment_id")
@JsonProperty("payment_id")
private Long payment;

@JoinColumn(name = "voucher_id")
@JsonProperty("voucher_id")
private Long voucher;

@JoinColumn(name = "collection_time")
@JsonProperty("created_at")
private LocalDateTime createdAt;

@JsonProperty("collection_time")
private LocalDateTime collectionTime;

@Builder
@QueryProjection
public OrderDTO(
Long orderId,
Expand All @@ -58,7 +59,8 @@ public OrderDTO(
String status,
Long payment,
Long voucher,
LocalDateTime collectionTime
LocalDateTime collectionTime,
LocalDateTime createdAt
) {

this.orderId = orderId;
Expand All @@ -71,5 +73,6 @@ public OrderDTO(
this.payment = payment;
this.voucher = voucher;
this.collectionTime = collectionTime;
this.createdAt = createdAt;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;


import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.f_lab.joyeuse_planete.core.domain.QCurrency.currency;
import static com.f_lab.joyeuse_planete.core.domain.QFood.food;
import static com.f_lab.joyeuse_planete.core.domain.QOrder.order;
import static com.f_lab.joyeuse_planete.core.domain.QPayment.payment;


public class OrderRepositoryCustomImpl implements OrderRepositoryCustom {

private Map<String, OrderSpecifier> sortByMap = new HashMap<>();
Expand Down Expand Up @@ -58,11 +57,13 @@ public Page<OrderDTO> findOrders(OrderSearchCondition condition, Pageable pageab
order.status.stringValue(),
order.payment.id.as("paymentId"),
order.voucher.id.as("voucherId"),
order.collectionTime
order.collectionTime.as("collectionTime"),
order.createdAt.as("createdAt")
))
.from(order)
.leftJoin(order.payment, payment)
.leftJoin(order.food, food)
.leftJoin(food.currency, currency)
.where(
eqStatus(condition.getStatus()),
dateGoe(condition.getStartDate()),
Expand Down
Loading

0 comments on commit adf1583

Please sign in to comment.