Digital Wallet Rest API
- Download and install maven from offical site.
- Download and install docker from offical site.
- Download and install docker-compose from offical site.
- Go to project directory and build appllication and create a .jar file with maven
mvn clean install - Run application with docker compose
docker-compose -f docker-compose-test.yml up- Spring Boot for create web service
- PostgreSQL store data on database
- Flyway update database and manage migrations
- Docker build and run container applications
- JsonWebToken generate JWT token, manage authorization and authentication
- Resilience4j Rate Limit for specific endpoints
- Actuator Application Health Check
- JaCoCo show test results
Application has 2 profile as test and prod. Actually they have same variables but it can changable by the profile.
All rules fallowed in case except add role column to customer(for authorization) and password column (for authentication)
- Role: id, role
- Customer: id, name, surname, TCKN, password, role_id
- Wallet: id, customer id, wallet name, currency, active for shopping, active for withdraw, balance, usable balance.
- Transaction: id, wallet id, amount, type, opposite party type, opposite party, status.
- Type is either DEPOSIT or WITHDRAW
- Opposite Party Type is either IBAN or PAYMENT
- Status is PENDING, APPROVED or DENIED
- Role is EMPLOYEE or CUSTOMER
When application starts, application add dummy customer and role with flyway. Customer has 2 role as EMPLOYEE and CUSTOMER. If you want do operation for another customer, you should have EMPLOYEE role.
INSERT INTO role (id, role) VALUES (nextval('role_seq'), 'CUSTOMER');
INSERT INTO customer (id, name, surname, tckn, password, role_id) VALUES (nextval('customer_seq'), 'John', 'Doe', '85659108642', '1234', '1');
INSERT INTO role (id, role) VALUES (nextval('role_seq'), 'EMPLOYEE');
INSERT INTO customer (id, name, surname, tckn, password, role_id) VALUES (nextval('customer_seq'), 'Max', 'Mustermann', '22197380642', '1234', '2');
JWT token used for authentication and authorization. Token keeps customer Tckn and roles. Only login can call without JWT token, atherwise you will see Forbidden error. We have the swageer and swagger updated for this token, when you open the swagger you will see Authorize button on right top, you can paste the token and login, it will add token to header automatically.
Application has some input validation like wallet_id should be UUID, balance should be digit format(because it is bigDecimal), not null fields etc. If input fieled validation is fail, you will see BAD REQUEST error. When you open request detail on Swagger-UI, you will see input field validations.
Transaction operations can only be completed from the EMPLOYEE role. Customer has not authorization on transaction operations.
If application has error when deploy with docker, it will try again because restart-policy is active.
If you want see test result with JaCoCo, after maven build command, you can see .html file in /target/site/jacoco folder. Test coverage is %90
If you want see application health status, you can go to Spring-Actuator URL
Application has Swagger-UI integration, You can see endpoints on Swagger-UI. Open Swagger-UI with
http://localhost:8080/swagger-ui/index.html#
Application has JWT authentication and authorization. So we should generate JWT token, we can login with login credentials.
POST /customers/login
It will return generated JWT token
POST /wallets/customer/{customerId}
It will create a new wallet by customer Id.
GET /wallets/customer/{customerId}
Get all wallets by customer id
GET /wallets/customer/{customerId}/currency/{currency}
Get all wallets by customer id and wallet currency
PUT /wallets/deposit
Deposit from wallet and return updated wallet.
When update wallet, it will create transaction automatically. Amount more than 1000 should be saved with status PENDING, less than this amount should be saved with status APPROVED.
Approved deposits should be reflected to balance and usable balance of the wallet. Pending deposits should only be reflected to balance of the wallet.
PUT /wallets/withdraw
Deposit from wallet and return updated wallet.
Wallet settings for shopping and withdraw will control, if settings not OK, it will return error.
Amount more than 1000 should be saved with status PENDING, less than this amount should be saved with status APPROVED.
Approved withdraws should be reflected to balance and usable balance of the wallet. Pending withdraws should only be reflected to usable balance of the wallet.
If not enough balance in wallet, application will return error.
GET /transactions/wallet/{walletId}
Only EMPLOYEE role can do this operation. List transactions by the wallet id.
PUT /transactions
Only EMPLOYEE role can do this operation. Update transaction by transactionId and status. If transaction is not PENDING status, application will return error.
If transaction will complete, related wallet balance or useableBalance will update by transaction status and type.