From 6409ed1ab99e4ede605d5670dee4be76a9bfb62b Mon Sep 17 00:00:00 2001 From: dartpopikyardo Date: Fri, 18 Mar 2016 17:33:28 +0300 Subject: [PATCH] - added GET /accounts/{accountId}/history endpoint to get transactions history by accountId - updated swagger schema --- .../accounts/AccountQueryController.java | 10 +- .../schemas/java-mt-demo-extended-api.json | 110 ++++++++++++++++++ 2 files changed, 119 insertions(+), 1 deletion(-) diff --git a/java-spring/accounts-query-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/queryside/accounts/AccountQueryController.java b/java-spring/accounts-query-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/queryside/accounts/AccountQueryController.java index 46a6434..888bf69 100644 --- a/java-spring/accounts-query-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/queryside/accounts/AccountQueryController.java +++ b/java-spring/accounts-query-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/queryside/accounts/AccountQueryController.java @@ -1,8 +1,10 @@ package net.chrisrichardson.eventstore.javaexamples.banking.web.queryside.accounts; import net.chrisrichardson.eventstore.EntityIdentifier; +import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts.AccountInfo; import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts.AccountNotFoundException; import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts.AccountQueryService; +import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts.AccountTransactionInfo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; @@ -22,7 +24,7 @@ public class AccountQueryController { this.accountInfoQueryService = accountInfoQueryService; } - @RequestMapping(value="/accounts/{accountId}", method = RequestMethod.GET) + @RequestMapping(value = "/accounts/{accountId}", method = RequestMethod.GET) public Observable get(@PathVariable String accountId) { return accountInfoQueryService.findByAccountId(new EntityIdentifier(accountId)) .map(accountInfo -> new GetAccountResponse(accountInfo.getId(), new BigDecimal(accountInfo.getBalance()), accountInfo.getTitle(), accountInfo.getDescription())); @@ -34,6 +36,12 @@ public class AccountQueryController { .map(accountInfoList -> accountInfoList.stream().map(accountInfo -> new GetAccountResponse(accountInfo.getId(), new BigDecimal(accountInfo.getBalance()), accountInfo.getTitle(), accountInfo.getDescription())).collect(Collectors.toList())); } + @RequestMapping(value = "/accounts/{accountId}/history", method = RequestMethod.GET) + public Observable> getTransactionsHistory(@PathVariable String accountId) { + return accountInfoQueryService.findByAccountId(new EntityIdentifier(accountId)) + .map(AccountInfo::getTransactions); + } + @ResponseStatus(value= HttpStatus.NOT_FOUND, reason="account not found") @ExceptionHandler(AccountNotFoundException.class) public void accountNotFound() { diff --git a/java-spring/schemas/java-mt-demo-extended-api.json b/java-spring/schemas/java-mt-demo-extended-api.json index 84fd542..56ee118 100644 --- a/java-spring/schemas/java-mt-demo-extended-api.json +++ b/java-spring/schemas/java-mt-demo-extended-api.json @@ -43,6 +43,39 @@ ], "paths": { "/accounts": { + "get": { + "tags": [ + "account-query-controller" + ], + "summary": "getAccountsForCustomer", + "operationId": "getAccountsForCustomerUsingGET", + "consumes": [ + "application/json" + ], + "produces": [ + "*/*" + ], + "parameters": [ + { + "name": "customerId", + "in": "query", + "description": "customerId", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/GetAccountResponse" + } + } + } + } + }, "post": { "tags": [ "account-controller" @@ -108,6 +141,41 @@ } } }, + "/accounts/{accountId}/history": { + "get": { + "tags": [ + "account-query-controller" + ], + "summary": "getTransactionsHistory", + "operationId": "getTransactionsHistoryUsingGET", + "consumes": [ + "application/json" + ], + "produces": [ + "*/*" + ], + "parameters": [ + { + "name": "accountId", + "in": "path", + "description": "accountId", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/AccountTransactionInfo" + } + } + } + } + } + }, "/customers": { "get": { "tags": [ @@ -312,6 +380,29 @@ } } } + }, + "/user": { + "get": { + "tags": [ + "auth-controller" + ], + "summary": "getCurrentUser", + "operationId": "getCurrentUserUsingGET", + "consumes": [ + "application/json" + ], + "produces": [ + "*/*" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/QuerySideCustomer" + } + } + } + } } }, "definitions": { @@ -385,6 +476,9 @@ }, "ToAccountInfo": { "properties": { + "description": { + "type": "string" + }, "id": { "type": "string" }, @@ -414,6 +508,12 @@ "balance": { "type": "number", "format": "double" + }, + "description": { + "type": "string" + }, + "title": { + "type": "string" } } }, @@ -422,6 +522,9 @@ "customerId": { "type": "string" }, + "description": { + "type": "string" + }, "initialBalance": { "type": "number", "format": "double" @@ -441,6 +544,13 @@ } } }, + "AccountTransactionInfo": {}, + "Map«string,ToAccountInfo»": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/ToAccountInfo" + } + }, "CreateMoneyTransferRequest": { "properties": { "amount": {