-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from companieshouse/lp-206-create-post-endpoint
LP-206 create initial version of post endpoint
- Loading branch information
Showing
6 changed files
with
161 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...n/java/uk/gov/companieshouse/limitedpartnershipsapi/controller/PartnershipController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...ouse/limitedpartnershipsapi/model/dto/LimitedPartnershipSubmissionCreatedResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...va/uk/gov/companieshouse/limitedpartnershipsapi/controller/PartnershipControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |