feat(insc): add safca connector
This commit is contained in:
parent
743a6911f5
commit
f3fe80fa46
@ -25,6 +25,7 @@ public class MembreModel {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Access(AccessType.PROPERTY)
|
||||
@Schema(description = "L'identifiant du membre.", example = "1")
|
||||
Long id;
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@ import fr.titionfire.ffsaf.data.repository.*;
|
||||
import fr.titionfire.ffsaf.net2.ServerCustom;
|
||||
import fr.titionfire.ffsaf.net2.data.SimpleCompet;
|
||||
import fr.titionfire.ffsaf.net2.request.SReqCompet;
|
||||
import fr.titionfire.ffsaf.net2.request.SReqRegister;
|
||||
import fr.titionfire.ffsaf.rest.data.CompetitionData;
|
||||
import fr.titionfire.ffsaf.rest.data.RegisterRequestData;
|
||||
import fr.titionfire.ffsaf.rest.data.SimpleCompetData;
|
||||
@ -71,10 +72,11 @@ public class CompetitionService {
|
||||
if (id == 0) {
|
||||
return Uni.createFrom()
|
||||
.item(new CompetitionData(null, "", "", new Date(), CompetitionSystem.SAFCA,
|
||||
null, "", ""));
|
||||
null, "", "", null));
|
||||
}
|
||||
return permService.hasViewPerm(securityCtx, id)
|
||||
.map(CompetitionData::fromModel)
|
||||
.chain(competitionModel -> Mutiny.fetch(competitionModel.getInsc())
|
||||
.map(insc -> CompetitionData.fromModel(competitionModel).addInsc(insc)))
|
||||
.chain(data ->
|
||||
vertx.getOrCreateContext().executeBlocking(() -> {
|
||||
keycloakService.getUser(UUID.fromString(data.getOwner()))
|
||||
@ -206,6 +208,12 @@ public class CompetitionService {
|
||||
r = new RegisterEmbeddable(combModel, data.getWeight(), data.getOverCategory());
|
||||
insc.add(r);
|
||||
}
|
||||
|
||||
if (c.getSystem() == CompetitionSystem.SAFCA) {
|
||||
SReqRegister.sendIfNeed(serverCustom.clients,
|
||||
new CompetitionData.SimpleRegister(r.getMembre().getId(),
|
||||
r.getOverCategory(), r.getWeight()), c.getId());
|
||||
}
|
||||
return Panache.withTransaction(() -> repository.persist(c)).map(__ -> r);
|
||||
}))))
|
||||
.chain(r -> Mutiny.fetch(r.getMembre().getLicences())
|
||||
@ -235,8 +243,13 @@ public class CompetitionService {
|
||||
return permService.hasEditPerm(securityCtx, id)
|
||||
.chain(c -> Mutiny.fetch(c.getInsc())
|
||||
.chain(Unchecked.function(insc -> {
|
||||
if (insc.removeIf(m -> m.getMembre().getId().equals(combId)))
|
||||
if (insc.removeIf(m -> m.getMembre().getId().equals(combId))) {
|
||||
if (c.getSystem() == CompetitionSystem.SAFCA) {
|
||||
SReqRegister.sendRmIfNeed(serverCustom.clients, combId, id);
|
||||
}
|
||||
|
||||
return Panache.withTransaction(() -> repository.persist(c)).map(__ -> null);
|
||||
}
|
||||
throw new DBadRequestException("Combattant non inscrit");
|
||||
})));
|
||||
}
|
||||
|
||||
@ -11,16 +11,6 @@ import java.util.HashMap;
|
||||
public class RComb {
|
||||
private static final Logger LOGGER = Logger.getLogger(RComb.class);
|
||||
|
||||
final IAction findComb = (client_Thread, message) -> {
|
||||
try {
|
||||
SimpleCombModel combModel = ServerCustom.getInstance().membreService.find(message.data().get("licence").asInt(), message.data().get("np").asText());
|
||||
client_Thread.sendRepTo(combModel, message);
|
||||
} catch (Throwable e) {
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
client_Thread.sendErrTo(e.getMessage(), message);
|
||||
}
|
||||
};
|
||||
|
||||
final CIA<Long> findByIdOptionalComb = new CIA<>(Long.class, (client_Thread, message) -> {
|
||||
try {
|
||||
SimpleCombModel combModel = ServerCustom.getInstance().membreService.findByIdOptionalComb(message.data());
|
||||
@ -34,7 +24,6 @@ public class RComb {
|
||||
public static void register(HashMap<String, IAction> iMap) {
|
||||
RComb rComb = new RComb();
|
||||
|
||||
iMap.put("findComb", rComb.findComb);
|
||||
iMap.put("findByIdOptionalComb", rComb.findByIdOptionalComb);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,29 @@
|
||||
package fr.titionfire.ffsaf.net2.request;
|
||||
|
||||
import fr.titionfire.ffsaf.net2.Client_Thread;
|
||||
import fr.titionfire.ffsaf.rest.data.CompetitionData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class SReqRegister {
|
||||
public static void sendIfNeed(ArrayList<Client_Thread> client_Thread, CompetitionData.SimpleRegister simpleRegister, Long competitionId) {
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("simpleRegister", simpleRegister);
|
||||
map.put("competitionId", competitionId);
|
||||
|
||||
for (Client_Thread client : client_Thread) {
|
||||
client.sendNotify(map, "sendRegister");
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendRmIfNeed(ArrayList<Client_Thread> clients, Long combId, Long id) {
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("combId", combId);
|
||||
map.put("competitionId", id);
|
||||
|
||||
for (Client_Thread client : clients) {
|
||||
client.sendNotify(map, "sendRmRegister");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2,11 +2,13 @@ package fr.titionfire.ffsaf.rest.data;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.CompetitionModel;
|
||||
import fr.titionfire.ffsaf.utils.CompetitionSystem;
|
||||
import fr.titionfire.ffsaf.utils.RegisterEmbeddable;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@ -20,12 +22,28 @@ public class CompetitionData {
|
||||
private Long club;
|
||||
private String clubName;
|
||||
private String owner;
|
||||
private List<SimpleRegister> registers;
|
||||
|
||||
public static CompetitionData fromModel(CompetitionModel model) {
|
||||
if (model == null)
|
||||
return null;
|
||||
|
||||
return new CompetitionData(model.getId(), model.getName(), model.getUuid(), model.getDate(), model.getSystem(),
|
||||
model.getClub().getId(), model.getClub().getName(), model.getOwner());
|
||||
model.getClub().getId(), model.getClub().getName(), model.getOwner(), null);
|
||||
}
|
||||
|
||||
public CompetitionData addInsc(List<RegisterEmbeddable> insc) {
|
||||
this.registers = insc.stream()
|
||||
.map(i -> new SimpleRegister(i.getMembre().getId(), i.getOverCategory(), i.getWeight())).toList();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@RegisterForReflection
|
||||
public static class SimpleRegister {
|
||||
long id;
|
||||
int overCategory;
|
||||
Integer weight;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user