diff --git a/docs/deletePartner/curl-request.adoc b/docs/deletePartner/curl-request.adoc new file mode 100644 index 0000000..ddf42b5 --- /dev/null +++ b/docs/deletePartner/curl-request.adoc @@ -0,0 +1,4 @@ +[source,bash] +---- +$ curl 'http://localhost:8080/partner/2' -i -X DELETE +---- \ No newline at end of file diff --git a/docs/deletePartner/http-request.adoc b/docs/deletePartner/http-request.adoc new file mode 100644 index 0000000..83e1dfa --- /dev/null +++ b/docs/deletePartner/http-request.adoc @@ -0,0 +1,6 @@ +[source,http,options="nowrap"] +---- +DELETE /partner/2 HTTP/1.1 +Host: localhost:8080 + +---- \ No newline at end of file diff --git a/docs/deletePartner/http-response.adoc b/docs/deletePartner/http-response.adoc new file mode 100644 index 0000000..bc07789 --- /dev/null +++ b/docs/deletePartner/http-response.adoc @@ -0,0 +1,5 @@ +[source,http,options="nowrap"] +---- +HTTP/1.1 200 OK + +---- \ No newline at end of file diff --git a/docs/deletePartner/httpie-request.adoc b/docs/deletePartner/httpie-request.adoc new file mode 100644 index 0000000..359dedd --- /dev/null +++ b/docs/deletePartner/httpie-request.adoc @@ -0,0 +1,4 @@ +[source,bash] +---- +$ http DELETE 'http://localhost:8080/partner/2' +---- \ No newline at end of file diff --git a/docs/deletePartner/path-parameters.adoc b/docs/deletePartner/path-parameters.adoc new file mode 100644 index 0000000..742dca3 --- /dev/null +++ b/docs/deletePartner/path-parameters.adoc @@ -0,0 +1,8 @@ +.+/partner/{id}+ +|=== +|Parameter|Description + +|`+id+` +|The id of the partner to delete + +|=== \ No newline at end of file diff --git a/docs/deletePartner/request-body.adoc b/docs/deletePartner/request-body.adoc new file mode 100644 index 0000000..dab5f81 --- /dev/null +++ b/docs/deletePartner/request-body.adoc @@ -0,0 +1,4 @@ +[source,options="nowrap"] +---- + +---- \ No newline at end of file diff --git a/docs/deletePartner/response-body.adoc b/docs/deletePartner/response-body.adoc new file mode 100644 index 0000000..dab5f81 --- /dev/null +++ b/docs/deletePartner/response-body.adoc @@ -0,0 +1,4 @@ +[source,options="nowrap"] +---- + +---- \ No newline at end of file diff --git a/docs/partnerapi.adoc b/docs/partnerapi.adoc index e04cf3d..10a499a 100644 --- a/docs/partnerapi.adoc +++ b/docs/partnerapi.adoc @@ -34,11 +34,11 @@ Most of the following sections have been generated with https://spring.io/proje A `GET` request is used to access all the partners read. ==== Request structure -include::getAllPartners/http-request.adoc[] +include::./getAllPartners/http-request.adoc[] ==== Example response -include::getAllPartners/http-response.adoc[] +include::./getAllPartners/http-response.adoc[] ==== CURL request include::getAllPartners/curl-request.adoc[] @@ -61,7 +61,7 @@ include::getAPartner/curl-request.adoc[] === Accessing the partner POST -A `POST` request is used to add a partners resource. +A `POST` request is used to add a partner resource. ==== Request structure include::createPartner/http-request.adoc[] @@ -71,3 +71,38 @@ include::createPartner/http-response.adoc[] ==== CURL request include::createPartner/curl-request.adoc[] + +=== Accessing the partner PUT +A `PUT` request is used to update a partner resource. + +==== Request structure +include::./updatePartner/http-request.adoc[] + +==== Example response +include::./updatePartner/http-response.adoc[] + +==== CURL request +include::./updatePartner/curl-request.adoc[] + +=== Accessing the partner DELETE +A `DELETE` request is used to delete the partner. + +==== Request structure +include::./deletePartner/http-request.adoc[] + +==== Path Parameters +include::./deletePartner/path-parameters.adoc[] + +==== Example response +include::./deletePartner/http-response.adoc[] + +==== CURL request +include::./deletePartner/curl-request.adoc[] + + +== Conseils de déploiement +Build le jar pour le deploiement : +---- +gradle clean bootJar +---- +NOTE: build/libs/monjardeproduction.jar \ No newline at end of file diff --git a/docs/updatePartner/curl-request.adoc b/docs/updatePartner/curl-request.adoc new file mode 100644 index 0000000..34ecfcb --- /dev/null +++ b/docs/updatePartner/curl-request.adoc @@ -0,0 +1,6 @@ +[source,bash] +---- +$ curl 'http://localhost:8080/partner/3' -i -X PUT \ + -H 'Content-Type: application/json' \ + -d '{"reference":"FYI255","expirationTime":"2022-05-23T12:18:46+01:00","name":"DHL","locale":"de_DE"}' +---- \ No newline at end of file diff --git a/docs/updatePartner/http-request.adoc b/docs/updatePartner/http-request.adoc new file mode 100644 index 0000000..9636050 --- /dev/null +++ b/docs/updatePartner/http-request.adoc @@ -0,0 +1,9 @@ +[source,http,options="nowrap"] +---- +PUT /partner/3 HTTP/1.1 +Content-Type: application/json +Content-Length: 97 +Host: localhost:8080 + +{"reference":"FYI255","expirationTime":"2022-05-23T12:18:46+01:00","name":"DHL","locale":"de_DE"} +---- \ No newline at end of file diff --git a/docs/updatePartner/http-response.adoc b/docs/updatePartner/http-response.adoc new file mode 100644 index 0000000..00b5d03 --- /dev/null +++ b/docs/updatePartner/http-response.adoc @@ -0,0 +1,8 @@ +[source,http,options="nowrap"] +---- +HTTP/1.1 200 OK +Content-Type: application/json +Content-Length: 104 + +{"id":3,"name":"DHL","reference":"FYI255","locale":"de_DE","expirationTime":"2022-05-23T12:18:46+01:00"} +---- \ No newline at end of file diff --git a/docs/updatePartner/httpie-request.adoc b/docs/updatePartner/httpie-request.adoc new file mode 100644 index 0000000..c165269 --- /dev/null +++ b/docs/updatePartner/httpie-request.adoc @@ -0,0 +1,5 @@ +[source,bash] +---- +$ echo '{"reference":"FYI255","expirationTime":"2022-05-23T12:18:46+01:00","name":"DHL","locale":"de_DE"}' | http PUT 'http://localhost:8080/partner/3' \ + 'Content-Type:application/json' +---- \ No newline at end of file diff --git a/docs/updatePartner/path-parameters.adoc b/docs/updatePartner/path-parameters.adoc new file mode 100644 index 0000000..6f57f14 --- /dev/null +++ b/docs/updatePartner/path-parameters.adoc @@ -0,0 +1,8 @@ +.+/partner/{id}+ +|=== +|Parameter|Description + +|`+id+` +|The id of the partner to update + +|=== \ No newline at end of file diff --git a/docs/updatePartner/request-body.adoc b/docs/updatePartner/request-body.adoc new file mode 100644 index 0000000..593c357 --- /dev/null +++ b/docs/updatePartner/request-body.adoc @@ -0,0 +1,4 @@ +[source,options="nowrap"] +---- +{"reference":"FYI255","expirationTime":"2022-05-23T12:18:46+01:00","name":"DHL","locale":"de_DE"} +---- \ No newline at end of file diff --git a/docs/updatePartner/response-body.adoc b/docs/updatePartner/response-body.adoc new file mode 100644 index 0000000..dc310c1 --- /dev/null +++ b/docs/updatePartner/response-body.adoc @@ -0,0 +1,4 @@ +[source,options="nowrap"] +---- +{"id":3,"name":"DHL","reference":"FYI255","locale":"de_DE","expirationTime":"2022-05-23T12:18:46+01:00"} +---- \ No newline at end of file diff --git a/docs/updatePartner/response-fields.adoc b/docs/updatePartner/response-fields.adoc new file mode 100644 index 0000000..0067ce5 --- /dev/null +++ b/docs/updatePartner/response-fields.adoc @@ -0,0 +1,24 @@ +|=== +|Path|Type|Description + +|`+id+` +|`+Number+` +|The id of the updated partner + +|`+name+` +|`+String+` +|The name of the partner + +|`+reference+` +|`+String+` +|The unique reference of the partner + +|`+locale+` +|`+String+` +|A valid Locale of the partner + +|`+expirationTime+` +|`+String+` +|The ISO-8601 UTC date time when the partner is going to expire + +|=== \ No newline at end of file diff --git a/src/test/java/com/example/apispringgradleb2boost/restdoc/ApiPartnerDocIntegrationTest.java b/src/test/java/com/example/apispringgradleb2boost/restdoc/ApiPartnerDocIntegrationTest.java index 770b21a..3373cc6 100644 --- a/src/test/java/com/example/apispringgradleb2boost/restdoc/ApiPartnerDocIntegrationTest.java +++ b/src/test/java/com/example/apispringgradleb2boost/restdoc/ApiPartnerDocIntegrationTest.java @@ -25,8 +25,7 @@ import java.util.Map; import static org.hamcrest.Matchers.containsString; import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration; -import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; -import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*; import static org.springframework.restdocs.operation.preprocess.Preprocessors.*; import static org.springframework.restdocs.payload.PayloadDocumentation.*; import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; @@ -100,4 +99,35 @@ public class ApiPartnerDocIntegrationTest { fieldWithPath("locale").description("A valid Locale of the partner"), fieldWithPath("expirationTime").description("The ISO-8601 UTC date time when the partner is going to expire")))); } + + @Test + @DisplayName("Example DELETE /partner") + public void whenDeletePartner_thenSuccessful() throws Exception { + this.mockMvc.perform(delete("/partner/{id}", 2)) + .andExpect(status().isOk()) + .andDo(document("deletePartner", pathParameters(parameterWithName("id").description("The id of the partner to delete")))); + } + + @Test + @DisplayName("Example PUT /partner") + public void whenUpdatePartner_thenSuccessful() throws Exception { + + ConstraintDescriptions desc = new ConstraintDescriptions(Partner.class); + + Map partner = new HashMap<>(); + partner.put("name", "DHL"); + partner.put("reference", "FYI255"); + partner.put("locale", "de_DE"); + partner.put("expirationTime", "2022-05-23T12:18:46+01:00"); + + this.mockMvc.perform(put("/partner/{id}", 3).contentType(MediaType.APPLICATION_JSON) + .content(this.objectMapper.writeValueAsString(partner))) + .andExpect(status().isOk()) + .andDo(document("updatePartner", pathParameters(parameterWithName("id").description("The id of the partner to update")), + responseFields(fieldWithPath("id").description("The id of the updated partner" + collectionToDelimitedString(desc.descriptionsForProperty("id"), ". ")), + fieldWithPath("name").description("The name of the partner"), + fieldWithPath("reference").description("The unique reference of the partner"), + fieldWithPath("locale").description("A valid Locale of the partner"), + fieldWithPath("expirationTime").description("The ISO-8601 UTC date time when the partner is going to expire")))); + } }