feat: club
This commit is contained in:
@@ -308,7 +308,13 @@ public class AffiliationService {
|
||||
}
|
||||
}))
|
||||
.chain(club ->
|
||||
Panache.withTransaction(() -> repository.persist(new AffiliationModel(null, club, saison))))
|
||||
Panache.withTransaction(() -> repository.persist(new AffiliationModel(null, club, saison))
|
||||
.chain(c -> (club.getNo_affiliation() != null) ? Uni.createFrom().item(c) :
|
||||
sequenceRepository.getNextValueInTransaction(SequenceType.Affiliation)
|
||||
.invoke(club::setNo_affiliation)
|
||||
.chain(() -> clubRepository.persist(club))
|
||||
.map(o -> c)
|
||||
)))
|
||||
.map(SimpleAffiliation::fromModel);
|
||||
}
|
||||
|
||||
|
||||
@@ -122,13 +122,15 @@ public class ClubService {
|
||||
|
||||
m.setName(input.getName());
|
||||
m.setCountry(input.getCountry());
|
||||
m.setInternational(input.isInternational());
|
||||
|
||||
if (!input.isInternational()) {
|
||||
m.setTraining_location(input.getTraining_location());
|
||||
m.setTraining_day_time(input.getTraining_day_time());
|
||||
m.setContact_intern(input.getContact_intern());
|
||||
m.setRNA(input.getRna());
|
||||
m.setSIRET(input.getSiret());
|
||||
if (input.getSiret() != null && !input.getSiret().isBlank())
|
||||
m.setSIRET(Long.parseLong(input.getSiret()));
|
||||
m.setAddress(input.getAddress());
|
||||
|
||||
try {
|
||||
@@ -145,7 +147,37 @@ public class ClubService {
|
||||
}
|
||||
|
||||
public Uni<Long> add(FullClubForm input) {
|
||||
return Uni.createFrom().nullItem();
|
||||
TypeReference<HashMap<Contact, String>> typeRef = new TypeReference<>() {
|
||||
};
|
||||
|
||||
return Uni.createFrom().nullItem()
|
||||
.chain(() -> {
|
||||
ClubModel clubModel = new ClubModel();
|
||||
|
||||
clubModel.setName(input.getName());
|
||||
clubModel.setCountry(input.getCountry());
|
||||
clubModel.setInternational(input.isInternational());
|
||||
clubModel.setNo_affiliation(null);
|
||||
if (!input.isInternational()) {
|
||||
clubModel.setTraining_location(input.getTraining_location());
|
||||
clubModel.setTraining_day_time(input.getTraining_day_time());
|
||||
clubModel.setContact_intern(input.getContact_intern());
|
||||
clubModel.setRNA(input.getRna());
|
||||
if (input.getSiret() != null && !input.getSiret().isBlank())
|
||||
clubModel.setSIRET(Long.parseLong(input.getSiret()));
|
||||
clubModel.setAddress(input.getAddress());
|
||||
|
||||
try {
|
||||
clubModel.setContact(MAPPER.readValue(input.getContact(), typeRef));
|
||||
} catch (JsonProcessingException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
return Panache.withTransaction(() -> repository.persist(clubModel));
|
||||
})
|
||||
.call(clubModel -> keycloakService.getGroupFromClub(clubModel)) // create group in keycloak
|
||||
.invoke(clubModel -> SReqClub.sendAddIfNeed(serverCustom.clients, SimpleClubModel.fromModel(clubModel)))
|
||||
.map(ClubModel::getId);
|
||||
}
|
||||
|
||||
public Uni<?> delete(long id) {
|
||||
@@ -155,8 +187,10 @@ public class ClubService {
|
||||
combModel.setClub(null);
|
||||
combModel.setRole(RoleAsso.MEMBRE);
|
||||
}).toList())
|
||||
.call(list -> Uni.join().all(list.stream().filter(m -> m.getUserId() != null)
|
||||
.map(m -> keycloakService.clearUser(m.getUserId())).toList()).andCollectFailures())
|
||||
.call(list -> (list.isEmpty()) ? Uni.createFrom().voidItem() :
|
||||
Uni.join().all(list.stream().filter(m -> m.getUserId() != null)
|
||||
.map(m -> keycloakService.clearUser(m.getUserId())).toList())
|
||||
.andCollectFailures())
|
||||
.chain(list -> Panache.withTransaction(() -> combRepository.persist(list)))
|
||||
.map(o -> club)
|
||||
)
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.eclipse.microprofile.config.inject.ConfigProperty;
|
||||
import org.eclipse.microprofile.jwt.JsonWebToken;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -57,6 +58,14 @@ public class ClubEndpoints {
|
||||
return clubService.getAll().map(clubModels -> clubModels.stream().map(SimpleClubModel::fromModel).toList());
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/contact_type")
|
||||
@Authenticated
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Uni<HashMap<String, String>> getConcatType() {
|
||||
return Uni.createFrom().item(Contact.toSite());
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/find")
|
||||
@RolesAllowed({"federation_admin"})
|
||||
@@ -111,11 +120,12 @@ public class ClubEndpoints {
|
||||
});
|
||||
}
|
||||
|
||||
@POST
|
||||
@PUT
|
||||
@RolesAllowed({"federation_admin"})
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
public Uni<Long> addAdminClub(FullClubForm input) {
|
||||
System.out.println(input);
|
||||
return clubService.add(input)
|
||||
.invoke(Unchecked.consumer(id -> {
|
||||
if (id == null) throw new InternalError("Fail to create club data");
|
||||
|
||||
@@ -37,7 +37,7 @@ public class FullClubForm {
|
||||
private String rna = null;
|
||||
|
||||
@FormParam("siret")
|
||||
private Long siret = null;
|
||||
private String siret = null;
|
||||
|
||||
@FormParam("international")
|
||||
private boolean international = false;
|
||||
|
||||
Reference in New Issue
Block a user