Skip to content

Commit

Permalink
Merge pull request #1290 from ministryofjustice/APS-82-return-regions…
Browse files Browse the repository at this point in the history
…-when-listing-premises-summaries

(APS-175) Return region name with premises summaries
  • Loading branch information
pezholio authored Jan 4, 2024
2 parents 36b4239 + c78cae9 commit be5b460
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,27 @@ interface PremisesRepository : JpaRepository<PremisesEntity, UUID> {
)
fun findAllTemporaryAccommodationSummary(regionId: UUID): List<TemporaryAccommodationPremisesSummary>

@Query("SELECT new uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.ApprovedPremisesSummary(p.id, p.name, p.addressLine1, p.addressLine2, p.postcode, p.status, CAST(COUNT(b) as int), p.apCode) FROM ApprovedPremisesEntity p LEFT JOIN p.rooms r LEFT JOIN r.beds b GROUP BY p.id, p.name, p.addressLine1, p.addressLine2, p.postcode, p.apCode, p.status")
@Query(
"""
SELECT
new uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.ApprovedPremisesSummary(
p.id,
p.name,
p.addressLine1,
p.addressLine2,
p.postcode,
p.status,
CAST(COUNT(b) as int),
p.apCode,
region.name
)
FROM ApprovedPremisesEntity p
LEFT JOIN p.rooms r
LEFT JOIN r.beds b
LEFT JOIN p.probationRegion region
GROUP BY p.id, p.name, p.addressLine1, p.addressLine2, p.postcode, p.apCode, p.status, region.name
""",
)
fun findAllApprovedPremisesSummary(): List<ApprovedPremisesSummary>

@Query("SELECT p as premises, (SELECT CAST(COUNT(b) as int) FROM p.rooms r JOIN r.beds b WHERE r.premises = p GROUP BY p) as roomCount FROM PremisesEntity p WHERE TYPE(p) = :type")
Expand Down Expand Up @@ -273,6 +293,7 @@ data class ApprovedPremisesSummary(
val status: PropertyStatus,
val bedCount: Int,
val apCode: String,
val regionName: String,
)

data class TemporaryAccommodationPremisesSummary(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ class PremisesSummaryTransformer() {
bedCount = domain.bedCount,
apCode = domain.apCode,
service = "CAS1",
probationRegion = domain.regionName,
)
}
3 changes: 3 additions & 0 deletions src/main/resources/static/_shared.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,11 @@ components:
apCode:
type: string
example: NEHOPE1
probationRegion:
type: string
required:
- apCode
- probationRegion
TemporaryAccommodationPremisesSummary:
allOf:
- $ref: '#/components/schemas/PremisesSummary'
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/static/codegen/built-api-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4408,8 +4408,11 @@ components:
apCode:
type: string
example: NEHOPE1
probationRegion:
type: string
required:
- apCode
- probationRegion
TemporaryAccommodationPremisesSummary:
allOf:
- $ref: '#/components/schemas/PremisesSummary'
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/static/codegen/built-cas2-api-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,11 @@ components:
apCode:
type: string
example: NEHOPE1
probationRegion:
type: string
required:
- apCode
- probationRegion
TemporaryAccommodationPremisesSummary:
allOf:
- $ref: '#/components/schemas/PremisesSummary'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class PremisesSummaryTransformerTest {
status = PropertyStatus.active,
bedCount = 1,
apCode = "APCODE",
regionName = "Some region",
)

val result = premisesSummaryTransformer.transformDomainToApi(domainPremisesSummary)
Expand All @@ -73,6 +74,7 @@ class PremisesSummaryTransformerTest {
bedCount = 1,
apCode = "APCODE",
service = "CAS1",
probationRegion = "Some region",
),
)
}
Expand Down

0 comments on commit be5b460

Please sign in to comment.