-
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.
[#16] Add offers endpoint and respective service, repository and entity
- Loading branch information
Showing
55 changed files
with
792 additions
and
490 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.i8ai.training.store.model; | ||
|
||
import jakarta.persistence.*; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.*; | ||
|
||
import java.util.Date; | ||
|
||
@Entity | ||
@Getter | ||
@Setter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class Offer { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@NotNull | ||
@Column(nullable = false) | ||
private Double price; | ||
|
||
|
||
@NotNull | ||
@Column(nullable = false) | ||
private Date createdAt; | ||
|
||
@Column | ||
private Double discount; | ||
|
||
@ManyToOne | ||
@JoinColumn(nullable = false, updatable = false) | ||
private Pack pack; | ||
} |
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 |
---|---|---|
|
@@ -28,6 +28,6 @@ public class Product { | |
@Column(nullable = false) | ||
private String measure; | ||
|
||
@Column | ||
private String description; | ||
|
||
} |
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 |
---|---|---|
|
@@ -24,6 +24,6 @@ public class Shop { | |
@Column(nullable = false) | ||
private String address; | ||
|
||
@Column | ||
private String description; | ||
|
||
} |
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
41 changes: 41 additions & 0 deletions
41
src/main/java/com/i8ai/training/store/repository/OfferRepository.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,41 @@ | ||
package com.i8ai.training.store.repository; | ||
|
||
import com.i8ai.training.store.model.Offer; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
@Repository | ||
public interface OfferRepository extends JpaRepository<Offer, Long> { | ||
|
||
@Query("select o from Offer o where o.pack.soldAmount = null or o.pack.amount - o.pack.soldAmount > 0 " + | ||
"order by o.createdAt desc") | ||
List<Offer> findAllAvailable(); | ||
|
||
@Query("select o from Offer o where (o.pack.soldAmount = null or o.pack.amount - o.pack.soldAmount > 0) " + | ||
"and o.pack.shop.id = :shopId order by o.createdAt desc") | ||
List<Offer> findAllAvailableByShopId(Long shopId); | ||
|
||
@Query("select o from Offer o where (o.pack.soldAmount = null or o.pack.amount - o.pack.soldAmount > 0) " + | ||
"and o.pack.lot.product.id = :productId order by o.createdAt desc") | ||
List<Offer> findAllAvailableByProductId(Long productId); | ||
|
||
@Query("select o from Offer o where (o.pack.soldAmount = null or o.pack.amount - o.pack.soldAmount > 0) " + | ||
"and o.pack.shop.id = :shopId and o.pack.lot.product.id = :productId order by o.createdAt desc") | ||
List<Offer> findAllAvailableByShopIdAndProductId(Long shopId, Long productId); | ||
|
||
List<Offer> findAllByCreatedAtBetween(Date start, Date end); | ||
|
||
List<Offer> findAllByCreatedAtBetweenAndPackShopId(Date start, Date end, Long shopId); | ||
|
||
List<Offer> findAllByCreatedAtBetweenAndPackLotProductId(Date start, Date end, Long productId); | ||
|
||
List<Offer> findAllByCreatedAtBetweenAndPackShopIdAndPackLotProductId( | ||
Date start, Date end, Long shopId, Long productId | ||
); | ||
} | ||
|
||
|
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
Oops, something went wrong.