feat: add licence admin gestion
This commit is contained in:
@@ -53,6 +53,6 @@ public class MembreModel {
|
||||
|
||||
String url_photo;
|
||||
|
||||
@OneToMany(mappedBy = "membre", fetch = FetchType.EAGER)
|
||||
@OneToMany(mappedBy = "membre", fetch = FetchType.LAZY)
|
||||
List<LicenceModel> licences;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package fr.titionfire.ffsaf.data.repository;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.LicenceModel;
|
||||
import io.quarkus.hibernate.reactive.panache.PanacheRepositoryBase;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
|
||||
@ApplicationScoped
|
||||
public class LicenceRepository implements PanacheRepositoryBase<LicenceModel, Long> {
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package fr.titionfire.ffsaf.domain.service;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.LicenceModel;
|
||||
import fr.titionfire.ffsaf.data.repository.CombRepository;
|
||||
import fr.titionfire.ffsaf.data.repository.LicenceRepository;
|
||||
import fr.titionfire.ffsaf.rest.from.LicenceForm;
|
||||
import io.quarkus.hibernate.reactive.panache.Panache;
|
||||
import io.quarkus.hibernate.reactive.panache.common.WithSession;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.hibernate.reactive.mutiny.Mutiny;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@WithSession
|
||||
@ApplicationScoped
|
||||
public class LicenceService {
|
||||
|
||||
@Inject
|
||||
LicenceRepository repository;
|
||||
|
||||
@Inject
|
||||
CombRepository combRepository;
|
||||
|
||||
public Uni<List<LicenceModel>> getLicence(long id) {
|
||||
return combRepository.findById(id).chain(combRepository -> Mutiny.fetch(combRepository.getLicences()));
|
||||
}
|
||||
|
||||
public Uni<LicenceModel> setLicence(long id, LicenceForm form) {
|
||||
if (form.getId() == -1) {
|
||||
return combRepository.findById(id).chain(combRepository -> {
|
||||
LicenceModel model = new LicenceModel();
|
||||
model.setMembre(combRepository);
|
||||
model.setSaison(form.getSaison());
|
||||
model.setCertificate(form.isCertificate());
|
||||
model.setValidate(form.isValidate());
|
||||
return Panache.withTransaction(() -> repository.persist(model));
|
||||
});
|
||||
} else {
|
||||
return repository.findById(form.getId()).chain(model -> {
|
||||
model.setCertificate(form.isCertificate());
|
||||
model.setValidate(form.isValidate());
|
||||
return Panache.withTransaction(() -> repository.persist(model));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public Uni<?> deleteLicence(long id) {
|
||||
return Panache.withTransaction(() -> repository.deleteById(id));
|
||||
}
|
||||
}
|
||||
@@ -79,4 +79,5 @@ public class MembreService {
|
||||
return Panache.withTransaction(() -> repository.persist(membreModel));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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