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

story(ccls-1797) add application provider details endpoints #16

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
161 changes: 147 additions & 14 deletions caab-api/open-api-specification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,71 @@ paths:
description: 'Not found'
'500':
description: 'Internal server error'
/applications/{id}/provider-details:
get:
tags:
- applications
summary: 'get an applications provider details'
operationId: 'getApplicationProviderDetails'
parameters:
- name: 'id'
in: 'path'
required: true
schema:
type: 'integer'
format: 'int64'
example: '1234567890'
responses:
'200':
description: 'Successful operation'
content:
application/json:
schema:
$ref: "#/components/schemas/applicationProviderDetails"
'400':
description: 'Bad request'
'401':
description: 'Unauthorized'
'404':
description: 'Not found'
'500':
description: 'Internal server error'
patch:
tags:
- applications
summary: 'patch an applications provider details'
operationId: 'patchApplicationProviderDetails'
requestBody:
description: patch an application's application type
content:
application/json:
schema:
$ref: '#/components/schemas/applicationProviderDetails'
parameters:
- name: 'id'
in: 'path'
required: true
schema:
type: 'integer'
format: 'int64'
example: '1234567890'
- name: 'Caab-user-Login-Id'
in: header
required: true
schema:
type: 'string'
example: '[email protected]'
responses:
'200':
description: 'Successful operation'
'400':
description: 'Bad request'
'401':
description: 'Unauthorized'
'404':
description: 'Not found'
'500':
description: 'Internal server error'
components:
schemas:
intDisplayValue:
Expand Down Expand Up @@ -551,7 +616,7 @@ components:
type: 'number'
default: 0.00
leave_of_court_required_ind:
type: 'string'
type: 'boolean'
offered_amount:
type: 'number'
default: 0.00
Expand Down Expand Up @@ -580,7 +645,64 @@ components:
format: 'date'
time_related_recovery_details:
type: 'string'
liableParty:
type: 'object'
properties:
award_type:
type: 'string'
opponent_id:
type: 'string'
auditTrail:
$ref: "#/components/schemas/auditDetail"
baseAward:
type: 'object'
discriminator:
propertyName: 'discriminator'
properties:
award_type:
type: 'string'
date_of_order:
type: 'string'
format: 'date'
awarded_by:
type: 'string'
description:
type: 'string'
award_amount:
type: 'number'
update_allowed:
type: 'boolean'
delete_allowed:
type: 'boolean'
default: true
ebs_id:
type: 'string'
award_code:
type: 'string'
triggering_event:
type: 'string'
effective_date:
type: 'string'
format: 'date'
time_related_recovery_details:
type: 'string'
cost_or_financial:
type: 'boolean'
default: false
opponents_to_select:
type: 'boolean'
default: false
opponent_id:
type: 'string'
liable_parties:
type: 'array'
items:
$ref: '#/components/schemas/liableParty'
auditTrail:
$ref: "#/components/schemas/auditDetail"
costAward:
allOf:
- $ref: '#/components/schemas/baseAward'
type: 'object'
properties:
court_assessment_status:
Expand Down Expand Up @@ -620,6 +742,8 @@ components:
recovery:
$ref: "#/components/schemas/recovery"
financialAward:
allOf:
- $ref: '#/components/schemas/baseAward'
type: 'object'
properties:
interim_award:
Expand All @@ -645,6 +769,8 @@ components:
recovery:
$ref: "#/components/schemas/recovery"
landAward:
allOf:
- $ref: '#/components/schemas/baseAward'
type: 'object'
properties:
description:
Expand Down Expand Up @@ -682,7 +808,7 @@ components:
registration_ref:
type: 'string'
recovery_of_award_time_related:
type: 'string'
type: 'boolean'
address_line_1:
type: 'string'
address_line_2:
Expand All @@ -692,6 +818,8 @@ components:
time_recovery:
$ref: "#/components/schemas/timeRecovery"
otherAssetAward:
allOf:
- $ref: '#/components/schemas/baseAward'
type: 'object'
properties:
description:
Expand Down Expand Up @@ -847,22 +975,12 @@ components:
user_defined_ind:
type: 'boolean'
applicationDetail:
allOf:
- $ref: "#/components/schemas/applicationProviderDetails"
type: 'object'
properties:
case_reference_number:
type: 'string'
provider_case_reference:
type: 'string'
provider:
$ref: "#/components/schemas/intDisplayValue"
office:
$ref: "#/components/schemas/intDisplayValue"
supervisor:
$ref: "#/components/schemas/stringDisplayValue"
fee_earner:
$ref: "#/components/schemas/stringDisplayValue"
provider_contact:
$ref: "#/components/schemas/stringDisplayValue"
category_of_law:
$ref: "#/components/schemas/stringDisplayValue"
relation_to_linked_case:
Expand Down Expand Up @@ -957,6 +1075,21 @@ components:
- provider
- category_of_law
- client
applicationProviderDetails:
type: 'object'
properties:
provider:
$ref: "#/components/schemas/intDisplayValue"
office:
$ref: "#/components/schemas/intDisplayValue"
fee_earner:
$ref: "#/components/schemas/stringDisplayValue"
supervisor:
$ref: "#/components/schemas/stringDisplayValue"
provider_contact:
$ref: "#/components/schemas/stringDisplayValue"
provider_case_reference:
type: 'string'
auditDetail:
type: 'object'
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class AbstractIntegrationTest {
public static OracleContainer oracleDB;

static {
oracleDB = new OracleContainer("gvenzl/oracle-xe:21-slim");
oracleDB = new OracleContainer("gvenzl/oracle-xe:21-slim-faststart");
oracleDB.start();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.util.Date;
import java.util.TimeZone;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpStatus;
Expand All @@ -28,6 +30,7 @@
import uk.gov.laa.ccms.caab.api.service.ApplicationService;
import uk.gov.laa.ccms.caab.model.Address;
import uk.gov.laa.ccms.caab.model.ApplicationDetail;
import uk.gov.laa.ccms.caab.model.ApplicationProviderDetails;
import uk.gov.laa.ccms.caab.model.ApplicationType;
import uk.gov.laa.ccms.caab.model.Client;
import uk.gov.laa.ccms.caab.model.CostLimit;
Expand Down Expand Up @@ -332,6 +335,76 @@ public void testPatchApplicationType() {
assertEquals(amendedApplicationTypeDisplay, result.getApplicationTypeDisplayValue());
}

@ParameterizedTest
@CsvSource({
"24, NewProviderCaseRef1, New Provider Display1, 12345, 67890, FeeEarnerId1, SupervisorId1, ProviderContactId1, TestUser",
"21, NewProviderCaseRef2, New Provider Display2, 54321, 98760, FeeEarnerId2, SupervisorId2, ProviderContactId2, AnotherUser",
"41, NewProviderCaseRef3, New Provider Display3, 13579, 24680, FeeEarnerId3, SupervisorId3, ProviderContactId3, ThirdUser"
})
@Sql(scripts = "/sql/application_insert.sql")
public void testPatchProviderDetails(
Long applicationId,
String newProviderCaseReference,
String newProviderDisplayValue,
Integer newProviderId,
Integer newOfficeId,
String newFeeEarnerId,
String newSupervisorId,
String newProviderContactId,
String caabUserLoginId) {

// Create an ApplicationProviderDetails instance with the provided values
ApplicationProviderDetails providerDetails = new ApplicationProviderDetails();
IntDisplayValue provider = new IntDisplayValue().id(newProviderId).displayValue(newProviderDisplayValue);
IntDisplayValue office = new IntDisplayValue().id(newOfficeId);
StringDisplayValue feeEarner = new StringDisplayValue().id(newFeeEarnerId);
StringDisplayValue supervisor = new StringDisplayValue().id(newSupervisorId);
StringDisplayValue providerContact = new StringDisplayValue().id(newProviderContactId);

providerDetails.setProvider(provider);
providerDetails.setProviderCaseReference(newProviderCaseReference);
providerDetails.setOffice(office);
providerDetails.setFeeEarner(feeEarner);
providerDetails.setSupervisor(supervisor);
providerDetails.setProviderContact(providerContact);

// Call the patchProviderDetails method
applicationService.patchProviderDetails(applicationId, caabUserLoginId, providerDetails);

// Fetch the application from the database after the update
Application updatedApplication = applicationRepository.findById(applicationId).orElse(null);

// Assert that the updated application has the expected provider details
assertNotNull(updatedApplication);
assertEquals(newProviderCaseReference, updatedApplication.getProviderCaseReference());
assertEquals(newProviderDisplayValue, updatedApplication.getProviderDisplayValue());

// Assert for other provider details
assertEquals(provider.getId().toString(), updatedApplication.getProviderId());
assertEquals(office.getId().toString(), updatedApplication.getOfficeId().toString());
assertEquals(feeEarner.getId(), updatedApplication.getFeeEarner());
assertEquals(supervisor.getId(), updatedApplication.getSupervisor());
assertEquals(providerContact.getId(), updatedApplication.getProviderContact());
}

@Test
@Sql(scripts = "/sql/application_insert.sql")
public void testPatchProviderDetails_ApplicationNotFound() {
Long nonExistentApplicationId = 999L;

ApplicationProviderDetails providerDetails = new ApplicationProviderDetails();

// Use assertThrows to check if the method throws the expected exception
CaabApiException exception = assertThrows(CaabApiException.class, () -> {
applicationService.patchProviderDetails(nonExistentApplicationId, "TestUser", providerDetails);
});

assertEquals(
String.format("Application with id %s not found", nonExistentApplicationId),
exception.getMessage());
assertEquals(HttpStatus.NOT_FOUND, exception.getHttpStatus());
}


private ApplicationDetail buildRequiredApplicationDetail() {
ApplicationDetail application = new ApplicationDetail();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import uk.gov.laa.ccms.caab.api.ApplicationsApi;
import uk.gov.laa.ccms.caab.api.service.ApplicationService;
import uk.gov.laa.ccms.caab.model.ApplicationDetail;
import uk.gov.laa.ccms.caab.model.ApplicationProviderDetails;
import uk.gov.laa.ccms.caab.model.ApplicationType;

/**
Expand Down Expand Up @@ -52,6 +53,15 @@ public ResponseEntity<ApplicationDetail> getApplication(
return new ResponseEntity<>(application, HttpStatus.OK);
}

@Override
public ResponseEntity<ApplicationProviderDetails> getApplicationProviderDetails(Long id) {

ApplicationProviderDetails applicationProviderDetails =
applicationService.getApplicationProviderDetails(id);

return new ResponseEntity<>(applicationProviderDetails, HttpStatus.OK);
}

@Override
public ResponseEntity<ApplicationType> getApplicationType(
final Long id) {
Expand All @@ -61,6 +71,17 @@ public ResponseEntity<ApplicationType> getApplicationType(
return new ResponseEntity<>(applicationType, HttpStatus.OK);
}

@Override
public ResponseEntity<Void> patchApplicationProviderDetails(
Long id,
String caabUserLoginId,
ApplicationProviderDetails applicationProviderDetails) {

applicationService.patchProviderDetails(id, caabUserLoginId, applicationProviderDetails);

return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

@Override
public ResponseEntity<Void> patchApplicationType(
final Long id,
Expand Down
Loading
Loading