From 5563c0c7745b589801f27fdc88d5c9f1f45ba7ce Mon Sep 17 00:00:00 2001 From: aarbit Date: Wed, 3 Dec 2025 16:07:48 -0600 Subject: [PATCH] Adds records and repositories for DB tables --- .../scavengerhuntapi/model/FoundStatus.kt | 8 +++++++ .../scavengerhuntapi/model/TypeAlias.kt | 9 ++++++++ .../model/record/FoundRecord.kt | 23 +++++++++++++++++++ .../model/record/HuntItemRecord.kt | 17 ++++++++++++++ .../model/record/HuntRecord.kt | 22 ++++++++++++++++++ .../model/record/HunterHuntRecord.kt | 20 ++++++++++++++++ .../model/record/HunterRecord.kt | 21 +++++++++++++++++ .../model/record/HunterTeamRecord.kt | 17 ++++++++++++++ .../model/record/ItemRecord.kt | 18 +++++++++++++++ .../model/record/TeamHuntRecord.kt | 17 ++++++++++++++ .../model/record/TeamRecord.kt | 17 ++++++++++++++ .../repository/FoundRepository.kt | 9 ++++++++ .../repository/HuntRepository.kt | 9 ++++++++ .../repository/HunterRepository.kt | 9 ++++++++ .../repository/ItemRepository.kt | 9 ++++++++ .../repository/TeamRepository.kt | 9 ++++++++ src/main/resources/application.properties | 2 ++ 17 files changed, 236 insertions(+) create mode 100644 src/main/kotlin/net/halfbinary/scavengerhuntapi/model/FoundStatus.kt create mode 100644 src/main/kotlin/net/halfbinary/scavengerhuntapi/model/TypeAlias.kt create mode 100644 src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/FoundRecord.kt create mode 100644 src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/HuntItemRecord.kt create mode 100644 src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/HuntRecord.kt create mode 100644 src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/HunterHuntRecord.kt create mode 100644 src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/HunterRecord.kt create mode 100644 src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/HunterTeamRecord.kt create mode 100644 src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/ItemRecord.kt create mode 100644 src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/TeamHuntRecord.kt create mode 100644 src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/TeamRecord.kt create mode 100644 src/main/kotlin/net/halfbinary/scavengerhuntapi/repository/FoundRepository.kt create mode 100644 src/main/kotlin/net/halfbinary/scavengerhuntapi/repository/HuntRepository.kt create mode 100644 src/main/kotlin/net/halfbinary/scavengerhuntapi/repository/HunterRepository.kt create mode 100644 src/main/kotlin/net/halfbinary/scavengerhuntapi/repository/ItemRepository.kt create mode 100644 src/main/kotlin/net/halfbinary/scavengerhuntapi/repository/TeamRepository.kt diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/FoundStatus.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/FoundStatus.kt new file mode 100644 index 0000000..79caaa3 --- /dev/null +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/FoundStatus.kt @@ -0,0 +1,8 @@ +package net.halfbinary.scavengerhuntapi.model + +enum class FoundStatus { + SUBMITTED, + APPROVED, + REJECTED, + REMOVED +} \ No newline at end of file diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/TypeAlias.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/TypeAlias.kt new file mode 100644 index 0000000..b944653 --- /dev/null +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/TypeAlias.kt @@ -0,0 +1,9 @@ +package net.halfbinary.scavengerhuntapi.model + +import java.util.* + +typealias FoundId = UUID +typealias HuntId = UUID +typealias HunterId = UUID +typealias ItemId = UUID +typealias TeamId = UUID \ No newline at end of file diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/FoundRecord.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/FoundRecord.kt new file mode 100644 index 0000000..033dcd2 --- /dev/null +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/FoundRecord.kt @@ -0,0 +1,23 @@ +package net.halfbinary.scavengerhuntapi.model.record + +import jakarta.persistence.Entity +import jakarta.persistence.Id +import jakarta.persistence.Table +import net.halfbinary.scavengerhuntapi.model.* +import java.time.LocalDateTime + +/** + * Represents a found Item for a Hunt by a Hunter + */ +@Entity +@Table(name = "found") +data class FoundRecord( + @Id + val id: FoundId, + val itemId: ItemId, + val huntId: HuntId, + val hunterId: HunterId, + val foundDateTime: LocalDateTime, + val imageName: String, + val status: FoundStatus +) diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/HuntItemRecord.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/HuntItemRecord.kt new file mode 100644 index 0000000..d38356f --- /dev/null +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/HuntItemRecord.kt @@ -0,0 +1,17 @@ +package net.halfbinary.scavengerhuntapi.model.record + +import jakarta.persistence.Entity +import jakarta.persistence.Id +import jakarta.persistence.Table +import net.halfbinary.scavengerhuntapi.model.HuntId +import net.halfbinary.scavengerhuntapi.model.ItemId +import java.util.* + +@Entity +@Table(name = "hunt_item") +data class HuntItemRecord( + @Id + val id: UUID, + val huntId: HuntId, + val itemId: ItemId +) diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/HuntRecord.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/HuntRecord.kt new file mode 100644 index 0000000..6a615e8 --- /dev/null +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/HuntRecord.kt @@ -0,0 +1,22 @@ +package net.halfbinary.scavengerhuntapi.model.record + +import jakarta.persistence.Entity +import jakarta.persistence.Id +import jakarta.persistence.Table +import net.halfbinary.scavengerhuntapi.model.HuntId +import java.time.LocalDateTime + +/** + * Represents a scavenger hunt event + * @property isTerminated Is the event prematurely stopped + */ +@Entity +@Table(name = "hunt") +data class HuntRecord( + @Id + val id: HuntId, + val title: String, + val startDateTime: LocalDateTime, + val endDateTime: LocalDateTime, + val isTerminated: Boolean +) \ No newline at end of file diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/HunterHuntRecord.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/HunterHuntRecord.kt new file mode 100644 index 0000000..57eb78b --- /dev/null +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/HunterHuntRecord.kt @@ -0,0 +1,20 @@ +package net.halfbinary.scavengerhuntapi.model.record + +import jakarta.persistence.Entity +import jakarta.persistence.Id +import jakarta.persistence.Table +import net.halfbinary.scavengerhuntapi.model.HuntId +import net.halfbinary.scavengerhuntapi.model.HunterId +import java.util.* + +/** + * Connects a Hunter to a Hunt as a judge + */ +@Entity +@Table(name = "hunter_hunt") +data class HunterHuntRecord( + @Id + val id: UUID, + val hunterId: HunterId, + val huntId: HuntId +) diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/HunterRecord.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/HunterRecord.kt new file mode 100644 index 0000000..120bb18 --- /dev/null +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/HunterRecord.kt @@ -0,0 +1,21 @@ +package net.halfbinary.scavengerhuntapi.model.record + +import jakarta.persistence.Entity +import jakarta.persistence.Id +import jakarta.persistence.Table +import net.halfbinary.scavengerhuntapi.model.HunterId + +/** + * Represents a user + * @property isAdmin Is a site administrator + */ +@Entity +@Table(name = "hunter") +data class HunterRecord( + @Id + val id: HunterId, + val email: String, + val name: String, + val password: String, + val isAdmin: Boolean +) \ No newline at end of file diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/HunterTeamRecord.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/HunterTeamRecord.kt new file mode 100644 index 0000000..61e8668 --- /dev/null +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/HunterTeamRecord.kt @@ -0,0 +1,17 @@ +package net.halfbinary.scavengerhuntapi.model.record + +import jakarta.persistence.Entity +import jakarta.persistence.Id +import jakarta.persistence.Table +import net.halfbinary.scavengerhuntapi.model.HunterId +import net.halfbinary.scavengerhuntapi.model.TeamId +import java.util.* + +@Entity +@Table(name = "hunter_team") +data class HunterTeamRecord( + @Id + val id: UUID, + val hunterId: HunterId, + val teamId: TeamId +) \ No newline at end of file diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/ItemRecord.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/ItemRecord.kt new file mode 100644 index 0000000..596c131 --- /dev/null +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/ItemRecord.kt @@ -0,0 +1,18 @@ +package net.halfbinary.scavengerhuntapi.model.record + +import jakarta.persistence.Entity +import jakarta.persistence.Id +import jakarta.persistence.Table +import net.halfbinary.scavengerhuntapi.model.ItemId + +/** + * Represents an item to be found on a Hunt + */ +@Entity +@Table(name = "item") +data class ItemRecord( + @Id + val id: ItemId, + val name: String, + val points: Int +) \ No newline at end of file diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/TeamHuntRecord.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/TeamHuntRecord.kt new file mode 100644 index 0000000..32d4204 --- /dev/null +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/TeamHuntRecord.kt @@ -0,0 +1,17 @@ +package net.halfbinary.scavengerhuntapi.model.record + +import jakarta.persistence.Entity +import jakarta.persistence.Id +import jakarta.persistence.Table +import net.halfbinary.scavengerhuntapi.model.HuntId +import net.halfbinary.scavengerhuntapi.model.TeamId +import java.util.* + +@Entity +@Table(name = "team_hunt") +data class TeamHuntRecord( + @Id + val id: UUID, + val teamId: TeamId, + val huntId: HuntId +) diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/TeamRecord.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/TeamRecord.kt new file mode 100644 index 0000000..91f0440 --- /dev/null +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/TeamRecord.kt @@ -0,0 +1,17 @@ +package net.halfbinary.scavengerhuntapi.model.record + +import jakarta.persistence.Entity +import jakarta.persistence.Id +import jakarta.persistence.Table +import net.halfbinary.scavengerhuntapi.model.TeamId + +/** + * Represents a group (1+) of people hunting on a Hunt + */ +@Entity +@Table(name = "team") +data class TeamRecord( + @Id + val id: TeamId, + val name: String, +) \ No newline at end of file diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/repository/FoundRepository.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/repository/FoundRepository.kt new file mode 100644 index 0000000..c863089 --- /dev/null +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/repository/FoundRepository.kt @@ -0,0 +1,9 @@ +package net.halfbinary.scavengerhuntapi.repository + +import net.halfbinary.scavengerhuntapi.model.FoundId +import net.halfbinary.scavengerhuntapi.model.record.FoundRecord +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.stereotype.Repository + +@Repository +interface FoundRepository : JpaRepository \ No newline at end of file diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/repository/HuntRepository.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/repository/HuntRepository.kt new file mode 100644 index 0000000..d2d6b60 --- /dev/null +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/repository/HuntRepository.kt @@ -0,0 +1,9 @@ +package net.halfbinary.scavengerhuntapi.repository + +import net.halfbinary.scavengerhuntapi.model.HuntId +import net.halfbinary.scavengerhuntapi.model.record.HuntRecord +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.stereotype.Repository + +@Repository +interface HuntRepository : JpaRepository \ No newline at end of file diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/repository/HunterRepository.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/repository/HunterRepository.kt new file mode 100644 index 0000000..56b8ac5 --- /dev/null +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/repository/HunterRepository.kt @@ -0,0 +1,9 @@ +package net.halfbinary.scavengerhuntapi.repository + +import net.halfbinary.scavengerhuntapi.model.HunterId +import net.halfbinary.scavengerhuntapi.model.record.HunterRecord +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.stereotype.Repository + +@Repository +interface HunterRepository : JpaRepository \ No newline at end of file diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/repository/ItemRepository.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/repository/ItemRepository.kt new file mode 100644 index 0000000..8acd6e6 --- /dev/null +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/repository/ItemRepository.kt @@ -0,0 +1,9 @@ +package net.halfbinary.scavengerhuntapi.repository + +import net.halfbinary.scavengerhuntapi.model.ItemId +import net.halfbinary.scavengerhuntapi.model.record.ItemRecord +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.stereotype.Repository + +@Repository +interface ItemRepository : JpaRepository \ No newline at end of file diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/repository/TeamRepository.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/repository/TeamRepository.kt new file mode 100644 index 0000000..8cf9575 --- /dev/null +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/repository/TeamRepository.kt @@ -0,0 +1,9 @@ +package net.halfbinary.scavengerhuntapi.repository + +import net.halfbinary.scavengerhuntapi.model.TeamId +import net.halfbinary.scavengerhuntapi.model.record.TeamRecord +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.stereotype.Repository + +@Repository +interface TeamRepository : JpaRepository \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 3ab0935..5c5b534 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -2,6 +2,8 @@ spring.application.name=scavengerhuntapi spring.jpa.hibernate.ddl-auto=update +spring.jpa.properties.hibernate.type.preferred_uuid_jdbc_type=CHAR + spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver spring.datasource.url=${DB_URL} spring.datasource.username=${DB_USER}