Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/db entity model #2

Merged
merged 8 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id("uk.gov.justice.hmpps.gradle-spring-boot") version "6.1.2"
kotlin("plugin.spring") version "2.0.21"
kotlin("plugin.spring") version "2.0.0"
kotlin("plugin.jpa") version "2.0.0"
}

configurations {
Expand All @@ -12,19 +13,31 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.7.0")

// implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
// implementation("org.flywaydb:flyway-core:10.16.0")
implementation("org.postgresql:postgresql:42.7.3")

// runtimeOnly("org.flywaydb:flyway-database-postgresql:10.16.0")

testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.boot:spring-boot-starter-webflux")
testImplementation("uk.gov.justice.service.hmpps:hmpps-kotlin-spring-boot-starter-test:1.1.0")
testImplementation("org.wiremock:wiremock-standalone:3.9.2")
testImplementation("io.swagger.parser.v3:swagger-parser:2.1.24") {
exclude(group = "io.swagger.core.v3")
}
testImplementation("com.h2database:h2:2.3.232")
}

kotlin {
jvmToolchain(21)
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
}

tasks {
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
compilerOptions.jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_21
kotlinOptions {
jvmTarget = "21"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package uk.gov.justice.digital.hmpps.managingprisonerappsapi

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.boot.runApplication

@SpringBootApplication
@EnableConfigurationProperties
class ManagingPrisonerAppsApi

fun main(args: Array<String>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package uk.gov.justice.digital.hmpps.managingprisonerappsapi.model

import jakarta.persistence.ElementCollection
import jakarta.persistence.Entity
import jakarta.persistence.Id
import java.time.LocalDateTime
import java.util.UUID

@Entity
data class App(
@Id
val id: UUID,
val reference: String,
val assignedGroup: UUID,
val appType: AppType,
val createdDate: LocalDateTime,
val lastModifiedDateTime: LocalDateTime,
val lastModifiedBy: UUID,
@ElementCollection
val comments: List<UUID>,
// @ElementCollection
// val requests: List<Map<String, JvmType.Object>>,
val requestedDateTime: LocalDateTime,
val requestedBy: UUID,
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as App

return id == other.id
}

override fun hashCode(): Int {
return id.hashCode()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package uk.gov.justice.digital.hmpps.managingprisonerappsapi.model

enum class AppType {
PIN_PHONE_CREDIT_TOP_UP,
PIN_PHONE_EMERGENCY_CREDIT_TOP_UP,
PIN_PHONE_ADD_NEW_CONTACT,
PIN_PHONE_REMOVE_CONTACT,
PIN_PHONE_CREDIT_SWAP_VISITING_ORDERS,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package uk.gov.justice.digital.hmpps.managingprisonerappsapi.model

import jakarta.persistence.Column
import jakarta.persistence.ElementCollection
import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.Table
import java.time.LocalDateTime
import java.util.*

@Entity
@Table(name = "comment")
data class Comment(
@Id
val id: UUID,
@Column(name = "message")
val message: String,
@Column(name = "created_date")
val createdDate: LocalDateTime,
@Column(name = "created_by")
val createdBy: UUID,
@ElementCollection
val users: Set<UUID>,
@Column(name = "app")
val app: UUID,
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as Comment

return id == other.id
}

override fun hashCode(): Int {
return id.hashCode()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package uk.gov.justice.digital.hmpps.managingprisonerappsapi.model

enum class Decision {
APPROVED,
DECLINED,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package uk.gov.justice.digital.hmpps.managingprisonerappsapi.model

import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.Table
import java.util.UUID

@Entity
@Table(name = "establishment")
data class Establishment(
@Id
val id: UUID,
val name: String,
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as Establishment

return id == other.id
}

override fun hashCode(): Int {
return id.hashCode()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package uk.gov.justice.digital.hmpps.managingprisonerappsapi.model

import jakarta.persistence.Entity
import jakarta.persistence.Id
import java.util.*

@Entity
data class EstablishmentRole(
@Id
val id: UUID,
val establishment: UUID,
val role: Role,
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as EstablishmentRole

return id == other.id
}

override fun hashCode(): Int {
return id.hashCode()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package uk.gov.justice.digital.hmpps.managingprisonerappsapi.model

enum class GroupType {
WING,
DEPARTMENT,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package uk.gov.justice.digital.hmpps.managingprisonerappsapi.model

import jakarta.persistence.ElementCollection
import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.Table
import java.util.UUID

@Entity
@Table(name = "groups")
data class Groups(
@Id
val id: UUID,
val name: String,
val establishment: UUID,
@ElementCollection
val staffs: Set<UUID>,
@ElementCollection
val initialsApps: List<AppType>,
val type: GroupType,
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as Groups

return id == other.id
}

override fun hashCode(): Int {
return id.hashCode()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package uk.gov.justice.digital.hmpps.managingprisonerappsapi.model

import jakarta.persistence.Entity
import jakarta.persistence.Id
import java.util.UUID

@Entity
data class Prisoner(
@Id
val id: UUID,
val firstName: String,
val lastName: String,
val category: UserCategory,
val location: String,
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as Prisoner

return id == other.id
}

override fun hashCode(): Int {
return id.hashCode()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package uk.gov.justice.digital.hmpps.managingprisonerappsapi.model

import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.Table
import java.time.LocalDateTime
import java.util.UUID

@Entity
@Table(name = "response")
data class Response(
@Id
val id: UUID,
val reason: String,
val decision: Decision,
val createdDate: LocalDateTime,
val createdBy: UUID,
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as Response

return id == other.id
}

override fun hashCode(): Int {
return id.hashCode()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package uk.gov.justice.digital.hmpps.managingprisonerappsapi.model

enum class Role {
ADMIN,
USER,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package uk.gov.justice.digital.hmpps.managingprisonerappsapi.model

import jakarta.persistence.ElementCollection
import jakarta.persistence.Entity
import jakarta.persistence.Id
import java.util.*

@Entity
data class Staff(
@Id
val id: UUID,
val firstName: String,
val lastName: String,
val category: UserCategory,
@ElementCollection
val roles: Set<UUID>,
val jobTitle: String,
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as Staff

return id == other.id
}

override fun hashCode(): Int {
return id.hashCode()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package uk.gov.justice.digital.hmpps.managingprisonerappsapi.model

enum class UserCategory() {
STAFF,
PRISONER,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package uk.gov.justice.digital.hmpps.managingprisonerappsapi.repository

import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository
import uk.gov.justice.digital.hmpps.managingprisonerappsapi.model.App
import java.util.UUID

@Repository
interface AppRepository : JpaRepository<App, UUID>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package uk.gov.justice.digital.hmpps.managingprisonerappsapi.repository

import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository
import uk.gov.justice.digital.hmpps.managingprisonerappsapi.model.Comment
import java.util.UUID

@Repository
interface CommentRepository : JpaRepository<Comment, UUID>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package uk.gov.justice.digital.hmpps.managingprisonerappsapi.repository

import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository
import uk.gov.justice.digital.hmpps.managingprisonerappsapi.model.Groups
import java.util.UUID

@Repository
interface GroupRepository : JpaRepository<Groups, UUID>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package uk.gov.justice.digital.hmpps.managingprisonerappsapi.repository

import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository
import uk.gov.justice.digital.hmpps.managingprisonerappsapi.model.Response
import java.util.UUID

@Repository
interface ResponseRepository : JpaRepository<Response, UUID>
Loading