diff --git a/backend/src/main/java/ropold/backend/controller/MemoryController.java b/backend/src/main/java/ropold/backend/controller/MemoryController.java index 184cb47..d66686c 100644 --- a/backend/src/main/java/ropold/backend/controller/MemoryController.java +++ b/backend/src/main/java/ropold/backend/controller/MemoryController.java @@ -27,11 +27,17 @@ public class MemoryController { private final CloudinaryService cloudinaryService; private final AppUserService appUserService; - @GetMapping("active/match-id/{numberOfMatchId}") + @GetMapping("/active/match-id/{numberOfMatchId}") public List getActiveMemoriesFilterByMatchId(@PathVariable int numberOfMatchId) { return memoryService.getActiveMemoriesFilterByMatchId(numberOfMatchId); } + @GetMapping("/active/match-ids") + public List getActiveMemoriesMatchIds() { + return memoryService.getActiveMemoriesMatchIds(); + } + + @GetMapping("/favorites") public List getUserFavorites(@AuthenticationPrincipal OAuth2User authentication) { List favoriteMemoryIds = appUserService.getUserFavorites(authentication.getName()); diff --git a/backend/src/main/java/ropold/backend/service/MemoryService.java b/backend/src/main/java/ropold/backend/service/MemoryService.java index 86b668d..866ebde 100644 --- a/backend/src/main/java/ropold/backend/service/MemoryService.java +++ b/backend/src/main/java/ropold/backend/service/MemoryService.java @@ -162,4 +162,13 @@ public List getMemoriesForGithubUser(String githubId) { .toList(); } + public List getActiveMemoriesMatchIds() { + return memoryRepository.findAll().stream() // Alle MemoryModel-Objekte laden + .filter(MemoryModel::isActive) // Nur aktive Einträge filtern + .map(MemoryModel::matchId) // matchId extrahieren + .distinct() // Duplikate entfernen + .sorted() // Sortieren + .toList(); // Mit Stream.toList() die Liste zurückgeben + } + } diff --git a/backend/src/test/java/ropold/backend/controller/MemoryControllerIntegrationTest.java b/backend/src/test/java/ropold/backend/controller/MemoryControllerIntegrationTest.java index b592c7f..6562c95 100644 --- a/backend/src/test/java/ropold/backend/controller/MemoryControllerIntegrationTest.java +++ b/backend/src/test/java/ropold/backend/controller/MemoryControllerIntegrationTest.java @@ -203,6 +203,15 @@ void getAllMemories_shouldReturnAllMemories() throws Exception { """)); } + @Test + void getActiveMatchIds_shouldReturnListOfIntWithMatchIds() throws Exception { + mockMvc.perform(MockMvcRequestBuilders.get("/api/memory-hub/active/match-ids") + .with(oidcLogin().idToken(i -> i.claim("sub", "user"))) + ) + .andExpect(status().isOk()) + .andExpect(content().json("[101]")); + } + @Test void getActiveMemoriesFilterByMatchId_shouldReturnFilteredMemories() throws Exception { // Beispiel für eine 'matchId' (z.B. 101) diff --git a/backend/src/test/java/ropold/backend/service/MemoryServiceTest.java b/backend/src/test/java/ropold/backend/service/MemoryServiceTest.java index 11c8029..d4d3d29 100644 --- a/backend/src/test/java/ropold/backend/service/MemoryServiceTest.java +++ b/backend/src/test/java/ropold/backend/service/MemoryServiceTest.java @@ -579,7 +579,74 @@ void getMemoriesForGithubUser_NoMemoriesForGithubId() { verify(memoryRepository, times(1)).findAll(); // Verify all memories were fetched } + @Test + void getActiveMemoriesMatchIds_Success() { + // Given + List expectedMatchIds = List.of(101); // Erwartete sortierte matchId-Liste + when(memoryRepository.findAll()).thenReturn(memories); + + // When + List actualMatchIds = memoryService.getActiveMemoriesMatchIds(); + + // Then + assertEquals(expectedMatchIds, actualMatchIds); // Verifizieren, dass die zurückgegebene Liste korrekt ist + } + + @Test + void getActiveMemoriesMatchIds_MultipleMatches() { + // Given + MemoryModel avatarMemory = new MemoryModel( + "1", + "Avatar Erinnerung", + 101, + Category.GITHUB_AVATAR, + "Eine Erinnerung, die mit einem GitHub-Avatar verknüpft ist", + true, + "github123", + "user1", + "https://avatars.example.com/user1.png", + "https://github.com/user1", + "https://example.com/image1.jpg" + ); + + MemoryModel cloudinaryMemory = new MemoryModel( + "2", + "Cloudinary Erinnerung", + 102, + Category.CLOUDINARY_IMAGE, + "Eine Erinnerung, die mit einem Cloudinary-Bild gespeichert ist", + false, + "github456", + "user2", + "https://avatars.example.com/user2.png", + "https://github.com/user2", + "https://example.com/image2.jpg" + ); + + MemoryModel additionalMemory = new MemoryModel( + "3", + "Neue Erinnerung", + 103, + Category.GITHUB_AVATAR, + "Eine weitere Erinnerung", + true, + "github789", + "user3", + "https://avatars.example.com/user3.png", + "https://github.com/user3", + "https://example.com/image3.jpg" + ); + + // Speichern der Erinnerungen + when(memoryRepository.findAll()).thenReturn(List.of(avatarMemory, cloudinaryMemory, additionalMemory)); + + // When + List actualMatchIds = memoryService.getActiveMemoriesMatchIds(); + // Then + List expectedMatchIds = List.of(101, 103); // Erwartete Liste mit matchIds der aktiven Erinnerungen + assertEquals(expectedMatchIds, actualMatchIds); // Verifizieren, dass die Liste korrekt ist + } } diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 433659a..20cb728 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -161,11 +161,6 @@ export default function App() { useEffect(() => { getUser(); - getActiveMemories(); - getAllMemories(); - getHighScoresFor10Cards(); - getHighScoresFor20Cards(); - getHighScoresFor32Cards(); }, []); useEffect(() => { @@ -181,20 +176,20 @@ export default function App() { return ( <> - + } /> - } /> + } /> } /> - } /> + } /> } /> - } /> + } /> }> } /> - } /> + } /> } /> - } /> + } />