-
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.
- Loading branch information
Showing
24 changed files
with
370 additions
and
109 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,13 +33,13 @@ public Argon2PasswordEncoder passwordEncoder() { | |
@Bean | ||
CommandLineRunner run(AppUserServices appUserServices, ProductServices productServices) { | ||
return args -> { | ||
appUserServices.saveRole(new Role( "ROLE_USER")); | ||
appUserServices.saveRole(new Role( "ROLE_ADMIN")); | ||
|
||
appUserServices.saveAppUser(new User( "Tuan", "Nguyen", "tuanxsokoh", "[email protected]", | ||
"123456", new HashSet<>())); | ||
|
||
appUserServices.addRoleToAppUser("tuanxsokoh", "ROLE_ADMIN"); | ||
// appUserServices.saveRole(new Role( "ROLE_USER")); | ||
// appUserServices.saveRole(new Role( "ROLE_ADMIN")); | ||
// | ||
// appUserServices.saveAppUser(new User( "Tuan", "Nguyen", "tuanxsokoh", "[email protected]", | ||
// "123456", new HashSet<>())); | ||
// | ||
// appUserServices.addRoleToAppUser("tuanxsokoh", "ROLE_ADMIN"); | ||
}; | ||
} | ||
|
||
|
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
50 changes: 50 additions & 0 deletions
50
src/main/java/com/example/DOTSAPI/dto/product/ProductDto.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,50 @@ | ||
package com.example.DOTSAPI.dto.product; | ||
|
||
import lombok.Getter; | ||
|
||
import javax.persistence.Temporal; | ||
import javax.persistence.TemporalType; | ||
import javax.validation.constraints.Min; | ||
import javax.validation.constraints.NotBlank; | ||
import javax.validation.constraints.NotEmpty; | ||
import javax.validation.constraints.NotNull; | ||
import java.util.Date; | ||
import java.util.Set; | ||
|
||
@Getter | ||
public class ProductDto { | ||
@NotBlank(message = "NAME_NOT_VALID") | ||
private String productName; | ||
|
||
@NotBlank(message = "DESCRIPTION_NOT_VALID") | ||
private String description; | ||
|
||
@NotBlank(message = "CATEGORY_NOT_VALID") | ||
private String category; | ||
|
||
@NotBlank(message = "IMAGEURL_NOT_VALID") | ||
private String imageUrl; | ||
|
||
@NotNull(message = "PRICE_MISSING") | ||
@Min(value = 0, message = "PRICE_NOT_VALID") | ||
private double unitPrice; | ||
|
||
@NotNull(message = "STOCK_MISSING") | ||
@Min(value = 0,message = "STOCK_NOT_VALID") | ||
private Long stock; | ||
|
||
@NotBlank(message = "BRAND_NOT_VALID") | ||
private String brand; | ||
|
||
@NotNull(message = "OVERALL_RATING_NOT_VALID") | ||
private float overallRating; | ||
|
||
@NotNull(message = "TOTAL_RATING_NOT_VALID") | ||
@Min(value = 0, message = "TOTAL_RATING_NOT_VALID") | ||
private Integer totalRating; | ||
|
||
@NotEmpty(message = "SIZE_NOT_VALID") | ||
private Set<Integer> size; | ||
@NotEmpty(message = "COLOR_NOT_VALID") | ||
private Set<String> color; | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/example/DOTSAPI/dto/product/RateProductDto.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.example.DOTSAPI.dto.product; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import javax.validation.constraints.Max; | ||
import javax.validation.constraints.Min; | ||
import javax.validation.constraints.NotNull; | ||
|
||
@Getter | ||
public class RateProductDto { | ||
@NotNull(message = "PRODUCT_ID_MISSING") | ||
private Long productId; | ||
|
||
@NotNull(message = "RATING_NOT_VALID") | ||
@Min(value = 0, message = "RATING_NOT_VALID") | ||
@Max(value = 5, message = "RATING_NOT_VALID") | ||
private Integer rating; | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/com/example/DOTSAPI/dto/product/ResponseProductDto.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,52 @@ | ||
package com.example.DOTSAPI.dto.product; | ||
|
||
import com.example.DOTSAPI.model.Product; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import javax.persistence.Temporal; | ||
import javax.persistence.TemporalType; | ||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
|
||
@Getter | ||
@Setter | ||
public class ResponseProductDto { | ||
private Long productId; | ||
private String productName; | ||
private String category; | ||
private String imageUrl; | ||
private double unitPrice; | ||
private Long stock; | ||
private String brand; | ||
private float overallRating; | ||
private Integer totalRating; | ||
private Set<Integer> size; | ||
private Set<String> color; | ||
|
||
@Temporal(TemporalType.DATE) | ||
private Date createdAt; | ||
|
||
@Temporal(TemporalType.DATE) | ||
private Date modifiedAt; | ||
|
||
public ResponseProductDto(Product product) { | ||
this.productId = product.getId(); | ||
this.productName = product.getName(); | ||
this.category = product.getCategory().getName(); | ||
this.imageUrl = product.getImageUrl(); | ||
this.stock = product.getStock(); | ||
this.size = product.getSize(); | ||
this.unitPrice = product.getPrice(); | ||
this.color = product.getColor(); | ||
this.brand = product.getBrand().getName(); | ||
this.overallRating = product.getOverallRating(); | ||
this.totalRating = product.getTotalRating(); | ||
this.setCreatedAt(product.getCreatedAt()); | ||
this.setModifiedAt(product.getModifiedAt()); | ||
} | ||
} |
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.example.DOTSAPI.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import javax.persistence.*; | ||
import javax.validation.constraints.NotBlank; | ||
import javax.validation.constraints.Size; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
@Entity | ||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
public class Brand { | ||
@JsonIgnore | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@NotBlank(message = "Brand name is missing") | ||
@Size(max = 15, message="Brand must be smaller than 15 characters long") | ||
@Column(unique = true, length = 60) | ||
private String name; | ||
|
||
public Brand(String name) { | ||
this.name = name; | ||
} | ||
|
||
@JsonIgnore | ||
@OneToMany(mappedBy = "brand", cascade = CascadeType.ALL, fetch = FetchType.LAZY) | ||
private Set<Product> products = new HashSet<>(); | ||
} |
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.