diff --git a/pom.xml b/pom.xml index f6eb2d0..767ca4c 100644 --- a/pom.xml +++ b/pom.xml @@ -21,6 +21,7 @@ UTF-8 3.3.4 3.3.4 + 6.0.21 3.0.20 2.24.1 3.4.2 @@ -67,6 +68,11 @@ structured-logging ${structured-logging.version} + + uk.gov.companieshouse + api-sdk-java + ${api-sdk-java.version} + diff --git a/spec/schema.json b/spec/schema.json index 759b260..32fcc52 100644 --- a/spec/schema.json +++ b/spec/schema.json @@ -1,32 +1,91 @@ { - "swagger": "2.0", + "openapi": "3.0.1", "info": { "title": "Companies House - Limited Partnerships API", - "description": "An API to allow the registration, transition and update of limited partnerships", + "description": "An API to allow the registration, transition and update of Limited Partnerships", "version": "1.0.0" }, - "host": "api.companieshouse.gov.uk", + "servers": [ + { + "url": "https://api.companieshouse.gov.uk/" + } + ], "tags": [ { "name": "Limited Partnerships" } ], "paths": { + "/transactions/{transaction_id}/limited-partnership/partnership": { + "post": { + "tags": [ + "Limited Partnership" + ], + "summary": "Create a Limited Partnership submission", + "parameters": [ + { + "name": "transaction_id", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "201": { + "description": "Limited Partnership Submission has been successfully created.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/LimitedPartnershipSubmissionCreatedResponse" + } + } + } + }, + "400": { + "description": "Bad Request" + }, + "401": { + "description": "Unauthorised" + }, + "500": { + "description": "Internal Server Error" + } + } + } + }, "/limited-partnership/healthcheck": { "get": { "summary": "Health check URL returns 200 if service is running", - "produces": [ - "application/json" - ], "tags": [ - "Limited Partnerships" + "Limited Partnership" ], "responses": { "200": { - "description": "Request has been received" + "description": "Request has been received", + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + } + } + } + } + } + }, + "components": { + "schemas": { + "LimitedPartnershipSubmissionCreatedResponse": { + "type": "object", + "properties": { + "id": { + "type": "string" } } } } } -} \ No newline at end of file +} diff --git a/src/main/java/uk/gov/companieshouse/limitedpartnershipsapi/controller/PartnershipController.java b/src/main/java/uk/gov/companieshouse/limitedpartnershipsapi/controller/PartnershipController.java new file mode 100644 index 0000000..61f1a40 --- /dev/null +++ b/src/main/java/uk/gov/companieshouse/limitedpartnershipsapi/controller/PartnershipController.java @@ -0,0 +1,30 @@ +package uk.gov.companieshouse.limitedpartnershipsapi.controller; + +import jakarta.servlet.http.HttpServletRequest; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import uk.gov.companieshouse.limitedpartnershipsapi.model.dto.LimitedPartnershipSubmissionCreatedResponseDto; +import uk.gov.companieshouse.limitedpartnershipsapi.utils.ApiLogger; + +import java.net.URI; + +import static uk.gov.companieshouse.limitedpartnershipsapi.utils.Constants.URL_PARAM_TRANSACTION_ID; + +@RestController +@RequestMapping("/transactions/{" + URL_PARAM_TRANSACTION_ID + "}/limited-partnership/partnership") +public class PartnershipController { + + @PostMapping + public ResponseEntity createPartnership( + HttpServletRequest request) { + + ApiLogger.debug("createPartnership"); + + URI location = URI.create("/transactions/12321123/limited-partnership/partnership/3235233232"); + LimitedPartnershipSubmissionCreatedResponseDto response = new LimitedPartnershipSubmissionCreatedResponseDto(); + response.setId("3235233232"); + return ResponseEntity.created(location).body(response); + } +} diff --git a/src/main/java/uk/gov/companieshouse/limitedpartnershipsapi/model/dto/LimitedPartnershipSubmissionCreatedResponseDto.java b/src/main/java/uk/gov/companieshouse/limitedpartnershipsapi/model/dto/LimitedPartnershipSubmissionCreatedResponseDto.java new file mode 100644 index 0000000..1b91dc2 --- /dev/null +++ b/src/main/java/uk/gov/companieshouse/limitedpartnershipsapi/model/dto/LimitedPartnershipSubmissionCreatedResponseDto.java @@ -0,0 +1,17 @@ +package uk.gov.companieshouse.limitedpartnershipsapi.model.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class LimitedPartnershipSubmissionCreatedResponseDto { + + @JsonProperty("id") + private String id; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } +} diff --git a/src/main/java/uk/gov/companieshouse/limitedpartnershipsapi/utils/Constants.java b/src/main/java/uk/gov/companieshouse/limitedpartnershipsapi/utils/Constants.java index 101d552..34bdcde 100644 --- a/src/main/java/uk/gov/companieshouse/limitedpartnershipsapi/utils/Constants.java +++ b/src/main/java/uk/gov/companieshouse/limitedpartnershipsapi/utils/Constants.java @@ -6,4 +6,7 @@ private Constants() { } // Request header names public static final String ERIC_REQUEST_ID_KEY = "X-Request-Id"; + + // URL path parameters + public static final String URL_PARAM_TRANSACTION_ID = "transaction_id"; } diff --git a/src/test/java/uk/gov/companieshouse/limitedpartnershipsapi/controller/PartnershipControllerTest.java b/src/test/java/uk/gov/companieshouse/limitedpartnershipsapi/controller/PartnershipControllerTest.java new file mode 100644 index 0000000..df2e2c8 --- /dev/null +++ b/src/test/java/uk/gov/companieshouse/limitedpartnershipsapi/controller/PartnershipControllerTest.java @@ -0,0 +1,37 @@ +package uk.gov.companieshouse.limitedpartnershipsapi.controller; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.mock.web.MockHttpServletRequest; +import uk.gov.companieshouse.limitedpartnershipsapi.model.dto.LimitedPartnershipSubmissionCreatedResponseDto; + +import java.util.Objects; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@ExtendWith(MockitoExtension.class) +class PartnershipControllerTest { + + @InjectMocks + private PartnershipController partnershipController; + + @Mock + private MockHttpServletRequest mockHttpServletRequest; + + @Test + void testCreatePartnership() { + var response = partnershipController.createPartnership(mockHttpServletRequest); + + assertEquals(HttpStatus.CREATED.value(), response.getStatusCode().value()); + var responseHeaderLocation = Objects.requireNonNull(response.getHeaders().get(HttpHeaders.LOCATION)).getFirst(); + assertEquals("/transactions/12321123/limited-partnership/partnership/3235233232", responseHeaderLocation); + LimitedPartnershipSubmissionCreatedResponseDto responseBody = (LimitedPartnershipSubmissionCreatedResponseDto) response.getBody(); + assert responseBody != null; + assertEquals("3235233232", responseBody.getId()); + } +}