Merge pull request 'SES-129 Endpoint zaklęć' (#53) from SES-129 into dev
Reviewed-on: #53
This commit is contained in:
commit
046ba41ebb
@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user