Skip to content

Commit

Permalink
[Gepardec/mega#735] Add endpoint for Mail automatism
Browse files Browse the repository at this point in the history
  • Loading branch information
Ollitod committed Feb 11, 2024
1 parent ddd4948 commit 7db7b0d
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void sendReminderToUser() {
.forEach(user -> mailSender.send(EMPLOYEE_CHECK_PROJECTTIME, user.getEmail(), user.getFirstname(), applicationConfig.getDefaultLocale()));
logSentNotification(EMPLOYEE_CHECK_PROJECTTIME);
} else {
logger.info("NO Reminder to employes sent, cause mega.mail.employees.notification-property is false");
logger.info("NO Reminder to employees sent, cause mega.mail.employees.notification-property is false");
}
}

Expand Down
25 changes: 25 additions & 0 deletions src/main/java/com/gepardec/mega/rest/api/MailResource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.gepardec.mega.rest.api;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.tags.Tag;

@Path("/mail")
@Tag(name = "MailResource")
@Produces(MediaType.APPLICATION_JSON)
public interface MailResource {

@Operation(operationId = "sendReminder", description = "Sends reminder emails to affected employees.")
@GET
@Path("/sendReminder")
Response sendReminder();

@Operation(operationId = "retrieveZepEmailsFromInbox", description = "Webhook for new emails from ZEP to trigger comment creation.")
@GET
@Path("/retrieveZepEmails")
Response retrieveZepEmailsFromInbox();
}
46 changes: 46 additions & 0 deletions src/main/java/com/gepardec/mega/rest/impl/MailResourceImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.gepardec.mega.rest.impl;

import com.gepardec.mega.notification.mail.ReminderEmailSender;
import com.gepardec.mega.notification.mail.receiver.MailReceiver;
import com.gepardec.mega.rest.api.MailResource;
import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.core.Response;
import org.slf4j.Logger;

@RequestScoped
public class MailResourceImpl implements MailResource {

@Inject
ReminderEmailSender reminderEmailSender;

@Inject
MailReceiver mailReceiver;

@Inject
Logger logger;

@Override
public Response sendReminder() {
try {
reminderEmailSender.sendReminder();
} catch (Exception e) {
logger.error(e.getMessage());
return Response.serverError().entity(e.getMessage()).build();
}

return Response.ok().build();
}

@Override
public Response retrieveZepEmailsFromInbox() {
try {
mailReceiver.retrieveZepEmailsFromInbox();
} catch (Exception e) {
logger.error(e.getMessage());
return Response.serverError().entity(e.getMessage()).build();
}

return Response.ok().build();
}
}

0 comments on commit 7db7b0d

Please sign in to comment.