The Casino Loyalty API is a RESTful API that allows users to create and manage loyalty points for their customers.
To install the Casino Loyalty API, please follow these steps:
- Clone the repository to your local machine.
git clone https://github.com/your_username/casino_loyalty.git
- Install dependencies using Composer.
composer install
-
Create the database structure. The Schema files are located in db_structure
-
Configure the database settings in the src/config.php file.
DB::$user = 'apiUser';
DB::$password = 'Password123#@!';
DB::$dbName = 'loyalty_program';
- Start the server.
composer start
All tests are located within testRoutes.php. To run the tests use the following command
./vendor/bin/phpunit --verbose tests/testRoutes.php
Tests will truncate the table as a way to test correctly.
All endpoints require sending the X-Api-Key
header with the value abc123
to work.
This endpoint retrieves a list of users with pagination support.
page
(optional): the page number to retrieve. Defaults to 1.per_page
(optional): the number of users to retrieve per page. Defaults to 10.
Returns a JSON array of user objects with the following properties:
id
(integer): the unique ID of the username
(string): the name of the useremail
(string): the email address of the userpoints
(integer): the number of loyalty points the user has accumulated
GET /users?page=2&per_page=20
HTTP/1.1 200 OK Content-Type: application/json
[
{
"id": 21,
"name": "John Doe",
"email": "[email protected]",
"points": 3500
},
{
"id": 22,
"name": "Jane Doe",
"email": "[email protected]",
"points": 1200
},
...
]
This endpoint creates a new user with the provided name and email.
name
(required): the name of the useremail
(required): the email address of the user
Returns a JSON object with the following properties:
id
(integer): the unique ID of the new username
(string): the name of the new useremail
(string): the email address of the new userpoints
(integer): the initial number of loyalty points the new user has accumulated (always 0)
POST /users Content-Type: application/x-www-form-urlencoded name=John+Doe&[email protected]
POST /users
Content-Type: application/x-www-form-urlencoded
name=John+Doe&[email protected]
{
"id": 23,
"name": "John Doe",
"email": "[email protected]",
"points": 0
}
This API provides the ability for users to earn and redeem points. The following endpoints are available:
This endpoint allows users to earn points. The following parameters are required:
id
: the ID of the user who will be earning pointspoints
: the number of points to be earneddescription
: a brief description of why the user is earning points
POST /users/123/earn HTTP/1.1
Host: example.com
Content-Type: application/x-www-form-urlencoded
points=10&description=Visited+the+casino+today
HTTP/1.1 200 OK Content-Type: application/json
{
"message": "Points earned successfully",
"data": {
"user_id": 123,
"points": 10,
"description": "Visited the casino today"
}
}
200 OK
: The points were successfully earned.400 Bad Request
: The request was missing required parameters or had invalid values.404 Not Found
: The user ID provided does not exist in the system.
This endpoint allows users to redeem points. The following parameters are required:
id
: the ID of the user who will be redeeming pointspoints
: the number of points to be redeemeddescription
: a brief description of why the user is redeeming points
POST /users/123/redeem HTTP/1.1
Host: example.com
Content-Type: application/x-www-form-urlencoded
points=5&description=Redeemed+points+for+prize
HTTP/1.1 200 OK Content-Type: application/json
{
"message": "Points redeemed successfully",
"data": {
"user_id": 123,
"points": 5,
"description": "Redeemed points for prize"
}
}
200 OK
: The points were successfully redeemed.400 Bad Request
: The request was missing required parameters or had invalid values.403 Forbidden
: The user does not have enough points to redeem.404 Not Found
: The user ID provided does not exist in the system.
Sure! Here's an example README for the DELETE /users/{id} endpoint:
Deletes the user with the specified ID from the database.
- HTTP Method: DELETE
- URI:
/users/{id}
- URL Parameters:
id
(required): The ID of the user to delete.
- Request Body: None
- HTTP Status Code:
204 No Content
- Response Body: None
- HTTP Status Code:
404 Not Found
- The specified user ID does not exist in the database.
- HTTP Status Code:
500 Internal Server Error
- The server encountered an error while processing the request.
DELETE /users/1234
HTTP/1.1 204 No Content
By importing the Loyalty API.postman_collection.json file into Postman all of the endpoints will populate for testing.