All checks were successful
Deploy Production Server / if_merged (pull_request) Successful in 6m50s
86 lines
4.0 KiB
Java
86 lines
4.0 KiB
Java
package fr.titionfire.ffsaf.rest;
|
|
|
|
import fr.titionfire.ffsaf.data.model.MembreModel;
|
|
import fr.titionfire.ffsaf.domain.service.SelectionService;
|
|
import fr.titionfire.ffsaf.rest.data.SimpleSelection;
|
|
import fr.titionfire.ffsaf.rest.exception.DForbiddenException;
|
|
import fr.titionfire.ffsaf.utils.SecurityCtx;
|
|
import io.smallrye.mutiny.Uni;
|
|
import io.smallrye.mutiny.unchecked.Unchecked;
|
|
import jakarta.annotation.security.RolesAllowed;
|
|
import jakarta.inject.Inject;
|
|
import jakarta.ws.rs.*;
|
|
import jakarta.ws.rs.core.MediaType;
|
|
import org.eclipse.microprofile.openapi.annotations.Operation;
|
|
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
|
|
import org.eclipse.microprofile.openapi.annotations.responses.APIResponses;
|
|
|
|
import java.util.List;
|
|
import java.util.function.Consumer;
|
|
|
|
@Path("api/selection")
|
|
public class SelectionEndpoints {
|
|
|
|
@Inject
|
|
SelectionService selectionService;
|
|
|
|
@Inject
|
|
SecurityCtx securityCtx;
|
|
|
|
Consumer<MembreModel> checkPerm = Unchecked.consumer(membreModel -> {
|
|
if (!securityCtx.roleHas("federation_admin") && !securityCtx.isInClubGroup(membreModel.getClub().getId()))
|
|
throw new DForbiddenException();
|
|
});
|
|
|
|
@GET
|
|
@Path("{id}")
|
|
@RolesAllowed({"federation_admin", "club_president", "club_secretaire", "club_tresorier", "club_respo_intra",
|
|
"ffsaf_selectionneur"})
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
@Operation(summary = "Renvoie les séléctions d'un membre", description = "Renvoie les séléctions d'un membre en fonction " +
|
|
"de son identifiant")
|
|
@APIResponses(value = {
|
|
@APIResponse(responseCode = "200", description = "La liste des séléctions du membre"),
|
|
@APIResponse(responseCode = "403", description = "Accès refusé"),
|
|
@APIResponse(responseCode = "404", description = "Le membre n'existe pas"),
|
|
@APIResponse(responseCode = "500", description = "Erreur interne du serveur")
|
|
})
|
|
public Uni<List<SimpleSelection>> getSelection(@PathParam("id") long id) {
|
|
return selectionService.getSelection(id, checkPerm)
|
|
.map(selectionModels -> selectionModels.stream().map(SimpleSelection::fromModel).toList());
|
|
}
|
|
|
|
@POST
|
|
@Path("{id}")
|
|
@RolesAllowed({"federation_admin", "ffsaf_selectionneur"})
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
|
@Operation(summary = "Créer une séléction", description = "Créer une séléction en fonction de son identifiant et des " +
|
|
"informations fournies dans le formulaire (pour les administrateurs)")
|
|
@APIResponses(value = {
|
|
@APIResponse(responseCode = "200", description = "La séléction a été mise à jour avec succès"),
|
|
@APIResponse(responseCode = "403", description = "Accès refusé"),
|
|
@APIResponse(responseCode = "404", description = "La séléction n'existe pas"),
|
|
@APIResponse(responseCode = "500", description = "Erreur interne du serveur")
|
|
})
|
|
public Uni<SimpleSelection> setSelection(@PathParam("id") long id, SimpleSelection data) {
|
|
return selectionService.setSelection(id, data).map(SimpleSelection::fromModel);
|
|
}
|
|
|
|
@DELETE
|
|
@Path("{id}")
|
|
@RolesAllowed({"federation_admin", "ffsaf_selectionneur"})
|
|
@Produces(MediaType.TEXT_PLAIN)
|
|
@Operation(summary = "Supprime une séléction", description = "Supprime une séléction en fonction de son identifiant " +
|
|
"(pour les administrateurs)")
|
|
@APIResponses(value = {
|
|
@APIResponse(responseCode = "204", description = "La séléction a été supprimée avec succès"),
|
|
@APIResponse(responseCode = "403", description = "Accès refusé"),
|
|
@APIResponse(responseCode = "404", description = "La séléction n'existe pas"),
|
|
@APIResponse(responseCode = "500", description = "Erreur interne du serveur")
|
|
})
|
|
public Uni<?> deleteSelection(@PathParam("id") long id) {
|
|
return selectionService.deleteSelection(id);
|
|
}
|
|
}
|