SES-152 Endpoint zwracający sklepikarzy #79

Merged
s426134 merged 11 commits from SES-152 into dev 2021-01-20 19:26:12 +01:00
Showing only changes of commit dcf17cf1de - Show all commits

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();
}
}
}