REST endpoints: POST /lobbies, POST /lobbies/:code/join, GET /lobbies #31

Open
opened 2026-04-19 07:23:35 +00:00 by forgejo-lila · 0 comments
Owner

Context

Players need HTTP endpoints to create, join, and browse lobbies before establishing a WebSocket connection.

What to do

Add REST endpoints following the existing layered architecture: router > controller > service > model.

Files to create/change

  • apps/api/src/routes/lobbyRouter.ts — new file.
  • apps/api/src/routes/apiRouter.ts — mount lobbyRouter on /lobbies.
  • apps/api/src/controllers/lobbyController.ts — new file.
  • apps/api/src/services/lobbyService.ts — new file.
  • packages/db/src/models/lobbyModel.ts — new file.
  • packages/shared/src/schemas/lobby.ts — new file. Zod schemas.

Endpoint specs

POST /api/v1/lobbies (auth required)
  Body: { game_mode, is_private?, max_players? }
  Response: { lobby: { id, code, status, game_mode, is_private, max_players } }

POST /api/v1/lobbies/:code/join (auth required)
  Response: { lobby: { id, code, status, game_mode, players: [...] } }
  Errors: 404 (not found), 400 (full, already started)

GET /api/v1/lobbies (auth required)
  Response: { lobbies: [...] } — public lobbies with status 'waiting'

Acceptance criteria

  • Creating a lobby generates a unique, human-readable code
  • Host is automatically added as first player
  • Joining full lobby returns 400
  • Joining in_progress lobby returns 400
  • Public lobbies listable; private not
  • All endpoints require auth
  • Input validated with Zod schemas from packages/shared
  • Integration tests with supertest

Notes

Follow patterns in apps/api/src/controllers/gameController.ts and apps/api/src/services/gameService.ts. Code generation: adjective-number (WOLF-42) or 6-digit alphanumeric. Ensure uniqueness via DB constraint.

## Context Players need HTTP endpoints to create, join, and browse lobbies before establishing a WebSocket connection. ## What to do Add REST endpoints following the existing layered architecture: router > controller > service > model. ## Files to create/change - `apps/api/src/routes/lobbyRouter.ts` — new file. - `apps/api/src/routes/apiRouter.ts` — mount lobbyRouter on `/lobbies`. - `apps/api/src/controllers/lobbyController.ts` — new file. - `apps/api/src/services/lobbyService.ts` — new file. - `packages/db/src/models/lobbyModel.ts` — new file. - `packages/shared/src/schemas/lobby.ts` — new file. Zod schemas. ## Endpoint specs ``` POST /api/v1/lobbies (auth required) Body: { game_mode, is_private?, max_players? } Response: { lobby: { id, code, status, game_mode, is_private, max_players } } POST /api/v1/lobbies/:code/join (auth required) Response: { lobby: { id, code, status, game_mode, players: [...] } } Errors: 404 (not found), 400 (full, already started) GET /api/v1/lobbies (auth required) Response: { lobbies: [...] } — public lobbies with status 'waiting' ``` ## Acceptance criteria - Creating a lobby generates a unique, human-readable code - Host is automatically added as first player - Joining full lobby returns 400 - Joining in_progress lobby returns 400 - Public lobbies listable; private not - All endpoints require auth - Input validated with Zod schemas from packages/shared - Integration tests with supertest ## Notes Follow patterns in `apps/api/src/controllers/gameController.ts` and `apps/api/src/services/gameService.ts`. Code generation: adjective-number (WOLF-42) or 6-digit alphanumeric. Ensure uniqueness via DB constraint.
forgejo-lila added the
multiplayer
label 2026-04-19 07:23:35 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: forgejo-lila/lila#31
No description provided.