Skip to content

Commit

Permalink
add(product dtos): dto's involved in request and response
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelribeiroo committed Dec 23, 2024
1 parent 2cd0ae8 commit ca88115
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/main/java/auth/api/model/product/ProductRequestDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package auth.api.model.product;

public class ProductRequestDTO {

private String title;
private double price;

public ProductRequestDTO(String title, double price) {
setTitle(title);
setPrice(price);
}

// Getters
public String getTitle() {
return title;
}

public double getPrice() {
return price;
}

// Setters

public void setTitle(String title) {
if (title == null || title.trim().isBlank()) {
throw new IllegalArgumentException("O nome do produto não deve ser vazio ou nulo.");
}

this.title = title;
}

public void setPrice(double price) {
if (price <= 0) {
throw new IllegalArgumentException("O preço do produto não deve ser zerado.");
}

this.price = price;
}

}
39 changes: 39 additions & 0 deletions src/main/java/auth/api/model/product/ProductResponseDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package auth.api.model.product;

public class ProductResponseDTO {
private Long id;
private String title;
private double price;

public ProductResponseDTO(Long id, String title, double price) {
this.id = id;
this.title = title;
this.price = price;
}

// Getters
public Long getId() {
return id;
}

public String getTitle() {
return title;
}

public double getPrice() {
return price;
}

// Setters
public void setId(Long id) {
this.id = id;
}

public void setTitle(String title) {
this.title = title;
}

public void setPrice(double price) {
this.price = price;
}
}

0 comments on commit ca88115

Please sign in to comment.