The Rise of the Tamagotchi
This project will create an API that allows a user to create and care for a virtual pet, reminiscent of a Tamagotchi. The basic functionality will include the four parts of a web API: create, read, update, and delete.
Objectives
- Create an API that implements CRUD features against a database.
- Practice creating ASP.NET Web API endpoints.
- Practice EF Core.
Setup
dotnet new sdg-api -o TamagotchiAPI
Resources
Explorer Mode
Create and new
sdg-apithat has the following featuresYou may use
dotnet ef migrations addorpgcli+CREATE TABLE- You the student can choose which you prefer to use.Create a database with a table named
Pets.- Should use a POCO called
Petwith the following columns:Id(int - automatic primary key)Name(string)Birthday(DateTime)HungerLevel(int)HappinessLevel(int)
- Should use a POCO called
Create a table named
Playtimesthat has the following columns:Id(int - automatic primary key)When(DateTime)PetId(int - foreign key to Pet)
Create a table named
Feedingsthat has the following columns:Id(int - automatic primary key)When(DateTime)PetId(int - foreign key to Pet)
Create a table named
Scoldingsthat has the following columns:Id(int - automatic primary key)When(DateTime)PetId(int - foreign key to Pet)
The API will have the following endpoints.
GET /Petsshould return all pets in your database.GET /Pets/{id}should return the pet with the corresponding id.POST /Petsshould create a new pet. The controller should ensure the following:Birthdaydefaults to the current DateTime,HungerLeveldefaults to0andHappinessLeveldefaults to0.DELETE /Pets/{id}, should delete a pet from the database by IdPOST /Pets/{id}/Playtimesshould find the pet by id and add five to its happiness level and add three to its hunger level. It should also create a newPlaytimefor this pet and the current time.POST /Pets/{id}/Feedingsshould find the pet by id and subtract five from its hunger level and add three to its happiness level. It should also create a newFeedingfor this pet and the current time.POST /Pets/{id}/Scoldingsshould find the pet by id and subtract five from its happiness level. It should also create a newScoldingfor this pet and the current time.
Demonstrate the API works
- Using Insomnia, create three Pets. Include a screenshot containing the API request and the response. Post the image in the comment when turning in the assignment.
- Using Insomnia, create a playtime for one of your pets. Show the API request and the response. Post the image in the comment when turning in the assignment.
- Using Insomnia, create a feeding for one of your pets. Show the API request and the response. Post the image in the comment when turning in the assignment.
- Using Insomnia, create a scolding for one of your pets. Show the API request and the response. Post the image in the comment when turning in the assignment.
- Using Insomnia, show the details of all the pets. Show the API request and the response. Post the image in the comment when turning in the assignment.
Adventure Mode
Add the following features to the API
- Add columns
LastInteractedWithDate(DateTime). When a pet is updated, set theLastInteractedWithDateto the current time. Add a property namedIsDeadto yourPet.The logic of this method will returntrue if LastInteractedWithDate is over three days old; otherwise, it will returnfalse`. - Add a query parameter to
GET /Petsthat only returns Pets that are alive.
Epic mode
Create a console app that interacts with the API that:
- Allows the user to see all pets
- Select a pet to take care of and then play with, scold, or feed the selected pet.
- Create a new pet.
- Delete a pet.