Adds various team endpoints

This commit is contained in:
2026-05-12 10:10:55 -05:00
parent 46a78bfc08
commit fd754a7ee7
13 changed files with 182 additions and 11 deletions

View File

@@ -1,10 +1,18 @@
package net.halfbinary.scavengerhuntapi.controller
import io.swagger.v3.oas.annotations.Operation
import jakarta.validation.Valid
import net.halfbinary.scavengerhuntapi.model.HuntId
import net.halfbinary.scavengerhuntapi.model.ItemId
import net.halfbinary.scavengerhuntapi.model.TeamId
import net.halfbinary.scavengerhuntapi.model.converter.toResponse
import net.halfbinary.scavengerhuntapi.model.request.TeamRequest
import net.halfbinary.scavengerhuntapi.model.response.PhotoResponse
import net.halfbinary.scavengerhuntapi.model.response.TeamItemResponse
import net.halfbinary.scavengerhuntapi.model.response.TeamResponse
import net.halfbinary.scavengerhuntapi.service.TeamService
import org.springframework.http.ResponseEntity
import org.springframework.security.core.Authentication
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
@@ -13,15 +21,44 @@ import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
@RestController
@RequestMapping("hunt/{id}/team")
class TeamController {
@RequestMapping("hunt/{huntId}/team")
class TeamController(private val teamService: TeamService) {
@GetMapping
fun listHuntTeams(@PathVariable id: HuntId): ResponseEntity<List<TeamResponse>> {
TODO()
@Operation(summary = "List all teams for the specified hunt")
fun listHuntTeams(@PathVariable huntId: HuntId): ResponseEntity<List<TeamResponse>> {
return ResponseEntity.ok(teamService.getListOfTeamsForHunt(huntId).map { it.toResponse()})
}
@PostMapping
fun createHuntTeam(@PathVariable id: HuntId, @Valid @RequestBody team: TeamRequest) {
@Operation(summary = "Create a new team for the specified hunt")
fun createHuntTeam(@PathVariable huntId: HuntId, @Valid @RequestBody team: TeamRequest) {
val teamResponse = teamService.createTeam(team.name)
teamService.addTeamToHunt(huntId, teamResponse.id)
}
@GetMapping("/{teamId}")
fun getTeam(@PathVariable huntId: HuntId, @PathVariable teamId: TeamId): ResponseEntity<TeamResponse> {
return ResponseEntity.ok(teamService.getTeamFromHunt(huntId, teamId).toResponse())
}
@PostMapping("/{teamId}")
fun joinTeamForHunt(@PathVariable huntId: HuntId, @PathVariable teamId: TeamId, authentication: Authentication) {
teamService.joinTeam(teamId, authentication.name)
}
@GetMapping("/{teamId}/item/{itemId}")
fun getItemsForTeam(@PathVariable huntId: HuntId,
@PathVariable teamId: TeamId,
@PathVariable itemId: ItemId): ResponseEntity<TeamItemResponse> {
TODO()
}
@GetMapping("/{teamId}/item/{itemId}/photo")
fun getPhotosForTeam(@PathVariable huntId: HuntId,
@PathVariable teamId: TeamId,
@PathVariable itemId: ItemId): ResponseEntity<PhotoResponse> {
TODO()
}
}