Add pet action management and update requests

This commit is contained in:
2025-02-01 00:29:33 -03:00
parent 4c4036a266
commit e1c5eed02d
12 changed files with 337 additions and 36 deletions

View File

@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using pet_companion_api.Models;
using pet_companion_api.Services;
namespace pet_companion_api.Controllers
@@ -22,5 +23,26 @@ namespace pet_companion_api.Controllers
{
return Ok(petService.GetAllPets(userId));
}
[HttpPost("")]
public IActionResult CreatePet([FromBody] PetCreationRequest petRequest)
{
var createdPet = petService.CreatePet(userId, petRequest);
return CreatedAtAction(nameof(GetAllPets), new { id = createdPet.Id }, createdPet);
}
[HttpPut("{petId}/action")]
public IActionResult UpdatePetAction(string petId, [FromBody] PetUpdateActionRequest actionRequest)
{
try
{
var updatedPet = petService.UpdatePetAction(petId, userId.ToString(), actionRequest);
return Ok(updatedPet);
}
catch (Exception ex)
{
return NotFound(ex.Message);
}
}
}
}