Skip to content

Commit

Permalink
Feature/db entity model (#2)
Browse files Browse the repository at this point in the history
* adding enums and entity class app, users

* updating entity data model class

* updating entity classes

* updating entity model class and adding test data generator

* revertinng ddl auto alue to none

* adding spring boo test annotations

* refactoring, code clean up and tests
  • Loading branch information
varunkumar139 authored Feb 4, 2025
1 parent 6a9bb2b commit 10a3de4
Show file tree
Hide file tree
Showing 28 changed files with 659 additions and 15 deletions.
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

0 comments on commit 10a3de4

Please sign in to comment.