feat: card for team
This commit is contained in:
@@ -3,8 +3,8 @@ package fr.titionfire.ffsaf.ws.recv;
|
||||
import fr.titionfire.ffsaf.data.model.CardModel;
|
||||
import fr.titionfire.ffsaf.data.model.MatchModel;
|
||||
import fr.titionfire.ffsaf.data.repository.CardRepository;
|
||||
import fr.titionfire.ffsaf.data.repository.CombRepository;
|
||||
import fr.titionfire.ffsaf.data.repository.CompetitionGuestRepository;
|
||||
import fr.titionfire.ffsaf.data.repository.ClubCardRepository;
|
||||
import fr.titionfire.ffsaf.data.repository.CompetitionRepository;
|
||||
import fr.titionfire.ffsaf.data.repository.MatchRepository;
|
||||
import fr.titionfire.ffsaf.domain.service.CardService;
|
||||
import fr.titionfire.ffsaf.domain.service.TradService;
|
||||
@@ -21,6 +21,7 @@ import io.smallrye.mutiny.unchecked.Unchecked;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@WithSession
|
||||
@@ -31,6 +32,9 @@ public class RCard {
|
||||
@Inject
|
||||
MatchRepository matchRepository;
|
||||
|
||||
@Inject
|
||||
ClubCardRepository clubCardRepository;
|
||||
|
||||
@Inject
|
||||
CardRepository cardRepository;
|
||||
|
||||
@@ -38,10 +42,7 @@ public class RCard {
|
||||
CardService cardService;
|
||||
|
||||
@Inject
|
||||
CombRepository combRepository;
|
||||
|
||||
@Inject
|
||||
CompetitionGuestRepository competitionGuestRepository;
|
||||
CompetitionRepository competitionRepository;
|
||||
|
||||
@Inject
|
||||
TradService trad;
|
||||
@@ -63,6 +64,16 @@ public class RCard {
|
||||
return getById(matchId, connection).chain(matchModel -> cardService.getForMatch(matchModel));
|
||||
}
|
||||
|
||||
@WSReceiver(code = "getAllForTeamNoDetail", permission = PermLevel.VIEW)
|
||||
public Uni<List<SendTeamCards>> getAllForTeamNoDetail(WebSocketConnection connection, Object o) {
|
||||
return competitionRepository.find("uuid", connection.pathParam("uuid")).firstResult()
|
||||
.chain(c -> clubCardRepository.list("competition = ?1", c.getId()))
|
||||
.map(cards -> cards.stream()
|
||||
.map(card -> new SendTeamCards(card.getTeamUuid(), card.getTeamName(), List.of(),
|
||||
card.getType(), card.getReason(), card.getDate()))
|
||||
.toList());
|
||||
}
|
||||
|
||||
@WSReceiver(code = "sendCardAdd", permission = PermLevel.TABLE)
|
||||
public Uni<Void> sendCardAdd(WebSocketConnection connection, SendCardAdd card) {
|
||||
return getById(card.matchId(), connection)
|
||||
@@ -74,11 +85,12 @@ public class RCard {
|
||||
model.setCategory(matchModel.getCategory().getId());
|
||||
model.setCompetition(matchModel.getCategory().getCompet().getId());
|
||||
model.setType(card.type());
|
||||
model.setReason(card.reason());
|
||||
|
||||
return Panache.withTransaction(() -> cardRepository.persist(model));
|
||||
})
|
||||
)
|
||||
.invoke(cardModel -> SSCard.sendCard(connection, cardModel))
|
||||
.invoke(cardModel -> SSCard.sendCards(connection, List.of(cardModel)))
|
||||
.replaceWithVoid();
|
||||
}
|
||||
|
||||
@@ -91,14 +103,55 @@ public class RCard {
|
||||
.invoke(Unchecked.consumer(o -> {
|
||||
if (o == null)
|
||||
throw new DNotFoundException(trad.t("carton.non.trouver"));
|
||||
SSCard.sendRmCard(connection, o.getId());
|
||||
SSCard.sendRmCards(connection, List.of(o.getId()));
|
||||
}))
|
||||
.chain(cardModel -> Panache.withTransaction(() -> cardRepository.delete(cardModel)))
|
||||
)
|
||||
.replaceWithVoid();
|
||||
}
|
||||
|
||||
@WSReceiver(code = "applyTeamCards", permission = PermLevel.TABLE)
|
||||
public Uni<Void> applyTeamCards(WebSocketConnection connection, SendTeamCards teamCards) {
|
||||
return competitionRepository.find("uuid", connection.pathParam("uuid")).firstResult()
|
||||
.chain(c -> cardService.addTeamCard(c, teamCards.teamUuid(), teamCards.teamName(), teamCards.type,
|
||||
teamCards.reason()))
|
||||
.invoke(cards -> SSCard.sendTeamCard(connection,
|
||||
new SendTeamCards(teamCards.teamUuid(), teamCards.teamName(), cards, teamCards.type(),
|
||||
teamCards.reason(), new Date())))
|
||||
.replaceWithVoid();
|
||||
}
|
||||
|
||||
@WSReceiver(code = "sendTeamCardReturnState", permission = PermLevel.TABLE)
|
||||
public Uni<Void> sendTeamCardReturnState(WebSocketConnection connection, SendTeamCardReturnState state) {
|
||||
if (state.state <= 0 || state.state > 2)
|
||||
return Uni.createFrom().voidItem();
|
||||
|
||||
return competitionRepository.find("uuid", connection.pathParam("uuid")).firstResult()
|
||||
.chain(c -> cardService.recvReturnState(c, state))
|
||||
.invoke(cards -> SSCard.sendCards(connection, cards))
|
||||
.replaceWithVoid();
|
||||
}
|
||||
|
||||
@WSReceiver(code = "removeTeamCards", permission = PermLevel.TABLE)
|
||||
public Uni<Void> removeTeamCards(WebSocketConnection connection, SendTeamCards teamCards) {
|
||||
return competitionRepository.find("uuid", connection.pathParam("uuid")).firstResult()
|
||||
.chain(c -> cardService.rmTeamCard(c, teamCards.teamUuid(), teamCards.teamName(), teamCards.type))
|
||||
.invoke(cards -> SSCard.sendRmCards(connection, cards))
|
||||
.invoke(__ -> SSCard.rmTeamCard(connection, teamCards))
|
||||
.replaceWithVoid();
|
||||
}
|
||||
|
||||
@RegisterForReflection
|
||||
public record SendCardAdd(long matchId, long combId, CardModel.CardType type) {
|
||||
public record SendCardAdd(long matchId, long combId, CardModel.CardType type, String reason) {
|
||||
}
|
||||
|
||||
@RegisterForReflection
|
||||
public record SendTeamCards(String teamUuid, String teamName, List<CardModel> cards, CardModel.CardType type,
|
||||
String reason, Date date) {
|
||||
}
|
||||
|
||||
@RegisterForReflection
|
||||
public record SendTeamCardReturnState(String teamUuid, String teamName, CardModel.CardType type,
|
||||
int state, Long selectedCategory, Long selectedMatch) {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user