diff --git a/README.md b/README.md index 991b41a..409ab80 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Banking Application using Java8, Spring Boot, Spring Security and H2 DB +# Banking Application using Java 11, Spring Boot, Spring Security and H2 DB RESTful API to simulate simple banking operations. @@ -17,7 +17,35 @@ RESTful API to simulate simple banking operations. git clone https://github.com/sbathina/BankApp ``` -2. Enable Lombok support on your IDE +2. Ensure Java 11 JDK is installed + +Download and install Java 11 JDK from: +``` +https://adoptium.net/ (recommended) +or +https://www.oracle.com/java/technologies/downloads/#java11 + +``` + +Set the JAVA_HOME environment variable: +``` +# Linux/macOS +export JAVA_HOME=/path/to/java-11-jdk +export PATH=$JAVA_HOME/bin:$PATH + +# Windows +set JAVA_HOME=C:\path\to\java-11-jdk +set PATH=%JAVA_HOME%\bin;%PATH% + +``` + +Verify Java version: +``` +java -version + +``` + +3. Enable Lombok support on your IDE Refer to the following link for instructions: @@ -25,7 +53,7 @@ Refer to the following link for instructions: https://projectlombok.org/setup/eclipse ``` -3. Open IDE of your choice and Import as existing maven project in your workspace +4. Open IDE of your choice and Import as existing maven project in your workspace ``` - Import existing maven project @@ -33,14 +61,14 @@ https://projectlombok.org/setup/eclipse - If using STS, Run As Spring Boot App ``` -4. Default port for the api is 8989 +5. Default port for the api is 8989 ### Prerequisites -* Java 8 +* Java 11 JDK * Spring Tool Suite 4 or similar IDE -* [Maven](https://maven.apache.org/) - Dependency Management +* [Maven](https://maven.apache.org/) 3.6+ - Dependency Management ### Maven Dependencies @@ -52,16 +80,15 @@ spring-boot-starter-web spring-boot-devtools h2 - Inmemory database lombok - to reduce boilerplate code -springfox-swagger2 -springfox-swagger-ui +springdoc-openapi-ui - OpenAPI 3.0 documentation spring-boot-starter-test spring-security-test ``` -## Swagger +## API Documentation -Please find the Rest API documentation in the below url +The application uses SpringDoc OpenAPI 3.0 for API documentation. Access the interactive API documentation at: ``` http://localhost:8989/bank-api/swagger-ui.html diff --git a/pom.xml b/pom.xml index 36931d2..4b1bbb0 100644 --- a/pom.xml +++ b/pom.xml @@ -5,8 +5,8 @@ org.springframework.boot spring-boot-starter-parent - 2.1.4.RELEASE - + 2.7.18 + com.coding.exercise bank-app @@ -15,7 +15,7 @@ Bank App Spring Boot Project - 1.8 + 11 @@ -52,15 +52,10 @@ true - io.springfox - springfox-swagger2 - 2.9.2 + org.springdoc + springdoc-openapi-ui + 1.6.15 - - io.springfox - springfox-swagger-ui - 2.10.0 - org.springframework.boot spring-boot-starter-test diff --git a/src/main/java/com/coding/exercise/bankapp/config/ApplicationConfig.java b/src/main/java/com/coding/exercise/bankapp/config/ApplicationConfig.java index 67845f3..0df0ffe 100644 --- a/src/main/java/com/coding/exercise/bankapp/config/ApplicationConfig.java +++ b/src/main/java/com/coding/exercise/bankapp/config/ApplicationConfig.java @@ -3,29 +3,18 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import springfox.documentation.builders.ApiInfoBuilder; -import springfox.documentation.builders.PathSelectors; -import springfox.documentation.service.ApiInfo; -import springfox.documentation.spi.DocumentationType; -import springfox.documentation.spring.web.plugins.Docket; -import springfox.documentation.swagger2.annotations.EnableSwagger2; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Info; @Configuration -@EnableSwagger2 public class ApplicationConfig { @Bean - public Docket api() { - return new Docket(DocumentationType.SWAGGER_2) - .apiInfo(apiInfo()) - .select() - .paths(PathSelectors.any()) - .build(); - } - - private ApiInfo apiInfo() { - return new ApiInfoBuilder().title("BANKING APPLICATION REST API") - .description("API for Banking Application.") - .version("1.0.0").build(); + public OpenAPI customOpenAPI() { + return new OpenAPI() + .info(new Info() + .title("BANKING APPLICATION REST API") + .description("API for Banking Application.") + .version("1.0.0")); } } diff --git a/src/main/java/com/coding/exercise/bankapp/controller/AccountController.java b/src/main/java/com/coding/exercise/bankapp/controller/AccountController.java index b35f625..6636d01 100644 --- a/src/main/java/com/coding/exercise/bankapp/controller/AccountController.java +++ b/src/main/java/com/coding/exercise/bankapp/controller/AccountController.java @@ -17,62 +17,32 @@ import com.coding.exercise.bankapp.domain.TransferDetails; import com.coding.exercise.bankapp.service.BankingServiceImpl; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; - @RestController @RequestMapping("accounts") -@Api(tags = { "Accounts and Transactions REST endpoints" }) public class AccountController { @Autowired private BankingServiceImpl bankingService; @GetMapping(path = "/{accountNumber}") - @ApiOperation(value = "Get account details", notes = "Find account details by account number") - @ApiResponses(value = { @ApiResponse(code = 200, message = "Success"), - @ApiResponse(code = 400, message = "Bad Request"), - @ApiResponse(code = 500, message = "Internal Server Error") }) - public ResponseEntity getByAccountNumber(@PathVariable Long accountNumber) { - return bankingService.findByAccountNumber(accountNumber); } @PostMapping(path = "/add/{customerNumber}") - @ApiOperation(value = "Add a new account", notes = "Create an new account for existing customer.") - @ApiResponses(value = { @ApiResponse(code = 200, message = "Success"), - @ApiResponse(code = 400, message = "Bad Request"), - @ApiResponse(code = 500, message = "Internal Server Error") }) - public ResponseEntity addNewAccount(@RequestBody AccountInformation accountInformation, @PathVariable Long customerNumber) { - return bankingService.addNewAccount(accountInformation, customerNumber); } @PutMapping(path = "/transfer/{customerNumber}") - @ApiOperation(value = "Transfer funds between accounts", notes = "Transfer funds between accounts.") - @ApiResponses(value = { @ApiResponse(code = 200, message = "Success", response = Object.class), - @ApiResponse(code = 400, message = "Bad Request"), - @ApiResponse(code = 500, message = "Internal Server Error") }) - public ResponseEntity transferDetails(@RequestBody TransferDetails transferDetails, @PathVariable Long customerNumber) { - return bankingService.transferDetails(transferDetails, customerNumber); } @GetMapping(path = "/transactions/{accountNumber}") - @ApiOperation(value = "Get all transactions", notes = "Get all Transactions by account number") - @ApiResponses(value = { @ApiResponse(code = 200, message = "Success"), - @ApiResponse(code = 400, message = "Bad Request"), - @ApiResponse(code = 500, message = "Internal Server Error") }) - public List getTransactionByAccountNumber(@PathVariable Long accountNumber) { - return bankingService.findTransactionsByAccountNumber(accountNumber); } } diff --git a/src/main/java/com/coding/exercise/bankapp/controller/CustomerController.java b/src/main/java/com/coding/exercise/bankapp/controller/CustomerController.java index 58e9044..72f6d1c 100644 --- a/src/main/java/com/coding/exercise/bankapp/controller/CustomerController.java +++ b/src/main/java/com/coding/exercise/bankapp/controller/CustomerController.java @@ -16,73 +16,36 @@ import com.coding.exercise.bankapp.domain.CustomerDetails; import com.coding.exercise.bankapp.service.BankingServiceImpl; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; - @RestController @RequestMapping("customers") -@Api(tags = { "Customer REST endpoints" }) public class CustomerController { @Autowired private BankingServiceImpl bankingService; @GetMapping(path = "/all") - @ApiOperation(value = "Find all customers", notes = "Gets details of all the customers") - @ApiResponses(value = { @ApiResponse(code = 200, message = "Success"), - @ApiResponse(code = 400, message = "Bad Request"), - @ApiResponse(code = 500, message = "Internal Server Error") }) - public List getAllCustomers() { - return bankingService.findAll(); } @PostMapping(path = "/add") - @ApiOperation(value = "Add a Customer", notes = "Add customer and create an account") - @ApiResponses(value = { @ApiResponse(code = 200, message = "Success"), - @ApiResponse(code = 400, message = "Bad Request"), - @ApiResponse(code = 500, message = "Internal Server Error") }) - public ResponseEntity addCustomer(@RequestBody CustomerDetails customer) { - return bankingService.addCustomer(customer); } @GetMapping(path = "/{customerNumber}") - @ApiOperation(value = "Get customer details", notes = "Get Customer details by customer number.") - @ApiResponses(value = { - @ApiResponse(code = 200, message = "Success", response = CustomerDetails.class, responseContainer = "Object"), - @ApiResponse(code = 400, message = "Bad Request"), - @ApiResponse(code = 500, message = "Internal Server Error") }) - public CustomerDetails getCustomer(@PathVariable Long customerNumber) { - return bankingService.findByCustomerNumber(customerNumber); } @PutMapping(path = "/{customerNumber}") - @ApiOperation(value = "Update customer", notes = "Update customer and any other account information associated with him.") - @ApiResponses(value = { @ApiResponse(code = 200, message = "Success", response = Object.class), - @ApiResponse(code = 400, message = "Bad Request"), - @ApiResponse(code = 500, message = "Internal Server Error") }) - public ResponseEntity updateCustomer(@RequestBody CustomerDetails customerDetails, @PathVariable Long customerNumber) { - return bankingService.updateCustomer(customerDetails, customerNumber); } @DeleteMapping(path = "/{customerNumber}") - @ApiOperation(value = "Delete customer and related accounts", notes = "Delete customer and all accounts associated with him.") - @ApiResponses(value = { @ApiResponse(code = 200, message = "Success", response = Object.class), - @ApiResponse(code = 400, message = "Bad Request"), - @ApiResponse(code = 500, message = "Internal Server Error") }) - public ResponseEntity deleteCustomer(@PathVariable Long customerNumber) { - return bankingService.deleteCustomer(customerNumber); } diff --git a/src/test/java/com/coding/exercise/bankapp/BankingApplicationTests.java b/src/test/java/com/coding/exercise/bankapp/BankingApplicationTests.java index 803c91d..6b76be1 100644 --- a/src/test/java/com/coding/exercise/bankapp/BankingApplicationTests.java +++ b/src/test/java/com/coding/exercise/bankapp/BankingApplicationTests.java @@ -1,11 +1,8 @@ package com.coding.exercise.bankapp; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringRunner.class) @SpringBootTest public class BankingApplicationTests {