feat(validation): add request and domain validation for email use case

This commit is contained in:
2025-09-14 14:46:23 +02:00
parent 421d160c12
commit fff9362ea8
6 changed files with 71 additions and 27 deletions

View File

@@ -0,0 +1,22 @@
package com.pablotj.restemailbridge.domain.service;
import com.pablotj.restemailbridge.domain.model.Email;
public class EmailValidatorService {
/**
* Validates business rules for Email.
*/
public void validate(Email email) {
if (email == null) throw new IllegalArgumentException("Email cannot be null");
if (email.getTo() == null || !email.getTo().matches(".+@.+\\..+"))
throw new IllegalArgumentException("Recipient email is invalid");
if (email.getFrom() == null || email.getFrom().isBlank())
throw new IllegalArgumentException("Sender email is required");
if (email.getSubject() == null || email.getSubject().isBlank())
throw new IllegalArgumentException("Subject is required");
if (email.getBody() == null || email.getBody().isBlank())
throw new IllegalArgumentException("Body is required");
}
}