Logo Passei Direto
Buscar

Java

ESTÁCIO
@Entity @Getter @NoArgsConstructor public class Coupon { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String code; private String description; private Double discountValue; private LocalDate expirationDate; private boolean published; private boolean deleted = false; // Soft Delete public Coupon(String code, String description, Double discountValue, LocalDate expirationDate, boolean published) { this.code = sanitizeCode(code); validate(discountValue, expirationDate); this.description = description; this.discountValue = discountValue; this.expirationDate = expirationDate; this.published = published; } private String sanitizeCode(String code) { if (code == null) throw new IllegalArgumentException("Código obrigatório"); // Remove caracteres especiais e garante 6 caracteres String cleanCode = code.replaceAll("[^a-zA-Z0-9]", ""); if (cleanCode.length() != 6) { throw new IllegalArgumentException("O código deve ter exatamente 6 caracteres alfanuméricos"); } return cleanCode; } private void validate(Double discount, LocalDate expiration) { if (discount < 0.5) throw new IllegalArgumentException("Desconto mínimo é 0.5"); if (expiration.isBefore(LocalDate.now())) throw new IllegalArgumentException("Data não pode ser no passado"); } public void delete() { if (this.deleted) throw new IllegalStateException("Cupom já deletado"); this.deleted = true; } }
User badge image
Gisele Quintas

há 4 semanas

Respostas

User badge image

Ed Verified user icon

há 4 semanas

Parece que você compartilhou um trecho de código Java que representa uma classe `Coupon` com anotações do JPA e métodos para manipulação de cupons. No entanto, você não fez uma pergunta específica sobre esse código. Para que eu possa ajudar, você precisa criar uma nova pergunta que especifique o que você gostaria de saber sobre essa classe ou sobre Java em geral.

Essa resposta te ajudou?

0
Dislike0

Ainda com dúvidas?

Envie uma pergunta e tenha sua dúvida de estudo respondida!