Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<MemoryModel> getActiveMemoriesFilterByMatchId(@PathVariable int numberOfMatchId) {
return memoryService.getActiveMemoriesFilterByMatchId(numberOfMatchId);
}

@GetMapping("/active/match-ids")
public List<Integer> getActiveMemoriesMatchIds() {
return memoryService.getActiveMemoriesMatchIds();
}


@GetMapping("/favorites")
public List<MemoryModel> getUserFavorites(@AuthenticationPrincipal OAuth2User authentication) {
List<String> favoriteMemoryIds = appUserService.getUserFavorites(authentication.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,13 @@ public List<MemoryModel> getMemoriesForGithubUser(String githubId) {
.toList();
}

public List<Integer> 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
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,74 @@ void getMemoriesForGithubUser_NoMemoriesForGithubId() {
verify(memoryRepository, times(1)).findAll(); // Verify all memories were fetched
}

@Test
void getActiveMemoriesMatchIds_Success() {
// Given
List<Integer> expectedMatchIds = List.of(101); // Erwartete sortierte matchId-Liste
when(memoryRepository.findAll()).thenReturn(memories);

// When
List<Integer> 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<Integer> actualMatchIds = memoryService.getActiveMemoriesMatchIds();

// Then
List<Integer> expectedMatchIds = List.of(101, 103); // Erwartete Liste mit matchIds der aktiven Erinnerungen
assertEquals(expectedMatchIds, actualMatchIds); // Verifizieren, dass die Liste korrekt ist
}

}

17 changes: 6 additions & 11 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,6 @@ export default function App() {

useEffect(() => {
getUser();
getActiveMemories();
getAllMemories();
getHighScoresFor10Cards();
getHighScoresFor20Cards();
getHighScoresFor32Cards();
}, []);

useEffect(() => {
Expand All @@ -181,20 +176,20 @@ export default function App() {

return (
<>
<Navbar user={user} getUser={getUser} getActiveMemories={getActiveMemories} getAllMemories={getAllMemories} toggleSearchBar={toggleSearchBar} showSearch={showSearch} resetCurrentPage={resetCurrentPage} resetEditingState={resetEditingState} getHighScoresFor10Cards={getHighScoresFor10Cards} getHighScoresFor20Cards={getHighScoresFor20Cards} getHighScoresFor32Cards={getHighScoresFor32Cards}/>
<Navbar userDetails={userDetails} getUserDetails={getUserDetails} user={user} getUser={getUser} getActiveMemories={getActiveMemories} toggleSearchBar={toggleSearchBar} showSearch={showSearch} resetCurrentPage={resetCurrentPage} resetEditingState={resetEditingState} getHighScoresFor10Cards={getHighScoresFor10Cards} getHighScoresFor20Cards={getHighScoresFor20Cards} getHighScoresFor32Cards={getHighScoresFor32Cards}/>
<Routes>
<Route path="*" element={<NotFound />} />
<Route path="/" element={<Welcome />} />
<Route path="/" element={<Welcome userDetails={userDetails}/>} />
<Route path="/list-of-all-cards" element={<ListOfAllCards activeMemories={activeMemories} toggleFavorite={toggleFavorite} favorites={favorites} user={user} showSearch={showSearch} currentPage={currentPage} paginate={setCurrentPage}/>} />
<Route path="/play" element={<Play activeMemories={activeMemories} highScores10={highScores10} highScores20={highScores20} highScores32={highScores32} user={user}/>} />
<Route path="/play" element={<Play highScores10={highScores10} highScores20={highScores20} highScores32={highScores32} user={user}/>} />
<Route path="/memory/:id" element={<Details allMemories={allMemories} favorites={favorites} user={user} toggleFavorite={toggleFavorite}/>} />
<Route path="/high-score" element={<HighScore highScores10={highScores10} highScores20={highScores20} highScores32={highScores32}/>} />
<Route path="/high-score" element={<HighScore highScores10={highScores10} highScores20={highScores20} highScores32={highScores32} getHighScoresFor10Cards={getHighScoresFor10Cards} getHighScoresFor20Cards={getHighScoresFor20Cards} getHighScoresFor32Cards={getHighScoresFor32Cards}/>} />

<Route element={<ProtectedRoute user={user} />}>
<Route path="/favorites" element={<Favorites favorites={favorites} user={user} toggleFavorite={toggleFavorite}/>} />
<Route path="/my-memories" element={<MyMemories userDetails={userDetails} user={user} favorites={favorites} toggleFavorite={toggleFavorite} allMemories={allMemories} setAllMemories={setAllMemories} isEditing={isEditing} setIsEditing={setIsEditing}/>} />
<Route path="/my-memories" element={<MyMemories userDetails={userDetails} user={user} favorites={favorites} toggleFavorite={toggleFavorite} allMemories={allMemories} setAllMemories={setAllMemories} isEditing={isEditing} setIsEditing={setIsEditing} getAllMemories={getAllMemories}/>} />
<Route path="/add" element={<AddMemoryCard userDetails={userDetails} handleSubmit={handleNewMemorySubmit} />} />
<Route path="/profile" element={<Profile userDetails={userDetails} />} />
<Route path="/profile" element={<Profile user={user} userDetails={userDetails} highScores10={highScores10} highScores20={highScores20} highScores32={highScores32} getHighScoresFor10Cards={getHighScoresFor10Cards} getHighScoresFor20Cards={getHighScoresFor20Cards} getHighScoresFor32Cards={getHighScoresFor32Cards}/>} />
</Route>
</Routes>
<Footer />
Expand Down
14 changes: 10 additions & 4 deletions frontend/src/components/AddMemoryCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function AddMemoryCard(props: Readonly<MemoryCardProps>) {
const [description, setDescription] = useState<string>("");
const [image, setImage] = useState<File | null>(null);
const [imageUrl, setImageUrl] = useState<string>(""); // Setzt den Image-URL State
const [matchId, setMatchId] = useState<number>(1); // Defaultwert als Zahl (1)
const [matchId, setMatchId] = useState<number>(0); // Defaultwert als Zahl (1)
const [errorMessages, setErrorMessages] = useState<string[]>([]);
const [showPopup, setShowPopup] = useState(false);

Expand All @@ -37,6 +37,12 @@ export default function AddMemoryCard(props: Readonly<MemoryCardProps>) {
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();

if (matchId === 0) {
setErrorMessages(["Please choose a valid Match ID!"]); // Fehlermeldung hinzufügen
setShowPopup(true); // Popup anzeigen
return; // Verhindert das Absenden des Formulars
}

const memoryData = {
name,
matchId,
Expand Down Expand Up @@ -142,7 +148,7 @@ export default function AddMemoryCard(props: Readonly<MemoryCardProps>) {
</label>

<label>
Bildquelle:
Image Source:
<select
className="input-small"
value={category}
Expand All @@ -164,13 +170,14 @@ export default function AddMemoryCard(props: Readonly<MemoryCardProps>) {
</label>

<label>
Game Deck ID:
Game Deck:
<select
className="input-small"
value={matchId}
onChange={(e) => setMatchId(Number(e.target.value))}
required
>
<option value={0}>Please select a Game-Deck Number</option> {/* Pflichtfeld als Platzhalter */}
{[...Array(20).keys()].map((n) => n + 1).map((n) => (
<option key={n} value={n}>
{n}
Expand All @@ -179,7 +186,6 @@ export default function AddMemoryCard(props: Readonly<MemoryCardProps>) {
</select>
</label>


<label>
Image:
<input
Expand Down
Loading