diff --git a/src/main/java/com/example/comerce/core/entities/Address.java b/src/main/java/com/example/comerce/core/entities/Address.java new file mode 100644 index 0000000..d5bd513 --- /dev/null +++ b/src/main/java/com/example/comerce/core/entities/Address.java @@ -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; +} diff --git a/src/main/java/com/example/comerce/core/entities/Category.java b/src/main/java/com/example/comerce/core/entities/Category.java new file mode 100644 index 0000000..d6dcd7d --- /dev/null +++ b/src/main/java/com/example/comerce/core/entities/Category.java @@ -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; +} diff --git a/src/main/java/com/example/comerce/core/entities/Order.java b/src/main/java/com/example/comerce/core/entities/Order.java new file mode 100644 index 0000000..13dbebf --- /dev/null +++ b/src/main/java/com/example/comerce/core/entities/Order.java @@ -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; +} diff --git a/src/main/java/com/example/comerce/core/entities/ProductCategoryId.java b/src/main/java/com/example/comerce/core/entities/ProductCategoryId.java new file mode 100644 index 0000000..479c68a --- /dev/null +++ b/src/main/java/com/example/comerce/core/entities/ProductCategoryId.java @@ -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; +} diff --git a/src/main/java/com/example/comerce/core/entities/User.java b/src/main/java/com/example/comerce/core/entities/User.java index fda010c..647e49f 100644 --- a/src/main/java/com/example/comerce/core/entities/User.java +++ b/src/main/java/com/example/comerce/core/entities/User.java @@ -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; -} \ No newline at end of file + @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; +}