Adds user level hunt endpoints

This commit is contained in:
2026-05-12 10:08:34 -05:00
parent ab34f16a45
commit 46a78bfc08
4 changed files with 83 additions and 3 deletions

View File

@@ -10,6 +10,7 @@ import net.halfbinary.scavengerhuntapi.model.request.HuntStatus
import net.halfbinary.scavengerhuntapi.repository.HuntRepository
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import java.time.LocalDateTime
@Service
class HuntService(private val huntRepository: HuntRepository) {
@@ -30,6 +31,27 @@ class HuntService(private val huntRepository: HuntRepository) {
return huntRepository.findAllOngoingByHunter(hunterId).map { it.toDomain() }
}
fun getHuntsByEmail(email: String, status: HuntStatus?): List<Hunt> {
val allHunts = huntRepository.findHuntsByEmail(email)
val filteredHunts = when (status) {
HuntStatus.ONGOING -> {
allHunts
.filter { !it.isTerminated && it.startDateTime < LocalDateTime.now() && it.endDateTime > LocalDateTime.now() }
.toList()
}
HuntStatus.CLOSED -> {
allHunts
.filter { it.isTerminated || it.endDateTime < LocalDateTime.now() }
}
HuntStatus.UNSTARTED -> {
allHunts
.filter { !it.isTerminated && it.startDateTime > LocalDateTime.now() }
}
else -> { allHunts }
}
return filteredHunts.map { it.toDomain() }
}
fun createHunt(hunt: Hunt): Hunt {
return huntRepository.save(hunt.toRecord()).toDomain()
}