To start your journey you will be creating an API that allows a user to create and care for a virtual pet, reminiscent of a Tamagotchi. The basic functionality will walk you through the four basic parts of a web API, create, read, update and delete.
Objectives
Create an API that can implement CRUD features against a Database.
Practice creating ASP.NET Web API endpoints.
Practice EF Core.
Explorer Mode
Create and new sdg-api that has the following features
Create a database with one table named Pets.
Should use a POCO called Pet with the following columns:
Id (int)
Name (string)
Birthday (DateTime)
HungerLevel (int)
HappinessLevel (int)
Your API should have the following endpoints
[x] GET /pets, should return all pets in your database.
[x] GET /pets/{id}, should return the pet with the corresponding id.
[x] POST /pets, should create a new pet. The body of the request should contain a JSON object with a key of "name" and a value of the pet's name. The pets Birthday should default to the current datetime, HungerLeveldefaults to 0 and HappinessLeveldefaults to 0.
[ ] POST /pets/{id}/playtimes, should find the pet by id and add 5 to its happiness level and 3 to its hungry level.
[ ] POST /pets/{id}/feedings, should find the pet by id and subtract 5 from its hungry level and 3 from its happiness level.
[ ] POST /pets/{id}/scoldings, should find the pet by id and subtract 5 from its happiness level.
[ ] DELETE /pets/{id}, should delete a pet from the database by Id
Adventure Mode
Add the following features to your API
Add columns LastInteractedWithDate (DateTime). Every time a pet us updated in the database, set the LastInteractedWithDate to the current time. Add a property named IsDead to your Pets that has logic such that if the LastInteractedWithDate is over 3 days old, the property returns true otherwise false.
Add a query parameter go GET /pets that only returns Pets that are alive.
Epic mode
Create a console app that interacts with your 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.
To start your journey you will be creating an API that allows a user to create and care for a virtual pet, reminiscent of a Tamagotchi. The basic functionality will walk you through the four basic parts of a web API, create, read, update and delete.
Objectives
Explorer Mode
Create and new
sdg-api
that has the following featuresCreate a database with one table named
Pets
.Pet
with the following columns:Your API should have the following endpoints
GET /pets
, should return all pets in your database.GET /pets/{id}
, should return the pet with the corresponding id.POST /pets
, should create a new pet. The body of the request should contain a JSON object with a key of "name" and a value of the pet's name. The petsBirthday
should default to the current datetime,HungerLevel
defaults to 0 andHappinessLevel
defaults to 0.POST /pets/{id}/playtimes
, should find the pet by id and add 5 to its happiness level and 3 to its hungry level.POST /pets/{id}/feedings
, should find the pet by id and subtract 5 from its hungry level and 3 from its happiness level.POST /pets/{id}/scoldings
, should find the pet by id and subtract 5 from its happiness level.DELETE /pets/{id}
, should delete a pet from the database by IdAdventure Mode
Add the following features to your API
LastInteractedWithDate
(DateTime). Every time a pet us updated in the database, set theLastInteractedWithDate
to the current time. Add a property namedIsDead
to yourPets
that has logic such that if theLastInteractedWithDate
is over 3 days old, the property returnstrue
otherwisefalse
.GET /pets
that only returns Pets that are alive.Epic mode
Create a console app that interacts with your API that:
Resources