SES-152 Add Endpoint to get shopkeepers

This commit is contained in:
Karol Górzyński 2021-01-20 19:04:46 +01:00
parent 39fbd6c3bf
commit dcf17cf1de

View File

@ -0,0 +1,36 @@
using Microsoft.AspNetCore.Mvc;
using SessionCompanion.Extensions.EitherType;
using SessionCompanion.Services.Interfaces;
using SessionCompanion.ViewModels.ApiResponses;
using SessionCompanion.ViewModels.ShopkeeperViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace SessionCompanion.Controllers
{
[ApiController]
[Route("api/shopkeeper")]
public class ShopkeeperController : Controller
{
private IShopkeeperService _service;
public ShopkeeperController(IShopkeeperService shopkeeperService)
{
_service = shopkeeperService;
}
/// <summary>
/// Endpoint zwracający liste sklepikarzy
/// </summary>
/// <returns>Lista sklepikarzy</returns>
[HttpGet("getShopkeepers")]
public async Task<Either<ErrorResponse, List<ShopkeeperViewModel>>> GetShopkeepers()
{
var shopkeepers = _service.Get();
if (!shopkeepers.Any())
return new ErrorResponse() { StatusCode = 204, Message = "No shopkeepers in database" };
return shopkeepers.ToList();
}
}
}