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.
- Create an API that can implement CRUD features against a Database.
- Practice creating ASP.NET Web API endpoints.
- Practice EF Core.
-
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)
- Should use a POCO called
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 Id
Add the following features to your API
- Add columns
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
. - Add a query parameter go
GET /pets
that only returns Pets that are alive.
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.
- Create a new pet.
- Delete a pet.