Documentation for the framework can be found on the Lumen website.
- Build a simple API that allows to handle user loans: users, loans, and repayments
- The loan term calculates as default is year.
- The payment will pay for loan by period is 12 months(1 year).
- The interest rate can be dynamic: year, month, quarter.
- The user can create many loans and make repayments by each period.
- Requirement:
- PHP >= 7.0.1
- Mysql >= 5.6
- Postman >= 7.1
- Setup:
- Git clone: [email protected]:kieugol/mini-aspire-lumen5.git
- Run composer: composer install
- Change db configuration at .env file
DB_HOST=localhost DB_PORT=3306 DB_DATABASE=test DB_USERNAME=root DB_PASSWORD=root
- Run migration: php artisan migrate --force
- Setup apache, nginx to use local to run source code can refer here: Lumen Installation
- Test api domain: https://krol.diqit.io/api/v1
- Can import collection mini-aspire-project-api.postman_collection.json to test directly on Postman
- Using post method: https://krol.diqit.io/api/v1/user
- Sample params:
{ "name": "Rol Kieu", "email": "[email protected]", "birthday": "1990-09-22", "phone": "09174747775", "address": "HCM City" }
- Sample output:
{ "code": 200, "message": "Created successfully.", "data": { "name": "Rol Kieu", "email": "[email protected]", "birthday": "1990-09-22", "phone": "09174747775", "address": "HCM City", "updated_at": "2020-03-10 03:37:13", "created_at": "2020-03-10 03:37:13", "id": 2 } }
- Sample output:
- Using get method: https://krol.diqit.io/api/v1/user?page=1&limit=10
- Sample params:
- page: 1,2,3
- limit: 10,20,30..500
- Using post method: https://krol.diqit.io/api/v1/loan
- Sample params:
{ "user": 1, "repayment_frequency": 2, "loan_term": 2, "interest_rate": 6, "amount": 10000 }
- user: go to api [Get list user](#get-list-user) - repayment_frequency: go to api [Get all repayment frequency](#get-all-user)
- Sample output:
{ "code": 200, "message": "Created successfully.", "data": { "id": 1 } }
- Using get method: https://krol.diqit.io/api/v1/loan?page=1&limit=10
- Sample params:
- page: 1,2,3
- limit: 10,20,30..500
- Sample output:
{
"code": 200,
"message": "",
"data": {
"page": 1,
"length": 10,
"total_record": 1,
"total_page": 1,
"rows": [
{
"id": 1,
"user_id": 1,
"term": 2,
"start_date": "2020-03-09",
"end_date": "2022-03-09",
"repayment_frequency": "Quarter",
"Loan_status": "Paying",
"interest_rate": 6,
"amount": 10000,
"payment_amount": 12500,
"interest_amount": 2500,
"remarks": "",
"created_at": "2020-03-09 16:13:17",
"updated_at": "2020-03-09 16:14:36"
}
]
}
}
- Using get method: https://krol.diqit.io/api/v1/loan/by-user/{user_id}
- Sample params:
- user_id: 1,2,3
- limit: 10,20,30..500
- Sample output:
{
"code": 200,
"message": "",
"data": [
{
"id": 1,
"user_id": 1,
"term": 2,
"start_date": "2020-03-09",
"end_date": "2022-03-09",
"repayment_frequency": "Quarter",
"Loan_status": "Paying",
"interest_rate": 6,
"amount": 10000,
"payment_amount": 12500,
"interest_amount": 2500,
"remarks": "",
"created_at": "2020-03-09 16:13:17",
"updated_at": "2020-03-09 16:14:36"
}
]
}
- Using get method: https://krol.diqit.io/api/v1/loan-payment/repayment
- Sample params:
- user: the user id
- loan: loan id belongs to user
- payment_date: the period need to pay
- amount: the money need to pay for 1 period
{ "user": 1, "loan": 1, "payment_date": "2020-3-01", "amount": 880 }
- Sample output:
{
"code": 200,
"message": "Your payment updated successfully.",
"data": ""
}
- Using get method: https://krol.diqit.io/api/v1/loan-payment/by-loan/{loan_id}
- Sample params:
- loan_id: 1,2,3 // get from list loan
- is_active: [0,1] // 0 => the payment by period still not paid, 1=> already paid
- Sample output:
{
"code": 200,
"message": "",
"data": [
{
"id": 2,
"loan_id": 1,
"due_date": "2020-04-30",
"amount": 608.34,
"principal_amount": 416.67,
"interest_amount": 191.67,
"balance": 9166.66,
"remarks": "",
"is_active": 0,
"created_by": 0,
"updated_by": 0,
"created_at": "2020-03-09 16:13:17",
"updated_at": "2020-03-09 16:13:17"
}
]
}