Implements Hunt basic create and get, and adds field validation to controllers
This commit is contained in:
@@ -1,9 +1,49 @@
|
||||
package net.halfbinary.scavengerhuntapi.repository
|
||||
|
||||
import net.halfbinary.scavengerhuntapi.model.HuntId
|
||||
import net.halfbinary.scavengerhuntapi.model.HunterId
|
||||
import net.halfbinary.scavengerhuntapi.model.record.HuntRecord
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.data.jpa.repository.Query
|
||||
import org.springframework.stereotype.Repository
|
||||
|
||||
@Repository
|
||||
interface HuntRepository : JpaRepository<HuntRecord, HuntId>
|
||||
interface HuntRepository : JpaRepository<HuntRecord, HuntId> {
|
||||
@Query("""
|
||||
SELECT h.*
|
||||
FROM hunter u
|
||||
INNER JOIN hunter_team ht ON u.id = ht.hunter_id
|
||||
INNER JOIN team t ON ht.team_id = t.id
|
||||
INNER JOIN team_hunt th ON t.id = th.team_id
|
||||
INNER JOIN hunt h ON th.hunt_id = h.id
|
||||
WHERE u.id = :hunterId
|
||||
AND h.is_terminated = FALSE
|
||||
AND h.start_date_time < NOW()
|
||||
AND h.end_date_time > NOW()
|
||||
""", nativeQuery = true)
|
||||
fun findAllOngoingByHunter(hunterId: HunterId): List<HuntRecord>
|
||||
|
||||
@Query("""
|
||||
SELECT h.*
|
||||
FROM hunt h
|
||||
WHERE h.is_terminated = FALSE
|
||||
AND h.start_date_time < NOW()
|
||||
AND h.end_date_time > NOW()
|
||||
""", nativeQuery = true)
|
||||
fun findAllOngoing(): List<HuntRecord>
|
||||
|
||||
@Query("""
|
||||
SELECT h.*
|
||||
FROM hunt h
|
||||
WHERE h.is_terminated = FALSE
|
||||
AND h.start_date_time > NOW()
|
||||
""", nativeQuery = true)
|
||||
fun findAllUnstarted(): List<HuntRecord>
|
||||
|
||||
@Query("""
|
||||
SELECT h.*
|
||||
FROM hunt h
|
||||
WHERE h.is_terminated = TRUE
|
||||
""", nativeQuery = true)
|
||||
fun findAllClosed(): List<HuntRecord>
|
||||
}
|
||||
Reference in New Issue
Block a user