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:
@@ -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
|
||||
|
Reference in New Issue
Block a user