diff --git a/backend/internal/models/models.go b/backend/internal/models/models.go index 7965aa6..edb3748 100644 --- a/backend/internal/models/models.go +++ b/backend/internal/models/models.go @@ -85,13 +85,16 @@ type Option struct { } type QuizAttempt struct { - ID int `json:"id"` - UserID int64 `json:"user_id"` - QuizID int `json:"quiz_id"` - Score int `json:"score"` - StarsEarned int `json:"stars_earned"` - CompletedAt time.Time `json:"completed_at"` - Answers []UserAnswer `json:"answers"` // Stored as JSONB + ID int `json:"id"` + UserID int64 `json:"user_id"` + QuizID int `json:"quiz_id"` + Score int `json:"score"` + StarsEarned int `json:"stars_earned"` + CompletedAt time.Time `json:"completed_at"` + Answers []UserAnswer `json:"answers"` // Stored as JSONB + // Additional fields for response + CorrectAnswers int `json:"correct_answers"` + TotalQuestions int `json:"total_questions"` } type Reward struct { diff --git a/backend/internal/service/quiz_service.go b/backend/internal/service/quiz_service.go index 74a6f7e..20d0bd6 100644 --- a/backend/internal/service/quiz_service.go +++ b/backend/internal/service/quiz_service.go @@ -125,11 +125,13 @@ func (s *quizService) SubmitQuiz(ctx context.Context, userID int64, quizID int, // --- Database Transaction --- attempt := &models.QuizAttempt{ - UserID: userID, - QuizID: quizID, - Score: score, - StarsEarned: starsEarned, - Answers: submission.Answers, + UserID: userID, + QuizID: quizID, + Score: score, + StarsEarned: starsEarned, + Answers: submission.Answers, + CorrectAnswers: score, + TotalQuestions: len(quiz.Questions), } tx, err := s.db.Begin(ctx) diff --git a/frontend/src/components/DeepLinkHandler.tsx b/frontend/src/components/DeepLinkHandler.tsx index fa87102..7745ce0 100644 --- a/frontend/src/components/DeepLinkHandler.tsx +++ b/frontend/src/components/DeepLinkHandler.tsx @@ -75,7 +75,7 @@ export const DeepLinkHandler: React.FC = ({ onActionComple setResult({ type: 'reward', value: stars, - message: response.data.message || `Вы получили ${stars} ⭐!` + message: response.data.message || `Вы получили ${stars}!` }); // Update user balance @@ -232,7 +232,7 @@ export const DeepLinkHandler: React.FC = ({ onActionComple variant="body1" sx={{ color: '#ffffff', mb: 1 }} > - Вы получили {result.value} ⭐ + Вы получили {result.value} = ({ }} /> } - label={`+${quiz.reward_stars} ⭐`} + label={`+${quiz.reward_stars}`} size="small" sx={{ backgroundColor: 'rgba(255, 215, 0, 0.15)', diff --git a/frontend/src/components/ui/CardReward.tsx b/frontend/src/components/ui/CardReward.tsx index 7e07615..a69c3e2 100644 --- a/frontend/src/components/ui/CardReward.tsx +++ b/frontend/src/components/ui/CardReward.tsx @@ -229,7 +229,7 @@ export const CardReward: React.FC = ({ }} /> } - label={`${reward.price_stars.toLocaleString()} ⭐`} + label={`${reward.price_stars.toLocaleString()}`} size="small" sx={{ backgroundColor: canAfford @@ -314,7 +314,7 @@ export const CardReward: React.FC = ({ }} > {!canAfford - ? `Не хватает ${reward.price_stars - userStars} ⭐` + ? `Не хватает ${reward.price_stars - userStars} звёзд` : !inStock ? 'Нет в наличии' : !isActive diff --git a/frontend/src/components/ui/HeaderProfile.tsx b/frontend/src/components/ui/HeaderProfile.tsx index 93feac8..ae49340 100644 --- a/frontend/src/components/ui/HeaderProfile.tsx +++ b/frontend/src/components/ui/HeaderProfile.tsx @@ -107,7 +107,7 @@ export const HeaderProfile: React.FC = ({ fontSize: 20, }} > - {starsBalance.toLocaleString()} ⭐ + {starsBalance.toLocaleString()} diff --git a/frontend/src/pages/AdminPage.tsx b/frontend/src/pages/AdminPage.tsx index 59a0fc1..8e34582 100644 --- a/frontend/src/pages/AdminPage.tsx +++ b/frontend/src/pages/AdminPage.tsx @@ -625,7 +625,7 @@ export const AdminPage: React.FC = () => { {quiz.title} {quiz.questions?.length || 0} - {quiz.reward_stars} ⭐ + {quiz.reward_stars} { {rewards.map((reward) => ( {reward.title} - {reward.price_stars} ⭐ + {reward.price_stars} {reward.stock === -1 ? '∞' : reward.stock} diff --git a/frontend/src/pages/ProfilePage.tsx b/frontend/src/pages/ProfilePage.tsx index 1e7d931..9b7454f 100644 --- a/frontend/src/pages/ProfilePage.tsx +++ b/frontend/src/pages/ProfilePage.tsx @@ -94,10 +94,7 @@ export const ProfilePage: React.FC = () => { }); }; - const handleLogout = () => { - logout(); - }; - + if (loading) { return ( @@ -193,7 +190,7 @@ export const ProfilePage: React.FC = () => { sx={{ display: 'flex', alignItems: 'center', - justifyContent: 'space-between', + justifyContent: 'center', backgroundColor: 'rgba(255, 215, 0, 0.1)', p: 2, borderRadius: 1, @@ -206,23 +203,9 @@ export const ProfilePage: React.FC = () => { variant="h6" sx={{ color: '#FFD700', fontWeight: 'bold' }} > - {user?.stars_balance} ⭐ + {user?.stars_balance} - @@ -296,7 +279,7 @@ export const ProfilePage: React.FC = () => { } /> { /> { // Handle different response structures if (response.data.type === 'REWARD') { transformedData.value = response.data.data.amount; - transformedData.message = `Вы получили ${response.data.data.amount} ⭐`; + transformedData.message = `Вы получили ${response.data.data.amount}`; } else if (response.data.type === 'OPEN_QUIZ') { transformedData.value = response.data.data.id; transformedData.message = `Викторина: ${response.data.data.title}`; @@ -375,7 +375,7 @@ export const QRScannerPage: React.FC = () => { variant="body1" sx={{ color: '#ffffff', mb: 1 }} > - Вы получили {result.value} ⭐ + Вы получили {result.value} { try { const response = await apiService.submitQuiz(parseInt(id), { answers }); + console.log('Submit quiz response:', response); if (response.success && response.data) { + console.log('Quiz submission successful, data:', response.data); // Update user balance with earned stars if (response.data.stars_earned > 0) { updateUser({ @@ -129,6 +131,7 @@ export const QuizPage: React.FC = () => { } }); } else { + console.log('Quiz submission failed:', response); setError('Не удалось отправить ответы'); } } catch (err) { diff --git a/frontend/src/pages/QuizResultPage.tsx b/frontend/src/pages/QuizResultPage.tsx index 11aa0b2..1cd2fea 100644 --- a/frontend/src/pages/QuizResultPage.tsx +++ b/frontend/src/pages/QuizResultPage.tsx @@ -28,6 +28,10 @@ export const QuizResultPage: React.FC = () => { const state = location.state as LocationState; + useEffect(() => { + console.log('QuizResultPage state:', state); + }, [state]); + useEffect(() => { if (!state) { navigate('/home'); @@ -56,6 +60,14 @@ export const QuizResultPage: React.FC = () => { ? Math.round((result.correct_answers / result.total_questions) * 100) : 0; + console.log('Result data:', { + result, + quizTitle, + percentage, + correctAnswers: result.correct_answers, + totalQuestions: result.total_questions + }); + return ( {/* Result Header */} @@ -96,31 +108,38 @@ export const QuizResultPage: React.FC = () => { {/* Score Circle */} - - {percentage}% - + + {percentage}% + + {/* Score Details */} - + { fontWeight: 'bold', }} > - +{result.stars_earned} ⭐ начислено! + +{result.stars_earned} начислено! diff --git a/frontend/src/pages/ShopPage.tsx b/frontend/src/pages/ShopPage.tsx index 0872a44..5a2668f 100644 --- a/frontend/src/pages/ShopPage.tsx +++ b/frontend/src/pages/ShopPage.tsx @@ -138,7 +138,7 @@ export const ShopPage: React.FC = () => { gap: 1, }} > - Ваш баланс: {user?.stars_balance} ⭐ + Ваш баланс: {user?.stars_balance} @@ -195,7 +195,7 @@ export const ShopPage: React.FC = () => { {/* Price and Status */} { }} > {!canAfford(reward.price_stars) - ? 'Недостаточно ⭐' + ? 'Недостаточно звёзд' : !isInStock(reward.stock) ? 'Нет в наличии' : 'Купить' @@ -315,7 +315,7 @@ export const ShopPage: React.FC = () => { variant="body1" sx={{ color: '#888', mb: 1 }} > - Вы уверены, что хотите купить "{selectedReward?.title}" за {selectedReward?.price_stars} ⭐? + Вы уверены, что хотите купить "{selectedReward?.title}" за {selectedReward?.price_stars}?