This is a simple API for user can search kost for room that have been added by owner. Also, user can ask about room availability using credit system.
Regular user will have 20 credit and premium user will have 40 credit per month.
- Regular user will be given 20 credit, premium user will be given 40 credit after register.
- Owner will have no credit.
- Owner can add more than 1 kost
- Search kost by several criteria: name, location, price
- Search kost sorted by: price
- Ask about room availability will reduce user credit by 5 point
- Owner API & ask room availability API need to have authentication
- Implement scheduled command to recharge user credit on every start of the month
- PHP 7.3.28
- Laravel 8.83.7
- Laravel Sanctum for Authentication
- Composer
- MySQL
This project also implement scheduled command to recharge user credit on every start of the month named monthly:recharge.
To run scheduling task you can use Crontab:
- Open crontab file
crontab -e
- Edit crontab file and add
0 0 1 * * cd /your-project-path && php artisan monthly:recharge >> /dev/null 2>&1
- Clone this Repo
git clone https://github.com/yogahilmi/mykost-api.git
- Copy file .env.example and rename it to .env
cp .env.example .env
-
Edit .env, fill DB setting and save
-
Migrate DB
php artisan migrate
- Run the project, to open port 8000
php artisan serve
Because the web server runs only one single-threaded process, so PHP applications will stall if a request is blocked.
- Run the project again with other terminal, to open port 8001 for API Call
php artisan serve
Owner Dashboard using for management kost with CRUD. Owner can view his kost, create, update and delete. To open Dashboard, please access below :
http://localhost:8000
You can login as owner or create new user.
Register User
POST /api/auth/register
Body:
{
"name": "Yoga Hilmi Tasanah",
"email": "[email protected]",
"password": "12345678",
"role": 0
}
Login User
POST /api/auth/login
Body:
{
"email": "[email protected]",
"password": "12345678"
}
Logout User
POST /api/auth/logout
Authorization: Bearer Token
Create New Kost
POST /api/kosts/create
Authorization: Bearer Token
Body:
{
"name" : "Kost Murah",
"location" : "Jakarta",
"price" : 950000,
"description" : "Kost dengan fasilitas lengkap di pusat kota"
}
Update Kost Detail
PUT /api/kost/edit/{id}
Authorization: Bearer Token
Body:
{
"name" : "Kost Murah",
"location" : "Jakarta",
"price" : 950000,
"description" : "Kost dengan fasilitas lengkap di pusat kota"
}
Delete Kost
DELETE /api/kost/edit/{id}
Authorization: Bearer Token
Show Kost Data By Owner
GET /api/kost/data/list
Authorization: Bearer Token
Show All Kost Data
GET /api/kost/
Show Kost Data By ID
GET /api/kost/{id}
Authorization: Bearer Token
Search Kost Data By Params
GET /api/kost/search
Authorization: Bearer Token
Body:
{
"name" : "",
"location" : "",
"price" :
}
Ask Availability
POST /api/availability/kost/{id}/ask
Authorization: Bearer Token
Give Availability
POST /api/availability/{id}/give
Authorization: Bearer Token
Body:
{
"is_available" : 1
}
Show Availability By ID
GET /api/availability/kost/{id}
Authorization: Bearer Token
Show All Availability
GET /api/availability
Authorization: Bearer Token