dev #107
@ -94,6 +94,38 @@ public class CardService {
|
||||
});
|
||||
}
|
||||
|
||||
public Uni<List<CardModel>> addTeamCartToNewComb(Long combId, String teamUuid, String teamName,
|
||||
CompetitionModel competition) {
|
||||
return clubCardRepository.list("competition = ?1 AND (teamUuid = ?2 OR teamName = ?3)",
|
||||
Sort.ascending("type"), competition.getId(), teamUuid, teamName)
|
||||
.chain(clubCards -> {
|
||||
Uni<?> queue = Uni.createFrom().voidItem();
|
||||
List<CardModel> addCards = new ArrayList<>();
|
||||
for (ClubCardModel clubCard : clubCards) {
|
||||
CardModel model = new CardModel();
|
||||
model.setCompetition(competition);
|
||||
model.setCompetitionId(competition.getId());
|
||||
model.setComb(combId);
|
||||
model.setTeamCard(true);
|
||||
model.setType(clubCard.getType());
|
||||
model.setDate(clubCard.getDate());
|
||||
|
||||
queue = queue.call(__ -> Panache.withTransaction(() -> cardRepository.persist(model))
|
||||
.invoke(addCards::add)
|
||||
.call(() -> {
|
||||
clubCard.getCardIds().add(model.getId());
|
||||
return Panache.withTransaction(() -> clubCardRepository.persist(clubCard));
|
||||
}));
|
||||
}
|
||||
return queue.replaceWith(addCards);
|
||||
});
|
||||
}
|
||||
|
||||
public Uni<Void> rmTeamCardFromComb(Long combId, String uuid) {
|
||||
return cardRepository.delete("comb = ?1 AND competition.uuid = ?2 AND teamCard = True", combId, uuid)
|
||||
.replaceWithVoid();
|
||||
}
|
||||
|
||||
public Uni<List<CardModel>> addTeamCard(CompetitionModel competition, String teamUuid, String teamName,
|
||||
CardModel.CardType type, String reason) {
|
||||
return clubCardRepository.find("competition = ?1 AND (teamUuid = ?2 OR teamName = ?3)",
|
||||
|
||||
@ -97,9 +97,10 @@ public class RCard {
|
||||
|
||||
@WSReceiver(code = "sendCardRm", permission = PermLevel.ADMIN)
|
||||
public Uni<Void> sendCardRm(WebSocketConnection connection, SendCardAdd card) {
|
||||
return getById(card.matchId(), connection)
|
||||
.chain(matchModel -> cardRepository.find("match = ?1 AND comb = ?2 AND type = ?3",
|
||||
matchModel.getId(), card.combId(), card.type())
|
||||
return competitionRepository.find("uuid", connection.pathParam("uuid")).firstResult()
|
||||
.chain(competition -> cardRepository.find(
|
||||
"match IS NULL AND comb = ?1 AND type = ?2 AND competition = ?3 AND match " + (card.matchId() == null ? "IS NULL" : "= " + card.matchId()),
|
||||
card.combId(), card.type(), competition)
|
||||
.firstResult()
|
||||
.invoke(Unchecked.consumer(o -> {
|
||||
if (o == null)
|
||||
@ -143,7 +144,7 @@ public class RCard {
|
||||
}
|
||||
|
||||
@RegisterForReflection
|
||||
public record SendCardAdd(long matchId, long combId, CardModel.CardType type, String reason) {
|
||||
public record SendCardAdd(Long matchId, long combId, CardModel.CardType type, String reason) {
|
||||
}
|
||||
|
||||
@RegisterForReflection
|
||||
|
||||
@ -3,6 +3,7 @@ package fr.titionfire.ffsaf.ws.send;
|
||||
import fr.titionfire.ffsaf.data.model.CompetitionGuestModel;
|
||||
import fr.titionfire.ffsaf.data.model.RegisterModel;
|
||||
import fr.titionfire.ffsaf.domain.entity.CombEntity;
|
||||
import fr.titionfire.ffsaf.domain.service.CardService;
|
||||
import fr.titionfire.ffsaf.net2.MessageType;
|
||||
import fr.titionfire.ffsaf.ws.CompetitionWS;
|
||||
import fr.titionfire.ffsaf.ws.MessageOut;
|
||||
@ -25,16 +26,27 @@ public class SRegister {
|
||||
@Inject
|
||||
OpenConnections connections;
|
||||
|
||||
@Inject
|
||||
CardService cardService;
|
||||
|
||||
public Uni<Void> sendRegister(String uuid, RegisterModel registerModel) {
|
||||
return send(uuid, "sendRegister", CombEntity.fromModel(registerModel));
|
||||
return send(uuid, "sendRegister", CombEntity.fromModel(registerModel))
|
||||
.call(__ -> cardService.addTeamCartToNewComb(registerModel.getMembre().getId(),
|
||||
registerModel.getClub2().getClubId(), registerModel.getClub2().getName(),
|
||||
registerModel.getCompetition())
|
||||
.chain(cardModels -> send(uuid, "sendCards", cardModels)));
|
||||
}
|
||||
|
||||
public Uni<Void> sendRegister(String uuid, CompetitionGuestModel model) {
|
||||
return send(uuid, "sendRegister", CombEntity.fromModel(model));
|
||||
return send(uuid, "sendRegister", CombEntity.fromModel(model))
|
||||
.call(__ -> cardService.addTeamCartToNewComb(model.getId() * -1,
|
||||
null, model.getClub(), model.getCompetition())
|
||||
.chain(cardModels -> send(uuid, "sendCards", cardModels)));
|
||||
}
|
||||
|
||||
public Uni<Void> sendRegisterRemove(String uuid, Long combId) {
|
||||
return send(uuid, "sendRegisterRemove", combId);
|
||||
return send(uuid, "sendRegisterRemove", combId)
|
||||
.call(__ -> cardService.rmTeamCardFromComb(combId, uuid));
|
||||
}
|
||||
|
||||
public Uni<Void> send(String uuid, String code, Object data) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user