feat: add licence admin gestion
This commit is contained in:
@@ -49,6 +49,7 @@ public class CombEndpoints {
|
||||
return membreService.getById(id).map(SimpleMembre::fromModel);
|
||||
}
|
||||
|
||||
|
||||
@POST
|
||||
@Path("{id}")
|
||||
@RolesAllowed("federation_admin")
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package fr.titionfire.ffsaf.rest.data;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.LicenceModel;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@RegisterForReflection
|
||||
public class SimpleLicence {
|
||||
Long id;
|
||||
Long membre;
|
||||
int saison;
|
||||
boolean certificate;
|
||||
boolean validate;
|
||||
|
||||
public static SimpleLicence fromModel(LicenceModel model) {
|
||||
if (model == null)
|
||||
return null;
|
||||
|
||||
return new SimpleLicenceBuilder()
|
||||
.id(model.getId())
|
||||
.membre(model.getMembre().getId())
|
||||
.saison(model.getSaison())
|
||||
.certificate(model.isCertificate())
|
||||
.validate(model.isValidate())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
24
src/main/java/fr/titionfire/ffsaf/rest/from/LicenceForm.java
Normal file
24
src/main/java/fr/titionfire/ffsaf/rest/from/LicenceForm.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package fr.titionfire.ffsaf.rest.from;
|
||||
|
||||
import jakarta.ws.rs.FormParam;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
public class LicenceForm {
|
||||
@FormParam("id")
|
||||
private long id;
|
||||
|
||||
@FormParam("membre")
|
||||
private long membre;
|
||||
|
||||
@FormParam("saison")
|
||||
private int saison;
|
||||
|
||||
@FormParam("certificate")
|
||||
private boolean certificate;
|
||||
|
||||
@FormParam("validate")
|
||||
private boolean validate;
|
||||
}
|
||||
Reference in New Issue
Block a user