diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/domain/Hunt.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/domain/Hunt.kt index 80e6036..8b52111 100644 --- a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/domain/Hunt.kt +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/domain/Hunt.kt @@ -1,16 +1,16 @@ package net.halfbinary.scavengerhuntapi.model.domain import net.halfbinary.scavengerhuntapi.model.HuntId -import java.time.LocalDateTime +import java.time.OffsetDateTime import java.util.* data class Hunt( val id: HuntId = UUID.randomUUID(), val title: String, - val startDateTime: LocalDateTime, - val endDateTime: LocalDateTime, + val startDateTime: OffsetDateTime, + val endDateTime: OffsetDateTime, val isTerminated: Boolean ) { val isOngoing: Boolean - get() = !isTerminated && startDateTime < LocalDateTime.now() && endDateTime > LocalDateTime.now() + get() = !isTerminated && startDateTime < OffsetDateTime.now() && endDateTime > OffsetDateTime.now() } \ No newline at end of file diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/domain/Photo.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/domain/Photo.kt index 0700dd4..b9037d4 100644 --- a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/domain/Photo.kt +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/domain/Photo.kt @@ -5,7 +5,7 @@ import net.halfbinary.scavengerhuntapi.model.HunterId import net.halfbinary.scavengerhuntapi.model.ItemId import net.halfbinary.scavengerhuntapi.model.PhotoId import net.halfbinary.scavengerhuntapi.model.PhotoStatus -import java.time.LocalDateTime +import java.time.OffsetDateTime import java.util.* data class Photo( @@ -13,7 +13,7 @@ data class Photo( val itemId: ItemId, val huntId: HuntId, val hunterId: HunterId, - val foundDateTime: LocalDateTime, + val foundDateTime: OffsetDateTime, val status: PhotoStatus, - val statusChangeDateTime: LocalDateTime + val statusChangeDateTime: OffsetDateTime ) diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/HuntRecord.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/HuntRecord.kt index 6a615e8..36cb3fa 100644 --- a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/HuntRecord.kt +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/HuntRecord.kt @@ -4,7 +4,7 @@ import jakarta.persistence.Entity import jakarta.persistence.Id import jakarta.persistence.Table import net.halfbinary.scavengerhuntapi.model.HuntId -import java.time.LocalDateTime +import java.time.OffsetDateTime /** * Represents a scavenger hunt event @@ -16,7 +16,7 @@ data class HuntRecord( @Id val id: HuntId, val title: String, - val startDateTime: LocalDateTime, - val endDateTime: LocalDateTime, + val startDateTime: OffsetDateTime, + val endDateTime: OffsetDateTime, val isTerminated: Boolean ) \ No newline at end of file diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/PhotoRecord.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/PhotoRecord.kt index de8d0e1..c607c73 100644 --- a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/PhotoRecord.kt +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/PhotoRecord.kt @@ -8,7 +8,7 @@ import net.halfbinary.scavengerhuntapi.model.HunterId import net.halfbinary.scavengerhuntapi.model.ItemId import net.halfbinary.scavengerhuntapi.model.PhotoId import net.halfbinary.scavengerhuntapi.model.PhotoStatus -import java.time.LocalDateTime +import java.time.OffsetDateTime /** * Represents a found Item for a Hunt by a Hunter @@ -21,7 +21,7 @@ data class PhotoRecord( val itemId: ItemId, val huntId: HuntId, val hunterId: HunterId, - val foundDateTime: LocalDateTime, + val foundDateTime: OffsetDateTime, val status: PhotoStatus, - val statusChangeDateTime: LocalDateTime, + val statusChangeDateTime: OffsetDateTime, ) diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/RefreshTokenRecord.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/RefreshTokenRecord.kt index ce492bc..cff2562 100644 --- a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/RefreshTokenRecord.kt +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/record/RefreshTokenRecord.kt @@ -4,7 +4,7 @@ import jakarta.persistence.Entity import jakarta.persistence.Id import jakarta.persistence.Table import net.halfbinary.scavengerhuntapi.model.RefreshId -import java.time.LocalDateTime +import java.time.OffsetDateTime @Entity @Table(name = "refresh_token") @@ -12,5 +12,5 @@ data class RefreshTokenRecord( @Id val token: RefreshId, val email: String, - val expiryDateTime: LocalDateTime + val expiryDateTime: OffsetDateTime ) diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/request/HuntCreateRequest.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/request/HuntCreateRequest.kt index bf57a6b..6b8b4dc 100644 --- a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/request/HuntCreateRequest.kt +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/request/HuntCreateRequest.kt @@ -2,13 +2,13 @@ package net.halfbinary.scavengerhuntapi.model.request import jakarta.validation.constraints.Future import jakarta.validation.constraints.NotBlank -import java.time.LocalDateTime +import java.time.OffsetDateTime data class HuntCreateRequest( @field:NotBlank(message = "Hunt title is required") val title: String, @field:Future - val startDateTime: LocalDateTime, + val startDateTime: OffsetDateTime, @field:Future - val endDateTime: LocalDateTime, + val endDateTime: OffsetDateTime, ) diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/request/HuntUpdateRequest.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/request/HuntUpdateRequest.kt index 186d17a..0e7c752 100644 --- a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/request/HuntUpdateRequest.kt +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/request/HuntUpdateRequest.kt @@ -1,10 +1,10 @@ package net.halfbinary.scavengerhuntapi.model.request -import java.time.LocalDateTime +import java.time.OffsetDateTime data class HuntUpdateRequest( val title: String?, - val startDateTime: LocalDateTime?, - val endDateTime: LocalDateTime?, + val startDateTime: OffsetDateTime?, + val endDateTime: OffsetDateTime?, val isTerminated: Boolean? ) diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/response/HuntResponse.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/response/HuntResponse.kt index b6c006c..5d1fe07 100644 --- a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/response/HuntResponse.kt +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/response/HuntResponse.kt @@ -1,12 +1,12 @@ package net.halfbinary.scavengerhuntapi.model.response import net.halfbinary.scavengerhuntapi.model.HuntId -import java.time.LocalDateTime +import java.time.OffsetDateTime data class HuntResponse( val id: HuntId, val title: String, - val startDateTime: LocalDateTime, - val endDateTime: LocalDateTime, + val startDateTime: OffsetDateTime, + val endDateTime: OffsetDateTime, val isTerminated: Boolean ) diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/response/PhotoResponse.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/response/PhotoResponse.kt index 6301f2d..25f7245 100644 --- a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/response/PhotoResponse.kt +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/response/PhotoResponse.kt @@ -2,12 +2,12 @@ package net.halfbinary.scavengerhuntapi.model.response import net.halfbinary.scavengerhuntapi.model.PhotoId import net.halfbinary.scavengerhuntapi.model.PhotoStatus -import java.time.LocalDateTime +import java.time.OffsetDateTime data class PhotoResponse( val id: PhotoId, val hunterName: String, - val photoUploadDateTime: LocalDateTime, + val photoUploadDateTime: OffsetDateTime, val photoStatus: PhotoStatus, - val photoStatusChangeDateTime: LocalDateTime, + val photoStatusChangeDateTime: OffsetDateTime, ) diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/service/HuntService.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/service/HuntService.kt index 9dcf57c..301d46a 100644 --- a/src/main/kotlin/net/halfbinary/scavengerhuntapi/service/HuntService.kt +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/service/HuntService.kt @@ -18,7 +18,7 @@ import net.halfbinary.scavengerhuntapi.repository.HuntRepository import net.halfbinary.scavengerhuntapi.repository.ItemRepository import org.springframework.data.repository.findByIdOrNull import org.springframework.stereotype.Service -import java.time.LocalDateTime +import java.time.OffsetDateTime @Service class HuntService( @@ -49,16 +49,16 @@ class HuntService( val filteredHunts = when (status) { HuntStatus.ONGOING -> { allHunts - .filter { !it.isTerminated && it.startDateTime < LocalDateTime.now() && it.endDateTime > LocalDateTime.now() } + .filter { !it.isTerminated && it.startDateTime < OffsetDateTime.now() && it.endDateTime > OffsetDateTime.now() } .toList() } HuntStatus.CLOSED -> { allHunts - .filter { it.isTerminated || it.endDateTime < LocalDateTime.now() } + .filter { it.isTerminated || it.endDateTime < OffsetDateTime.now() } } HuntStatus.UNSTARTED -> { allHunts - .filter { !it.isTerminated && it.startDateTime > LocalDateTime.now() } + .filter { !it.isTerminated && it.startDateTime > OffsetDateTime.now() } } else -> { allHunts } } diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/service/PhotoService.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/service/PhotoService.kt index 38b55d6..416e0df 100644 --- a/src/main/kotlin/net/halfbinary/scavengerhuntapi/service/PhotoService.kt +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/service/PhotoService.kt @@ -27,7 +27,7 @@ import org.springframework.stereotype.Service import org.springframework.web.multipart.MultipartFile import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream -import java.time.LocalDateTime +import java.time.OffsetDateTime private const val PHOTO_NOT_FOUND = "Photo not found" @@ -56,7 +56,7 @@ class PhotoService( throw BadFileException("Image type is not supported") } - val now = LocalDateTime.now() + val now = OffsetDateTime.now() val photo = Photo( itemId = itemId, huntId = huntId, @@ -171,7 +171,7 @@ class PhotoService( if (photoRecord.status == PhotoStatus.APPROVED) throw ConflictException("Cannot remove an approved photo") - photoRepository.save(photoRecord.copy(status = PhotoStatus.REMOVED, statusChangeDateTime = LocalDateTime.now())) + photoRepository.save(photoRecord.copy(status = PhotoStatus.REMOVED, statusChangeDateTime = OffsetDateTime.now())) } fun getItemPhotos(huntId: HuntId, teamId: TeamId, itemId: ItemId, email: String): List { @@ -197,7 +197,7 @@ class PhotoService( fun updatePhotoStatus(photoId: PhotoId, status: PhotoStatus) { val record = photoRepository.findByIdOrNull(photoId) ?: throw NotFoundException(PHOTO_NOT_FOUND) - photoRepository.save(record.copy(status = status, statusChangeDateTime = LocalDateTime.now())) + photoRepository.save(record.copy(status = status, statusChangeDateTime = OffsetDateTime.now())) } private fun toJpeg(bytes: ByteArray): ByteArray { diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/service/RefreshTokenService.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/service/RefreshTokenService.kt index e55f7fe..0f60a80 100644 --- a/src/main/kotlin/net/halfbinary/scavengerhuntapi/service/RefreshTokenService.kt +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/service/RefreshTokenService.kt @@ -10,7 +10,7 @@ import net.halfbinary.scavengerhuntapi.repository.RefreshTokenRepository import org.slf4j.LoggerFactory import org.springframework.data.repository.findByIdOrNull import org.springframework.stereotype.Service -import java.time.LocalDateTime +import java.time.OffsetDateTime import java.time.temporal.ChronoUnit @Service @@ -33,11 +33,11 @@ class RefreshTokenService(private val refreshTokenRepository: RefreshTokenReposi } fun generateRefreshToken(email: String): RefreshId { - return refreshTokenRepository.save(RefreshTokenRecord(RefreshId.randomUUID(), email, LocalDateTime.now().plus(1, ChronoUnit.MONTHS))).token + return refreshTokenRepository.save(RefreshTokenRecord(RefreshId.randomUUID(), email, OffsetDateTime.now().plus(1, ChronoUnit.MONTHS))).token } fun isTokenExpired(token: RefreshTokenRecord): Boolean { - return token.expiryDateTime.isBefore(LocalDateTime.now()) + return token.expiryDateTime.isBefore(OffsetDateTime.now()) } fun getToken(token: RefreshId): RefreshTokenRecord? {