This repository has been archived by the owner on Dec 4, 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.
Merge pull request #35 from 7SOATSquad30/refactor/immutable-dtos-and-…
…simplify-mappers refactor: make dtos immutable and simplify code that needed mappers
- Loading branch information
Showing
66 changed files
with
511 additions
and
1,135 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
2 changes: 1 addition & 1 deletion
2
...e/persistence/entities/PaymentStatus.java → ...rupo30/fastfood/domain/PaymentStatus.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
43 changes: 20 additions & 23 deletions
43
src/main/java/br/com/fiap/grupo30/fastfood/domain/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 |
---|---|---|
@@ -1,44 +1,41 @@ | ||
package br.com.fiap.grupo30.fastfood.domain.entities; | ||
|
||
import br.com.fiap.grupo30.fastfood.infrastructure.persistence.entities.CategoryEntity; | ||
import br.com.fiap.grupo30.fastfood.presentation.presenters.dto.CategoryDTO; | ||
import java.util.Objects; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
public class Category { | ||
|
||
private Long id; | ||
private String name; | ||
|
||
public Category() {} | ||
|
||
public Category(Long id, String name) { | ||
this.id = id; | ||
this.name = name; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
public static Category create(String name) { | ||
return new Category(null, name); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof Category category)) return false; | ||
return Objects.equals(id, category.id); | ||
return Objects.equals(name, category.name); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id); | ||
return Objects.hash(name); | ||
} | ||
|
||
public CategoryDTO toDTO() { | ||
return new CategoryDTO(name); | ||
} | ||
|
||
public CategoryEntity toPersistence() { | ||
return new CategoryEntity(id, name); | ||
} | ||
} |
61 changes: 20 additions & 41 deletions
61
src/main/java/br/com/fiap/grupo30/fastfood/domain/entities/Customer.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 |
---|---|---|
@@ -1,64 +1,43 @@ | ||
package br.com.fiap.grupo30.fastfood.domain.entities; | ||
|
||
import br.com.fiap.grupo30.fastfood.domain.valueobjects.CPF; | ||
import br.com.fiap.grupo30.fastfood.infrastructure.persistence.entities.CustomerEntity; | ||
import br.com.fiap.grupo30.fastfood.presentation.presenters.dto.CustomerDTO; | ||
import java.util.Objects; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
public class Customer { | ||
private Long id; | ||
private String name; | ||
private CPF cpf; | ||
private String email; | ||
|
||
public Customer() {} | ||
|
||
public Customer(Long id, String name, CPF cpf, String email) { | ||
this.id = id; | ||
this.name = name; | ||
this.cpf = cpf; | ||
this.email = email; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public CPF getCpf() { | ||
return cpf; | ||
} | ||
|
||
public void setCpf(CPF cpf) { | ||
this.cpf = cpf; | ||
} | ||
|
||
public String getEmail() { | ||
return email; | ||
} | ||
|
||
public void setEmail(String email) { | ||
this.email = email; | ||
public static Customer create(String name, String cpf, String email) { | ||
return new Customer(null, name, new CPF(cpf), email); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof Customer customer)) return false; | ||
return Objects.equals(id, customer.id); | ||
return Objects.equals(cpf.value(), customer.cpf.value()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id); | ||
return Objects.hash(cpf.value()); | ||
} | ||
|
||
public CustomerDTO toDTO() { | ||
return new CustomerDTO(name, cpf.value(), email); | ||
} | ||
|
||
public CustomerEntity toPersistence() { | ||
return new CustomerEntity(id, name, cpf.value(), email); | ||
} | ||
} |
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
57 changes: 21 additions & 36 deletions
57
src/main/java/br/com/fiap/grupo30/fastfood/domain/entities/OrderItem.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 |
---|---|---|
@@ -1,59 +1,44 @@ | ||
package br.com.fiap.grupo30.fastfood.domain.entities; | ||
|
||
public class OrderItem { | ||
|
||
private Long id; | ||
import br.com.fiap.grupo30.fastfood.infrastructure.persistence.entities.OrderItemEntity; | ||
import br.com.fiap.grupo30.fastfood.presentation.presenters.dto.OrderItemDTO; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
private Order order; | ||
@Getter | ||
public class OrderItem { | ||
private Product product; | ||
private Long quantity; | ||
private Double totalPrice; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
@Setter(AccessLevel.NONE) | ||
private Double totalPrice; | ||
|
||
public OrderItem(Order order, Product product, Long quantity) { | ||
this.order = order; | ||
public OrderItem(Product product, Long quantity) { | ||
this.product = product; | ||
this.quantity = quantity; | ||
this.recalculateTotalPrice(); | ||
} | ||
|
||
public Order getOrder() { | ||
return order; | ||
} | ||
|
||
public void setOrder(Order order) { | ||
this.order = order; | ||
} | ||
|
||
public Product getProduct() { | ||
return product; | ||
recalculateTotalPrice(); | ||
} | ||
|
||
public void setProduct(Product product) { | ||
this.product = product; | ||
} | ||
|
||
public Long getQuantity() { | ||
return quantity; | ||
recalculateTotalPrice(); | ||
} | ||
|
||
public void setQuantity(Long quantity) { | ||
this.quantity = quantity; | ||
this.recalculateTotalPrice(); | ||
} | ||
|
||
public Double getTotalPrice() { | ||
return totalPrice; | ||
recalculateTotalPrice(); | ||
} | ||
|
||
private void recalculateTotalPrice() { | ||
this.totalPrice = this.product.getPrice() * this.quantity; | ||
} | ||
|
||
public OrderItemDTO toDTO() { | ||
return new OrderItemDTO(product.toDTO(), quantity, totalPrice); | ||
} | ||
|
||
public OrderItemEntity toPersistence() { | ||
return new OrderItemEntity(product.toPersistence(), quantity, totalPrice); | ||
} | ||
} |
Oops, something went wrong.