Skip to content

Commit

Permalink
LP-206 create initial version of post endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
markpit committed Nov 8, 2024
1 parent 13efae9 commit f11f768
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 9 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-boot-dependencies.version>3.3.4</spring-boot-dependencies.version>
<spring-boot-maven-plugin.version>3.3.4</spring-boot-maven-plugin.version>
<api-sdk-java.version>6.0.21</api-sdk-java.version>
<structured-logging.version>3.0.20</structured-logging.version>
<log4j.version>2.24.1</log4j.version>
<jib-maven-plugin.version>3.4.2</jib-maven-plugin.version>
Expand Down Expand Up @@ -67,6 +68,11 @@
<artifactId>structured-logging</artifactId>
<version>${structured-logging.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.companieshouse</groupId>
<artifactId>api-sdk-java</artifactId>
<version>${api-sdk-java.version}</version>
</dependency>

<!-- Test dependencies -->
<dependency>
Expand Down
77 changes: 68 additions & 9 deletions spec/schema.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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<Object> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit f11f768

Please sign in to comment.