Skip to content

Commit

Permalink
bank details commited by by lakshmi
Browse files Browse the repository at this point in the history
  • Loading branch information
manisha-spt committed Sep 5, 2019
1 parent 011829a commit 3be8de3
Showing 16 changed files with 444 additions and 0 deletions.
115 changes: 115 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.hcl</groupId>
<artifactId>FavoriteBank</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>FavoriteBank</name>
<description>Demo project for Spring Boot</description>

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

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.6.0.1398</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.3</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.0</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
13 changes: 13 additions & 0 deletions src/main/java/com/hcl/IngAccountsApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.hcl;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class IngAccountsApplication {

public static void main(String[] args) {
SpringApplication.run(IngAccountsApplication.class, args);
}

}
40 changes: 40 additions & 0 deletions src/main/java/com/hcl/controller/BankController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.hcl.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import com.hcl.dto.BankDetailsDto;
import com.hcl.service.BankService;

/**
*
* @author Lakshmi
*/
@RestController
@CrossOrigin(origins = {"*","*/"},allowedHeaders = {"*","*/"})
public class BankController {

private static final Logger LOGGER = LoggerFactory.getLogger(BankController.class);

@Autowired
BankService bankService;

/**
* This method is intended for login of customer
* @param ibanNumber
* @return BankDetailsDto
*/
@GetMapping("/bank/{ibanNumber}")
public ResponseEntity<BankDetailsDto> bank(@PathVariable("ibanNumber") String ibanNumber){
LOGGER.debug("BankController login()");
BankDetailsDto bankDetailsDto = bankService.bank(ibanNumber);
return new ResponseEntity<>(bankDetailsDto,HttpStatus.OK);
}
}
15 changes: 15 additions & 0 deletions src/main/java/com/hcl/dto/BankDetailsDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.hcl.dto;

import java.io.Serializable;

import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
public class BankDetailsDto implements Serializable{

private static final long serialVersionUID = -5123563162222506239L;

private String bankName;
}
13 changes: 13 additions & 0 deletions src/main/java/com/hcl/dto/ResponseDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.hcl.dto;

import lombok.Getter;
import lombok.Setter;

@Setter @Getter
public class ResponseDto {

private String message;
private Integer statusCode;


}
21 changes: 21 additions & 0 deletions src/main/java/com/hcl/entity/Bank.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.hcl.entity;

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

import lombok.Getter;
import lombok.Setter;

@Entity
@Setter
@Getter
public class Bank {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer bankId;
private Integer bankCode;
private String bankName;

}
30 changes: 30 additions & 0 deletions src/main/java/com/hcl/exception/GlobalExceptionHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.hcl.exception;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

import com.hcl.dto.ResponseDto;



@ControllerAdvice
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {


@ExceptionHandler(IngBankException.class)
public ResponseEntity<ResponseDto> ecomorseExceptionHandler(IngBankException ex, WebRequest request) {

ResponseDto responseDto = new ResponseDto();
responseDto.setMessage(ex.getMessage());
responseDto.setStatusCode(401);

return new ResponseEntity<>(responseDto, HttpStatus.UNAUTHORIZED);

}


}
11 changes: 11 additions & 0 deletions src/main/java/com/hcl/exception/IngBankException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.hcl.exception;

public class IngBankException extends RuntimeException {

private static final long serialVersionUID = 1L;

public IngBankException(String message) {
super(message);
}

}
13 changes: 13 additions & 0 deletions src/main/java/com/hcl/repository/BankRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.hcl.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;

import com.hcl.entity.Bank;

public interface BankRepository extends JpaRepository<Bank, Integer> {

public List<Bank> findByBankCode(Integer bankCode);

}
7 changes: 7 additions & 0 deletions src/main/java/com/hcl/service/BankService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.hcl.service;

import com.hcl.dto.BankDetailsDto;

public interface BankService {
public BankDetailsDto bank(String ibanNumber);
}
57 changes: 57 additions & 0 deletions src/main/java/com/hcl/service/BankServiceImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.hcl.service;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hcl.dto.BankDetailsDto;
import com.hcl.entity.Bank;
import com.hcl.exception.IngBankException;
import com.hcl.repository.BankRepository;
import com.hcl.util.IngConstants;

/**
*
* @author Lakshmi
*/
@Service
public class BankServiceImpl implements BankService{

private static final Logger LOGGER = LoggerFactory.getLogger(BankServiceImpl.class);

@Autowired
BankRepository bankRepository;

/**
* This method is intended for bank details of customer
* @param ibanNumber
* @return BankDetailsDto
*/
public BankDetailsDto bank(String ibanNumber) {

LOGGER.debug("BankServiceImpl bank");
BankDetailsDto bankDetailsDto = new BankDetailsDto();
String result;
if(ibanNumber.length()>=20) {
result = ibanNumber.substring(4,8);
}
else {
throw new IngBankException(IngConstants.IBAN_NOT_VALID);
}
Integer bankCode = Integer.parseInt(result);
List<Bank> banks = bankRepository.findByBankCode(bankCode);
if(banks.isEmpty()) {
throw new IngBankException(IngConstants.BANK_NAME_NOT_FOUND);
}
else {
Bank bank = banks.get(0);
BeanUtils.copyProperties(bank, bankDetailsDto);
}
return bankDetailsDto;
}

}
23 changes: 23 additions & 0 deletions src/main/java/com/hcl/swaggerconfig/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.hcl.swaggerconfig;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/hcl/util/IngConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.hcl.util;

public class IngConstants {

private IngConstants() {

}
public static final String BANK_NAME_NOT_FOUND = "Bank name does not exists with the give bank code";
public static final String IBAN_NOT_VALID = "Please Enter 20 digits IBAN Number";
}
Loading

0 comments on commit 3be8de3

Please sign in to comment.