From 46132bb4fd0542d5ed43092f3a070cd4913c9c4f Mon Sep 17 00:00:00 2001 From: aarbit Date: Wed, 13 May 2026 00:08:08 -0500 Subject: [PATCH] Implements getting the team info for a Hunter in a Hunt --- .../scavengerhuntapi/controller/HunterController.kt | 2 +- .../scavengerhuntapi/repository/HunterTeamRepository.kt | 5 ++++- .../halfbinary/scavengerhuntapi/service/TeamService.kt | 8 ++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/controller/HunterController.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/controller/HunterController.kt index d548abf..4861e9c 100644 --- a/src/main/kotlin/net/halfbinary/scavengerhuntapi/controller/HunterController.kt +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/controller/HunterController.kt @@ -46,6 +46,6 @@ class HunterController(private val hunterService: HunterService, @GetMapping("/hunt/{huntId}/team") @Operation(summary = "Gets the Team for the Hunter for the specified Hunt") fun getHunterHuntTeam(@PathVariable huntId: HuntId, authentication: Authentication): ResponseEntity { - TODO("Get the Team information for the Hunt for the Hunter (AKA the user)") + return ResponseEntity.ok(teamService.getTeamForHunterInHunt(huntId, authentication.name).toResponse()) } } \ No newline at end of file diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/repository/HunterTeamRepository.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/repository/HunterTeamRepository.kt index 1edd62b..74dfec8 100644 --- a/src/main/kotlin/net/halfbinary/scavengerhuntapi/repository/HunterTeamRepository.kt +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/repository/HunterTeamRepository.kt @@ -1,9 +1,12 @@ package net.halfbinary.scavengerhuntapi.repository +import net.halfbinary.scavengerhuntapi.model.HunterId import net.halfbinary.scavengerhuntapi.model.record.HunterTeamRecord import org.springframework.data.jpa.repository.JpaRepository import org.springframework.stereotype.Repository import java.util.* @Repository -interface HunterTeamRepository : JpaRepository +interface HunterTeamRepository : JpaRepository { + fun findByHunterId(hunterId: HunterId): List +} diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/service/TeamService.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/service/TeamService.kt index 498ed71..e872060 100644 --- a/src/main/kotlin/net/halfbinary/scavengerhuntapi/service/TeamService.kt +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/service/TeamService.kt @@ -41,6 +41,14 @@ class TeamService( .elementAt(0) } + fun getTeamForHunterInHunt(huntId: HuntId, email: String): Team { + val hunter = hunterRepository.findByEmail(email) ?: throw NotFoundException("No hunter with email $email found") + val hunterTeamIds = hunterTeamRepository.findByHunterId(hunter.id).map { it.teamId }.toSet() + return getTeamsForHunt(huntId) + .firstOrNull { it.id in hunterTeamIds } + ?: throw NotFoundException("No team found for hunter $email in hunt $huntId") + } + fun joinTeam(teamId: TeamId, email: String) { val hunter = hunterRepository.findByEmail(email) ?: throw NotFoundException("No hunter with email $email found") hunterTeamRepository.save(HunterTeamRecord(UUID.randomUUID(), hunter.id, teamId))