diff --git a/SerpentRace_Backend/src/Api/routers/deckRouter.ts b/SerpentRace_Backend/src/Api/routers/deckRouter.ts index fe35d6cb..55b35f42 100644 --- a/SerpentRace_Backend/src/Api/routers/deckRouter.ts +++ b/SerpentRace_Backend/src/Api/routers/deckRouter.ts @@ -199,12 +199,12 @@ deckRouter.patch('/:id', authRequired, async (req, res) => { try { const deckId = req.params.id; const userId = (req as any).user.userId; - logRequest('Update deck endpoint accessed', req, res, { deckId, userId, updateFields: Object.keys(req.body) }); + // Convert string enum values to integers const updateData = convertEnumValues(req.body); - const result = await container.updateDeckCommandHandler.execute({ id: deckId, ...updateData }); + const result = await container.updateDeckCommandHandler.execute({ id: deckId, userstate: userState, ...updateData }); logRequest('Deck updated successfully', req, res, { deckId, userId }); res.json(result); @@ -244,7 +244,6 @@ deckRouter.delete('/:id', authRequired, async (req, res) => { try { const deckId = req.params.id; const userId = (req as any).user.userId; - logRequest('Soft delete deck endpoint accessed', req, res, { deckId, userId }); const result = await container.deleteDeckCommandHandler.execute({ id: deckId, soft: true }); diff --git a/SerpentRace_Frontend/src/api/deckApi.js b/SerpentRace_Frontend/src/api/deckApi.js index f67cd22f..77dbf91e 100644 --- a/SerpentRace_Frontend/src/api/deckApi.js +++ b/SerpentRace_Frontend/src/api/deckApi.js @@ -20,6 +20,28 @@ export const getDecksPage = async (from = 0, to = 49) => { } } -export default { - createDeck +// Get a specific deck by ID (authenticated) +export const getDeckById = async (deckId) => { + try { + const response = await apiClient.get(`/decks/${deckId}`) + return response.data + } catch (err) { + throw err + } +} + +// Update an existing deck (authenticated) +export const updateDeck = async (deckId, deck) => { + try { + const response = await apiClient.patch(`/decks/${deckId}`, deck) + return response.data + } catch (err) { + throw err + } +} + +export default { + createDeck, + getDeckById, + updateDeck } diff --git a/SerpentRace_Frontend/src/components/PopUp/DeckInfoPopUp.jsx b/SerpentRace_Frontend/src/components/PopUp/DeckInfoPopUp.jsx index 1db050ea..e6fc13e7 100644 --- a/SerpentRace_Frontend/src/components/PopUp/DeckInfoPopUp.jsx +++ b/SerpentRace_Frontend/src/components/PopUp/DeckInfoPopUp.jsx @@ -1,4 +1,5 @@ import React, { useEffect } from "react" +import { useNavigate } from "react-router-dom" import { FaUser, FaLock, @@ -12,11 +13,13 @@ import { } from "react-icons/fa" export default function DeckInfoPopUp({ deck, onClose }) { + const navigate = useNavigate() + if (!deck) return null // Debug: Log the deck structure to see what we're working with console.log('Deck in popup:', deck) - console.log('Cards:', deck.cards) + console.log('Raw deck data:', deck.raw) // Scroll blokkolás amikor a popup nyitva van useEffect(() => { @@ -29,50 +32,98 @@ export default function DeckInfoPopUp({ deck, onClose }) { } }, []) - const deckTypes = { - "Luck": { label: "Szerencse", color: "var(--color-luck)" }, - "Question": { label: "Kérdés", color: "var(--color-question)" }, - "Fun": { label: "Joker", color: "var(--color-fun)" } + // Backend enum mapping + const deckTypeMapping = { + 0: { label: "Szerencse", color: "var(--color-luck)" }, // LUCK + 1: { label: "Joker", color: "var(--color-fun)" }, // JOKER + 2: { label: "Kérdés", color: "var(--color-question)" } // QUESTION } - const currentDeckType = deckTypes[deck.type] || { label: deck.type, color: "var(--color-success)" } + const ctypeMapping = { + 0: "Publikus", // PUBLIC + 1: "Privát", // PRIVATE + 2: "Vállalati" // ORGANIZATION + } - // Use real deck data with safe fallbacks - const creator = deck.creatorName || deck.creator || (deck.user && deck.user.name) || "Ismeretlen" - const privacy = deck.origin === "Vállalati" || deck.ctype === 1 || deck.privacy === 'public' ? "Publikus" : "Privát" + const stateMapping = { + 0: "Aktív", // ACTIVE + 1: "Törölt" // SOFT_DELETE + } - // Get data from raw if available + // Get data from raw (backend data) const rawData = deck.raw || deck - // Use played number from raw data for answers count - const questionsCount = rawData.cardCount || 0 - const answersCount = rawData.playedNumber || 0 + // Type info + const deckTypeInfo = deckTypeMapping[rawData.type] || { label: "Ismeretlen", color: "var(--color-success)" } + + // Privacy/CType + const privacy = ctypeMapping[rawData.ctype] || "Ismeretlen" + + // State + const state = stateMapping[rawData.state] || "Ismeretlen" + + // Creator + const creator = rawData.user?.name || rawData.creatorName || rawData.creator || "Ismeretlen" + + // Card count + const cardCount = rawData.cardCount || 0 + + // Played count + const playedNumber = rawData.playedNumber || 0 - console.log('Calculated counts:', { questionsCount, answersCount, rawData }) + console.log('Mapped data:', { + type: rawData.type, + deckTypeInfo, + ctype: rawData.ctype, + privacy, + state, + cardCount, + playedNumber + }) const mockData = { - ...deck, + name: rawData.name || deck.name || "Névtelen pakli", creator, privacy, - questionsCount, - answersCount + state, + questionsCount: cardCount, + answersCount: playedNumber, + created: rawData.creationdate || rawData.created || deck.created || new Date().toISOString(), + description: rawData.description || "" } const formatDate = (dateString) => { - const date = new Date(dateString) - return date.toLocaleDateString('hu-HU', { - year: 'numeric', - month: 'long', - day: 'numeric' - }) + try { + const date = new Date(dateString) + return date.toLocaleDateString('hu-HU', { + year: 'numeric', + month: 'long', + day: 'numeric' + }) + } catch (e) { + return dateString + } } const handleOpenDeck = () => { + // TODO: Megnyitás funkció - később implementálható alert("⚠️ A pakli megnyitás funkció még fejlesztés alatt áll!") } const handleEditDeck = () => { - alert("⚠️ A pakli szerkesztés funkció még fejlesztés alatt áll!") + // Get the deck ID from raw data + const deckId = rawData.id || deck.id + + if (!deckId) { + alert("⚠️ Hiba: A pakli azonosítója nem található!") + return + } + + // Navigate to deck creator with the deck ID + navigate(`/deck-creator/${deckId}`) + + // Close the popup + onClose() } return ( @@ -86,7 +137,7 @@ export default function DeckInfoPopUp({ deck, onClose }) { {/* Header with deck type color */}
{/* Close button */} @@ -108,13 +159,18 @@ export default function DeckInfoPopUp({ deck, onClose }) { - {currentDeckType.label} + {deckTypeInfo.label} + {mockData.description && ( ++ {mockData.description} +
+ )} {/* Data grid */} @@ -149,13 +205,13 @@ export default function DeckInfoPopUp({ deck, onClose }) {