feat: rework competition perm, naming, competition data
All checks were successful
Deploy Production Server / if_merged (pull_request) Successful in 10m6s
All checks were successful
Deploy Production Server / if_merged (pull_request) Successful in 10m6s
This commit is contained in:
@@ -3,7 +3,7 @@ package fr.titionfire.ffsaf.domain.service;
|
||||
import fr.titionfire.ffsaf.data.model.MatchModel;
|
||||
import fr.titionfire.ffsaf.data.repository.CombRepository;
|
||||
import fr.titionfire.ffsaf.data.repository.MatchRepository;
|
||||
import fr.titionfire.ffsaf.data.repository.PouleRepository;
|
||||
import fr.titionfire.ffsaf.data.repository.CategoryRepository;
|
||||
import fr.titionfire.ffsaf.rest.data.MatchData;
|
||||
import fr.titionfire.ffsaf.rest.exception.DNotFoundException;
|
||||
import fr.titionfire.ffsaf.utils.CompetitionSystem;
|
||||
@@ -25,7 +25,7 @@ public class MatchService {
|
||||
MatchRepository repository;
|
||||
|
||||
@Inject
|
||||
PouleRepository pouleRepository;
|
||||
CategoryRepository categoryRepository;
|
||||
|
||||
@Inject
|
||||
CombRepository combRepository;
|
||||
@@ -33,17 +33,17 @@ public class MatchService {
|
||||
@Inject
|
||||
CompetPermService permService;
|
||||
|
||||
public Uni<MatchData> getById(SecurityCtx securityCtx, CompetitionSystem system, Long id) {
|
||||
public Uni<MatchData> getByIdAdmin(SecurityCtx securityCtx, CompetitionSystem system, Long id) {
|
||||
return repository.find("systemId = ?1 AND system = ?2", id, system).firstResult()
|
||||
.onItem().ifNull().failWith(() -> new DNotFoundException("Match not found"))
|
||||
.call(data -> permService.hasViewPerm(securityCtx, data.getPoule().getCompet()))
|
||||
.call(data -> permService.hasAdminViewPerm(securityCtx, data.getCategory().getCompet()))
|
||||
.map(MatchData::fromModel);
|
||||
}
|
||||
|
||||
public Uni<List<MatchData>> getAllByPoule(SecurityCtx securityCtx, CompetitionSystem system, Long id) {
|
||||
return pouleRepository.find("systemId = ?1 AND system = ?2", id, system).firstResult()
|
||||
public Uni<List<MatchData>> getAllByPouleAdmin(SecurityCtx securityCtx, CompetitionSystem system, Long id) {
|
||||
return categoryRepository.find("systemId = ?1 AND system = ?2", id, system).firstResult()
|
||||
.onItem().ifNull().failWith(() -> new DNotFoundException("Poule not found"))
|
||||
.call(data -> permService.hasViewPerm(securityCtx, data.getCompet()))
|
||||
.call(data -> permService.hasAdminViewPerm(securityCtx, data.getCompet()))
|
||||
.chain(data -> repository.list("poule = ?1", data.getId())
|
||||
.map(o -> o.stream().map(MatchData::fromModel).toList()));
|
||||
}
|
||||
@@ -52,21 +52,21 @@ public class MatchService {
|
||||
return repository.find("systemId = ?1 AND system = ?2", data.getId(), system).firstResult()
|
||||
.chain(o -> {
|
||||
if (o == null) {
|
||||
return pouleRepository.find("systemId = ?1 AND system = ?2", data.getPoule(), system)
|
||||
return categoryRepository.find("systemId = ?1 AND system = ?2", data.getCategory(), system)
|
||||
.firstResult()
|
||||
.onItem().ifNull().failWith(() -> new DNotFoundException("Poule not found"))
|
||||
.call(o2 -> permService.hasEditPerm(securityCtx, o2.getCompet()))
|
||||
.map(pouleModel -> {
|
||||
.map(categoryModel -> {
|
||||
MatchModel model = new MatchModel();
|
||||
|
||||
model.setId(null);
|
||||
model.setSystem(system);
|
||||
model.setSystemId(data.getId());
|
||||
model.setPoule(pouleModel);
|
||||
model.setCategory(categoryModel);
|
||||
return model;
|
||||
});
|
||||
} else {
|
||||
return pouleRepository.find("systemId = ?1 AND system = ?2", data.getPoule(), system)
|
||||
return categoryRepository.find("systemId = ?1 AND system = ?2", data.getCategory(), system)
|
||||
.firstResult()
|
||||
.onItem().ifNull().failWith(() -> new DNotFoundException("Poule not found"))
|
||||
.call(o2 -> permService.hasEditPerm(securityCtx, o2.getCompet()))
|
||||
@@ -77,7 +77,7 @@ public class MatchService {
|
||||
.chain(o -> {
|
||||
o.setC1_str(data.getC1_str());
|
||||
o.setC2_str(data.getC2_str());
|
||||
o.setPoule_ord(data.getPoule_ord());
|
||||
o.setCategory_ord(data.getCategory_ord());
|
||||
o.getScores().clear();
|
||||
o.getScores().addAll(data.getScores());
|
||||
|
||||
@@ -97,7 +97,7 @@ public class MatchService {
|
||||
List<ScoreEmbeddable> scores) {
|
||||
return repository.find("systemId = ?1 AND system = ?2", id, system).firstResult()
|
||||
.onItem().ifNull().failWith(() -> new DNotFoundException("Match not found"))
|
||||
.call(o2 -> permService.hasEditPerm(securityCtx, o2.getPoule().getCompet()))
|
||||
.call(o2 -> permService.hasEditPerm(securityCtx, o2.getCategory().getCompet()))
|
||||
.invoke(data -> {
|
||||
data.getScores().clear();
|
||||
data.getScores().addAll(scores);
|
||||
@@ -109,7 +109,7 @@ public class MatchService {
|
||||
public Uni<?> delete(SecurityCtx securityCtx, CompetitionSystem system, Long id) {
|
||||
return repository.find("systemId = ?1 AND system = ?2", id, system).firstResult()
|
||||
.onItem().ifNull().failWith(() -> new DNotFoundException("Match not found"))
|
||||
.call(o2 -> permService.hasEditPerm(securityCtx, o2.getPoule().getCompet()))
|
||||
.call(o2 -> permService.hasEditPerm(securityCtx, o2.getCategory().getCompet()))
|
||||
.chain(data -> Panache.withTransaction(() -> repository.delete(data)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user