Backend service which uses Spring boot framework and Inmemory database (h2) to find permutation for a given number or a list of numbers
- Java
- Spring boot
- JPA
- H2 database (in memory database)
- Docker
- Spock for Unit testing
- SonarLint and PWD for code quality analysis
- Swagger for documentation
- Install Maven and set the environmental variables
- Clone the project
- Import as a maven project in IDE (used Eclipse)
- Do right click project -> maven -> download sources -> to download dependencies in pom.xml
- Run as Java Application (or) without importing porject in IDE, do mvn spring-boot:run from location where pom.xml is present. This will start the service
- Web Service will run in localhost on port 8080
API endpoints:
- GET method - /permutation/permutations/{input} - input param -> For a given input Integer, permutaions are calcualted and response is retruned as a JSON response.Input should be an Integer, else error resposne will be returned
- POST method - /permutation/permutations/list - for given set of integer values, permuataions are calculated and response is returned. Input values are given as payload as part of post request.
Unit test cases:
- Spock teesting using Groovy
- Run as a junit test application to get the result based on test cases written
- Attached test coverage report with 100% code test coverage
Swagger documentaion:
- Run web server
- Swagger api ui will run on localhost:8080/swwagger-ui.html
- Run mvn clean install and generate the jar for permutation service
- Install docker and docker compose
- Create the docker file -sample docker file is uploaded
- Create image using command docker build -t in the directory where docker file is present
- Execute command docker-compose up, this will take images from docker.yml file and run all the images which is mentioned in that.Docker compose will run all the services paralley thereby reducing the effort to run each service seperately
- Once application is started, it can be accessed in the ip where docker is running
Working:
- Once application is started, and when user hits on api to get permutation results, internally it will check whether Input is already processed and stored in database
- If entry present in db, results are taken from db and response is returned
- If entry is not present, it will process further to find permutation list and store the entry in db
- Incase of exceptions, error resposne will be thrown with success as false and with reason
Database architecture:
Two tables, Input table which stores input number and OutputVal table which has Input ID as foreigh key present and combination column which stores result of permutation. Basically it is an one-many relationship, wherein each input will be having multiple permutaions.