From 59a049e09cb44d912c12fd744f244d6c82a1d528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Runar=20Skjong=20R=C3=B8ssevold?= Date: Fri, 8 May 2026 12:39:47 +0200 Subject: [PATCH] added checkmark upon task completion for individual users --- frontend/src/pages/ChallengeListPage.jsx | 15 ++++++++++++--- .../controller/SubmissionController.java | 12 ++++++++++++ .../repository/SubmissionRepository.java | 1 + 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/frontend/src/pages/ChallengeListPage.jsx b/frontend/src/pages/ChallengeListPage.jsx index ece5f5b..7ce2a2f 100644 --- a/frontend/src/pages/ChallengeListPage.jsx +++ b/frontend/src/pages/ChallengeListPage.jsx @@ -16,12 +16,17 @@ const TYPE_LABEL = { export default function ChallengeListPage() { const [challenges, setChallenges] = useState([]) + const [passedIds, setPassedIds] = useState(new Set()) const [error, setError] = useState(null) useEffect(() => { - api.get('/challenges') - .then(res => setChallenges(res.data)) - .catch(() => setError('Failed to load challenges.')) + Promise.all([ + api.get('/challenges'), + api.get('/submissions/me/passed'), + ]).then(([challengesRes, passedRes]) => { + setChallenges(challengesRes.data) + setPassedIds(new Set(passedRes.data)) + }).catch(() => setError('Failed to load challenges.')) }, []) return ( @@ -37,6 +42,7 @@ export default function ChallengeListPage() { + @@ -49,6 +55,9 @@ export default function ChallengeListPage() { key={c.id} style={{ borderBottom: '1px solid #1a202c' }} > +
# Title Type + {passedIds.has(c.id) ? '✓' : ''} + {i + 1} diff --git a/src/main/java/no/hvl/schemalab/controller/SubmissionController.java b/src/main/java/no/hvl/schemalab/controller/SubmissionController.java index 4dfc6af..fa97e0f 100644 --- a/src/main/java/no/hvl/schemalab/controller/SubmissionController.java +++ b/src/main/java/no/hvl/schemalab/controller/SubmissionController.java @@ -58,4 +58,16 @@ public List mySubmissions() { .orElseThrow(() -> new RuntimeException("User not found")); return submissionRepository.findByUser(user); } + + @GetMapping("/me/passed") + public List passedChallengeIds() { + String username = SecurityContextHolder.getContext().getAuthentication().getName(); + AppUser user = appUserRepository.findByUsername(username) + .orElseThrow(() -> new RuntimeException("User not found")); + return submissionRepository.findByUserAndStatus(user, "PASS") + .stream() + .map(s -> s.getChallenge().getId()) + .distinct() + .toList(); + } } diff --git a/src/main/java/no/hvl/schemalab/repository/SubmissionRepository.java b/src/main/java/no/hvl/schemalab/repository/SubmissionRepository.java index 8a636d3..2e65af2 100644 --- a/src/main/java/no/hvl/schemalab/repository/SubmissionRepository.java +++ b/src/main/java/no/hvl/schemalab/repository/SubmissionRepository.java @@ -8,4 +8,5 @@ public interface SubmissionRepository extends JpaRepository { List findByUser(AppUser user); + List findByUserAndStatus(AppUser user, String status); }