Refactor pet action management: rename PetAction to PetBasicAction, update related properties and methods, and enhance pet stats with maximum values.

This commit is contained in:
2025-02-01 23:08:25 -03:00
parent d6d3dc9f44
commit df62710b9a
14 changed files with 173 additions and 239 deletions

View File

@@ -36,44 +36,7 @@ namespace pet_companion_api.Controllers
return CreatedAtAction(nameof(GetAllPets), new { id = createdPet.Id }, createdPet);
}
/// <summary>
///
/// </summary>
/// <param name="petId"></param>
/// <param name="action">One of `feed`, `play`, `sleep`</param>
/// <returns></returns>
[HttpPut("{petId}/action/{action}")]
public IActionResult UpdatePetAction(string petId, string action)
{
try
{
PetAction petAction;
switch (action.ToLower())
{
case "feed":
petAction = PetAction.FEED;
break;
case "play":
petAction = PetAction.PLAY;
break;
case "sleep":
petAction = PetAction.SLEEP;
break;
default:
return BadRequest("Invalid action. Valid actions are: feed, play, sleep");
}
var actionRequest = new PetUpdateActionRequest { Action = petAction };
var updatedPet = petService.UpdatePetAction(petId, userId.ToString(), actionRequest);
return Ok(updatedPet);
}
catch (Exception ex)
{
return NotFound(ex.Message);
}
}
[HttpPut("{petId}/action/gather")]
[HttpPut("{petId}/action")]
public IActionResult UpdatePetActionGather(string petId, [FromBody] PetUpdateActionRequest actionRequest)
{
try