Implements get photos for an item

This commit is contained in:
2026-05-15 13:40:25 -05:00
parent 6327e0d034
commit eed5a0dd56
4 changed files with 22 additions and 4 deletions

View File

@@ -157,6 +157,24 @@ class PhotoService(
photoRepository.save(photoRecord.copy(status = PhotoStatus.REMOVED, statusChangeDateTime = LocalDateTime.now()))
}
fun getItemPhotos(huntId: HuntId, teamId: TeamId, itemId: ItemId, email: String): List<PhotoResponse> {
val requestingHunter = hunterService.getHunterByEmail(email)
if (!requestingHunter.isAdmin) {
val team = try {
teamService.getTeamForHunterInHunt(huntId, email)
} catch (_: NotFoundException) {
throw ForbiddenException()
}
if (team.id != teamId) throw ForbiddenException()
}
val teamHunterIds = teamService.getHunterIdsForTeam(teamId)
return photoRepository.findByHuntIdAndItemId(huntId, itemId)
.filter { it.hunterId in teamHunterIds && it.status != PhotoStatus.REMOVED }
.map { it.toDomain().toResponse(hunterService.getHunterById(it.hunterId)) }
}
fun updatePhotoStatus(photoId: PhotoId, status: PhotoStatus) {
val record = photoRepository.findByIdOrNull(photoId)
?: throw NotFoundException(PHOTO_NOT_FOUND)