Fusion : séances accessibles et règles sous la main en séance
# Conflicts: # web/src/app/campaigns/campaign/campaign-detail/campaign-detail.component.ts # web/src/assets/i18n/en.json # web/src/assets/i18n/fr.json
This commit is contained in:
@@ -111,6 +111,11 @@ public class SessionService {
|
||||
return sessionRepository.findActive();
|
||||
}
|
||||
|
||||
/** Toutes les sessions en cours, la plus récente d'abord (raccourci « Séance en cours »). */
|
||||
public List<Session> getAllActive() {
|
||||
return sessionRepository.findAllActive();
|
||||
}
|
||||
|
||||
public Optional<Session> getActiveByPlaythrough(String playthroughId) {
|
||||
return sessionRepository.findActiveByPlaythroughId(playthroughId);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,9 @@ public interface SessionRepository {
|
||||
/** Retourne UNE session active dans l'app (sémantique « legacy » — multi-actives possibles). */
|
||||
Optional<Session> findActive();
|
||||
|
||||
/** Toutes les sessions en cours (toutes Parties confondues), la plus récente d'abord. */
|
||||
List<Session> findAllActive();
|
||||
|
||||
/** Retourne la session active du Playthrough donné, s'il y en a une. */
|
||||
Optional<Session> findActiveByPlaythroughId(String playthroughId);
|
||||
|
||||
|
||||
+2
@@ -17,5 +17,7 @@ public interface SessionJpaRepository extends JpaRepository<SessionJpaEntity, Lo
|
||||
|
||||
Optional<SessionJpaEntity> findFirstByEndedAtIsNull();
|
||||
|
||||
List<SessionJpaEntity> findByEndedAtIsNullOrderByStartedAtDesc();
|
||||
|
||||
Optional<SessionJpaEntity> findFirstByPlaythroughIdAndEndedAtIsNull(Long playthroughId);
|
||||
}
|
||||
|
||||
+7
@@ -52,6 +52,13 @@ public class PostgresSessionRepository implements SessionRepository {
|
||||
return jpaRepository.findFirstByEndedAtIsNull().map(this::toDomain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Session> findAllActive() {
|
||||
return jpaRepository.findByEndedAtIsNullOrderByStartedAtDesc().stream()
|
||||
.map(this::toDomain)
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Session> findActiveByPlaythroughId(String playthroughId) {
|
||||
return jpaRepository.findFirstByPlaythroughIdAndEndedAtIsNull(Long.parseLong(playthroughId))
|
||||
|
||||
+14
-2
@@ -13,15 +13,18 @@ import com.loremind.domain.campaigncontext.ports.NpcRepository;
|
||||
import com.loremind.domain.campaigncontext.ports.QuestRepository;
|
||||
import com.loremind.domain.campaigncontext.ports.RandomTableRepository;
|
||||
import com.loremind.domain.campaigncontext.ports.SceneRepository;
|
||||
import com.loremind.domain.playcontext.ports.PlaythroughRepository;
|
||||
import com.loremind.infrastructure.web.dto.campaigncontext.ArcDTO;
|
||||
import com.loremind.infrastructure.web.dto.campaigncontext.ChapterDTO;
|
||||
import com.loremind.infrastructure.web.dto.campaigncontext.NpcDTO;
|
||||
import com.loremind.infrastructure.web.dto.campaigncontext.QuestDTO;
|
||||
import com.loremind.infrastructure.web.dto.campaigncontext.RandomTableDTO;
|
||||
import com.loremind.infrastructure.web.dto.campaigncontext.SceneDTO;
|
||||
import com.loremind.infrastructure.web.dto.playcontext.PlaythroughDTO;
|
||||
import com.loremind.infrastructure.web.mapper.ArcMapper;
|
||||
import com.loremind.infrastructure.web.mapper.ChapterMapper;
|
||||
import com.loremind.infrastructure.web.mapper.NpcMapper;
|
||||
import com.loremind.infrastructure.web.mapper.PlaythroughMapper;
|
||||
import com.loremind.infrastructure.web.mapper.QuestMapper;
|
||||
import com.loremind.infrastructure.web.mapper.RandomTableMapper;
|
||||
import com.loremind.infrastructure.web.mapper.SceneMapper;
|
||||
@@ -37,7 +40,7 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* Endpoint AGRÉGÉ de l'arbre de campagne : tout ce dont la sidebar a besoin en UNE
|
||||
* requête HTTP — arcs → chapitres → scènes, PNJ, tables, ennemis, quêtes et readiness.
|
||||
* requête HTTP — arcs → chapitres → scènes, PNJ, tables, ennemis, quêtes, parties et readiness.
|
||||
*
|
||||
* <p>Remplace la rafale d'appels du front (~1 + N arcs + M chapitres + 5 listes ≈ 15-20
|
||||
* requêtes À CHAQUE navigation) : la latence HTTP par appel dominait le temps de rendu
|
||||
@@ -56,6 +59,7 @@ public class CampaignTreeController {
|
||||
private final RandomTableRepository randomTableRepository;
|
||||
private final EnemyRepository enemyRepository;
|
||||
private final QuestRepository questRepository;
|
||||
private final PlaythroughRepository playthroughRepository;
|
||||
private final CampaignReadinessService readinessService;
|
||||
private final ArcMapper arcMapper;
|
||||
private final ChapterMapper chapterMapper;
|
||||
@@ -63,6 +67,7 @@ public class CampaignTreeController {
|
||||
private final NpcMapper npcMapper;
|
||||
private final RandomTableMapper randomTableMapper;
|
||||
private final QuestMapper questMapper;
|
||||
private final PlaythroughMapper playthroughMapper;
|
||||
|
||||
// S107 (trop de paramètres) : constructeur d'INJECTION pur, sans logique — l'endpoint
|
||||
// est un agrégat volontaire (une requête pour toute la sidebar), il consomme donc
|
||||
@@ -77,13 +82,15 @@ public class CampaignTreeController {
|
||||
RandomTableRepository randomTableRepository,
|
||||
EnemyRepository enemyRepository,
|
||||
QuestRepository questRepository,
|
||||
PlaythroughRepository playthroughRepository,
|
||||
CampaignReadinessService readinessService,
|
||||
ArcMapper arcMapper,
|
||||
ChapterMapper chapterMapper,
|
||||
SceneMapper sceneMapper,
|
||||
NpcMapper npcMapper,
|
||||
RandomTableMapper randomTableMapper,
|
||||
QuestMapper questMapper) {
|
||||
QuestMapper questMapper,
|
||||
PlaythroughMapper playthroughMapper) {
|
||||
this.campaignRepository = campaignRepository;
|
||||
this.arcRepository = arcRepository;
|
||||
this.chapterRepository = chapterRepository;
|
||||
@@ -92,6 +99,7 @@ public class CampaignTreeController {
|
||||
this.randomTableRepository = randomTableRepository;
|
||||
this.enemyRepository = enemyRepository;
|
||||
this.questRepository = questRepository;
|
||||
this.playthroughRepository = playthroughRepository;
|
||||
this.readinessService = readinessService;
|
||||
this.arcMapper = arcMapper;
|
||||
this.chapterMapper = chapterMapper;
|
||||
@@ -99,6 +107,7 @@ public class CampaignTreeController {
|
||||
this.npcMapper = npcMapper;
|
||||
this.randomTableMapper = randomTableMapper;
|
||||
this.questMapper = questMapper;
|
||||
this.playthroughMapper = playthroughMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,6 +122,7 @@ public class CampaignTreeController {
|
||||
List<RandomTableDTO> randomTables,
|
||||
List<Enemy> enemies,
|
||||
List<QuestDTO> quests,
|
||||
List<PlaythroughDTO> playthroughs,
|
||||
CampaignReadinessAssessment readiness
|
||||
) {}
|
||||
|
||||
@@ -147,6 +157,8 @@ public class CampaignTreeController {
|
||||
enemyRepository.findByCampaignId(campaignId),
|
||||
questRepository.findByCampaignId(campaignId).stream()
|
||||
.map(questMapper::toDTO).toList(),
|
||||
playthroughRepository.findByCampaignId(campaignId).stream()
|
||||
.map(playthroughMapper::toDTO).toList(),
|
||||
readinessService.assess(campaignId)));
|
||||
}
|
||||
}
|
||||
|
||||
+16
-4
@@ -56,11 +56,23 @@ public class SessionController {
|
||||
.orElse(ResponseEntity.noContent().build());
|
||||
}
|
||||
|
||||
/**
|
||||
* Liste des sessions. {@code active=true} : uniquement celles en cours, toutes Parties
|
||||
* confondues, la plus récente d'abord (raccourci « Séance en cours » du menu, rafraîchi
|
||||
* à chaque navigation — évite de rapatrier tout l'historique).
|
||||
*/
|
||||
@GetMapping
|
||||
public ResponseEntity<List<SessionDTO>> getSessions(@RequestParam(value = "playthroughId", required = false) String playthroughId) {
|
||||
List<Session> sessions = (playthroughId == null || playthroughId.isBlank())
|
||||
? sessionService.getAll()
|
||||
: sessionService.getByPlaythroughId(playthroughId);
|
||||
public ResponseEntity<List<SessionDTO>> getSessions(
|
||||
@RequestParam(value = "playthroughId", required = false) String playthroughId,
|
||||
@RequestParam(value = "active", defaultValue = "false") boolean active) {
|
||||
List<Session> sessions;
|
||||
if (active) {
|
||||
sessions = sessionService.getAllActive();
|
||||
} else if (playthroughId == null || playthroughId.isBlank()) {
|
||||
sessions = sessionService.getAll();
|
||||
} else {
|
||||
sessions = sessionService.getByPlaythroughId(playthroughId);
|
||||
}
|
||||
List<SessionDTO> dtos = sessions.stream()
|
||||
.map(sessionMapper::toDTO)
|
||||
.toList();
|
||||
|
||||
+6
@@ -11,6 +11,8 @@ import com.loremind.domain.campaigncontext.ports.CampaignRepository;
|
||||
import com.loremind.domain.campaigncontext.ports.ChapterRepository;
|
||||
import com.loremind.domain.campaigncontext.ports.QuestRepository;
|
||||
import com.loremind.domain.campaigncontext.ports.SceneRepository;
|
||||
import com.loremind.domain.playcontext.Playthrough;
|
||||
import com.loremind.domain.playcontext.ports.PlaythroughRepository;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -39,6 +41,7 @@ class CampaignTreeControllerTest {
|
||||
@Autowired private ChapterRepository chapterRepository;
|
||||
@Autowired private SceneRepository sceneRepository;
|
||||
@Autowired private QuestRepository questRepository;
|
||||
@Autowired private PlaythroughRepository playthroughRepository;
|
||||
|
||||
private String campaignId;
|
||||
private String arcId;
|
||||
@@ -52,6 +55,7 @@ class CampaignTreeControllerTest {
|
||||
chapterId = chapterRepository.save(Chapter.builder().arcId(arcId).name("Chap").order(0).build()).getId();
|
||||
sceneRepository.save(Scene.builder().chapterId(chapterId).name("Scène").order(0).build());
|
||||
questRepository.save(Quest.builder().campaignId(campaignId).arcId(arcId).name("Quête").order(0).build());
|
||||
playthroughRepository.save(Playthrough.builder().campaignId(campaignId).name("Partie 1").build());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -65,6 +69,8 @@ class CampaignTreeControllerTest {
|
||||
.andExpect(jsonPath("$.scenesByChapter." + chapterId + "[0].name").value("Scène"))
|
||||
.andExpect(jsonPath("$.quests", hasSize(1)))
|
||||
.andExpect(jsonPath("$.quests[0].arcId").value(arcId))
|
||||
.andExpect(jsonPath("$.playthroughs", hasSize(1)))
|
||||
.andExpect(jsonPath("$.playthroughs[0].name").value("Partie 1"))
|
||||
.andExpect(jsonPath("$.readiness.campaignId").value(campaignId))
|
||||
.andExpect(jsonPath("$.readiness.gaps").isArray());
|
||||
}
|
||||
|
||||
+20
@@ -20,6 +20,11 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static org.hamcrest.Matchers.everyItem;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
|
||||
@@ -98,6 +103,21 @@ class SessionControllerTest {
|
||||
.andExpect(jsonPath("$").isArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getSessions_activeOnly_excludesEnded() throws Exception {
|
||||
Session running = saveSession();
|
||||
Session ended = sessionRepository.save(Session.builder()
|
||||
.name("ended").playthroughId(playthroughId)
|
||||
.startedAt(FIXED_TIME.minusHours(2))
|
||||
.endedAt(FIXED_TIME.minusHours(1))
|
||||
.build());
|
||||
mockMvc.perform(get("/api/sessions").param("active", "true"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$[*].active", everyItem(is(true))))
|
||||
.andExpect(jsonPath("$[*].id", hasItem(running.getId())))
|
||||
.andExpect(jsonPath("$[*].id", not(hasItem(ended.getId()))));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getActive_global_returnsActive() throws Exception {
|
||||
saveSession();
|
||||
|
||||
Reference in New Issue
Block a user