85 lines
2.5 KiB
C#

using Microsoft.AspNetCore.Mvc;
using PetCompanion.Models;
using PetCompanion.Services;
namespace PetCompanion.Controllers
{
public class PetController : BaseController
{
private readonly PetService petService;
private readonly PetClassService petClassService;
private readonly ILogger<PetController> logger;
public PetController(
ILogger<PetController> logger,
PetService petService,
PetClassService petClassService)
{
this.logger = logger;
this.petService = petService;
this.petClassService = petClassService;
}
[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 UpdatePetActionGather(string petId, [FromBody] PetUpdateActionRequest actionRequest)
{
try
{
var updatedPet = petService.UpdatePetAction(petId, userId.ToString(), actionRequest);
return Ok(updatedPet);
}
catch (Exception ex)
{
return NotFound(ex.Message);
}
}
[HttpGet("{petId}/resources/gathered")]
public IActionResult GetGatheredResources(string petId)
{
try
{
var resources = petService.GetGatheredResources(petId, userId.ToString());
return Ok(resources);
}
catch (Exception ex)
{
return NotFound(ex.Message);
}
}
[HttpPut("{petId}/resources/collect")]
public IActionResult CollectGatheredResources(string petId)
{
try
{
var updatedPet = petService.CollectPetGathered(petId, userId.ToString());
return Ok(updatedPet);
}
catch (Exception ex)
{
return NotFound(ex.Message);
}
}
[HttpGet("classes")]
public IActionResult GetAllPetClasses()
{
return Ok(petClassService.GetAllPetClasses());
}
}
}