feat: add licence admin gestion
This commit is contained in:
44
src/main/java/fr/titionfire/ffsaf/rest/LicenceEndpoints.java
Normal file
44
src/main/java/fr/titionfire/ffsaf/rest/LicenceEndpoints.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package fr.titionfire.ffsaf.rest;
|
||||
|
||||
import fr.titionfire.ffsaf.domain.service.LicenceService;
|
||||
import fr.titionfire.ffsaf.rest.data.SimpleLicence;
|
||||
import fr.titionfire.ffsaf.rest.from.LicenceForm;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.annotation.security.RolesAllowed;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Path("api/licence")
|
||||
public class LicenceEndpoints {
|
||||
|
||||
@Inject
|
||||
LicenceService licenceService;
|
||||
|
||||
@GET
|
||||
@Path("{id}")
|
||||
@RolesAllowed("federation_admin")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Uni<List<SimpleLicence>> getLicence(@PathParam("id") long id) {
|
||||
return licenceService.getLicence(id).map(licenceModels -> licenceModels.stream().map(SimpleLicence::fromModel).toList());
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("{id}")
|
||||
@RolesAllowed("federation_admin")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
public Uni<SimpleLicence> setLicence(@PathParam("id") long id, LicenceForm form) {
|
||||
return licenceService.setLicence(id, form).map(SimpleLicence::fromModel);
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("{id}")
|
||||
@RolesAllowed("federation_admin")
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
public Uni<?> deleteLicence(@PathParam("id") long id) {
|
||||
return licenceService.deleteLicence(id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user