Merge pull request 'SES-129 Endpoint zaklęć' (#53) from SES-129 into dev

Reviewed-on: #53
This commit is contained in:
Łukasz Góreczny 2021-01-09 14:09:32 +01:00
commit 046ba41ebb
2 changed files with 176 additions and 134 deletions

View File

@ -0,0 +1,42 @@
using Microsoft.AspNetCore.Mvc;
using SessionCompanion.Extensions.EitherType;
using SessionCompanion.Services.Interfaces;
using SessionCompanion.ViewModels.ApiResponses;
using SessionCompanion.ViewModels.SpellViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace SessionCompanion.Controllers
{
[Route("api/spell")]
[ApiController]
public class SpellController : Controller
{
private readonly ISpellService _service;
public SpellController(ISpellService service) => _service = service;
/// <summary>
/// Metoda zwraca wszystkie dostępne zaklecia
/// </summary>
/// <returns>Lista wszystkich zaklęć w bazie danych</returns>
[HttpGet("getAllSpells")]
public async Task<Either<List<SpellViewModel>, ErrorResponse>> GetSpells()
{
try
{
var spells = _service.Get().ToList();
return spells;
}
catch (Exception e)
{
return new ErrorResponse()
{
StatusCode = 204,
Message = e.Message
};
}
}
}
}