Implements getting the team info for a Hunter in a Hunt
This commit is contained in:
@@ -46,6 +46,6 @@ class HunterController(private val hunterService: HunterService,
|
|||||||
@GetMapping("/hunt/{huntId}/team")
|
@GetMapping("/hunt/{huntId}/team")
|
||||||
@Operation(summary = "Gets the Team for the Hunter for the specified Hunt")
|
@Operation(summary = "Gets the Team for the Hunter for the specified Hunt")
|
||||||
fun getHunterHuntTeam(@PathVariable huntId: HuntId, authentication: Authentication): ResponseEntity<TeamResponse> {
|
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())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
package net.halfbinary.scavengerhuntapi.repository
|
package net.halfbinary.scavengerhuntapi.repository
|
||||||
|
|
||||||
|
import net.halfbinary.scavengerhuntapi.model.HunterId
|
||||||
import net.halfbinary.scavengerhuntapi.model.record.HunterTeamRecord
|
import net.halfbinary.scavengerhuntapi.model.record.HunterTeamRecord
|
||||||
import org.springframework.data.jpa.repository.JpaRepository
|
import org.springframework.data.jpa.repository.JpaRepository
|
||||||
import org.springframework.stereotype.Repository
|
import org.springframework.stereotype.Repository
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
interface HunterTeamRepository : JpaRepository<HunterTeamRecord, UUID>
|
interface HunterTeamRepository : JpaRepository<HunterTeamRecord, UUID> {
|
||||||
|
fun findByHunterId(hunterId: HunterId): List<HunterTeamRecord>
|
||||||
|
}
|
||||||
|
|||||||
@@ -41,6 +41,14 @@ class TeamService(
|
|||||||
.elementAt(0)
|
.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) {
|
fun joinTeam(teamId: TeamId, email: String) {
|
||||||
val hunter = hunterRepository.findByEmail(email) ?: throw NotFoundException("No hunter with email $email found")
|
val hunter = hunterRepository.findByEmail(email) ?: throw NotFoundException("No hunter with email $email found")
|
||||||
hunterTeamRepository.save(HunterTeamRecord(UUID.randomUUID(), hunter.id, teamId))
|
hunterTeamRepository.save(HunterTeamRecord(UUID.randomUUID(), hunter.id, teamId))
|
||||||
|
|||||||
Reference in New Issue
Block a user