SES-152 Endpoint zwracający sklepikarzy #79
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user