feat: add membre
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package fr.titionfire.ffsaf.domain.service;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.ClubModel;
|
||||
import fr.titionfire.ffsaf.data.model.MembreModel;
|
||||
import fr.titionfire.ffsaf.data.repository.ClubRepository;
|
||||
import fr.titionfire.ffsaf.data.repository.CombRepository;
|
||||
@@ -9,10 +10,7 @@ import fr.titionfire.ffsaf.net2.request.SReqComb;
|
||||
import fr.titionfire.ffsaf.rest.data.SimpleMembre;
|
||||
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.RoleAsso;
|
||||
import fr.titionfire.ffsaf.utils.*;
|
||||
import io.quarkus.hibernate.reactive.panache.Panache;
|
||||
import io.quarkus.hibernate.reactive.panache.PanacheQuery;
|
||||
import io.quarkus.hibernate.reactive.panache.common.WithSession;
|
||||
@@ -163,10 +161,47 @@ public class MembreService {
|
||||
.map(__ -> "OK");
|
||||
}
|
||||
|
||||
public Uni<Long> add(FullMemberForm input) {
|
||||
return clubRepository.findById(input.getClub())
|
||||
.chain(clubModel -> {
|
||||
MembreModel model = getMembreModel(input, clubModel);
|
||||
return Panache.withTransaction(() -> repository.persist(model));
|
||||
})
|
||||
.invoke(membreModel -> SReqComb.sendIfNeedAdd(serverCustom.clients, SimpleCombModel.fromModel(membreModel)))
|
||||
.map(MembreModel::getId);
|
||||
}
|
||||
|
||||
public Uni<Long> add(FullMemberForm input, String subject) {
|
||||
return repository.find("userId = ?1", subject).firstResult()
|
||||
.chain(membreModel -> {
|
||||
MembreModel model = getMembreModel(input, membreModel.getClub());
|
||||
model.setRole(RoleAsso.MEMBRE);
|
||||
model.setGrade_arbitrage(GradeArbitrage.NA);
|
||||
return Panache.withTransaction(() -> repository.persist(model));
|
||||
})
|
||||
.invoke(membreModel -> SReqComb.sendIfNeedAdd(serverCustom.clients, SimpleCombModel.fromModel(membreModel)))
|
||||
.map(MembreModel::getId);
|
||||
}
|
||||
|
||||
public Uni<?> setUserId(Long id, String id1) {
|
||||
return repository.findById(id).chain(membreModel -> {
|
||||
membreModel.setUserId(id1);
|
||||
return Panache.withTransaction(() -> repository.persist(membreModel));
|
||||
});
|
||||
}
|
||||
|
||||
private static MembreModel getMembreModel(FullMemberForm input, ClubModel clubModel) {
|
||||
MembreModel model = new MembreModel();
|
||||
model.setFname(input.getFname());
|
||||
model.setLname(input.getLname());
|
||||
model.setEmail(input.getEmail());
|
||||
model.setGenre(input.getGenre());
|
||||
model.setCountry(input.getCountry());
|
||||
model.setBirth_date(input.getBirth_date());
|
||||
model.setCategorie(input.getCategorie());
|
||||
model.setClub(clubModel);
|
||||
model.setRole(input.getRole());
|
||||
model.setGrade_arbitrage(input.getGrade_arbitrage());
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ public class CombEndpoints {
|
||||
return membreService.getById(id).onItem().invoke(checkPerm).map(SimpleMembre::fromModel);
|
||||
}
|
||||
|
||||
@POST
|
||||
@PUT
|
||||
@Path("{id}")
|
||||
@RolesAllowed({"federation_admin"})
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
@@ -108,6 +108,22 @@ public class CombEndpoints {
|
||||
}
|
||||
|
||||
@POST
|
||||
@RolesAllowed({"federation_admin"})
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
public Uni<Long> addAdminMembre(FullMemberForm input) {
|
||||
return membreService.add(input)
|
||||
.invoke(Unchecked.consumer(id -> {
|
||||
if (id == null) throw new InternalError("Fail to creat member data");
|
||||
})).call(id -> {
|
||||
if (input.getPhoto_data().length > 0)
|
||||
return Uni.createFrom().future(replacePhoto(id, input.getPhoto_data()));
|
||||
else
|
||||
return Uni.createFrom().nullItem();
|
||||
});
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("club/{id}")
|
||||
@RolesAllowed({"club_president", "club_secretaire", "club_respo_intra"})
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
@@ -126,6 +142,23 @@ public class CombEndpoints {
|
||||
});
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("club")
|
||||
@RolesAllowed({"club_president", "club_secretaire", "club_respo_intra"})
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
public Uni<Long> addMembre(FullMemberForm input) {
|
||||
return membreService.add(input, idToken.getSubject())
|
||||
.invoke(Unchecked.consumer(id -> {
|
||||
if (id == null) throw new InternalError("Fail to creat member data");
|
||||
})).call(id -> {
|
||||
if (input.getPhoto_data().length > 0)
|
||||
return Uni.createFrom().future(replacePhoto(id, input.getPhoto_data()));
|
||||
else
|
||||
return Uni.createFrom().nullItem();
|
||||
});
|
||||
}
|
||||
|
||||
private Future<String> replacePhoto(long id, byte[] input) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try (InputStream is = new BufferedInputStream(new ByteArrayInputStream(input))) {
|
||||
|
||||
Reference in New Issue
Block a user