wip: club
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package fr.titionfire.ffsaf.data.model;
|
||||
|
||||
import fr.titionfire.ffsaf.utils.RoleAsso;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
@@ -20,24 +21,27 @@ public class AffiliationRequestModel {
|
||||
Long id;
|
||||
|
||||
String name;
|
||||
String siren;
|
||||
long siren;
|
||||
String RNA;
|
||||
String address;
|
||||
|
||||
String president_lname;
|
||||
String president_fname;
|
||||
String president_email;
|
||||
int president_lincence;
|
||||
String m1_lname;
|
||||
String m1_fname;
|
||||
String m1_email;
|
||||
int m1_lincence;
|
||||
RoleAsso m1_role;
|
||||
|
||||
String tresorier_lname;
|
||||
String tresorier_fname;
|
||||
String tresorier_email;
|
||||
int tresorier_lincence;
|
||||
String m2_lname;
|
||||
String m2_fname;
|
||||
String m2_email;
|
||||
int m2_lincence;
|
||||
RoleAsso m2_role;
|
||||
|
||||
String secretaire_lname;
|
||||
String secretaire_fname;
|
||||
String secretaire_email;
|
||||
int secretaire_lincence;
|
||||
String m3_lname;
|
||||
String m3_fname;
|
||||
String m3_email;
|
||||
int m3_lincence;
|
||||
RoleAsso m3_role;
|
||||
|
||||
int saison;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package fr.titionfire.ffsaf.domain.service;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.AffiliationRequestModel;
|
||||
import fr.titionfire.ffsaf.data.model.ClubModel;
|
||||
import fr.titionfire.ffsaf.data.repository.AffiliationRequestRepository;
|
||||
import fr.titionfire.ffsaf.data.repository.CombRepository;
|
||||
import fr.titionfire.ffsaf.rest.data.SimpleAffiliation;
|
||||
import fr.titionfire.ffsaf.rest.from.AffiliationForm;
|
||||
import fr.titionfire.ffsaf.rest.from.AffiliationRequestForm;
|
||||
import fr.titionfire.ffsaf.utils.Utils;
|
||||
import io.quarkus.hibernate.reactive.panache.Panache;
|
||||
@@ -12,6 +15,9 @@ import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@WithSession
|
||||
@ApplicationScoped
|
||||
public class AffiliationService {
|
||||
@@ -29,32 +35,49 @@ public class AffiliationService {
|
||||
AffiliationRequestModel affModel = form.toModel();
|
||||
affModel.setSaison(Utils.getSaison());
|
||||
|
||||
// noinspection ResultOfMethodCallIgnored
|
||||
return Uni.createFrom().item(affModel)
|
||||
.call(model -> ((model.getPresident_lincence() != 0) ? combRepository.find("licence",
|
||||
model.getPresident_lincence()).count().invoke(count -> {
|
||||
.call(model -> ((model.getM1_lincence() != 0) ? combRepository.find("licence",
|
||||
model.getM1_lincence()).count().invoke(count -> {
|
||||
if (count == 0) {
|
||||
throw new IllegalArgumentException("Licence président inconnue");
|
||||
throw new IllegalArgumentException("Licence membre n°1 inconnue");
|
||||
}
|
||||
}) : Uni.createFrom().nullItem())
|
||||
)
|
||||
.call(model -> ((model.getTresorier_lincence() != 0) ? combRepository.find("licence",
|
||||
model.getTresorier_lincence()).count().invoke(count -> {
|
||||
.call(model -> ((model.getM2_lincence() != 0) ? combRepository.find("licence",
|
||||
model.getM2_lincence()).count().invoke(count -> {
|
||||
if (count == 0) {
|
||||
throw new IllegalArgumentException("Licence trésorier inconnue");
|
||||
throw new IllegalArgumentException("Licence membre n°2 inconnue");
|
||||
}
|
||||
}) : Uni.createFrom().nullItem())
|
||||
)
|
||||
.call(model -> ((model.getSecretaire_lincence() != 0) ? combRepository.find("licence",
|
||||
model.getSecretaire_lincence()).count().invoke(count -> {
|
||||
.call(model -> ((model.getM3_lincence() != 0) ? combRepository.find("licence",
|
||||
model.getM3_lincence()).count().invoke(count -> {
|
||||
if (count == 0) {
|
||||
throw new IllegalArgumentException("Licence secrétaire inconnue");
|
||||
throw new IllegalArgumentException("Licence membre n°3 inconnue");
|
||||
}
|
||||
}) : Uni.createFrom().nullItem())
|
||||
).chain(model -> Panache.withTransaction(() -> repository.persist(model)))
|
||||
.call(model -> Uni.createFrom().future(Utils.replacePhoto(model.getId(), form.getLogo(), media,
|
||||
.onItem().invoke(model -> Uni.createFrom().future(Utils.replacePhoto(model.getId(), form.getLogo(), media,
|
||||
"aff_request/logo")))
|
||||
.call(model -> Uni.createFrom().future(Utils.replacePhoto(model.getId(), form.getStatus(), media,
|
||||
.onItem().invoke(model -> Uni.createFrom().future(Utils.replacePhoto(model.getId(), form.getStatus(), media,
|
||||
"aff_request/status")))
|
||||
.map(__ -> "Ok");
|
||||
}
|
||||
|
||||
public Uni<List<SimpleAffiliation>> getCurrentSaisonAffiliation() {
|
||||
return Uni.createFrom().nullItem(); // TODO
|
||||
}
|
||||
|
||||
public Uni<List<SimpleAffiliation>> getAffiliation(long id, Consumer<ClubModel> checkPerm) {
|
||||
return Uni.createFrom().nullItem(); // TODO
|
||||
}
|
||||
|
||||
public Uni<SimpleAffiliation> setAffiliation(long id, AffiliationForm form) {
|
||||
return Uni.createFrom().nullItem(); // TODO
|
||||
}
|
||||
|
||||
public Uni<?> deleteAffiliation(long id) {
|
||||
return Uni.createFrom().nullItem(); // TODO
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,20 @@ package fr.titionfire.ffsaf.domain.service;
|
||||
import fr.titionfire.ffsaf.data.model.ClubModel;
|
||||
import fr.titionfire.ffsaf.data.repository.ClubRepository;
|
||||
import fr.titionfire.ffsaf.net2.data.SimpleClubModel;
|
||||
import fr.titionfire.ffsaf.rest.from.FullClubForm;
|
||||
import fr.titionfire.ffsaf.utils.PageResult;
|
||||
import io.quarkus.hibernate.reactive.panache.Panache;
|
||||
import io.quarkus.hibernate.reactive.panache.PanacheQuery;
|
||||
import io.quarkus.hibernate.reactive.panache.common.WithSession;
|
||||
import io.quarkus.panache.common.Page;
|
||||
import io.quarkus.panache.common.Sort;
|
||||
import io.quarkus.vertx.VertxContextSupport;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import io.smallrye.mutiny.unchecked.Unchecked;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.BadRequestException;
|
||||
import org.hibernate.reactive.mutiny.Mutiny;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -39,4 +47,63 @@ public class ClubService {
|
||||
return Panache.withTransaction(() -> repository.persist(clubModel));
|
||||
});
|
||||
}
|
||||
|
||||
public Uni<PageResult<SimpleClubModel>> search(Integer limit, int page, String search, String country) {
|
||||
if (search == null)
|
||||
search = "";
|
||||
search = search + "%";
|
||||
|
||||
PanacheQuery<ClubModel> query;
|
||||
|
||||
if (country == null || country.isBlank())
|
||||
query = repository.find("name LIKE ?1",
|
||||
Sort.ascending("name"), search).page(Page.ofSize(limit));
|
||||
else
|
||||
query = repository.find("name LIKE ?1 AND country LIKE ?2",
|
||||
Sort.ascending("name"), search, country + "%").page(Page.ofSize(limit));
|
||||
return getPageResult(query, limit, page);
|
||||
}
|
||||
|
||||
private Uni<PageResult<SimpleClubModel>> getPageResult(PanacheQuery<ClubModel> query, int limit, int page) {
|
||||
return Uni.createFrom().item(new PageResult<SimpleClubModel>())
|
||||
.invoke(result -> result.setPage(page))
|
||||
.invoke(result -> result.setPage_size(limit))
|
||||
.call(result -> query.count().invoke(result::setResult_count))
|
||||
.call(result -> query.pageCount()
|
||||
.invoke(Unchecked.consumer(pages -> {
|
||||
if (page > pages) throw new BadRequestException();
|
||||
}))
|
||||
.invoke(result::setPage_count))
|
||||
.call(result -> query.page(Page.of(page, limit)).list()
|
||||
.map(membreModels -> membreModels.stream().map(SimpleClubModel::fromModel).toList())
|
||||
.invoke(result::setResult));
|
||||
}
|
||||
|
||||
public Uni<ClubModel> getById(long id) {
|
||||
return repository.findById(id).call(m -> Mutiny.fetch(m.getContact()));
|
||||
}
|
||||
|
||||
public Uni<ClubModel> getByClubId(String clubId) {
|
||||
return repository.find("clubId", clubId).firstResult();
|
||||
}
|
||||
|
||||
public Uni<String> update(long id, FullClubForm input) {
|
||||
/*return repository.findById(id)
|
||||
.onItem().transformToUni(m -> {
|
||||
m.setName(input.getName());
|
||||
m.setCountry(input.getCountry());
|
||||
m.setNo_affiliation(input.getNo_affiliation());
|
||||
m.setShieldURL(input.getShieldURL());
|
||||
return Panache.withTransaction(() -> repository.persist(m));
|
||||
});*/
|
||||
return Uni.createFrom().nullItem();
|
||||
}
|
||||
|
||||
public Uni<Long> add(FullClubForm input) {
|
||||
return Uni.createFrom().nullItem();
|
||||
}
|
||||
|
||||
public Uni<?> delete(long id) {
|
||||
return Uni.createFrom().nullItem();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,11 +17,13 @@ public class SimpleClubModel {
|
||||
String name;
|
||||
String country;
|
||||
String shieldURL;
|
||||
String no_affiliation;
|
||||
|
||||
public static SimpleClubModel fromModel(ClubModel model) {
|
||||
if (model == null)
|
||||
return null;
|
||||
|
||||
return new SimpleClubModel(model.getId(), model.getName(), model.getCountry(), model.getShieldURL());
|
||||
return new SimpleClubModel(model.getId(), model.getName(), model.getCountry(), model.getShieldURL(),
|
||||
model.getNo_affiliation());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,79 @@
|
||||
package fr.titionfire.ffsaf.rest;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.ClubModel;
|
||||
import fr.titionfire.ffsaf.domain.service.AffiliationService;
|
||||
import fr.titionfire.ffsaf.rest.data.SimpleAffiliation;
|
||||
import fr.titionfire.ffsaf.rest.from.AffiliationForm;
|
||||
import fr.titionfire.ffsaf.rest.from.AffiliationRequestForm;
|
||||
import fr.titionfire.ffsaf.utils.GroupeUtils;
|
||||
import io.quarkus.oidc.IdToken;
|
||||
import io.quarkus.security.identity.SecurityIdentity;
|
||||
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.jwt.JsonWebToken;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Path("api/affiliation")
|
||||
public class AffiliationEndpoints {
|
||||
|
||||
@Inject
|
||||
AffiliationService service;
|
||||
|
||||
@Inject
|
||||
@IdToken
|
||||
JsonWebToken idToken;
|
||||
|
||||
@Inject
|
||||
SecurityIdentity securityIdentity;
|
||||
|
||||
Consumer<ClubModel> checkPerm = Unchecked.consumer(clubModel -> {
|
||||
if (!securityIdentity.getRoles().contains("federation_admin") && !GroupeUtils.isInClubGroup(clubModel.getId(), idToken))
|
||||
throw new ForbiddenException();
|
||||
});
|
||||
|
||||
@POST
|
||||
@Path("save")
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
public Uni<String> saveAffRequest(AffiliationRequestForm form) {
|
||||
System.out.println(form);
|
||||
return Uni.createFrom().item("OK");
|
||||
}
|
||||
/*@POST
|
||||
@Path("affiliation")
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
public Uni<String> saveAffRequest(AffiliationRequestForm form) {
|
||||
System.out.println(form);
|
||||
return service.save(form);
|
||||
}*/
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/current")
|
||||
@RolesAllowed({"federation_admin"})
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Uni<List<SimpleAffiliation>> getCurrentSaisonLicenceAdmin() {
|
||||
return service.getCurrentSaisonAffiliation();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{id}")
|
||||
@RolesAllowed({"federation_admin", "club_president", "club_secretaire", "club_respo_intra"})
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Uni<List<SimpleAffiliation>> getLicence(@PathParam("id") long id) {
|
||||
return service.getAffiliation(id, checkPerm);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("{id}")
|
||||
@RolesAllowed("federation_admin")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
public Uni<SimpleAffiliation> setLicence(@PathParam("id") long id, AffiliationForm form) {
|
||||
return service.setAffiliation(id, form);
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("{id}")
|
||||
@RolesAllowed("federation_admin")
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
public Uni<?> deleteLicence(@PathParam("id") long id) {
|
||||
return service.deleteAffiliation(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,18 @@
|
||||
package fr.titionfire.ffsaf.rest;
|
||||
|
||||
import fr.titionfire.ffsaf.domain.service.AffiliationService;
|
||||
import fr.titionfire.ffsaf.rest.client.SirenService;
|
||||
import fr.titionfire.ffsaf.rest.data.UniteLegaleRoot;
|
||||
import fr.titionfire.ffsaf.rest.from.AffiliationRequestForm;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jodd.net.MimeTypes;
|
||||
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
||||
import org.eclipse.microprofile.rest.client.inject.RestClient;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.file.Files;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
@Path("api/asso")
|
||||
public class AssoEndpoints {
|
||||
|
||||
@RestClient
|
||||
SirenService sirenService;
|
||||
|
||||
@Inject
|
||||
AffiliationService service;
|
||||
|
||||
@ConfigProperty(name = "upload_dir")
|
||||
String media;
|
||||
|
||||
@GET
|
||||
@Path("siren/{siren}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@@ -42,12 +25,4 @@ public class AssoEndpoints {
|
||||
return throwable;
|
||||
});
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("affiliation")
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
public Uni<String> saveAffRequest(AffiliationRequestForm form) {
|
||||
return service.save(form);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,29 @@
|
||||
package fr.titionfire.ffsaf.rest;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.ClubModel;
|
||||
import fr.titionfire.ffsaf.domain.service.ClubService;
|
||||
import fr.titionfire.ffsaf.net2.data.SimpleClubModel;
|
||||
import fr.titionfire.ffsaf.rest.data.SimpleClub;
|
||||
import fr.titionfire.ffsaf.rest.from.FullClubForm;
|
||||
import fr.titionfire.ffsaf.utils.GroupeUtils;
|
||||
import fr.titionfire.ffsaf.utils.PageResult;
|
||||
import fr.titionfire.ffsaf.utils.Utils;
|
||||
import io.quarkus.oidc.IdToken;
|
||||
import io.quarkus.security.Authenticated;
|
||||
import io.quarkus.security.identity.SecurityIdentity;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import io.smallrye.mutiny.unchecked.Unchecked;
|
||||
import jakarta.annotation.security.RolesAllowed;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
||||
import org.eclipse.microprofile.jwt.JsonWebToken;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Path("api/club")
|
||||
public class ClubEndpoints {
|
||||
@@ -18,6 +31,22 @@ public class ClubEndpoints {
|
||||
@Inject
|
||||
ClubService clubService;
|
||||
|
||||
@Inject
|
||||
@IdToken
|
||||
JsonWebToken idToken;
|
||||
|
||||
@Inject
|
||||
SecurityIdentity securityIdentity;
|
||||
|
||||
@ConfigProperty(name = "upload_dir")
|
||||
String media;
|
||||
|
||||
Consumer<ClubModel> checkPerm = Unchecked.consumer(membreModel -> {
|
||||
if (!securityIdentity.getRoles().contains("federation_admin") && !GroupeUtils.isInClubGroup(membreModel.getId(),
|
||||
idToken))
|
||||
throw new ForbiddenException();
|
||||
});
|
||||
|
||||
@GET
|
||||
@Path("/no_detail")
|
||||
@Authenticated
|
||||
@@ -25,4 +54,110 @@ public class ClubEndpoints {
|
||||
public Uni<List<SimpleClubModel>> getAll() {
|
||||
return clubService.getAll().map(clubModels -> clubModels.stream().map(SimpleClubModel::fromModel).toList());
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/find")
|
||||
@RolesAllowed({"federation_admin"})
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Uni<PageResult<SimpleClubModel>> getFindAdmin(@QueryParam("limit") Integer limit,
|
||||
@QueryParam("page") Integer page,
|
||||
@QueryParam("search") String search,
|
||||
@QueryParam("country") String country) {
|
||||
if (limit == null)
|
||||
limit = 50;
|
||||
if (page == null || page < 1)
|
||||
page = 1;
|
||||
return clubService.search(limit, page - 1, search, country);
|
||||
}
|
||||
|
||||
|
||||
@GET
|
||||
@Path("{id}")
|
||||
@RolesAllowed({"federation_admin", "club_president", "club_secretaire", "club_respo_intra"})
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Uni<SimpleClub> getById(@PathParam("id") long id) {
|
||||
return clubService.getById(id).onItem().invoke(checkPerm).map(SimpleClub::fromModel);
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("{id}")
|
||||
@RolesAllowed({"federation_admin"})
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
public Uni<String> setAdminClub(@PathParam("id") long id, FullClubForm input) {
|
||||
return clubService.update(id, input)
|
||||
.invoke(Unchecked.consumer(out -> {
|
||||
if (!out.equals("OK")) throw new InternalError("Fail to update data: " + out);
|
||||
})).chain(() -> {
|
||||
if (input.getLogo().length > 0)
|
||||
return Uni.createFrom().future(Utils.replacePhoto(id, input.getLogo(), media, "ppClub"
|
||||
)).invoke(Unchecked.consumer(out -> {
|
||||
if (!out.equals("OK")) throw new InternalError("Fail to get MimeType " + out);
|
||||
}));
|
||||
else
|
||||
return Uni.createFrom().nullItem();
|
||||
}).chain(() -> {
|
||||
if (input.getStatus().length > 0)
|
||||
return Uni.createFrom().future(Utils.replacePhoto(id, input.getStatus(), media, "clubStatus"
|
||||
)).invoke(Unchecked.consumer(out -> {
|
||||
if (!out.equals("OK")) throw new InternalError("Fail to get MimeType " + out);
|
||||
}));
|
||||
else
|
||||
return Uni.createFrom().nullItem();
|
||||
});
|
||||
}
|
||||
|
||||
@POST
|
||||
@RolesAllowed({"federation_admin"})
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
public Uni<Long> addAdminClub(FullClubForm input) {
|
||||
return clubService.add(input)
|
||||
.invoke(Unchecked.consumer(id -> {
|
||||
if (id == null) throw new InternalError("Fail to create club data");
|
||||
})).call(id -> {
|
||||
if (input.getLogo().length > 0)
|
||||
return Uni.createFrom().future(Utils.replacePhoto(id, input.getLogo(), media, "ppClub"
|
||||
));
|
||||
else
|
||||
return Uni.createFrom().nullItem();
|
||||
}).call(id -> {
|
||||
if (input.getStatus().length > 0)
|
||||
return Uni.createFrom().future(Utils.replacePhoto(id, input.getStatus(), media, "clubStatus"
|
||||
));
|
||||
else
|
||||
return Uni.createFrom().nullItem();
|
||||
});
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("{id}")
|
||||
@RolesAllowed({"federation_admin"})
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
public Uni<?> deleteAdminClub(@PathParam("id") long id) {
|
||||
return clubService.delete(id);
|
||||
}
|
||||
|
||||
|
||||
@GET
|
||||
@Path("{clubId}/logo")
|
||||
@RolesAllowed({"federation_admin", "club_president", "club_secretaire", "club_respo_intra"})
|
||||
public Uni<Response> getLogo(@PathParam("clubId") String clubId) {
|
||||
return clubService.getByClubId(clubId).onItem().invoke(checkPerm).chain(Unchecked.function(clubModel -> {
|
||||
try {
|
||||
return Utils.getMediaFile((clubModel != null) ? clubModel.getId() : -1, media, "ppClub",
|
||||
Uni.createFrom().nullItem());
|
||||
} catch (URISyntaxException e) {
|
||||
throw new InternalError();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{id}/status")
|
||||
@RolesAllowed({"federation_admin", "club_president", "club_secretaire"})
|
||||
public Uni<Response> getStatus(@PathParam("id") long id) throws URISyntaxException {
|
||||
return Utils.getMediaFile(id, media, "clubStatus", clubService.getById(id).onItem().invoke(checkPerm));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import fr.titionfire.ffsaf.rest.from.ClubMemberForm;
|
||||
import fr.titionfire.ffsaf.rest.from.FullMemberForm;
|
||||
import fr.titionfire.ffsaf.utils.GroupeUtils;
|
||||
import fr.titionfire.ffsaf.utils.PageResult;
|
||||
import fr.titionfire.ffsaf.utils.Pair;
|
||||
import fr.titionfire.ffsaf.utils.Utils;
|
||||
import io.quarkus.oidc.IdToken;
|
||||
import io.quarkus.security.Authenticated;
|
||||
@@ -17,7 +16,6 @@ import io.smallrye.mutiny.unchecked.Unchecked;
|
||||
import jakarta.annotation.security.RolesAllowed;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.core.HttpHeaders;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import jodd.net.MimeTypes;
|
||||
@@ -25,7 +23,6 @@ import org.eclipse.microprofile.config.inject.ConfigProperty;
|
||||
import org.eclipse.microprofile.jwt.JsonWebToken;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.file.Files;
|
||||
@@ -51,7 +48,8 @@ public class CombEndpoints {
|
||||
SecurityIdentity securityIdentity;
|
||||
|
||||
Consumer<MembreModel> checkPerm = Unchecked.consumer(membreModel -> {
|
||||
if (!securityIdentity.getRoles().contains("federation_admin") && !GroupeUtils.isInClubGroup(membreModel.getClub().getId(), idToken))
|
||||
if (!securityIdentity.getRoles().contains("federation_admin") && !GroupeUtils.isInClubGroup(
|
||||
membreModel.getClub().getId(), idToken))
|
||||
throw new ForbiddenException();
|
||||
});
|
||||
|
||||
@@ -213,37 +211,7 @@ public class CombEndpoints {
|
||||
@Path("{id}/photo")
|
||||
@RolesAllowed({"federation_admin", "club_president", "club_secretaire", "club_respo_intra"})
|
||||
public Uni<Response> getPhoto(@PathParam("id") long id) throws URISyntaxException {
|
||||
Future<Pair<File, byte[]>> future = CompletableFuture.supplyAsync(() -> {
|
||||
FilenameFilter filter = (directory, filename) -> filename.startsWith(String.valueOf(id));
|
||||
File[] files = new File(media, "ppMembre").listFiles(filter);
|
||||
if (files != null && files.length > 0) {
|
||||
File file = files[0];
|
||||
try {
|
||||
byte[] data = Files.readAllBytes(file.toPath());
|
||||
return new Pair<>(file, data);
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
URI uri = new URI("https://mdbcdn.b-cdn.net/img/Photos/new-templates/bootstrap-chat/ava2.webp");
|
||||
|
||||
return membreService.getById(id).onItem().invoke(checkPerm).chain(__ -> Uni.createFrom().future(future)
|
||||
.map(filePair -> {
|
||||
if (filePair == null)
|
||||
return Response.temporaryRedirect(uri).build();
|
||||
|
||||
String mimeType = URLConnection.guessContentTypeFromName(filePair.getKey().getName());
|
||||
|
||||
Response.ResponseBuilder resp = Response.ok(filePair.getValue());
|
||||
resp.type(MediaType.APPLICATION_OCTET_STREAM);
|
||||
resp.header(HttpHeaders.CONTENT_LENGTH, filePair.getValue().length);
|
||||
resp.header(HttpHeaders.CONTENT_TYPE, mimeType);
|
||||
resp.header(HttpHeaders.CONTENT_DISPOSITION, "inline; ");
|
||||
|
||||
return resp.build();
|
||||
}));
|
||||
return Utils.getMediaFile(id, media, "ppMembre", membreService.getById(id).onItem().invoke(checkPerm));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package fr.titionfire.ffsaf.rest.data;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.AffiliationModel;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@RegisterForReflection
|
||||
public class SimpleAffiliation {
|
||||
Long id;
|
||||
Long club;
|
||||
int saison;
|
||||
boolean validate;
|
||||
|
||||
public static SimpleAffiliation fromModel(AffiliationModel model, boolean validate) {
|
||||
if (model == null)
|
||||
return null;
|
||||
|
||||
return new SimpleAffiliationBuilder()
|
||||
.id(model.getId())
|
||||
.club(model.getClub().getId())
|
||||
.saison(model.getSaison())
|
||||
.validate(validate)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
53
src/main/java/fr/titionfire/ffsaf/rest/data/SimpleClub.java
Normal file
53
src/main/java/fr/titionfire/ffsaf/rest/data/SimpleClub.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package fr.titionfire.ffsaf.rest.data;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.ClubModel;
|
||||
import fr.titionfire.ffsaf.utils.Contact;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@ToString
|
||||
@AllArgsConstructor
|
||||
@RegisterForReflection
|
||||
public class SimpleClub {
|
||||
private Long id;
|
||||
private String clubId;
|
||||
private String name;
|
||||
private String country;
|
||||
private String shieldURL;
|
||||
private Map<Contact, String> contact;
|
||||
private String training_location;
|
||||
private String training_day_time;
|
||||
private String contact_intern;
|
||||
private String RNA;
|
||||
private String SIRET;
|
||||
private String no_affiliation;
|
||||
private boolean international;
|
||||
|
||||
public static SimpleClub fromModel(ClubModel model) {
|
||||
if (model == null)
|
||||
return null;
|
||||
|
||||
return new SimpleClubBuilder()
|
||||
.id(model.getId())
|
||||
.clubId(model.getClubId())
|
||||
.name(model.getName())
|
||||
.country(model.getCountry())
|
||||
.shieldURL(model.getShieldURL())
|
||||
.contact(model.getContact())
|
||||
.training_location(model.getTraining_location())
|
||||
.training_day_time(model.getTraining_day_time())
|
||||
.contact_intern(model.getContact_intern())
|
||||
.RNA(model.getRNA())
|
||||
.SIRET(model.getSIRET())
|
||||
.no_affiliation(model.getNo_affiliation())
|
||||
.international(model.isInternational())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package fr.titionfire.ffsaf.rest.from;
|
||||
|
||||
public class AffiliationForm {
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package fr.titionfire.ffsaf.rest.from;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.AffiliationRequestModel;
|
||||
import fr.titionfire.ffsaf.utils.RoleAsso;
|
||||
import jakarta.ws.rs.FormParam;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import lombok.Getter;
|
||||
@@ -14,7 +15,7 @@ public class AffiliationRequestForm {
|
||||
private String name = null;
|
||||
|
||||
@FormParam("siren")
|
||||
private String siren = null;
|
||||
private Long siren = null;
|
||||
|
||||
@FormParam("rna")
|
||||
private String rna = null;
|
||||
@@ -30,32 +31,38 @@ public class AffiliationRequestForm {
|
||||
@PartType(MediaType.APPLICATION_OCTET_STREAM)
|
||||
private byte[] logo = new byte[0];
|
||||
|
||||
@FormParam("president-nom")
|
||||
private String president_lname = null;
|
||||
@FormParam("president-prenom")
|
||||
private String president_fname = null;
|
||||
@FormParam("president-mail")
|
||||
private String president_email = null;
|
||||
@FormParam("president-licence")
|
||||
private String president_lincence = null;
|
||||
@FormParam("m1_nom")
|
||||
private String m1_lname = null;
|
||||
@FormParam("m1_prenom")
|
||||
private String m1_fname = null;
|
||||
@FormParam("m1_mail")
|
||||
private String m1_email = null;
|
||||
@FormParam("m1_licence")
|
||||
private String m1_lincence = null;
|
||||
@FormParam("m1_role")
|
||||
private RoleAsso m1_role = null;
|
||||
|
||||
@FormParam("tresorier-nom")
|
||||
private String tresorier_lname = null;
|
||||
@FormParam("tresorier-prenom")
|
||||
private String tresorier_fname = null;
|
||||
@FormParam("tresorier-mail")
|
||||
private String tresorier_email = null;
|
||||
@FormParam("tresorier-licence")
|
||||
private String tresorier_lincence = null;
|
||||
@FormParam("m2_nom")
|
||||
private String m2_lname = null;
|
||||
@FormParam("m2_prenom")
|
||||
private String m2_fname = null;
|
||||
@FormParam("m2_mail")
|
||||
private String m2_email = null;
|
||||
@FormParam("m2_licence")
|
||||
private String m2_lincence = null;
|
||||
@FormParam("m2_role")
|
||||
private RoleAsso m2_role = null;
|
||||
|
||||
@FormParam("secretaire-nom")
|
||||
private String secretaire_lname = null;
|
||||
@FormParam("secretaire-prenom")
|
||||
private String secretaire_fname = null;
|
||||
@FormParam("secretaire-mail")
|
||||
private String secretaire_email = null;
|
||||
@FormParam("secretaire-licence")
|
||||
private String secretaire_lincence = null;
|
||||
@FormParam("m3_nom")
|
||||
private String m3_lname = null;
|
||||
@FormParam("m3_prenom")
|
||||
private String m3_fname = null;
|
||||
@FormParam("m3_mail")
|
||||
private String m3_email = null;
|
||||
@FormParam("m3_licence")
|
||||
private String m3_lincence = null;
|
||||
@FormParam("m3_role")
|
||||
private RoleAsso m3_role = null;
|
||||
|
||||
public AffiliationRequestModel toModel() {
|
||||
AffiliationRequestModel model = new AffiliationRequestModel();
|
||||
@@ -64,23 +71,26 @@ public class AffiliationRequestForm {
|
||||
model.setRNA(this.getRna());
|
||||
model.setAddress(this.getAdresse());
|
||||
|
||||
model.setPresident_lname(this.getPresident_lname());
|
||||
model.setPresident_fname(this.getPresident_fname());
|
||||
model.setPresident_email(this.getPresident_email());
|
||||
model.setPresident_lincence((this.getPresident_lincence() == null || this.getPresident_lincence().isBlank())
|
||||
? 0 : Integer.parseInt(this.getPresident_lincence()));
|
||||
model.setM1_lname(this.getM1_lname());
|
||||
model.setM1_fname(this.getM1_fname());
|
||||
model.setM1_email(this.getM1_email());
|
||||
model.setM1_lincence((this.getM1_lincence() == null || this.getM1_lincence().isBlank())
|
||||
? 0 : Integer.parseInt(this.getM1_lincence()));
|
||||
model.setM1_role(this.getM1_role());
|
||||
|
||||
model.setTresorier_lname(this.getTresorier_lname());
|
||||
model.setTresorier_fname(this.getTresorier_fname());
|
||||
model.setTresorier_email(this.getTresorier_email());
|
||||
model.setTresorier_lincence((this.getPresident_lincence() == null || this.getPresident_lincence().isBlank())
|
||||
? 0 : Integer.parseInt(this.getTresorier_lincence()));
|
||||
model.setM2_lname(this.getM2_lname());
|
||||
model.setM2_fname(this.getM2_fname());
|
||||
model.setM2_email(this.getM2_email());
|
||||
model.setM2_lincence((this.getM1_lincence() == null || this.getM1_lincence().isBlank())
|
||||
? 0 : Integer.parseInt(this.getM2_lincence()));
|
||||
model.setM2_role(this.getM2_role());
|
||||
|
||||
model.setSecretaire_lname(this.getSecretaire_lname());
|
||||
model.setSecretaire_fname(this.getSecretaire_fname());
|
||||
model.setSecretaire_email(this.getSecretaire_email());
|
||||
model.setSecretaire_lincence((this.getPresident_lincence() == null || this.getPresident_lincence().isBlank())
|
||||
? 0 : Integer.parseInt(this.getSecretaire_lincence()));
|
||||
model.setM3_lname(this.getM3_lname());
|
||||
model.setM3_fname(this.getM3_fname());
|
||||
model.setM3_email(this.getM3_email());
|
||||
model.setM3_lincence((this.getM1_lincence() == null || this.getM1_lincence().isBlank())
|
||||
? 0 : Integer.parseInt(this.getM3_lincence()));
|
||||
model.setM3_role(this.getM3_role());
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package fr.titionfire.ffsaf.rest.from;
|
||||
|
||||
import jakarta.ws.rs.FormParam;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import lombok.Getter;
|
||||
import org.jboss.resteasy.reactive.PartType;
|
||||
|
||||
@Getter
|
||||
public class FullClubForm {
|
||||
@FormParam("id")
|
||||
private String id = null;
|
||||
|
||||
@FormParam("name")
|
||||
private String name = null;
|
||||
|
||||
@FormParam("status")
|
||||
@PartType(MediaType.APPLICATION_OCTET_STREAM)
|
||||
private byte[] status = new byte[0];
|
||||
|
||||
@FormParam("logo")
|
||||
@PartType(MediaType.APPLICATION_OCTET_STREAM)
|
||||
private byte[] logo = new byte[0];
|
||||
}
|
||||
@@ -5,9 +5,13 @@ import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
@RegisterForReflection
|
||||
public enum RoleAsso {
|
||||
MEMBRE("Membre", 0),
|
||||
PRESIDENT("Président", 3),
|
||||
TRESORIER("Trésorier", 1),
|
||||
SECRETAIRE("Secrétaire", 2);
|
||||
PRESIDENT("Président", 7),
|
||||
VPRESIDENT("Vise-Président", 6),
|
||||
SECRETAIRE("Secrétaire", 5),
|
||||
VSECRETAIRE("Vise-Secrétaire", 4),
|
||||
TRESORIER("Trésorier", 3),
|
||||
VTRESORIER("Vise-Trésorier", 2),
|
||||
MEMBREBUREAU("Membre bureau", 1);
|
||||
|
||||
public final String name;
|
||||
public final int level;
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package fr.titionfire.ffsaf.utils;
|
||||
|
||||
public class StringSimilarity {
|
||||
|
||||
public static int similarity(String s1, String s2) {
|
||||
String longer = s1, shorter = s2;
|
||||
if (s1.length() < s2.length()) {
|
||||
longer = s2;
|
||||
shorter = s1;
|
||||
}
|
||||
int longerLength = longer.length();
|
||||
if (longerLength == 0) {
|
||||
return 1;
|
||||
}
|
||||
return editDistance(longer, shorter);
|
||||
|
||||
}
|
||||
|
||||
public static int editDistance(String s1, String s2) {
|
||||
s1 = s1.toLowerCase();
|
||||
s2 = s2.toLowerCase();
|
||||
|
||||
int[] costs = new int[s2.length() + 1];
|
||||
for (int i = 0; i <= s1.length(); i++) {
|
||||
int lastValue = i;
|
||||
for (int j = 0; j <= s2.length(); j++) {
|
||||
if (i == 0)
|
||||
costs[j] = j;
|
||||
else {
|
||||
if (j > 0) {
|
||||
int newValue = costs[j - 1];
|
||||
if (s1.charAt(i - 1) != s2.charAt(j - 1))
|
||||
newValue = Math.min(Math.min(newValue, lastValue),
|
||||
costs[j]) + 1;
|
||||
costs[j - 1] = lastValue;
|
||||
lastValue = newValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (i > 0)
|
||||
costs[s2.length()] = lastValue;
|
||||
}
|
||||
return costs[s2.length()];
|
||||
}
|
||||
|
||||
public static void printSimilarity(String s, String t) {
|
||||
System.out.printf(
|
||||
"%d is the similarity between \"%s\" and \"%s\"%n", similarity(s, t), s, t);
|
||||
}
|
||||
|
||||
/*public static void main(String[] args) {
|
||||
printSimilarity("Xavier Login", "Xavier Lojin");
|
||||
printSimilarity("Xavier Login", "Xavier ogin");
|
||||
printSimilarity("Xavier Login", "avier Login");
|
||||
printSimilarity("Xavier Login", "xavier login");
|
||||
printSimilarity("Xavier Login", "Xaviér Login");
|
||||
printSimilarity("Xavier Gomme Login", "Xavier Login");
|
||||
printSimilarity("Xavier Login", "Xavier Gomme Login");
|
||||
printSimilarity("Xavier Login", "Xavier");
|
||||
printSimilarity("Xavier Login", "Login");
|
||||
printSimilarity("Jule", "Julles");
|
||||
printSimilarity("Xavier", "Xaviér");
|
||||
printSimilarity("Xavier", "xavvie");
|
||||
}*/
|
||||
}
|
||||
@@ -1,8 +1,19 @@
|
||||
package fr.titionfire.ffsaf.utils;
|
||||
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.ws.rs.core.HttpHeaders;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import jodd.net.MimeTypes;
|
||||
import net.sf.jmimemagic.Magic;
|
||||
import net.sf.jmimemagic.MagicException;
|
||||
import net.sf.jmimemagic.MagicMatchNotFoundException;
|
||||
import net.sf.jmimemagic.MagicParseException;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Calendar;
|
||||
@@ -11,6 +22,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public class Utils {
|
||||
private static final org.jboss.logging.Logger LOGGER = Logger.getLogger(Utils.class);
|
||||
|
||||
public static int getSaison() {
|
||||
return getSaison(new Date());
|
||||
@@ -30,7 +42,12 @@ public class Utils {
|
||||
public static Future<String> replacePhoto(long id, byte[] input, String media, String dir) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try (InputStream is = new BufferedInputStream(new ByteArrayInputStream(input))) {
|
||||
String mimeType = URLConnection.guessContentTypeFromStream(is);
|
||||
String mimeType;
|
||||
try {
|
||||
mimeType = Magic.getMagicMatch(input, false).getMimeType();
|
||||
} catch (MagicParseException | MagicMatchNotFoundException | MagicException e) {
|
||||
mimeType = URLConnection.guessContentTypeFromStream(is);
|
||||
}
|
||||
String[] detectedExtensions = MimeTypes.findExtensionsByMimeTypes(mimeType, false);
|
||||
if (detectedExtensions.length == 0)
|
||||
throw new IOException("Fail to detect file extension for MIME type " + mimeType);
|
||||
@@ -57,4 +74,39 @@ public class Utils {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static Uni<Response> getMediaFile(long id, String media, String dirname,
|
||||
Uni<?> uniBase) throws URISyntaxException {
|
||||
Future<Pair<File, byte[]>> future = CompletableFuture.supplyAsync(() -> {
|
||||
FilenameFilter filter = (directory, filename) -> filename.startsWith(String.valueOf(id));
|
||||
File[] files = new File(media, dirname).listFiles(filter);
|
||||
if (files != null && files.length > 0) {
|
||||
File file = files[0];
|
||||
try {
|
||||
byte[] data = Files.readAllBytes(file.toPath());
|
||||
return new Pair<>(file, data);
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
URI uri = new URI("https://mdbcdn.b-cdn.net/img/Photos/new-templates/bootstrap-chat/ava2.webp");
|
||||
|
||||
return uniBase.chain(__ -> Uni.createFrom().future(future)
|
||||
.map(filePair -> {
|
||||
if (filePair == null)
|
||||
return Response.temporaryRedirect(uri).build();
|
||||
|
||||
String mimeType = URLConnection.guessContentTypeFromName(filePair.getKey().getName());
|
||||
|
||||
Response.ResponseBuilder resp = Response.ok(filePair.getValue());
|
||||
resp.type(MediaType.APPLICATION_OCTET_STREAM);
|
||||
resp.header(HttpHeaders.CONTENT_LENGTH, filePair.getValue().length);
|
||||
resp.header(HttpHeaders.CONTENT_TYPE, mimeType);
|
||||
resp.header(HttpHeaders.CONTENT_DISPOSITION, "inline; ");
|
||||
|
||||
return resp.build();
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user