- Clone the project.
- Run composer install.
composer install
- Copy the .env.example file.
cp .env.example .env
- Add database credentials to the
.env
file. - For local development you can run the
DevelopmentSeeder
.- A test user will be created.
- Email: [email protected]
- Password: password
- 10 coaches will be created with faker data.
- A test user will be created.
php artisan db:seed --class=DevelopmentSeeder
We've installed Laravel Pint to help with code style. Currently, we use the default Laravel preset.
vendor/bin/pint
Current PHPStan level: 7
Run PHPStan:
vendor/bin/phpstan
Create a table named: livewall_assessment_test
. This can be changed in the .env file.
Run all tests:
vendor/bin/phpunit
Postman collection: Collection
You can make changes to the API configuration in the config/api.php
file.
Pagination
By default, responses are paginated with 5 items per page.
http://www.example.com/api/login
Form data
- Email: [email protected]
- Password: password
Response
{
"token": "bearer-token"
}
You need to be authenticated to use the rest of the API, the token must be included in the Authorization header as a Bearer token.
http://www.example.com/api/logout
Response
{
"message": "Logged out"
}
http://www.example.com/api/me
Response
{
"data": {
"id": 1,
"name": "Development user",
"email": "[email protected]",
"appointments": [
{
"id": 1,
"date": "2024-06-24T00:00:00.000000Z",
"coach": {
"id": 1,
"name": "Maiya Boehm",
"email": "[email protected]",
"created_at": "2024-06-24T08:00:34.000000Z",
"updated_at": "2024-06-24T08:00:34.000000Z"
},
"start_time": "08:30:00",
"end_time": "09:30:00",
"created_at": "2024-06-24T08:02:21.000000Z",
"updated_at": "2024-06-24T08:02:21.000000Z"
},
{
"id": 2,
"date": "2024-06-24T00:00:00.000000Z",
"coach": {
"id": 1,
"name": "Maiya Boehm",
"email": "[email protected]",
"created_at": "2024-06-24T08:00:34.000000Z",
"updated_at": "2024-06-24T08:00:34.000000Z"
},
"start_time": "09:45:00",
"end_time": "10:30:00",
"created_at": "2024-06-24T08:16:23.000000Z",
"updated_at": "2024-06-24T08:16:23.000000Z"
}
],
"created_at": "2024-06-24T08:00:34.000000Z",
"updated_at": "2024-06-24T08:00:34.000000Z"
}
}
http://www.example.com/api/coaches
By default, the current week is used to show the schedule of the coaches. If you want to change this you can
include a start_date
and end_date
to view a different week.
Form data (optional)
- start_date: 2024-06-17
- end_date: 2024-06-23
Response
By default, the response will be paginated with 5 items per page. To keep this readme short the example will only show one record.
{
"data": [
{
"id": 1,
"name": "Maiya Boehm",
"email": "[email protected]",
"schedule": [
{
"id": 1,
"coach_id": 1,
"day": 1,
"day_name": "Monday",
"start_time": "08:30:00",
"end_time": "17:00:00",
"is_available": true,
"appointments": [
{
"id": 1,
"date": "2024-06-24T00:00:00.000000Z",
"start_time": "08:30:00",
"end_time": "09:30:00",
"created_at": "2024-06-24T08:02:21.000000Z",
"updated_at": "2024-06-24T08:02:21.000000Z"
}
],
"created_at": "2024-06-24T08:00:34.000000Z",
"updated_at": "2024-06-24T08:00:34.000000Z"
},
{
"id": 2,
"coach_id": 1,
"day": 2,
"day_name": "Tuesday",
"start_time": "08:30:00",
"end_time": "17:00:00",
"is_available": true,
"appointments": [],
"created_at": "2024-06-24T08:00:34.000000Z",
"updated_at": "2024-06-24T08:00:34.000000Z"
},
{
"id": 3,
"coach_id": 1,
"day": 3,
"day_name": "Wednesday",
"start_time": "08:30:00",
"end_time": "17:00:00",
"is_available": true,
"appointments": [],
"created_at": "2024-06-24T08:00:34.000000Z",
"updated_at": "2024-06-24T08:00:34.000000Z"
},
{
"id": 4,
"coach_id": 1,
"day": 4,
"day_name": "Thursday",
"start_time": "08:30:00",
"end_time": "17:00:00",
"is_available": true,
"appointments": [],
"created_at": "2024-06-24T08:00:34.000000Z",
"updated_at": "2024-06-24T08:00:34.000000Z"
},
{
"id": 5,
"coach_id": 1,
"day": 5,
"day_name": "Friday",
"start_time": "08:30:00",
"end_time": "17:00:00",
"is_available": true,
"appointments": [],
"created_at": "2024-06-24T08:00:34.000000Z",
"updated_at": "2024-06-24T08:00:34.000000Z"
},
{
"id": 6,
"coach_id": 1,
"day": 6,
"day_name": "Saturday",
"start_time": null,
"end_time": null,
"is_available": false,
"appointments": [],
"created_at": "2024-06-24T08:00:34.000000Z",
"updated_at": "2024-06-24T08:00:34.000000Z"
},
{
"id": 7,
"coach_id": 1,
"day": 0,
"day_name": "Sunday",
"start_time": null,
"end_time": null,
"is_available": false,
"appointments": [],
"created_at": "2024-06-24T08:00:34.000000Z",
"updated_at": "2024-06-24T08:00:34.000000Z"
}
],
"created_at": "2024-06-24T08:00:34.000000Z",
"updated_at": "2024-06-24T08:00:34.000000Z"
}
],
"links": {
"first": "http://livewall-assessment.test/api/coaches?page=1",
"last": "http://livewall-assessment.test/api/coaches?page=10",
"prev": null,
"next": "http://livewall-assessment.test/api/coaches?page=2"
},
"meta": {
"current_page": 1,
"from": 1,
"last_page": 10,
"links": [
{
"url": null,
"label": "« Previous",
"active": false
},
{
"url": "http://livewall-assessment.test/api/coaches?page=1",
"label": "1",
"active": true
},
{
"url": "http://livewall-assessment.test/api/coaches?page=2",
"label": "2",
"active": false
},
{
"url": "http://livewall-assessment.test/api/coaches?page=3",
"label": "3",
"active": false
},
{
"url": "http://livewall-assessment.test/api/coaches?page=4",
"label": "4",
"active": false
},
{
"url": "http://livewall-assessment.test/api/coaches?page=5",
"label": "5",
"active": false
},
{
"url": "http://livewall-assessment.test/api/coaches?page=6",
"label": "6",
"active": false
},
{
"url": "http://livewall-assessment.test/api/coaches?page=7",
"label": "7",
"active": false
},
{
"url": "http://livewall-assessment.test/api/coaches?page=8",
"label": "8",
"active": false
},
{
"url": "http://livewall-assessment.test/api/coaches?page=9",
"label": "9",
"active": false
},
{
"url": "http://livewall-assessment.test/api/coaches?page=10",
"label": "10",
"active": false
},
{
"url": "http://livewall-assessment.test/api/coaches?page=2",
"label": "Next »",
"active": false
}
],
"path": "http://livewall-assessment.test/api/coaches",
"per_page": 1,
"to": 1,
"total": 10
}
}
http://www.example.com/api/coaches/{coach_id}
By default, the current week is used to show the schedule of the coaches. If you want to change this you can
include a start_date
and end_date
to view a different week.
Form data (optional)
- start_date: 2024-06-17
- end_date: 2024-06-23
Response
{
"data": {
"id": 1,
"name": "Maiya Boehm",
"email": "[email protected]",
"schedule": [
{
"id": 1,
"coach_id": 1,
"day": 1,
"day_name": "Monday",
"start_time": "08:30:00",
"end_time": "17:00:00",
"is_available": true,
"appointments": [
{
"id": 1,
"date": "2024-06-24T00:00:00.000000Z",
"start_time": "08:30:00",
"end_time": "09:30:00",
"created_at": "2024-06-24T08:02:21.000000Z",
"updated_at": "2024-06-24T08:02:21.000000Z"
}
],
"created_at": "2024-06-24T08:00:34.000000Z",
"updated_at": "2024-06-24T08:00:34.000000Z"
},
{
"id": 2,
"coach_id": 1,
"day": 2,
"day_name": "Tuesday",
"start_time": "08:30:00",
"end_time": "17:00:00",
"is_available": true,
"appointments": [],
"created_at": "2024-06-24T08:00:34.000000Z",
"updated_at": "2024-06-24T08:00:34.000000Z"
},
{
"id": 3,
"coach_id": 1,
"day": 3,
"day_name": "Wednesday",
"start_time": "08:30:00",
"end_time": "17:00:00",
"is_available": true,
"appointments": [],
"created_at": "2024-06-24T08:00:34.000000Z",
"updated_at": "2024-06-24T08:00:34.000000Z"
},
{
"id": 4,
"coach_id": 1,
"day": 4,
"day_name": "Thursday",
"start_time": "08:30:00",
"end_time": "17:00:00",
"is_available": true,
"appointments": [],
"created_at": "2024-06-24T08:00:34.000000Z",
"updated_at": "2024-06-24T08:00:34.000000Z"
},
{
"id": 5,
"coach_id": 1,
"day": 5,
"day_name": "Friday",
"start_time": "08:30:00",
"end_time": "17:00:00",
"is_available": true,
"appointments": [],
"created_at": "2024-06-24T08:00:34.000000Z",
"updated_at": "2024-06-24T08:00:34.000000Z"
},
{
"id": 6,
"coach_id": 1,
"day": 6,
"day_name": "Saturday",
"start_time": null,
"end_time": null,
"is_available": false,
"appointments": [],
"created_at": "2024-06-24T08:00:34.000000Z",
"updated_at": "2024-06-24T08:00:34.000000Z"
},
{
"id": 7,
"coach_id": 1,
"day": 0,
"day_name": "Sunday",
"start_time": null,
"end_time": null,
"is_available": false,
"appointments": [],
"created_at": "2024-06-24T08:00:34.000000Z",
"updated_at": "2024-06-24T08:00:34.000000Z"
}
],
"created_at": "2024-06-24T08:00:34.000000Z",
"updated_at": "2024-06-24T08:00:34.000000Z"
}
}
http://www.example.com/api/appointments
Form data
- coach_id: 1
- date: 2024-06-24
- start_time: 08:30:00
- end_time: 09:00:00
Coaches must be available on the given date, and cannot have any appointments planned on the given date.
Validation error when the coach is not available on the given date.
{
"message": "The coach is not available on the given date or time.",
"errors": {
"coach_id": [
"The coach is not available on the given date or time."
]
}
}
Validation error when the coach already has an appointment on the given time.
{
"message": "The coach is not available at the given time.",
"errors": {
"coach_id": [
"The coach is not available at the given time."
]
}
}
Response
An email will be sent to the user and the coach confirming the appointment.
{
"data": {
"id": 2,
"date": "2024-06-24T00:00:00.000000Z",
"user": {
"id": 1,
"name": "Development user",
"email": "[email protected]",
"created_at": "2024-06-24T08:00:34.000000Z",
"updated_at": "2024-06-24T08:00:34.000000Z"
},
"coach": {
"id": 1,
"name": "Maiya Boehm",
"email": "[email protected]",
"created_at": "2024-06-24T08:00:34.000000Z",
"updated_at": "2024-06-24T08:00:34.000000Z"
},
"start_time": "09:45:00",
"end_time": "10:30:00",
"created_at": "2024-06-24T08:16:23.000000Z",
"updated_at": "2024-06-24T08:16:23.000000Z"
}
}