feat: add licence import endpoint
All checks were successful
Deploy Production Server / if_merged (pull_request) Successful in 9m50s

fix: pdf_gen
This commit is contained in:
Thibaut Valentin 2025-07-07 14:04:02 +02:00
parent bd59a17212
commit 824bedb99f
4 changed files with 45 additions and 7 deletions

View File

@ -373,7 +373,7 @@ public class ClubService {
return uniBase
.map(Unchecked.function(m -> {
if (m.getAffiliations().stream()
.noneMatch(licenceModel -> licenceModel.getSaison() == Utils.getSaison() - 1))
.noneMatch(licenceModel -> licenceModel.getSaison() == Utils.getSaison()))
throw new DNotFoundException("Pas d'affiliation pour la saison en cours");
try {

View File

@ -120,4 +120,29 @@ public class LicenceService {
}))
.chain(__ -> Panache.withTransaction(() -> repository.deleteById(id)));
}
public Uni<?> setImport(int licence, int saison, boolean valid) {
return combRepository.find("licence = ?1", licence).firstResult()
.chain(membreModel ->
repository.find("saison = ?1 AND membre = ?2", saison, membreModel).firstResult()
.chain(licenceModel -> {
if (licenceModel != null) {
if (licenceModel.getClub_id() == null)
licenceModel.setClub_id(
(membreModel.getClub() == null) ? null : membreModel.getClub()
.getId());
licenceModel.setValidate(valid);
return Panache.withTransaction(() -> repository.persist(licenceModel));
} else {
LicenceModel model = new LicenceModel();
model.setClub_id(
(membreModel.getClub() == null) ? null : membreModel.getClub().getId());
model.setMembre(membreModel);
model.setSaison(saison);
model.setCertificate("¤");
model.setValidate(valid);
return Panache.withTransaction(() -> repository.persist(model));
}
}));
}
}

View File

@ -46,7 +46,8 @@ public class LicenceEndpoints {
@APIResponse(responseCode = "500", description = "Erreur interne du serveur")
})
public Uni<List<SimpleLicence>> getLicence(@PathParam("id") long id) {
return licenceService.getLicence(id, checkPerm).map(licenceModels -> licenceModels.stream().map(SimpleLicence::fromModel).toList());
return licenceService.getLicence(id, checkPerm)
.map(licenceModels -> licenceModels.stream().map(SimpleLicence::fromModel).toList());
}
@GET
@ -60,7 +61,8 @@ public class LicenceEndpoints {
@APIResponse(responseCode = "500", description = "Erreur interne du serveur")
})
public Uni<List<SimpleLicence>> getCurrentSaisonLicenceAdmin() {
return licenceService.getCurrentSaisonLicence(null).map(licenceModels -> licenceModels.stream().map(SimpleLicence::fromModel).toList());
return licenceService.getCurrentSaisonLicence(null)
.map(licenceModels -> licenceModels.stream().map(SimpleLicence::fromModel).toList());
}
@GET
@ -74,7 +76,8 @@ public class LicenceEndpoints {
@APIResponse(responseCode = "500", description = "Erreur interne du serveur")
})
public Uni<List<SimpleLicence>> getCurrentSaisonLicenceClub() {
return licenceService.getCurrentSaisonLicence(securityCtx).map(licenceModels -> licenceModels.stream().map(SimpleLicence::fromModel).toList());
return licenceService.getCurrentSaisonLicence(securityCtx)
.map(licenceModels -> licenceModels.stream().map(SimpleLicence::fromModel).toList());
}
@POST
@ -142,4 +145,14 @@ public class LicenceEndpoints {
public Uni<?> deleteAskLicence(@PathParam("id") long id) {
return licenceService.deleteAskLicence(id, checkPerm);
}
// TODO remove after importe all data
@GET
@Path("import")
@RolesAllowed({"federation_admin"})
@Produces(MediaType.APPLICATION_JSON)
public Uni<?> setImport(@QueryParam("licence") int licence, @QueryParam("saison") int saison,
@QueryParam("valid") int valid) {
return licenceService.setImport(licence, saison, valid != 0);
}
}

View File

@ -32,7 +32,7 @@ public class Main {
pdfData.saison = Integer.parseInt(args[7]);
pdfData.licence = Integer.parseInt(args[8]);
pdfData.club = args[9];
pdfData.club_no = Integer.parseInt(args[10]);
pdfData.club_no = args[10].equals("null") ? -1 : Integer.parseInt(args[10]);
pdfData.birth_date = args[11];
pdfData.photo_file = new File(args[12]);
@ -165,7 +165,7 @@ public class Main {
pList.add(new Paragraph("CLUB AFFILIÉ SAISON " + pdfData.saison + "-" + (pdfData.saison + 1) + "\n ",
new Font(customFontBold, 24, Font.NORMAL)));
pList.add(new Paragraph(pdfData.name, new Font(customFontBold, 20, Font.NORMAL, new Color(0, 112, 192))));
pList.add(new Paragraph(String.format("- association n°%03d -\n ", pdfData.club_no),
pList.add(new Paragraph(String.format("- association n°%05d -\n ", pdfData.club_no),
new Font(customFont, 18, Font.TIMES_ROMAN)));
PdfPCell bodyCell = new PdfPCell();
@ -375,7 +375,7 @@ public class Main {
Paragraph memberClub = new Paragraph("CLUB : " + pdfData.club.toUpperCase(), bodyFont);
document.add(memberClub);
Paragraph memberClubNumber = new Paragraph(String.format("N° club : %03d ", pdfData.club_no), bodyFont);
Paragraph memberClubNumber = new Paragraph(String.format("N° club : %05d ", pdfData.club_no), bodyFont);
document.add(memberClubNumber);
// Adding spacing