Skip to content

Commit

Permalink
adiing createdBy, date format in app response
Browse files Browse the repository at this point in the history
  • Loading branch information
varunkumar139 committed Mar 10, 2025
1 parent c5d5106 commit ba738cf
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 97 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package uk.gov.justice.digital.hmpps.managingprisonerappsapi.dto

import com.fasterxml.jackson.annotation.JsonFormat
import java.time.LocalDateTime

data class AppRequestDto(
val reference: String,
val type: String,
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'")
val requestedDate: LocalDateTime,
val requests: List<Map<String, Any>>,
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.gov.justice.digital.hmpps.managingprisonerappsapi.dto

import com.fasterxml.jackson.annotation.JsonFormat
import uk.gov.justice.digital.hmpps.managingprisonerappsapi.model.AppType
import java.time.LocalDateTime
import java.util.*
Expand All @@ -9,11 +10,15 @@ data class AppResponseDto(
val reference: String,
val assignedGroup: AssignedGroupDto,
val appType: AppType,
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'")
val requestedDate: LocalDateTime,
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'")
val createdDate: LocalDateTime,
val lastModifiedDateTime: LocalDateTime,
val lastModifiedBy: UUID,
val createdBy: String,
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'")
val lastModifiedDate: LocalDateTime?,
val lastModifiedBy: String?,
val comments: List<UUID>?,
val requests: List<Map<String, Any>>?,
val requestedDateTime: LocalDateTime,
val requestedBy: Any,
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ data class App(
val reference: String,
val assignedGroup: UUID,
val appType: AppType,
val requestedDate: LocalDateTime,
val createdDate: LocalDateTime,
val lastModifiedDateTime: LocalDateTime,
val lastModifiedBy: UUID,
val createdBy: String,
val lastModifiedDate: LocalDateTime?,
val lastModifiedBy: String?,
@ElementCollection
val comments: List<UUID>,
@JdbcTypeCode(SqlTypes.JSON)
val requests: List<Map<String, Any>>,
val requestedDateTime: LocalDateTime,
val requestedBy: UUID,
val establishment: UUID,
val requestedBy: String,
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ enum class AppType {
if (type == PIN_PHONE_REMOVE_CONTACT.toString()) {
return PIN_PHONE_REMOVE_CONTACT
}
if (type == PIN_PHONE_REMOVE_CONTACT.toString()) {
return PIN_PHONE_REMOVE_CONTACT
if (type == PIN_PHONE_CREDIT_SWAP_VISITING_ORDERS.toString()) {
return PIN_PHONE_CREDIT_SWAP_VISITING_ORDERS
}
throw ApiException("$type do not match with any app type", HttpStatus.BAD_REQUEST)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
package uk.gov.justice.digital.hmpps.managingprisonerappsapi.model

import jakarta.persistence.Entity
import jakarta.persistence.Id

@Entity
data class Prisoner(
@Id
val id: String,
val username: String,
val userId: String,
val firstName: String,
val lastName: String,
val category: UserCategory,
val location: String,
val iep: 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 = id.hashCode()
}
)
Original file line number Diff line number Diff line change
@@ -1,29 +1,13 @@
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 username: String,
val userId: String,
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 = id.hashCode()
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import java.util.UUID

@Repository
interface AppRepository : JpaRepository<App, UUID> {
fun findAppsByRequestedBy(id: UUID): List<App>
// fun findAppsByRequestedBy(id: UUID): List<App>

fun findAppByEstablishment(id: UUID): List<App>
// fun findAppByEstablishment(id: UUID): List<App>
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import uk.gov.justice.digital.hmpps.managingprisonerappsapi.model.Staff
import uk.gov.justice.digital.hmpps.managingprisonerappsapi.repository.AppRepository
import uk.gov.justice.digital.hmpps.managingprisonerappsapi.resource.AppController
import java.time.LocalDateTime
import java.time.ZoneOffset
import java.util.*

@Service
Expand Down Expand Up @@ -94,20 +95,20 @@ class AppServiceImpl(

private fun convertAppRequestToAppEntity(prisoner: Prisoner, staff: Staff, appRequest: AppRequestDto): App {
// TODO("Not yet implemented")
val localDateTime = LocalDateTime.now()
val localDateTime = LocalDateTime.now(ZoneOffset.UTC)
return App(
UUID.randomUUID(),
appRequest.reference,
UUID.randomUUID(),
UUID.randomUUID(), // id
appRequest.reference, // reference
UUID.randomUUID(), // group id
AppType.getAppType(appRequest.type),
localDateTime,
localDateTime,
staff.id,
appRequest.requestedDate,
localDateTime, // created date
staff.username,
localDateTime, // last modified date
staff.username, // created by
arrayListOf(),
appRequest.requests,
localDateTime,
staff.id,
UUID.randomUUID(),
prisoner.username,
)
}

Expand All @@ -124,12 +125,13 @@ class AppServiceImpl(
app.reference,
assignedGroup,
app.appType,
app.requestedDate,
app.createdDate,
app.lastModifiedDateTime,
app.createdBy,
app.lastModifiedDate,
app.lastModifiedBy,
app.comments,
app.requests,
app.requestedDateTime,
prisoner,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class PrisonerServiceImpl : PrisonerService {
// Implement it later just adding placeholder for returning a prisoner
val prisoner = Prisoner(
id,
UUID.randomUUID().toString(),
"Test",
"Prisoner",
UserCategory.PRISONER,
Expand All @@ -23,7 +24,7 @@ class PrisonerServiceImpl : PrisonerService {
}

fun convertPrisonerToRequestByDto(prisoner: Prisoner): RequestedByDto = RequestedByDto(
prisoner.id,
prisoner.username,
prisoner.firstName,
prisoner.lastName,
prisoner.location,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class StaffServiceImpl : StaffService {
override fun getStaffById(id: String): Optional<Staff> {
// TODO("Not yet implemented")
val staff = Staff(
UUID.randomUUID(),
id,
UUID.randomUUID().toString(),
"Test",
"Staff",
UserCategory.STAFF,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ class AppRepositoryTest(@Autowired val appRepository: AppRepository) {
"new reference 123",
createdApp.assignedGroup,
createdApp.appType,
createdApp.requestedDate,
createdApp.createdDate,
createdApp.lastModifiedDateTime,
createdApp.createdBy,
createdApp.lastModifiedDate,
createdApp.lastModifiedBy,
createdApp.comments,
listOf(HashMap<String, Any>()),
createdApp.requestedDateTime,
createdApp.requestedBy,
UUID.randomUUID(),
)
app = appRepository.save(app)
Assertions.assertEquals("new reference 123", app.reference)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class DataGenerator {
)

fun generateStaff(): Staff = Staff(
UUID.randomUUID(),
"TEST_USER",
"Test",
"Test",
"Staff",
UserCategory.STAFF,
Expand All @@ -46,12 +47,12 @@ class DataGenerator {
AppType.PIN_PHONE_ADD_NEW_CONTACT,
LocalDateTime.now(),
LocalDateTime.now(),
UUID.randomUUID(),
"testStaaf@moj",
LocalDateTime.now(),
"testStaaf@moj",
arrayListOf(UUID.randomUUID()),
listOf(HashMap<String, Any>().apply { put("contact", 123456) }),
LocalDateTime.now(),
UUID.randomUUID(),
UUID.randomUUID(),
"testprisoner@moj",
)

fun generateAppRequestDto(): AppRequestDto = AppRequestDto(
Expand Down

0 comments on commit ba738cf

Please sign in to comment.