Sync: code local unifié
Synchronisation du code source local (fait foi). Signed-off-by: lions dev Team
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package dev.lions.unionflow.server.resource;
|
||||
|
||||
import dev.lions.unionflow.server.api.dto.notification.NotificationDTO;
|
||||
import dev.lions.unionflow.server.api.dto.notification.TemplateNotificationDTO;
|
||||
import dev.lions.unionflow.server.api.dto.notification.request.CreateNotificationRequest;
|
||||
import dev.lions.unionflow.server.api.dto.notification.request.CreateTemplateNotificationRequest;
|
||||
import dev.lions.unionflow.server.api.dto.notification.response.NotificationResponse;
|
||||
import dev.lions.unionflow.server.api.dto.notification.response.TemplateNotificationResponse;
|
||||
import dev.lions.unionflow.server.service.NotificationService;
|
||||
import jakarta.annotation.security.RolesAllowed;
|
||||
import jakarta.inject.Inject;
|
||||
@@ -12,7 +14,10 @@ import jakarta.ws.rs.core.Response;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import org.eclipse.microprofile.openapi.annotations.tags.Tag;
|
||||
import org.jboss.logging.Logger;
|
||||
import io.quarkus.security.identity.SecurityIdentity;
|
||||
import dev.lions.unionflow.server.repository.MembreRepository;
|
||||
|
||||
/**
|
||||
* Resource REST pour la gestion des notifications
|
||||
@@ -24,12 +29,64 @@ import org.jboss.logging.Logger;
|
||||
@Path("/api/notifications")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@RolesAllowed({"ADMIN", "MEMBRE", "USER"})
|
||||
@RolesAllowed({ "ADMIN", "MEMBRE", "USER" })
|
||||
@Tag(name = "Notifications", description = "Gestion des notifications : envoi, templates et notifications groupées")
|
||||
public class NotificationResource {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(NotificationResource.class);
|
||||
|
||||
@Inject NotificationService notificationService;
|
||||
@Inject
|
||||
NotificationService notificationService;
|
||||
|
||||
@Inject
|
||||
MembreRepository membreRepository;
|
||||
|
||||
@Inject
|
||||
SecurityIdentity securityIdentity;
|
||||
|
||||
/**
|
||||
* Notifications du membre connecté (sans passer par membreId).
|
||||
*/
|
||||
@GET
|
||||
@Path("/me")
|
||||
public Response mesNotifications() {
|
||||
try {
|
||||
String email = securityIdentity.getPrincipal().getName();
|
||||
var membre = membreRepository.findByEmail(email);
|
||||
if (membre.isEmpty()) {
|
||||
return Response.ok(List.of()).build();
|
||||
}
|
||||
List<NotificationResponse> result = notificationService.listerNotificationsParMembre(membre.get().getId());
|
||||
return Response.ok(result).build();
|
||||
} catch (Exception e) {
|
||||
LOG.errorf(e, "Erreur liste notifications membre connecté");
|
||||
return Response.status(Response.Status.BAD_REQUEST)
|
||||
.entity(new ErrorResponse("Erreur: " + e.getMessage()))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifications non lues du membre connecté.
|
||||
*/
|
||||
@GET
|
||||
@Path("/me/non-lues")
|
||||
public Response mesNotificationsNonLues() {
|
||||
try {
|
||||
String email = securityIdentity.getPrincipal().getName();
|
||||
var membre = membreRepository.findByEmail(email);
|
||||
if (membre.isEmpty()) {
|
||||
return Response.ok(List.of()).build();
|
||||
}
|
||||
List<NotificationResponse> result = notificationService.listerNotificationsNonLuesParMembre(membre.get().getId());
|
||||
return Response.ok(result).build();
|
||||
} catch (Exception e) {
|
||||
LOG.errorf(e, "Erreur liste notifications non lues");
|
||||
return Response.status(Response.Status.BAD_REQUEST)
|
||||
.entity(new ErrorResponse("Erreur: " + e.getMessage()))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// TEMPLATES
|
||||
@@ -42,11 +99,11 @@ public class NotificationResource {
|
||||
* @return Template créé
|
||||
*/
|
||||
@POST
|
||||
@RolesAllowed({"ADMIN", "MEMBRE"})
|
||||
@RolesAllowed({ "ADMIN", "MEMBRE" })
|
||||
@Path("/templates")
|
||||
public Response creerTemplate(@Valid TemplateNotificationDTO templateDTO) {
|
||||
public Response creerTemplate(@Valid CreateTemplateNotificationRequest request) {
|
||||
try {
|
||||
TemplateNotificationDTO result = notificationService.creerTemplate(templateDTO);
|
||||
TemplateNotificationResponse result = notificationService.creerTemplate(request);
|
||||
return Response.status(Response.Status.CREATED).entity(result).build();
|
||||
} catch (IllegalArgumentException e) {
|
||||
return Response.status(Response.Status.BAD_REQUEST)
|
||||
@@ -71,10 +128,10 @@ public class NotificationResource {
|
||||
* @return Notification créée
|
||||
*/
|
||||
@POST
|
||||
@RolesAllowed({"ADMIN", "MEMBRE"})
|
||||
public Response creerNotification(@Valid NotificationDTO notificationDTO) {
|
||||
@RolesAllowed({ "ADMIN", "MEMBRE" })
|
||||
public Response creerNotification(@Valid CreateNotificationRequest request) {
|
||||
try {
|
||||
NotificationDTO result = notificationService.creerNotification(notificationDTO);
|
||||
NotificationResponse result = notificationService.creerNotification(request);
|
||||
return Response.status(Response.Status.CREATED).entity(result).build();
|
||||
} catch (Exception e) {
|
||||
LOG.errorf(e, "Erreur lors de la création de la notification");
|
||||
@@ -91,11 +148,11 @@ public class NotificationResource {
|
||||
* @return Notification mise à jour
|
||||
*/
|
||||
@POST
|
||||
@RolesAllowed({"ADMIN", "MEMBRE"})
|
||||
@RolesAllowed({ "ADMIN", "MEMBRE" })
|
||||
@Path("/{id}/marquer-lue")
|
||||
public Response marquerCommeLue(@PathParam("id") UUID id) {
|
||||
try {
|
||||
NotificationDTO result = notificationService.marquerCommeLue(id);
|
||||
NotificationResponse result = notificationService.marquerCommeLue(id);
|
||||
return Response.ok(result).build();
|
||||
} catch (jakarta.ws.rs.NotFoundException e) {
|
||||
return Response.status(Response.Status.NOT_FOUND)
|
||||
@@ -119,7 +176,7 @@ public class NotificationResource {
|
||||
@Path("/{id}")
|
||||
public Response trouverNotificationParId(@PathParam("id") UUID id) {
|
||||
try {
|
||||
NotificationDTO result = notificationService.trouverNotificationParId(id);
|
||||
NotificationResponse result = notificationService.trouverNotificationParId(id);
|
||||
return Response.ok(result).build();
|
||||
} catch (jakarta.ws.rs.NotFoundException e) {
|
||||
return Response.status(Response.Status.NOT_FOUND)
|
||||
@@ -143,7 +200,7 @@ public class NotificationResource {
|
||||
@Path("/membre/{membreId}")
|
||||
public Response listerNotificationsParMembre(@PathParam("membreId") UUID membreId) {
|
||||
try {
|
||||
List<NotificationDTO> result = notificationService.listerNotificationsParMembre(membreId);
|
||||
List<NotificationResponse> result = notificationService.listerNotificationsParMembre(membreId);
|
||||
return Response.ok(result).build();
|
||||
} catch (Exception e) {
|
||||
LOG.errorf(e, "Erreur lors de la liste des notifications");
|
||||
@@ -163,7 +220,7 @@ public class NotificationResource {
|
||||
@Path("/membre/{membreId}/non-lues")
|
||||
public Response listerNotificationsNonLuesParMembre(@PathParam("membreId") UUID membreId) {
|
||||
try {
|
||||
List<NotificationDTO> result = notificationService.listerNotificationsNonLuesParMembre(membreId);
|
||||
List<NotificationResponse> result = notificationService.listerNotificationsNonLuesParMembre(membreId);
|
||||
return Response.ok(result).build();
|
||||
} catch (Exception e) {
|
||||
LOG.errorf(e, "Erreur lors de la liste des notifications non lues");
|
||||
@@ -184,7 +241,7 @@ public class NotificationResource {
|
||||
@Path("/en-attente-envoi")
|
||||
public Response listerNotificationsEnAttenteEnvoi() {
|
||||
try {
|
||||
List<NotificationDTO> result = notificationService.listerNotificationsEnAttenteEnvoi();
|
||||
List<NotificationResponse> result = notificationService.listerNotificationsEnAttenteEnvoi();
|
||||
return Response.ok(result).build();
|
||||
} catch (Exception e) {
|
||||
LOG.errorf(e, "Erreur lors de la liste des notifications en attente");
|
||||
@@ -203,13 +260,12 @@ public class NotificationResource {
|
||||
* @return Nombre de notifications créées
|
||||
*/
|
||||
@POST
|
||||
@RolesAllowed({"ADMIN", "MEMBRE"})
|
||||
@RolesAllowed({ "ADMIN", "MEMBRE" })
|
||||
@Path("/groupees")
|
||||
public Response envoyerNotificationsGroupees(NotificationGroupeeRequest request) {
|
||||
try {
|
||||
int notificationsCreees =
|
||||
notificationService.envoyerNotificationsGroupees(
|
||||
request.membreIds, request.sujet, request.corps, request.canaux);
|
||||
int notificationsCreees = notificationService.envoyerNotificationsGroupees(
|
||||
request.membreIds, request.sujet, request.corps, request.canaux);
|
||||
return Response.ok(Map.of("notificationsCreees", notificationsCreees)).build();
|
||||
} catch (IllegalArgumentException e) {
|
||||
return Response.status(Response.Status.BAD_REQUEST)
|
||||
@@ -241,6 +297,7 @@ public class NotificationResource {
|
||||
public String corps;
|
||||
public List<String> canaux;
|
||||
|
||||
public NotificationGroupeeRequest() {}
|
||||
public NotificationGroupeeRequest() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user