-
Notifications
You must be signed in to change notification settings - Fork 0
Schedule Gen Features #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b7090d3
Completed three tasks:1.4.4 Schedule Generation
rapidcoderx 76edc32
Initial plan
Copilot aa0f7be
Merge pull request #3 from carson-fn/copilot/sub-pr-2
rapidcoderx 1d2ade0
Fix .env.example
carson-fn 8fc4826
Potential fix for pull request finding
rapidcoderx 7ace7a7
Potential fix for pull request finding
rapidcoderx 9ca1901
Potential fix for pull request finding
rapidcoderx 7b23b26
Potential fix for pull request finding
rapidcoderx 85ae325
Potential fix for pull request finding
rapidcoderx 6d0cb88
Potential fix for pull request finding
rapidcoderx e7f2622
Completed Frontend Tournament Page and Backend Tournament API
rapidcoderx 1150d22
Merge branch 'main' into Nitish-DevBranch
rapidcoderx 717df1a
Initial plan
Copilot ce3d0c2
Initial plan
Copilot 0d84fcf
Update frontend/src/pages/tournaments/styles/tournamentStyles.css
rapidcoderx 75d2068
Merge pull request #8 from carson-fn/copilot/sub-pr-2-another-one
rapidcoderx e5e058a
Merge pull request #7 from carson-fn/copilot/sub-pr-2-again
rapidcoderx 4c07db9
Resolve merge conflicts in index.ts and LoginPage.tsx
carson-fn 4c90e2c
Remove unused imports
carson-fn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,30 @@ | ||
| import type { Request, Response } from "express"; | ||
| import { runPrompt } from "../services/geminiService.js"; | ||
|
|
||
| // Demo to test prompts for now | ||
| // Once tournament generation is complete, this will be integrated | ||
| export const runGeminiDemo = async (req: Request, res: Response) => { | ||
| const { prompt } = req.body ?? {}; | ||
|
|
||
| if (typeof prompt !== "string" || prompt.trim().length === 0) { | ||
| return res.status(400).json({ error: "Prompt is required" }); | ||
| } | ||
|
|
||
| try { | ||
| const result = await runPrompt(prompt); | ||
| return res.json(result); | ||
| } catch (err) { | ||
| console.error("GEMINI DEMO ERROR:", err); | ||
|
|
||
| const message = | ||
| err instanceof Error | ||
| ? err.message | ||
| : "Gemini request failed. Verify GEMINI_API_KEY and GEMINI_MODEL."; | ||
|
|
||
| return res.status(500).json({ | ||
| error: message, | ||
| hint: | ||
| "Ensure GEMINI_API_KEY is valid and GEMINI_MODEL (default gemini-2.5-flash) is supported. Try a smaller Flash/Pro variant if needed.", | ||
| }); | ||
| } | ||
| }; |
This file contains hidden or 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,216 @@ | ||
| import type { Request, Response } from "express"; | ||
| import { | ||
| createTournament, | ||
| generateTournamentSchedule, | ||
| getTournamentBracket, | ||
| getTournamentSchedule, | ||
| updateTournamentMatchResult, | ||
| type CreateTournamentPayload, | ||
| } from "../services/tournamentService.js"; | ||
|
|
||
| const parseTournamentId = (idParam: string): number | null => { | ||
| const parsed = Number(idParam); | ||
| if (!Number.isInteger(parsed) || parsed <= 0) { | ||
| return null; | ||
| } | ||
|
|
||
| return parsed; | ||
| }; | ||
|
|
||
| export const createTournamentHandler = async (req: Request, res: Response) => { | ||
| try { | ||
| const payload = req.body as Partial<CreateTournamentPayload>; | ||
|
|
||
| if ( | ||
| typeof payload.name !== "string" || | ||
| typeof payload.sport !== "string" || | ||
| (payload.bracketType !== "single_elimination" && payload.bracketType !== "round_robin") || | ||
| typeof payload.startDate !== "string" || | ||
| typeof payload.endDate !== "string" || | ||
| typeof payload.createdBy !== "number" || | ||
| !Array.isArray(payload.teams) || | ||
| !Array.isArray(payload.venues) | ||
| ) { | ||
| return res.status(400).json({ | ||
| success: false, | ||
| message: "Invalid request body.", | ||
| }); | ||
| } | ||
|
|
||
| const result = await createTournament({ | ||
| name: payload.name, | ||
| sport: payload.sport, | ||
| bracketType: payload.bracketType, | ||
| startDate: payload.startDate, | ||
| endDate: payload.endDate, | ||
| createdBy: payload.createdBy, | ||
| teams: payload.teams, | ||
| venues: payload.venues, | ||
| }); | ||
|
|
||
| return res.status(201).json({ | ||
| success: true, | ||
| tournamentId: result.tournamentId, | ||
| }); | ||
| } catch (error) { | ||
| // Log the underlying error for diagnostics, but do not expose details to the client. | ||
| console.error("Failed to create tournament:", error); | ||
| return res.status(500).json({ | ||
| success: false, | ||
| message: "Server error", | ||
| }); | ||
| } | ||
|
rapidcoderx marked this conversation as resolved.
|
||
| }; | ||
|
|
||
| export const generateScheduleHandler = async (req: Request, res: Response) => { | ||
| const idParam = req.params.id; | ||
|
|
||
| if (typeof idParam !== "string") { | ||
| return res.status(400).json({ | ||
| success: false, | ||
| message: "Invalid tournament id.", | ||
| }); | ||
| } | ||
|
|
||
| const tournamentId = parseTournamentId(idParam); | ||
|
|
||
| if (!tournamentId) { | ||
| return res.status(400).json({ | ||
| success: false, | ||
| message: "Invalid tournament id.", | ||
| }); | ||
| } | ||
|
|
||
| try { | ||
| const result = await generateTournamentSchedule(tournamentId); | ||
| return res.status(200).json({ | ||
| success: true, | ||
| generatedMatches: result.generatedMatches, | ||
| }); | ||
| } catch (error) { | ||
| if (error instanceof Error && error.message === "Tournament not found.") { | ||
| return res.status(404).json({ | ||
| success: false, | ||
| message: error.message, | ||
| }); | ||
| } | ||
|
|
||
| // Log unexpected errors and return a generic server error response. | ||
| console.error("Failed to generate tournament schedule:", error); | ||
| return res.status(500).json({ | ||
| success: false, | ||
| message: "Server error", | ||
| }); | ||
| } | ||
|
rapidcoderx marked this conversation as resolved.
rapidcoderx marked this conversation as resolved.
|
||
| }; | ||
|
|
||
| export const getScheduleHandler = async (req: Request, res: Response) => { | ||
| const idParam = req.params.id; | ||
|
|
||
| if (typeof idParam !== "string") { | ||
| return res.status(400).json({ | ||
| success: false, | ||
| message: "Invalid tournament id.", | ||
| }); | ||
| } | ||
|
|
||
| const tournamentId = parseTournamentId(idParam); | ||
|
|
||
| if (!tournamentId) { | ||
| return res.status(400).json({ | ||
| success: false, | ||
| message: "Invalid tournament id.", | ||
| }); | ||
| } | ||
|
|
||
| try { | ||
| const schedule = await getTournamentSchedule(tournamentId); | ||
|
|
||
| return res.status(200).json({ | ||
| success: true, | ||
| schedule, | ||
| }); | ||
| } catch (error) { | ||
| console.error("Failed to get tournament schedule:", error); | ||
| return res.status(500).json({ | ||
| success: false, | ||
| message: "Server error", | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| export const getBracketHandler = async (req: Request, res: Response) => { | ||
| const idParam = req.params.id; | ||
|
|
||
| if (typeof idParam !== "string") { | ||
| return res.status(400).json({ | ||
| success: false, | ||
| message: "Invalid tournament id.", | ||
| }); | ||
| } | ||
|
|
||
| const tournamentId = parseTournamentId(idParam); | ||
|
|
||
| if (!tournamentId) { | ||
| return res.status(400).json({ | ||
| success: false, | ||
| message: "Invalid tournament id.", | ||
| }); | ||
| } | ||
|
|
||
| try { | ||
| const bracket = await getTournamentBracket(tournamentId); | ||
| return res.status(200).json({ success: true, bracket }); | ||
| } catch (error) { | ||
| if (error instanceof Error && error.message === "Tournament not found.") { | ||
| return res.status(404).json({ success: false, message: error.message }); | ||
| } | ||
|
|
||
| console.error("Failed to get tournament bracket:", error); | ||
| return res.status(500).json({ success: false, message: "Server error" }); | ||
| } | ||
| }; | ||
|
|
||
| export const updateMatchResultHandler = async (req: Request, res: Response) => { | ||
| const tournamentIdParam = req.params.id; | ||
| const matchIdParam = req.params.matchId; | ||
|
|
||
| if (typeof tournamentIdParam !== "string" || typeof matchIdParam !== "string") { | ||
| return res.status(400).json({ success: false, message: "Invalid route parameters." }); | ||
| } | ||
|
|
||
| const tournamentId = parseTournamentId(tournamentIdParam); | ||
| const matchId = parseTournamentId(matchIdParam); | ||
|
|
||
| if (!tournamentId || !matchId) { | ||
| return res.status(400).json({ success: false, message: "Invalid route parameters." }); | ||
| } | ||
|
|
||
| const { homeScore, awayScore } = req.body as { homeScore?: number; awayScore?: number }; | ||
|
|
||
| if (typeof homeScore !== "number" || typeof awayScore !== "number") { | ||
| return res.status(400).json({ success: false, message: "homeScore and awayScore are required." }); | ||
| } | ||
|
|
||
| try { | ||
| const result = await updateTournamentMatchResult(tournamentId, matchId, homeScore, awayScore); | ||
| return res.status(200).json({ success: true, winnerTeamId: result.winnerTeamId }); | ||
| } catch (error) { | ||
| if (error instanceof Error) { | ||
| const knownMessages = new Set([ | ||
| "Match not found.", | ||
| "Both teams must be known before submitting a result.", | ||
| "Scores must be whole numbers greater than or equal to 0.", | ||
| "Matches cannot end in a tie.", | ||
| ]); | ||
|
|
||
| if (knownMessages.has(error.message)) { | ||
| const statusCode = error.message === "Match not found." ? 404 : 400; | ||
| return res.status(statusCode).json({ success: false, message: error.message }); | ||
| } | ||
| } | ||
|
|
||
| console.error("Failed to update match result:", error); | ||
| return res.status(500).json({ success: false, message: "Server error" }); | ||
| } | ||
| }; | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.