ShruthiRajaram closed pull request #478: FINERACT-628 self service APIs for client image management URL: https://github.com/apache/fineract/pull/478
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/api-docs/apiLive.htm b/api-docs/apiLive.htm index 1dcb321fb..c182e6588 100644 --- a/api-docs/apiLive.htm +++ b/api-docs/apiLive.htm @@ -3601,6 +3601,30 @@ <h2 class="flybar-button">Self Service</h2> <td></td> <td></td> </tr> + <tr> + <td></td> + <td>self/clients/{clientId}/images</td> + <td><a href="#self_client_images_upload">Upload client image (Data URI)</a></td> + <td></td> + <td></td> + <td></td> + </tr> + <tr> + <td></td> + <td>self/clients/{clientId}/images</td> + <td><a href="#self_client_images_upload_multi_part">Upload client image (Multi-part Form data)</a></td> + <td></td> + <td></td> + <td></td> + </tr> + <tr> + <td></td> + <td>self/clients/{clientId}/images</td> + <td></td> + <td></td> + <td></td> + <td><a href="#self_client_image_delete">Delete client image</a></td> + </tr> <tr> <td><a href="#selfloantemplate">Loans</a></td> <td>self/loans/template?templateType=individual</td> @@ -49110,6 +49134,98 @@ <h4>Obligee List</h4> </code> </div> </div> + + <a id="self_client_images_upload" name="self_client_images_upload" class="old-syle-anchor"> </a> + <div class="method-section"> + <div class="method-description"> + <h4>Upload client image (Data URI)</h4> + </div> + <div class="method-example"> + <code class="method-declaration"> +POST https://DomainName/api/v1/self/clients/{clientId}/images + </code> + <code class="method-request"> +POST self/clients/14/images +Content-Type: text/plain +Request Body: +data:image/png;base64,iVBORw0KGgoAA +AANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD///+l2Z/dAAAAM0l +EQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4Ug9C9zwz3gVLMDA/A6 +P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC + </code> + <code class="method-response"> +{ + "resourceId": 14, + "changes": {}, + "resourceIdentifier": "14" +} + </code> + </div> + </div> + + <a id="self_client_images_upload_multi_part" name="self_client_images_upload_multi_part" class="old-syle-anchor"> </a> + <div class="method-section"> + <div class="method-description"> + <h4>Upload client image (Multi-part Form data)</h4> + <table class=matrixHeading> + <tr class="matrixHeadingBG"> + <td><div class="fineractHeading2">Mandatory Fields</div></td> + </tr> + <tr class=alt> + <td>file + </td> + </tr> + </table> + <p> + The form should contain a required named body part with the + name "file". <br/> <br/> + If you are using a HTML form, a snippet like + <small> <input type="file" name="file"></input> </small> + can be used for uploading the image file + </p> + </div> + <div class="method-example"> + <code class="method-declaration"> +POST https://DomainName/api/v1/self/clients/{clientId}/images + </code> + <code class="method-request"> +POST self/clients/14/images +Content-Type: multipart/form-data +Request Body: <i>Not shown</i> + </code> + <code class="method-response"> +{ + "resourceId": 14, + "changes": {}, + "resourceIdentifier": "14" +} + </code> + </div> + </div> + <a id="self_client_image_delete" name="self_client_image_delete" class="old-syle-anchor"> </a> + <div class="method-section"> + <div class="method-description"> + <h4>Delete an client's Image</h4> + </div> + <div class="method-example"> + <code class="method-declaration"> +DELETE https://DomainName/api/v1/self/clients/{clientId}/images + </code> + <code class="method-request"> +DELETE self/clients/14/images +Content-Type: application/json +No Request Body: + </code> + <code class="method-response"> +{ + "resourceId": 14, + "changes": {}, + "resourceIdentifier": "14" +} + </code> + </div> + </div> + <!-- end of Customer Self Service APIs--> </div> <!-- main-content-wrapper --> diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientApiConstants.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientApiConstants.java index 6d6738153..64edab861 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientApiConstants.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientApiConstants.java @@ -188,6 +188,7 @@ public static final String datatables = "datatables"; public static final String obligeeData = "ObligeeDetails"; + public static final String clientEntityName = "clients"; /** * These parameters will match the class level parameters of diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/client/api/SelfClientsApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/client/api/SelfClientsApiResource.java index d9f1a06a6..d34ad27e4 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/client/api/SelfClientsApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/client/api/SelfClientsApiResource.java @@ -18,9 +18,14 @@ */ package org.apache.fineract.portfolio.self.client.api; +import java.io.InputStream; + import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @@ -44,6 +49,10 @@ import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; +import com.sun.jersey.core.header.FormDataContentDisposition; +import com.sun.jersey.multipart.FormDataBodyPart; +import com.sun.jersey.multipart.FormDataParam; + @Path("/self/clients") @Component @Scope("singleton") @@ -217,6 +226,43 @@ private void validateAppuserClientsMapping(final Long clientId) { throw new ClientNotFoundException(clientId); } } + + @POST + @Path("{clientId}/images") + @Consumes({ MediaType.MULTIPART_FORM_DATA }) + @Produces({ MediaType.APPLICATION_JSON }) + public String addNewClientImage(@PathParam("clientId") final Long clientId, + @HeaderParam("Content-Length") final Long fileSize, @FormDataParam("file") final InputStream inputStream, + @FormDataParam("file") final FormDataContentDisposition fileDetails, + @FormDataParam("file") final FormDataBodyPart bodyPart) { + + validateAppuserClientsMapping(clientId); + return this.imagesApiResource.addNewClientImage(ClientApiConstants.clientEntityName, clientId, fileSize, + inputStream, fileDetails, bodyPart); + + } + + @POST + @Path("{clientId}/images") + @Consumes({ MediaType.TEXT_PLAIN, MediaType.TEXT_HTML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public String addNewClientImage(@PathParam("entity") final String entityName, + @PathParam("clientId") final Long clientId, final String jsonRequestBody) { + validateAppuserClientsMapping(clientId); + return this.imagesApiResource.addNewClientImage(ClientApiConstants.clientEntityName, clientId, jsonRequestBody); + + } + + @DELETE + @Path("{clientId}/images") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public String deleteClientImage(@PathParam("clientId") final Long clientId) { + + validateAppuserClientsMapping(clientId); + return this.imagesApiResource.deleteClientImage(ClientApiConstants.clientEntityName, clientId); + + } @GET @Path("{clientId}/obligeedetails") ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services