Skip to content

Commit

Permalink
fix: allows emailer to send w/o attachments (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
huang0h authored Jun 6, 2024
1 parent 4b4ef30 commit 65e3a95
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ public List<String> validateFields(String fieldPrefix) throws HandledException {
if (emailBody == null) {
fields.add(fieldName + "emailBody");
}
if (attachments == null) {
fields.add(fieldName + "emailAttachment");
}

return fields;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import com.codeforcommunity.api.IProtectedNeighborhoodsProcessor;
import com.codeforcommunity.auth.JWTData;
import com.codeforcommunity.dto.neighborhoods.EditCanopyCoverageRequest;
import com.codeforcommunity.dto.emailer.EmailAttachment;
import com.codeforcommunity.dto.neighborhoods.SendEmailRequest;
import com.codeforcommunity.exceptions.MalformedParameterException;
import com.codeforcommunity.exceptions.ResourceDoesNotExistException;
import com.codeforcommunity.requester.Emailer;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;

import org.jooq.DSLContext;
import org.jooq.generated.tables.records.NeighborhoodsRecord;
Expand All @@ -37,8 +37,11 @@ public void sendEmail(JWTData userData, SendEmailRequest sendEmailRequest) {

String emailSubject = sendEmailRequest.getEmailSubject();
String emailBody = sendEmailRequest.getEmailBody();
List<AttachmentResource> attachments = sendEmailRequest.getAttachments().stream()
.map(ea -> ea.getAttachmentResource()).collect(Collectors.toList());

List<AttachmentResource> attachments = new ArrayList<>();
if (sendEmailRequest.getAttachments() != null) {
sendEmailRequest.getAttachments().forEach(ea -> attachments.add(ea.getAttachmentResource()));
}

emailer.sendArbitraryEmail(new HashSet<>(emails), emailSubject, emailBody, attachments);
}
Expand Down

0 comments on commit 65e3a95

Please sign in to comment.