-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
130 additions
and
32 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
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
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 |
---|---|---|
|
@@ -30,6 +30,4 @@ public class Paymenttype extends BaseEntity { | |
private String type; | ||
|
||
|
||
|
||
|
||
} |
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
9 changes: 9 additions & 0 deletions
9
src/main/java/com/Optimart/repositories/OrderItemRepository.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,9 @@ | ||
package com.Optimart.repositories; | ||
|
||
import com.Optimart.models.OrderItem; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.UUID; | ||
|
||
public interface OrderItemRepository extends JpaRepository<OrderItem, UUID> { | ||
} |
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 |
---|---|---|
@@ -1,9 +1,14 @@ | ||
package com.Optimart.repositories; | ||
|
||
import com.Optimart.models.Order; | ||
import com.Optimart.models.User; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.domain.Specification; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.UUID; | ||
|
||
public interface OrderRepository extends JpaRepository<Order, UUID> { | ||
Page<Order> findAll(Specification<Order> specification, Pageable pageable); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/Optimart/repositories/ShippingAddressRepository.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 com.Optimart.repositories; | ||
|
||
import com.Optimart.models.Paymenttype; | ||
import com.Optimart.models.ShippingAddress; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.UUID; | ||
|
||
public interface ShippingAddressRepository extends JpaRepository<ShippingAddress, UUID> { | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/Optimart/repositories/Specification/OrderSpecification.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 |
---|---|---|
@@ -1,4 +1,41 @@ | ||
package com.Optimart.repositories.Specification; | ||
|
||
import com.Optimart.models.Order; | ||
import jakarta.persistence.criteria.JoinType; | ||
import org.springframework.data.jpa.domain.Specification; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public class OrderSpecification { | ||
public static Specification<Order> byStatus(String status){ | ||
return (root, query, criteriaBuilder) -> { | ||
if (status == null || status.isEmpty()) { | ||
return criteriaBuilder.conjunction(); | ||
} | ||
List<String> statusList = Arrays.asList(status.split("-")); | ||
return root.get("orderStatus").in(statusList); | ||
}; | ||
} | ||
|
||
public static Specification<Order> hasUserId(UUID userId) { | ||
return (root, query, criteriaBuilder) -> { | ||
if (userId == null) { | ||
return criteriaBuilder.conjunction(); | ||
} | ||
return criteriaBuilder.equal(root.get("user").get("id"), userId); | ||
}; | ||
} | ||
|
||
|
||
public static Specification<Order> filterOrderByUser(String statuses, UUID userId) { | ||
return (root, query, criteriaBuilder) -> { | ||
root.fetch("orderItemList", JoinType.LEFT); | ||
query.distinct(true); | ||
return Specification.where(byStatus(statuses)) | ||
.and(hasUserId(userId)) | ||
.toPredicate(root, query, criteriaBuilder); | ||
}; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/Optimart/responses/Order/OrderResponse.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,14 @@ | ||
package com.Optimart.responses.Order; | ||
|
||
import lombok.*; | ||
|
||
import java.util.UUID; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class OrderResponse { | ||
private UUID id; | ||
} |
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