- Introduction
- Features
- Setup
- Important Note
- Install Dependencies
- Database Initialization
- Database Schema
- Front-End Documentation
- API Documentation
Pet Kingdom: Rise of Guardians is an exciting RPG-inspired game where players engage in various activities with their digital pets. Players earn points by answering survey questions, which they can then use within the game. These points allow players to acquire, feed, shower, and play with their pets. Additionally, players can open chests to discover new pets, purchase armor to strengthen their pets, complete challenging quests, and even breed their pets to create unique offspring. Drawing inspiration from popular games like Dragon City and Talking Tom, Pet Kingdom: Rise of Guardians offers a rich and interactive experience for all players.
- Pet Management: Feed, shower, and play with your pets to keep them happy and healthy.
- Chest System: Open chests to obtain new pets of varying rarities.
- Store: Buy new armor for your pets to enhance their abilities.
- Quests: Complete quests to earn rewards and progress through the game.
-
Open Visual Studio Code (VSCode) on your local machine.
-
Click on the "Source Control" icon in the left sidebar (the icon looks like a branch).
-
Click on the "Clone Repository" button.
-
In the repository URL input field, enter ``.
-
Choose a local directory where you want to clone the repository.
-
Click on the "Clone" button to start the cloning process.
This repository provides instructions for setting up environment variables using a .env
file in an Express.js application. The environment variables will be used in the db.js
file located in the src/services
directory.
To set up environment variables for your Express.js application, follow these steps:
-
Create a file named
.env
in the root directory of your project. -
Open the
.env
file and add the following lines:DB_HOST=<your_database_host> DB_USER=<your_database_user> DB_PASSWORD=<your_database_password> DB_DATABASE=<your_database_name> JWT_SECRET_KEY=<your_secret_key> JWT_EXPIRES_IN=<duration> JWT_ALGORITHM=<selected_algorithm>
Replace
<your_database_host>
,<your_database_user>
,<your_database_password>
, and<your_database_name>
with the appropriate values for your database connection.Replace
<your_secret_key>
,<duration>
, and<selected_algorithm>
with the appropriate values for your JSON web token usage.For example:
DB_HOST=localhost DB_USER=root DB_PASSWORD=1234 DB_DATABASE=reviews JWT_SECRET_KEY=your-secret-key JWT_EXPIRES_IN=15m JWT_ALGORITHM=HS256
Note: Make sure there are no spaces around the equal sign (=) in each line.
-
Save the
.env
file.
Ensure that the .env
file is included in your .gitignore
file to prevent sensitive information (such as database credentials) from being exposed in your version control system.
That's it! You have successfully set up environment variables using a .env
file in your Express.js application. These variables can now be accessed in the db.js
file or any other part of your application where needed.
Now you can move on to next part below.
-
Open the terminal in VSCode by going to
View
>Terminal
or using the shortcut `Ctrl + ``. -
Navigate to the project root directory.
-
Install the required dependencies using npm:
npm install
-
Make sure you have a MySQL database available for the mock test. Update the database configuration details in the
.env
file. -
To initialize the database tables and populate them with sample data, open the terminal in VSCode and run the following command:
npm run init_tables
- user: Stores user information.
- surveyquestion: Stores survey questions.
- useranswer: Stores the user's answers for survey questions.
- pets: Stores all pet information.
- ownedpet: Stores information about pets owned by users.
- store: Stores information about store items (chests,armours).
- quests: Stores quest information.
- completedquest: Stores the completed quests for each pet.
Look at src/configs/initTables.js
for more information
URL: /index.html
Description: The Home Page serves as the entry point to the website. It provides an overview of the site's features and allows users to navigate to different sections.
Key Features:
- Welcome message
- Introduction to the website
- Instructions on how to interact with the gamified elements
URL: /login.html
Description: The login page is where the users login to access their account and profile. Note that without registering/logging in most of the webiste's functionality is limited.
Key Features:
- Login form
URL: /register.html
Description: The Register page is where the users create their account.
Key Features:
- Register form
URL: /pets.html
Description: The Owned Pets Page lists pets owned by different users. Users can view their pets and see details about each one.
Key Features:
- List of owned pets
- Pet details (name, type, etc.)
URL: /users.html
Description: The Users page lists all the registered users
Key Features:
- List of users with thier details
URL: /survey.html
Description: The Survey Page displays the survey questions and the options to update/delete/create questions. There is also a button to view all answers of a particular question, which would redirect to another html.
Key Features:
- List of survey questions
- Buttons to edit/delete/create questions
- Button to view all answers of a particular question
URL: /quest.html
Description: The Store Page displays all the quests
Key Features:
- List all the quests, including the quest description and boss stats
- Buttons to accept quests
URL: /store.html
Description: The Store Page displays all the store items such as the Chests and Armours
Key Features:
- List all the store items
- Button to buy store items
URL: /review.html
Description: The Review Page displays all the reviews created and the options to update/delete/create reviews.
Key Features:
- List of Reviews
- Buttons to edit/delete/create Reviews
URL: /profile.html
Description: The Profile page displays the user's details, including the user's points and the number of completed questions. It also displays the user's pets.
Key Features:
- List of User's Pets
- Button to update User's username
- Buttons to Play/Shower/Feed Pets
- Buttons to view Pet details
- URL:
/showAnswers.html
- Description: Webpage to show all answers of a particular question
- URL:
/singlePetInfo.html.html
- Description: Webpage to display pet details
- URL:
/singlePetInfoProfile.html
- Description: Webpage to display pet details with slightly more details
- URL:
/updateQuestion.html
- Description: Webpage to update a survey question
- URL:
/chooseArmourPet.html
- Description: Webpage to choose the pet which you want to equip the armour from the Store
- URL:
/chooseQuestPet.html
- Description: Webpage to choose the pet which you want to embark on the quest
Register a user. Essentially creating a new user in the database. Note that every new user will get a default pet, either a dog or a cat.
Example Request:
{
"username": "superSOC",
"password": "superSOC"
}
Response:
- 200 OK, if successful. Example Response body:
[
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjMsInRpbWVzdGFtcCI6IjIwMjQtMDctMzBUMDU6NTI6NTEuNDc3WiIsImlhdCI6MTcyMjMxODc3MSwiZXhwIjoxNzIyMzE5NjcxfQ.InjnOyLdvTD52_kdHLwXLqVhyWYMDxVHtV2WuK2hPUM"
}
]
Error Handling:
- 409 Conflict, if username is already associated with another user.
- 400 Bad Request, if the username/password is undefined
Register a user. Essentially creating a new user in the database.
Example Request:
{
"username": "superSOC",
"password": "superSOC"
}
Response:
- 200 OK, if successful. Example Response body:
[
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjMsInRpbWVzdGFtcCI6IjIwMjQtMDctMzBUMDU6NTI6NTEuNDc3WiIsImlhdCI6MTcyMjMxODc3MSwiZXhwIjoxNzIyMzE5NjcxfQ.InjnOyLdvTD52_kdHLwXLqVhyWYMDxVHtV2WuK2hPUM"
}
]
Error Handling:
- 400 Bad Request, if the username/password is undefined
- 404 Not Found, if the user not found
- 401 Unauthorized, if the user not found
Retrieve a list of all users with their respective user_id, username, and points
Response:
- 200 OK, if successful. Example Response body:
[
{
"user_id": 1,
"username": "socuser321",
"points": 0
},
{
"user_id": 2,
"username": "surveyKing",
"points": 0
}
]
Retrieve details of a specific user by providing their user_id.
Response:
- 200 OK, if successful. Example Response body:
{
"user_id": 1,
"username": "greenUser123",
"completed_questions": 10,
"points ": 10
}
Error Handling:
- 404 Not Found, if the requested user_id does not exist.
- 401 Unauthorized, if the token is expired or empty.
Retrieve the points of a specific user by providing their token
Response:
- 200 OK, if successful. Example Response body:
[
{
"points ": 10
}
]
Error Handling:
- 401 Unauthorized, if the token is expired or empty.
Update user details by providing user_id in the URL and updating username in the request body.
Example Request:
{
"username": " superSOC"
}
Response:
- 200 OK, if successful. Example Response body:
{
"user_id": 1,
"username": " superSOC ",
"points ": 10
}
Error Handling:
- 404 Not Found, if the requested user_id does not exist.
- 409 Conflict, if the provided username is already associated with another user.
- 401 Unauthorized, if the token is expired or empty.
Retrieve a list of all questions with their respective question_id, question, and creator_id.
Response:
- 200 OK, if successful. Example Response body:
[
{
"question_id": 1,
"question": "Do you buy fruits from FC6?",
"creator_id ": 1
},
{
"question_id": 2,
"question": "Is the fried chicken at FC5 salty?",
"creator_id ": 1
}
]
Update question details by providing question_id in the URL and updating questions in the request body.
Example Request:
{
"user_id": 1,
"question": "Do you buy fruits from FC4?"
}
Response:
- 200 OK, if successful. Example Response body:
{
"question_id": 1,
"question": "Do you buy fruits from FC4?",
"creator_id ": 1
}
Error Handling:
- 400 Bad Request, if the request body is missing question or user_id.
- 404 Not Found, if the requested question_id does not exist.
- 403 Forbidden, if creator_id is different from user_id due to not correct owner.
- 401 Unauthorized, if the token is expired or empty.
Delete a question by providing its question_id. The question's associated user answer, if any, will also be deleted
Response:
- 204 No Content, if successful.
Error Handling:
- 404 Not Found, if the requested question_id does not exist.
- 401 Unauthorized, if the token is expired or empty.
- 403 Forbidden, if creator_id is different from user_id due to not correct owner.
Create an answer from a user (marking a survey question complete) by providing question_id in URL parameter and user_id, answer creation_date, and additional_notes in the request body. Upon successfully completing a survey question, the user will receive 5 points.
Example Request:
{
"user_id": 1,
"answer": true,
"creation_date": "2023-07-30",
"additional_notes": "I love it"
}
Response:
- 201 Created, if successful. Example Response body:
{
"answer_id": 1,
"answered_question_id": 1,
"participant_id": 1,
"answer": true,
"creation_date" :"2023-07-30",
"additional_notes": "I love it"
}
Error Handling:
- 400 Bad Request, if the request body is missing creation_date,answer or user_id.
- 404 Not Found, if the requested user_id does not exist.
- 401 Unauthorized, if the token is expired or empty.
Retrieve answers given by participant on a particular question by providing its questions_id.
Response:
- 200 OK, if successful. Example Response body:
[
{
"participant_id": 2,
"answer": true,
"creation_date" :"2023-07-30",
"additional_notes": "I love it"
},
{
"participant_id": 3,
"answer": false,
"creation_date" :"2023-07-30",
"additional_notes": "I don’t like fruits"
}
]
Error Handling:
- 404 Not Found, if the requested question_id does not have any answer.
- 401 Unauthorized, if the token is expired or empty.
Create an review from a user. The review amount can only be 1-5.
Example Request:
{
"review_amt": 1
}
Response:
- 201 Created, if successful. Example Response body:
{
"message": "Review successfully created"
}
Error Handling:
- 400 Bad Request, if the request body is missing review amount or the review amount is more than 5 or less than 5.
- 401 Unauthorized, if the token is expired or empty.
Retrieve all reviews given by users.
Response:
- 200 OK, if successful. Example Response body:
[
{
id: 1,
review_amt: 4,
user_id: 1,
created_at: '2024-07-29 09:55:16',
username: 'no'
},
{
id: 3,
review_amt: 5,
user_id: 2,
created_at: '2024-07-30 11:45:45',
username: 'hi'
}
]
Update review by providing review_id in the URL and updating in the request body.
Example Request:
{
"review_amt": 5
}
Response:
- 204 No Content, if successful. Example Response body:
Error Handling:
- 400 Bad Request, if the request body is missing review amount or the review amount is more than 5 or less than 5.
- 401 Unauthorized, if the token is expired or empty.
- 403 Forbidden, if you are not the owner of this Review.
Delete a review by providing its id.
Response:
- 204 No Content, if successful.
Error Handling:
- 404 Not Found, if the requested review does not exist.
- 401 Unauthorized, if the token is expired or empty.
- 403 Forbidden, if you are not the owner of this Review.
Retrieve all pets owned by a user by providing their owner_id.
Response:
- 200 OK, if successful. Example Response body:
[
{
"pet_name": "Dog",
"category": "common",
"type1": "Melee",
"type2": null,
"type3": null,
"owned_pet_id": 1,
"owner_id": 1,
"pet_id": 1,
"pet_level": 1,
"pet_hp": 20,
"pet_atk": 30,
"pet_def": 25,
"last_fed": "2024-06-23 12:17:53",
"last_showered": "2024-06-23 12:17:53",
"last_time_spent": "2024-06-23 12:17:53",
"armour_id": null,
"armour_atk": null,
"armour_def": null,
"armour_name": null,
"armour_desc": null
},
{
"pet_name": "Aquacat",
"category": "common",
"type1": "Water",
"type2": "Melee",
"type3": null,
"owned_pet_id": 4,
"owner_id": 1,
"pet_id": 4,
"pet_level": 1,
"pet_hp": 22,
"pet_atk": 28,
"pet_def": 30,
"last_fed": "2024-06-23 12:32:35",
"last_showered": "2024-06-23 12:32:35",
"last_time_spent": "2024-06-23 12:32:35",
"armour_id": null,
"armour_atk": null,
"armour_def": null,
"armour_name": null,
"armour_desc": null
}
]
Error Handling:
- 404 Not Found, if the requested owner_id does not have any pets.
- 401 Unauthorized, if the token is expired or empty.
Retrieve a specific pet's details by providing its owned_pet_id.
Response:
- 200 OK, if successful. Example Response body:
[
{
"pet_name": "Dog",
"category": "common",
"type1": "Melee",
"type2": null,
"type3": null,
"owned_pet_id": 1,
"owner_id": 1,
"pet_id": 1,
"pet_level": 1,
"pet_hp": 20,
"pet_atk": 30,
"pet_def": 25,
"last_fed": "2024-06-23 12:17:53",
"last_showered": "2024-06-23 12:17:53",
"last_time_spent": "2024-06-23 12:17:53",
"armour_id": null,
"armour_atk": null,
"armour_def": null,
"armour_name": null,
"armour_desc": null
}
]
Error Handling:
- 404 Not Found, if the requested owned_pet_id does not exist.
Feed a pet by providing its owned_pet_id.
Cooldown: 1 hour
Cannot feed pet if cooldown is not over
Response:
- 200 OK, if successful. Example Response body:
{
"message": "Yum! Your pet just had a delicious meal and is feeling full and happy."
}
Error Handling:
- 404 Not Found, if the requested owned_pet_id does not exist.
- 409 Conflict, if the cooldown is not over yet
- 401 Unauthorized, if the token is expired or empty.
Shower a pet by providing its owned_pet_id.
Cooldown: 1.5 hour
Cannot shower pet if cooldown is not over
Response:
- 200 OK, if successful. Example Response body:
{
"message": "Splish splash! Your pet just had a refreshing shower and smells fantastic."
}
Error Handling:
- 404 Not Found, if the requested owned_pet_id does not exist.
- 409 Conflict, if the cooldown is not over yet.
- 401 Unauthorized, if the token is expired or empty.
Play with your pet by providing its owned_pet_id.
Cooldown: 1 hour
Cannot play with pet if cooldown is not over.
Response:
- 200 OK, if successful. Example Response body:
{
"message": "Woohoo! Your pet just had an epic playtime session"
}
Error Handling:
- 404 Not Found, if the requested owned_pet_id does not exist.
- 409 Conflict, if the cooldown is not over yet.
- 401 Unauthorized, if the token is expired or empty.
Retrieve all store items.
Response:
- 200 OK, if successful. Example Response body:
[
{
"item_id": 1,
"item_name": "Common Chest",
"item_desc": "Has a chance to drop a common or rare pet",
"cost": 50,
"atk": null,
"def": null,
"category": "common"
},
{
"item_id": 2,
"item_name": "Premium Chest",
"item_desc": "Has a chance to drop a common, rare, very rare, or unique pet",
"cost": 100,
"atk": null,
"def": null,
"category": "premium"
},
{
"item_id": 3,
"item_name": "Ultimate Chest",
"item_desc": "Has a chance to drop a very rare, unique, mythic, or god pet",
"cost": 150,
"atk": null,
"def": null,
"category": "ultimate"
},
{
"item_id": 4,
"item_name": "Leather Armor",
"item_desc": "Basic leather armor set",
"cost": 20,
"atk": 20,
"def": 30,
"category": "common"
},
...
]
Buy a common chest from store by providing the player's user_id.
Has a chance to drop a common or rare pet.
Cost: 50 points
Probability
Common Pet - 75%
Rare Pet - 25%
Response:
- 200 OK, if successful. Example Response body:
{
"message": "You just got a common pet !!!",
"Pet Stats": {
"pet_name": "Lynx",
"category": "common",
"type1": "Melee",
"type2": null,
"type3": null,
"owned_pet_id": 6,
"owner_id": 2,
"pet_id": 13,
"pet_level": 1,
"pet_hp": 26,
"pet_atk": 28,
"pet_def": 25,
"last_fed": "2024-06-23 13:13:12",
"last_showered": "2024-06-23 13:13:12",
"last_time_spent": "2024-06-23 13:13:12",
"armour_id": null,
"armour_atk": null,
"armour_def": null,
"armour_name": null,
"armour_desc": null
}
}
Error Handling:
- 404 Not Found, if user_id does not exist.
- 402 Payment Required, if player does not have enough points to purchase the chest
- 401 Unauthorized, if the token is expired or empty.
Buy a premium chest from store by providing the player's user_id.
Has a chance to drop a common, rare, very rare, or unique pet
Cost: 100 points
Probability
Common Pet - 55%
Rare Pet - 25%
Very Rare - 15%
Unique - 5%
Response:
- 200 OK, if successful. Example Response body:
{
"message": "You just got a rare pet !!!",
"Pet Stats": {
"pet_name": "Thunderclaw",
"category": "rare",
"type1": "Electric",
"type2": "Melee",
"type3": null,
"owned_pet_id": 7,
"owner_id": 2,
"pet_id": 31,
"pet_level": 1,
"pet_hp": 35,
"pet_atk": 38,
"pet_def": 32,
"last_fed": "2024-06-23 13:23:14",
"last_showered": "2024-06-23 13:23:14",
"last_time_spent": "2024-06-23 13:23:14",
"armour_id": null,
"armour_atk": null,
"armour_def": null,
"armour_name": null,
"armour_desc": null
}
}
Error Handling:
- 404 Not Found, if user_id does not exist.
- 402 Payment Required, if player does not have enough points to purchase the chest
- 401 Unauthorized, if the token is expired or empty.
Buy a ultimate chest from store by providing the player's user_id.
Has a chance to drop a very rare, unique, mythic, or god pet
Cost: 150 points
Probability
Very Rare - 55%
Unique - 20%
Mythic - 15%
God - 5%
Response:
- 200 OK, if successful. Example Response body:
{
"message": "You just got a unique pet !!!",
"Pet Stats": {
"pet_name": "Aqualisk",
"category": "unique",
"type1": "Water",
"type2": "Dragon",
"type3": null,
"owned_pet_id": 8,
"owner_id": 2,
"pet_id": 57,
"pet_level": 1,
"pet_hp": 110,
"pet_atk": 140,
"pet_def": 120,
"last_fed": "2024-06-23 13:29:13",
"last_showered": "2024-06-23 13:29:13",
"last_time_spent": "2024-06-23 13:29:13",
"armour_id": null,
"armour_atk": null,
"armour_def": null,
"armour_name": null,
"armour_desc": null
}
}
Error Handling:
- 404 Not Found, if user_id does not exist.
- 402 Payment Required, if player does not have enough points to purchase the chest
- 401 Unauthorized, if the token is expired or empty.
Buy armour from store by providing the pet's owned_pet_id and the armour's item_id. Armour will be immediately equipped by the pet. If the pet had armour already on, it would get replaced and the old armour would get deleted. Cost: Depends on type of armour
Response:
- 200 OK, if successful. Example Response body:
{
"message": "Congratulations! Cat just got equipped with the awesome Iron Armor! Ready to take on the world in style and strength!",
"Pet Stats": {
"pet_name": "Cat",
"category": "common",
"type1": "Melee",
"type2": null,
"type3": null,
"owned_pet_id": 2,
"owner_id": 2,
"pet_id": 2,
"pet_level": 1,
"pet_hp": 18,
"pet_atk": 25,
"pet_def": 32,
"last_fed": "2024-06-23 12:18:04",
"last_showered": "2024-06-23 12:18:04",
"last_time_spent": "2024-06-23 12:18:04",
"armour_id": 5,
"armour_atk": 25,
"armour_def": 35,
"armour_name": "Iron Armor",
"armour_desc": "Sturdy iron armor set"
}
}
Error Handling:
- 404 Not Found, if owned_pet_id or item_id does not exist.
- 402 Payment Required, if player does not have enough points to purchase the armour
- 401 Unauthorized, if the token is expired or empty.
- 400 Bad Request, if item_id is < 4. item_id 1-3 is reserved for the 3 chests.
Retrieve details of all quests.
Response:
- 200 OK, if successful. Example Response body:
[
{
"quest_id": 1,
"quest_level": 1,
"quest_name": "The Goblin Menace",
"quest_desc": "Defeat the Goblin King terrorizing the village.",
"boss_atk": 15,
"boss_def": 10,
"boss_hp": 100
},
{
"quest_id": 2,
"quest_level": 2,
"quest_name": "Bandit Hideout",
"quest_desc": "Clear out the bandits hiding in the forest.",
"boss_atk": 20,
"boss_def": 15,
"boss_hp": 120
},
{
"quest_id": 3,
"quest_level": 3,
"quest_name": "Wolf Pack",
"quest_desc": "Defeat the leader of the wild wolves.",
"boss_atk": 25,
"boss_def": 20,
"boss_hp": 140
},
...
]
Retrieve details of a specific quest by specifying its quest_id.
Response:
- 200 OK, if successful. Example Response body:
{
"quest_id": 1,
"quest_level": 1,
"quest_name": "The Goblin Menace",
"quest_desc": "Defeat the Goblin King terrorizing the village.",
"boss_atk": 15,
"boss_def": 10,
"boss_hp": 100
}
Error Handling:
- 404 Not Found, if the requested quest_id does not exist
Complete a quest by specifying the quest_id of the quest and the owned_pet_id of the pet that the player wants to use for the quest. The pet's stats and the quest's boss's stats are computed to determine the winner. If the pet wins, it levels up, increasing all its stats by 5.
A Pet cannot redo a quest that it has already completed.
Response:
- 200 OK, if:
- Pet wins. Example Response body:
{
"message": "Congratulations! Cat triumphed in the quest The Goblin Menace and came back victorious!",
"Your pet has leveled up !\n": {
"pet_name": "Cat",
"category": "common",
"type1": "Melee",
"type2": null,
"type3": null,
"pet_level": 2,
"pet_hp": 23,
"pet_atk": 30,
"pet_def": 37
}
}
- Pet loses. Example Response body:
{
"message": "Oh no! Dog gave it their all but couldn't complete the quest this time. Mission Failed, We'll get'em next time"
}
Error Handling:
- 404 Not Found, if the requested quest_id or owned_pet_id does not exist.
- 409 Conflict, if the pet has already completed the quest.
- 409 Conflict, if the pet is dirty.
- 409 Conflict, if the pet is hungry.
- 409 Conflict, if the pet is upset.
- 401 Unauthorized, if the token is expired or empty.