Add pet action management and update requests
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user