From c41492780391dbfaa452c3d835c67f3f61ef2e6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Antonio=20C=C3=B3rdoba=20G=C3=B3mez?= Date: Fri, 8 Jan 2021 13:18:41 +0100 Subject: [PATCH] #15 #18 POST fund. Add fund as customer user --- .../pepe/rest/resteasyjackson/FundResource.kt | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/funds/src/main/kotlin/com/pepe/rest/resteasyjackson/FundResource.kt b/funds/src/main/kotlin/com/pepe/rest/resteasyjackson/FundResource.kt index 0e982e34b..0be5ec1ba 100644 --- a/funds/src/main/kotlin/com/pepe/rest/resteasyjackson/FundResource.kt +++ b/funds/src/main/kotlin/com/pepe/rest/resteasyjackson/FundResource.kt @@ -31,6 +31,12 @@ class FundService { return "hello $name" } + fun addFund(f: Fund): Boolean{ + return funds.add(f) + + } + + fun getFunds(): Set{ return funds } @@ -41,6 +47,7 @@ class FundService { @Path("/") class FundResource { + @Inject @field: Default lateinit var service: FundService @@ -55,4 +62,21 @@ class FundResource { return service.getFunds() } + // Creates one funds + @POST + @Path("/funds") + fun add(f: Fund): Response { + val result = service.addFund(f) + if(result){ + println("POST -> Fund was created") + var m = Message("Created", "Fund was created"); + return Response.status(Response.Status.ACCEPTED).entity(m).build(); + } + println("POST -> Fund was NOT created") + var m = Message("Not Created", "Fund was not created"); + return Response.status(Response.Status.BAD_REQUEST).entity(m).build(); + + } + + } \ No newline at end of file