Implements getting the team info for a Hunter in a Hunt

This commit is contained in:
2026-05-13 00:08:08 -05:00
parent b2ba9ce676
commit 46132bb4fd
3 changed files with 13 additions and 2 deletions

View File

@@ -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<TeamResponse> {
TODO("Get the Team information for the Hunt for the Hunter (AKA the user)")
return ResponseEntity.ok(teamService.getTeamForHunterInHunt(huntId, authentication.name).toResponse())
}
}

View File

@@ -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<HunterTeamRecord, UUID>
interface HunterTeamRepository : JpaRepository<HunterTeamRecord, UUID> {
fun findByHunterId(hunterId: HunterId): List<HunterTeamRecord>
}

View File

@@ -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))