Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Banking Application using Java8, Spring Boot, Spring Security and H2 DB
# Banking Application using Java 17, Spring Boot, Spring Security and H2 DB

RESTful API to simulate simple banking operations.

Expand Down Expand Up @@ -38,7 +38,7 @@ https://projectlombok.org/setup/eclipse

### Prerequisites

* Java 8
* Java 17
* Spring Tool Suite 4 or similar IDE
* [Maven](https://maven.apache.org/) - Dependency Management

Expand Down
58 changes: 31 additions & 27 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<version>3.3.13</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.coding.exercise</groupId>
Expand All @@ -15,7 +15,7 @@
<description>Bank App Spring Boot Project</description>

<properties>
<java.version>1.8</java.version>
<java.version>17</java.version>
</properties>

<dependencies>
Expand All @@ -41,31 +41,27 @@
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.2.224</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
Expand All @@ -79,6 +75,14 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
package com.coding.exercise.bankapp.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;

/**
*
* Spring security denied access to h2-console.
* This configuration will resolve 403 forbidden error when accessing h2-console.
* Spring security configuration for H2 console access.
* This configuration resolves 403 forbidden error when accessing h2-console.
*
* @author sbathina
*
*/
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@EnableWebSecurity
public class SecurityConfig {

@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity.authorizeRequests().antMatchers("/").permitAll().and()
.authorizeRequests().antMatchers("/h2-console/**").permitAll();

httpSecurity.csrf().disable();
httpSecurity.headers().frameOptions().disable();
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests(auth -> auth
.anyRequest().permitAll()
)
.csrf(csrf -> csrf.disable())
.headers(headers -> headers.frameOptions(frame -> frame.disable()));

return http.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,60 +17,34 @@
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<Object> 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<Object> 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<Object> 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<TransactionDetails> getTransactionByAccountNumber(@PathVariable Long accountNumber) {

return bankingService.findTransactionsByAccountNumber(accountNumber);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,71 +16,39 @@
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<CustomerDetails> 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<Object> 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<Object> 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<Object> deleteCustomer(@PathVariable Long customerNumber) {

return bankingService.deleteCustomer(customerNumber);
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/com/coding/exercise/bankapp/model/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import java.util.Date;
import java.util.UUID;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;

import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/coding/exercise/bankapp/model/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import java.util.UUID;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;

import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/coding/exercise/bankapp/model/BankInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import java.util.UUID;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToOne;

import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/coding/exercise/bankapp/model/Contact.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import java.util.UUID;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;

import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down
Loading