generated from codersforcauses/django-nextjs-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from codersforcauses/issue-24-Refactor_Leaderb…
…oard_Module_and_Implement_Mock_API_for_Client-Side_Testing refactor: rename manager to leaderboard module, add mock API responses
- Loading branch information
Showing
16 changed files
with
141 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
import axios from "axios"; | ||
|
||
const api = axios.create({ baseURL: process.env.NEXT_PUBLIC_BACKEND_URL }); | ||
const baseURL = | ||
process.env.NODE_ENV === "development" | ||
? "http://localhost:3000/api" // temporarily use port 3000 in dev for mock data | ||
: process.env.NEXT_PUBLIC_BACKEND_URL; | ||
|
||
const api = axios.create({ baseURL }); | ||
|
||
export default api; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* API Route Handler for a simple ping response. | ||
* | ||
* This handler responds to API requests by returning a simple message. | ||
* It serves as a demonstration of a minimal API route implementation in Next.js. | ||
* | ||
* @fileoverview API endpoint located at `/api/ping` for returning a static response. | ||
* | ||
* @module /api/healthcheck/ping | ||
* @see {@link https://nextjs.org/docs/pages/building-your-application/routing/api-routes | Next.js API Routes Documentation} | ||
*/ | ||
|
||
import { NextApiRequest, NextApiResponse } from "next"; | ||
|
||
/** | ||
* API Route Handler for responding with a simple message. | ||
* | ||
* This endpoint demonstrates a basic API route in Next.js that sends a plain text response. | ||
* It serves as an example of setting up a minimal API route. | ||
* | ||
* @param {NextApiRequest} _req - The incoming HTTP request object. It is unused in this handler. | ||
* @param {NextApiResponse} res - The HTTP response object used to send the text response. | ||
* | ||
* @returns {void} Sends a plain text response indicating the source of the response. | ||
*/ | ||
export default function handler( | ||
_req: NextApiRequest, | ||
res: NextApiResponse, | ||
): void { | ||
res | ||
.status(200) | ||
.json("This response is from client.src.pages.api.healthcheck.ping"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* API Route Handler for fetching leaderboard data. | ||
* | ||
* This handler responds to API requests by returning a mock list of leaderboards. | ||
* It is used to simulate the backend behavior and serve static leaderboard data. | ||
* | ||
* @fileoverview API endpoint located at `/api/list` for fetching mock leaderboard data. | ||
* | ||
* @module /api/leaderboard/list | ||
* @see {@link https://nextjs.org/docs/pages/building-your-application/routing/api-routes | Next.js API Routes Documentation} | ||
*/ | ||
|
||
import { NextApiRequest, NextApiResponse } from "next"; | ||
|
||
import { Leaderboard } from "@/types/leaderboard"; | ||
|
||
/** | ||
* Mock data representing leaderboard entries. | ||
* | ||
* @constant {Leaderboard[]} | ||
*/ | ||
const mockLeaderboards: Leaderboard[] = [ | ||
{ | ||
name: "John Doe", | ||
school: "Springfield High", | ||
school_email: "[email protected]", | ||
user_name: "johndoe", | ||
password: "securepassword", | ||
individual_score: 95, | ||
team_name: "Team A", | ||
team_score: 320, | ||
status: "Active", | ||
}, | ||
{ | ||
name: "Jane Smith", | ||
school: "Shelbyville Academy", | ||
school_email: "[email protected]", | ||
user_name: "janesmith", | ||
password: "anothersecurepassword", | ||
individual_score: 88, | ||
team_name: "Team B", | ||
team_score: 290, | ||
status: "Active", | ||
}, | ||
{ | ||
name: "Alice Johnson", | ||
school: "Ridgeview College", | ||
school_email: "[email protected]", | ||
user_name: "alicejohnson", | ||
password: "password123", | ||
individual_score: 78, | ||
team_name: "Team C", | ||
team_score: 250, | ||
status: "Inactive", | ||
}, | ||
]; | ||
|
||
/** | ||
* Handles API requests to fetch leaderboard data. | ||
* | ||
* @function | ||
* @name handler | ||
* @param {NextApiRequest} _req - The API request object (not used in this handler). | ||
* @param {NextApiResponse<Leaderboard[]>} res - The API response object to return the leaderboard data. | ||
* | ||
* @returns {void} Responds with a status code of 200 and the mock leaderboard data in JSON format. | ||
*/ | ||
export default function handler( | ||
_req: NextApiRequest, | ||
res: NextApiResponse<Leaderboard[]>, | ||
): void { | ||
res.status(200).json(mockLeaderboards); | ||
} |
2 changes: 1 addition & 1 deletion
2
client/src/pages/manager/leaderboard.tsx → client/src/pages/leaderboard/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters