Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Business {
}
class Loyalty {
startDate
accumulatedPoints
}
class Inventory { }
class Category { }
Expand All @@ -81,16 +82,18 @@ class Product {
ingredients
allergens
rating
pointsGiven
pointsCost
isPartOfLoyaltyProgram
}

Customer "1" -- "1" Basket
Customer "1" -- "*" Order
Customer "1" -- "*" Loyalty
Basket "*" -- "*" Product
Order "*" -- "*" Product
Business "1" -- "*" Loyalty
Business "1" -- "*" Inventory
Loyalty "*" -- "1" Product
Inventory "1" -- "*" Product
Product "*" -- "1" Category

```
37 changes: 37 additions & 0 deletions src/main/java/cat/udl/eps/softarch/demo/domain/Loyalty.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package cat.udl.eps.softarch.demo.domain;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.PositiveOrZero;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.ZonedDateTime;

@Entity
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Loyalty extends UriEntity<Long> {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@NotNull
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private ZonedDateTime startDate;

@NotNull
@ManyToOne
private Customer customer;

@NotNull
@ManyToOne
private Business business;

@NotNull
@PositiveOrZero
private Integer accumulatedPoints = 0;
}
10 changes: 10 additions & 0 deletions src/main/java/cat/udl/eps/softarch/demo/domain/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ public class Product extends UriEntity<Long>{
@DecimalMax(value = "5")
private Double rating;

// Loyalty program related fields
@PositiveOrZero
private Integer pointsGiven; // Points given when purchasing this product

@PositiveOrZero
private Integer pointsCost; // Points needed to redeem this product

private boolean isPartOfLoyaltyProgram;


//TODO
// @ManyToMany(mappedBy = "products")
// private Set<Order> orders;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cat.udl.eps.softarch.demo.repository;

import cat.udl.eps.softarch.demo.domain.Loyalty;
import cat.udl.eps.softarch.demo.domain.Customer;
import cat.udl.eps.softarch.demo.domain.Business;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import java.util.List;

@RepositoryRestResource
public interface LoyaltyRepository extends PagingAndSortingRepository<Loyalty, Long>, CrudRepository<Loyalty, Long> {
List<Loyalty> findByCustomer(Customer customer);
List<Loyalty> findByAccumulatedPointsGreaterThanEqual(Integer points);
List<Loyalty> findByCustomerOrderByStartDateDesc(Customer customer);
List<Loyalty> findByCustomerAndBusiness(Customer customer, Business business);
List<Loyalty> findByBusiness(Business business);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ public interface ProductRepository extends CrudRepository<Product, Long>, Paging
//TODO List<Product> findByOrders(Order order);
// List<Product> findByBaskets(Basket basket);

// Loyalty related queries
List<Product> findByIsPartOfLoyaltyProgram(boolean isPartOfLoyaltyProgram);
List<Product> findByPointsCostLessThanEqual(Integer points);
List<Product> findByPointsGivenGreaterThan(Integer points);
}