Skip to content

Commit

Permalink
Story(CCLS-2099) Post assessment endpoint
Browse files Browse the repository at this point in the history
includes amendments to the PUT request to update existing assessments
  • Loading branch information
PhilDigitalJustice committed Jun 3, 2024
1 parent 92c9b7e commit a5700f3
Show file tree
Hide file tree
Showing 15 changed files with 251 additions and 107 deletions.
147 changes: 80 additions & 67 deletions assessment-api/open-api-specification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,9 @@ paths:
operationId: 'getAssessments'
parameters:
- $ref: '#/components/parameters/assessmentType'
- name: 'provider-id'
in: 'query'
schema:
type: 'string'
example: '1234567890'
- name: 'case-reference-number'
in: 'query'
schema:
type: 'string'
example: '1234567890'
- name: 'status'
in: 'query'
schema:
type: 'string'
example: 'INCOMPLETE'
- $ref: '#/components/parameters/providerId'
- $ref: '#/components/parameters/caseReferenceNumber'
- $ref: '#/components/parameters/status'
responses:
'200':
description: 'Successful operation'
Expand All @@ -41,28 +29,6 @@ paths:
description: 'Not found'
'500':
description: 'Internal server error'
put:
tags:
- assessments
summary: 'update an existing assessment'
operationId: 'updateAssessment'
parameters:
- $ref: '#/components/parameters/requiredUserLoginId'
requestBody:
description: update an existing assessment
content:
application/json:
schema:
$ref: '#/components/schemas/assessmentDetail'
responses:
'204':
description: 'Successful update'
'400':
description: 'Bad request'
'401':
description: 'Unauthorized'
'500':
description: 'Internal server error'
delete:
tags:
- assessments
Expand All @@ -83,11 +49,7 @@ paths:
schema:
type: 'string'
example: '1234567890'
- name: 'status'
in: 'query'
schema:
type: 'string'
example: 'INCOMPLETE'
- $ref: '#/components/parameters/status'
responses:
'204':
description: 'Successful deletion'
Expand All @@ -99,20 +61,36 @@ paths:
description: 'Not found'
'500':
description: 'Internal server error'
post:
tags:
- assessments
summary: 'create an assessment'
operationId: 'createAssessment'
parameters:
- $ref: '#/components/parameters/requiredUserLoginId'
requestBody:
description: create an assessment
content:
application/json:
schema:
$ref: '#/components/schemas/assessmentDetail'
responses:
'201':
description: 'Successful create'
'400':
description: 'Bad request'
'401':
description: 'Unauthorized'
'500':
description: 'Internal server error'
/assessments/{assessment-id}:
get:
tags:
- assessments
summary: 'get assessment by id '
operationId: 'getAssessment'
parameters:
- name: 'assessment-id'
in: 'path'
required: true
schema:
type: 'integer'
format: 'int64'
example: '1234567890'
- $ref: '#/components/parameters/assessmentId'
responses:
'200':
description: 'Successful operation'
Expand All @@ -128,6 +106,29 @@ paths:
description: 'Not found'
'500':
description: 'Internal server error'
put:
tags:
- assessments
summary: 'update an existing assessment'
operationId: 'updateAssessment'
parameters:
- $ref: '#/components/parameters/assessmentId'
- $ref: '#/components/parameters/requiredUserLoginId'
requestBody:
description: update an existing assessment
content:
application/json:
schema:
$ref: '#/components/schemas/assessmentDetail'
responses:
'204':
description: 'Successful update'
'400':
description: 'Bad request'
'401':
description: 'Unauthorized'
'500':
description: 'Internal server error'
patch:
tags:
- assessments
Expand All @@ -140,13 +141,7 @@ paths:
schema:
$ref: '#/components/schemas/patchAssessmentDetail'
parameters:
- name: 'assessment-id'
in: 'path'
required: true
schema:
type: 'integer'
format: 'int64'
example: '1234567890'
- $ref: '#/components/parameters/assessmentId'
- $ref: '#/components/parameters/requiredUserLoginId'
responses:
'204':
Expand All @@ -166,13 +161,7 @@ paths:
summary: 'delete checkpoint from assessment'
operationId: 'deleteAssessmentCheckpoint'
parameters:
- name: 'assessment-id'
in: 'path'
required: true
schema:
type: 'integer'
format: 'int64'
example: '1234567890'
- $ref: '#/components/parameters/assessmentId'
- $ref: '#/components/parameters/requiredUserLoginId'
responses:
'204':
Expand Down Expand Up @@ -204,14 +193,39 @@ components:
- 'meansAssessment_PREPOP'
- 'meritsAssessment'
- 'meritsAssessment_PREPOP'

assessmentId:
name: 'assessment-id'
in: 'path'
required: true
schema:
type: 'integer'
format: 'int64'
example: '1234567890'
requiredUserLoginId:
name: 'Caab-User-Login-Id'
in: header
required: true
schema:
type: 'string'
example: '[email protected]'
providerId:
name: 'provider-id'
in: 'query'
schema:
type: 'string'
example: '1234567890'
caseReferenceNumber:
name: 'case-reference-number'
in: 'query'
schema:
type: 'string'
example: '1234567890'
status:
name: 'status'
in: 'query'
schema:
type: 'string'
example: 'INCOMPLETE'

schemas:
assessmentDetails:
Expand Down Expand Up @@ -289,7 +303,6 @@ components:
items:
$ref: '#/components/schemas/assessmentEntityDetail'
required:
- id
- entityType
- entities
assessmentEntityDetail:
Expand All @@ -312,8 +325,9 @@ components:
$ref: '#/components/schemas/assessmentRelationshipDetail'
prepopulated:
type: boolean
completed:
type: boolean
required:
- id
- entityId
- prepopulated
assessmentAttributeDetail:
Expand All @@ -333,7 +347,6 @@ components:
asked:
type: boolean
required:
- id
- attributeId
assessmentRelationshipDetail:
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static uk.gov.laa.ccms.caab.assessment.audit.AuditorAwareImpl.currentUserHolder;

import jakarta.transaction.Transactional;
import java.util.List;
import java.util.stream.Stream;
import javax.management.relation.Relation;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
Expand All @@ -32,6 +33,26 @@ public abstract class BaseAssessmentControllerIntegrationTest {
@Autowired
private AssessmentController assessmentController;

protected final String caabUserLoginId = "[email protected]";

@Test
@Transactional
public void testCreateAssessment_expect201() {

currentUserHolder.set(caabUserLoginId);

AssessmentDetail assessment = new AssessmentDetail()
.name("assessment1")
.providerId("owner1")
.caseReferenceNumber("1234567890")
.status("status1");

ResponseEntity<Void> response =
assessmentController.createAssessment(caabUserLoginId, assessment);

assertEquals(HttpStatus.CREATED, response.getStatusCode());
}

//get by id expect 200
@Test
@Sql(scripts = "/sql/assessments_insert.sql")
Expand Down Expand Up @@ -189,11 +210,12 @@ private static Stream<Arguments> updateAssessmentArguments_base() {
@Sql(scripts = "/sql/assessments_insert.sql")
@Transactional
public void testUpdateAssessment() {
final String loginId = "testUser";
final Long assessmentId = 26L;
currentUserHolder.set(caabUserLoginId);

AssessmentDetail expected = buildAssessmentDetail();

ResponseEntity<Void> response = assessmentController.updateAssessment(loginId, expected);
ResponseEntity<Void> response = assessmentController.updateAssessment(assessmentId, caabUserLoginId, expected);
assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());

ResponseEntity<AssessmentDetail> updatedResponse = assessmentController.getAssessment(expected.getId());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package uk.gov.laa.ccms.caab.assessment.controller;

import java.net.URI;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import uk.gov.laa.ccms.caab.assessment.api.AssessmentsApi;
import uk.gov.laa.ccms.caab.assessment.model.AssessmentDetail;
import uk.gov.laa.ccms.caab.assessment.model.AssessmentDetails;
Expand Down Expand Up @@ -57,6 +59,21 @@ public ResponseEntity<AssessmentDetails> getAssessments(
return ResponseEntity.ok(assessmentService.getAssessments(criteria, name));
}

@Override
public ResponseEntity<Void> createAssessment(
final String caabUserLoginId,
final AssessmentDetail assessment) {

Long assessmentId = assessmentService.createAssessment(assessment);

URI uri = ServletUriComponentsBuilder.fromCurrentRequest()
.path("/{id}")
.buildAndExpand(assessmentId)
.toUri();

return ResponseEntity.created(uri).build();
}

@Override
public ResponseEntity<Void> deleteAssessmentCheckpoint(
final Long assessmentId,
Expand Down Expand Up @@ -117,17 +134,22 @@ public ResponseEntity<Void> patchAssessment(
/**
* updates an assessment.
*
* @param assessmentId The ID of the assessment to update.
* @param caabUserLoginId The CAAB user login ID performing the update.
* @param assessment The details to update the assessment with.
* @return ResponseEntity with the status of the update operation.
*/
@Override
public ResponseEntity<Void> updateAssessment(
final Long assessmentId,
final String caabUserLoginId,
final AssessmentDetail assessment) {

assessmentService.updateAssessment(assessment);
assessmentService.updateAssessment(assessmentId, assessment);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import java.util.Date;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import org.springframework.data.annotation.CreatedBy;
Expand All @@ -13,7 +14,8 @@
* Represents an audit trail for various entities within the CCMS system.
*/
@Embeddable
@Data
@Getter
@Setter
public class AuditTrail {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import jakarta.persistence.ManyToOne;
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.Table;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.type.NumericBooleanConverter;

/**
Expand All @@ -22,7 +23,8 @@
allocationSize = 1,
name = "XXCCMS_OPA_ATTRIBUTE_S",
sequenceName = "XXCCMS_OPA_GENERATED_ID_S")
@Data
@Getter
@Setter
public class OpaAttribute {

/**
Expand Down
Loading

0 comments on commit a5700f3

Please sign in to comment.