This repository has been archived by the owner on Dec 7, 2024. It is now read-only.
-
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.
feat(entities): basic JPA relationship mapping and your respective va…
…lidation
- Loading branch information
Showing
5 changed files
with
166 additions
and
4 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/main/java/com/example/comerce/core/entities/Address.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.comerce.core.entities; | ||
|
||
import jakarta.persistence.*; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.util.UUID; | ||
|
||
@Entity | ||
@Table(name = "address") | ||
@Getter | ||
@Setter | ||
public class Address { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
@Column(name = "address_id", nullable = false, unique = true, updatable = false, length = 36) | ||
@NotNull(message = "Address ID não pode ser null") | ||
private UUID address_id; | ||
|
||
@Column(nullable = false) | ||
@NotBlank(message = "CEP não pode estar em branco") | ||
private String postal_code; | ||
|
||
@Column(nullable = false) | ||
@NotBlank(message = "Rua não pode estar em branco") | ||
private String street; | ||
|
||
@Column(nullable = false) | ||
@NotBlank(message = "Número não pode estar em branco") | ||
private String number; | ||
|
||
@Column(nullable = false) | ||
@NotBlank(message = "Bairro não pode estar em branco") | ||
private String complement; | ||
|
||
@Column(nullable = false) | ||
@NotBlank(message = "Bairro não pode estar em branco") | ||
private String neighborhood; | ||
|
||
@Column(nullable = false) | ||
@NotBlank(message = "Cidade não pode estar em branco") | ||
private String city; | ||
|
||
@Column(nullable = false) | ||
@NotBlank(message = "Estado não pode estar em branco") | ||
private String state; | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/example/comerce/core/entities/Category.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,27 @@ | ||
package com.example.comerce.core.entities; | ||
|
||
import jakarta.persistence.*; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Size; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.Singular; | ||
|
||
import java.util.UUID; | ||
|
||
@Entity | ||
@Table(name = "category") | ||
@Getter | ||
@Setter | ||
public class Category { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
@Column(name = "category_id", nullable = false, unique = true, updatable = false, length = 36) | ||
@NotNull(message = "Category ID não pode ser null") | ||
private UUID category_id; | ||
|
||
@Column | ||
@Size(min = 10, max = 255, message = "A descrição da categoria deve ter entre 10 e 255 caracteres") | ||
private String description; | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/example/comerce/core/entities/Order.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,36 @@ | ||
package com.example.comerce.core.entities; | ||
|
||
import jakarta.persistence.*; | ||
import jakarta.validation.constraints.FutureOrPresent; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Positive; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.util.Date; | ||
import java.util.UUID; | ||
|
||
@Entity | ||
@Table(name = "orders") | ||
@Getter | ||
@Setter | ||
public class Order { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
@Column(name = "order_id", nullable = false, unique = true, updatable = false, length = 36) | ||
@NotNull(message = "Order ID não pode ser null") | ||
private UUID order_id; | ||
|
||
@Column(nullable = false) | ||
@NotNull(message = "Data do pedido não pode ser null") | ||
@FutureOrPresent(message = "Data do pedido deve ser no presente ou no futuro") | ||
private Date date; | ||
|
||
@Column | ||
@Positive(message = "O desconto deve ser um valor positivo") | ||
private double discount; | ||
|
||
@Column(nullable = false) | ||
@Positive(message = "O valor total deve ser um valor positivo") | ||
private double total_price; | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/example/comerce/core/entities/ProductCategoryId.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,21 @@ | ||
package com.example.comerce.core.entities; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embeddable; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.util.UUID; | ||
|
||
@Embeddable | ||
@Getter | ||
@Setter | ||
@EqualsAndHashCode | ||
public class ProductCategoryId { | ||
@Column(insertable = false, updatable = false) | ||
private UUID product_id; | ||
|
||
@Column(insertable = false, updatable = false) | ||
private UUID category_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,45 @@ | ||
package com.example.comerce.core.entities; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.*; | ||
import jakarta.validation.constraints.Email; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Size; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.util.UUID; | ||
|
||
@Entity | ||
@Table(name = "users") | ||
@Getter | ||
@Setter | ||
public class User { | ||
|
||
@Id | ||
private UUID id; | ||
} | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
@Column(name = "user_id", nullable = false, unique = true, updatable = false, length = 36) | ||
@NotNull(message = "User ID não pode ser null") | ||
private UUID user_id; | ||
|
||
@Column(length = 100, nullable = false) | ||
@NotBlank(message = "Nome não pode estar em branco") | ||
@Size(min = 3, max = 100, message = "Nome deve ter no mínimo 3 caracteres e no máximo 100 caracteres") | ||
private String name; | ||
|
||
@Column(length = 11, nullable = false, unique = true) | ||
@Size(min = 11, max = 11, message = "Telefone deve ter 11 caracteres") | ||
private String telephone; | ||
|
||
@Column(length = 11, nullable = false, unique = true) | ||
@Size(min = 11, max = 11, message = "CPF deve ter 11 caracteres") | ||
private String cpf; | ||
|
||
@Column(length = 100, nullable = false, unique = true) | ||
@NotBlank(message = "Email não pode estar em branco") | ||
@Email(message = "E-mail inválido") | ||
private String email; | ||
|
||
@Column(length = 255, nullable = false) | ||
private Address address; | ||
} |