banu4prasad commited on
Commit
5d5d3e8
Β·
1 Parent(s): 0826f71
backend/app/api/routes/tests/__init__.py CHANGED
@@ -9,7 +9,7 @@ from .history import my_history
9
  from .results import get_result
10
  from .schemas import AnswerSubmit, BulkAnswerSubmit
11
 
12
- from .catalog import router as catalog_router
13
  from .attempts import router as attempts_router
14
  from .results import router as results_router
15
  from .leaderboard import router as leaderboard_router
@@ -17,7 +17,8 @@ from .history import router as history_router
17
 
18
  router = APIRouter(prefix="/tests", tags=["Tests"])
19
 
20
- router.include_router(catalog_router)
 
21
  router.include_router(attempts_router)
22
  router.include_router(results_router)
23
  router.include_router(leaderboard_router)
 
9
  from .results import get_result
10
  from .schemas import AnswerSubmit, BulkAnswerSubmit
11
 
12
+ from .catalog import list_tests, get_test
13
  from .attempts import router as attempts_router
14
  from .results import router as results_router
15
  from .leaderboard import router as leaderboard_router
 
17
 
18
  router = APIRouter(prefix="/tests", tags=["Tests"])
19
 
20
+ router.add_api_route("", list_tests, methods=["GET"])
21
+ router.add_api_route("/{test_id}", get_test, methods=["GET"])
22
  router.include_router(attempts_router)
23
  router.include_router(results_router)
24
  router.include_router(leaderboard_router)
backend/app/api/routes/tests/catalog.py CHANGED
@@ -6,10 +6,6 @@ from app.api.deps import require_aspirant
6
  from app.core.database import get_db
7
  from app.models.models import Question, Test
8
 
9
- router = APIRouter()
10
-
11
-
12
- @router.get("/")
13
  def list_tests(db: Session = Depends(get_db), _=Depends(require_aspirant)):
14
  results = (
15
  db.query(Test, func.count(Question.id).label("question_count"))
@@ -38,7 +34,6 @@ def list_tests(db: Session = Depends(get_db), _=Depends(require_aspirant)):
38
  ]
39
 
40
 
41
- @router.get("/{test_id}")
42
  def get_test(test_id: int, db: Session = Depends(get_db), _=Depends(require_aspirant)):
43
  test = db.query(Test).filter(Test.id == test_id).first()
44
  if not test:
 
6
  from app.core.database import get_db
7
  from app.models.models import Question, Test
8
 
 
 
 
 
9
  def list_tests(db: Session = Depends(get_db), _=Depends(require_aspirant)):
10
  results = (
11
  db.query(Test, func.count(Question.id).label("question_count"))
 
34
  ]
35
 
36
 
 
37
  def get_test(test_id: int, db: Session = Depends(get_db), _=Depends(require_aspirant)):
38
  test = db.query(Test).filter(Test.id == test_id).first()
39
  if not test:
frontend/src/api/api.js CHANGED
@@ -33,7 +33,7 @@ export const adminAPI = {
33
 
34
  // ── Tests ─────────────────────────────────────────────────────────
35
  export const testAPI = {
36
- getTests: () => api.get('/tests/'),
37
  getTest: (id) => api.get(`/tests/${id}`),
38
  startTest: (id) => api.post(`/tests/${id}/start`),
39
  getQuestions: (testId, attemptId) => api.get(`/tests/${testId}/attempt/${attemptId}/questions`),
 
33
 
34
  // ── Tests ─────────────────────────────────────────────────────────
35
  export const testAPI = {
36
+ getTests: () => api.get('/tests'),
37
  getTest: (id) => api.get(`/tests/${id}`),
38
  startTest: (id) => api.post(`/tests/${id}/start`),
39
  getQuestions: (testId, attemptId) => api.get(`/tests/${testId}/attempt/${attemptId}/questions`),
frontend/src/pages/Dashboard.jsx CHANGED
@@ -17,7 +17,7 @@ import { Button } from '@/components/ui/button'
17
  export default function Dashboard() {
18
  const { user } = useAuth()
19
 
20
- const { data: tests = [], isLoading: testsLoading } = useSWR('/tests/', fetcher)
21
  const { data: history = [], isLoading: historyLoading } = useSWR('/tests/my/history', fetcher)
22
  const isInitialDataLoading = testsLoading || historyLoading
23
 
 
17
  export default function Dashboard() {
18
  const { user } = useAuth()
19
 
20
+ const { data: tests = [], isLoading: testsLoading } = useSWR('/tests', fetcher)
21
  const { data: history = [], isLoading: historyLoading } = useSWR('/tests/my/history', fetcher)
22
  const isInitialDataLoading = testsLoading || historyLoading
23
 
frontend/src/pages/MyResults.jsx CHANGED
@@ -10,7 +10,7 @@ import { ResultCardSkeleton } from '../components/shared/Skeletons'
10
 
11
  export default function MyResults() {
12
  const { data: historyData, isLoading: historyLoading } = useSWR('/tests/my/history', fetcher)
13
- const { data: testsData, isLoading: testsLoading } = useSWR('/tests/', fetcher)
14
 
15
  const loading = historyLoading || testsLoading
16
  const history = historyData || []
 
10
 
11
  export default function MyResults() {
12
  const { data: historyData, isLoading: historyLoading } = useSWR('/tests/my/history', fetcher)
13
+ const { data: testsData, isLoading: testsLoading } = useSWR('/tests', fetcher)
14
 
15
  const loading = historyLoading || testsLoading
16
  const history = historyData || []
frontend/src/pages/Tests.jsx CHANGED
@@ -103,7 +103,7 @@ function NavCard({ label, count, onClick, icon }) {
103
 
104
  // ── Main Page ─────────────────────────────────────────────────────
105
  export default function TestsPage() {
106
- const { data: testsData, isLoading: testsLoading } = useSWR('/tests/', fetcher)
107
  const { data: historyData, isLoading: historyLoading } = useSWR('/tests/my/history', fetcher)
108
 
109
  const loading = testsLoading || historyLoading
 
103
 
104
  // ── Main Page ─────────────────────────────────────────────────────
105
  export default function TestsPage() {
106
+ const { data: testsData, isLoading: testsLoading } = useSWR('/tests', fetcher)
107
  const { data: historyData, isLoading: historyLoading } = useSWR('/tests/my/history', fetcher)
108
 
109
  const loading = testsLoading || historyLoading