49 lines
1.5 KiB
C#
49 lines
1.5 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using pet_companion_api.Models;
|
|
using pet_companion_api.Services;
|
|
|
|
namespace pet_companion_api.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("api/v1/[controller]")]
|
|
public class PetController : ControllerBase
|
|
{
|
|
private readonly PetService petService;
|
|
private readonly ILogger<PetController> logger;
|
|
private Guid userId = Guid.Parse("f5f4b3b3-3b7b-4b7b-8b7b-7b7b7b7b7b7b");
|
|
|
|
public PetController(ILogger<PetController> logger, PetService petService)
|
|
{
|
|
this.logger = logger;
|
|
this.petService = petService;
|
|
}
|
|
|
|
[HttpGet("")]
|
|
public IActionResult GetAllPets()
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|