Implements Hunt basic create and get, and adds field validation to controllers
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package net.halfbinary.scavengerhuntapi.model.converter
|
||||
|
||||
import net.halfbinary.scavengerhuntapi.model.domain.Hunt
|
||||
import net.halfbinary.scavengerhuntapi.model.record.HuntRecord
|
||||
import net.halfbinary.scavengerhuntapi.model.request.HuntCreateRequest
|
||||
import net.halfbinary.scavengerhuntapi.model.response.HuntResponse
|
||||
|
||||
fun HuntRecord.toDomain(): Hunt {
|
||||
return Hunt(id, title, startDateTime, endDateTime, isTerminated)
|
||||
}
|
||||
|
||||
fun Hunt.toResponse(): HuntResponse {
|
||||
return HuntResponse(id, title, startDateTime, endDateTime, isTerminated)
|
||||
}
|
||||
|
||||
fun HuntCreateRequest.toDomain(): Hunt {
|
||||
return Hunt(title = title, startDateTime = startDateTime, endDateTime = endDateTime, isTerminated = false)
|
||||
}
|
||||
|
||||
fun Hunt.toRecord(): HuntRecord {
|
||||
return HuntRecord(id, title, startDateTime, endDateTime, isTerminated)
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package net.halfbinary.scavengerhuntapi.model.domain
|
||||
|
||||
import net.halfbinary.scavengerhuntapi.model.HuntId
|
||||
import java.time.LocalDateTime
|
||||
import java.util.*
|
||||
|
||||
data class Hunt(
|
||||
val id: HuntId = UUID.randomUUID(),
|
||||
val title: String,
|
||||
val startDateTime: LocalDateTime,
|
||||
val endDateTime: LocalDateTime,
|
||||
val isTerminated: Boolean
|
||||
)
|
||||
@@ -1,9 +1,10 @@
|
||||
package net.halfbinary.scavengerhuntapi.model.domain
|
||||
|
||||
import java.util.UUID
|
||||
import net.halfbinary.scavengerhuntapi.model.HunterId
|
||||
import java.util.*
|
||||
|
||||
data class Hunter(
|
||||
val id: UUID = UUID.randomUUID(),
|
||||
val id: HunterId = UUID.randomUUID(),
|
||||
val email: String,
|
||||
val name: String,
|
||||
val password: String,
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package net.halfbinary.scavengerhuntapi.model.request
|
||||
|
||||
import jakarta.validation.constraints.Future
|
||||
import jakarta.validation.constraints.NotBlank
|
||||
import java.time.LocalDateTime
|
||||
|
||||
data class HuntCreateRequest(
|
||||
@field:NotBlank(message = "Hunt title is required")
|
||||
val title: String,
|
||||
@field:Future
|
||||
val startDateTime: LocalDateTime,
|
||||
@field:Future
|
||||
val endDateTime: LocalDateTime,
|
||||
)
|
||||
@@ -0,0 +1,7 @@
|
||||
package net.halfbinary.scavengerhuntapi.model.request
|
||||
|
||||
enum class HuntStatus {
|
||||
UNSTARTED,
|
||||
ONGOING,
|
||||
CLOSED
|
||||
}
|
||||
@@ -1,7 +1,14 @@
|
||||
package net.halfbinary.scavengerhuntapi.model.request
|
||||
|
||||
import jakarta.validation.constraints.Email
|
||||
import jakarta.validation.constraints.NotBlank
|
||||
|
||||
data class HunterSignupRequest(
|
||||
@field:Email(message = "Must be a valid email address")
|
||||
@field:NotBlank(message = "Email must not be blank")
|
||||
val email: String,
|
||||
@field:NotBlank(message = "Name cannot be blank")
|
||||
val name: String,
|
||||
@field:NotBlank(message = "Password cannot be blank")
|
||||
val password: String
|
||||
)
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package net.halfbinary.scavengerhuntapi.model.request
|
||||
|
||||
import jakarta.validation.constraints.NotBlank
|
||||
|
||||
data class LoginRequest(
|
||||
@field:NotBlank(message = "Email cannot be blank")
|
||||
val email: String,
|
||||
@field:NotBlank(message = "Password cannot be blank")
|
||||
val password: String
|
||||
)
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package net.halfbinary.scavengerhuntapi.model.response
|
||||
|
||||
import net.halfbinary.scavengerhuntapi.model.HuntId
|
||||
import java.time.LocalDateTime
|
||||
|
||||
data class HuntResponse(
|
||||
val id: HuntId,
|
||||
val title: String,
|
||||
val startDateTime: LocalDateTime,
|
||||
val endDateTime: LocalDateTime,
|
||||
val isTerminated: Boolean
|
||||
)
|
||||
Reference in New Issue
Block a user