77 lines
2.4 KiB
C#
77 lines
2.4 KiB
C#
using BlueWest.Data.Auth.Context.Users;
|
|
using CodeLiturgy.Data.Application;
|
|
using CodeLiturgy.Domain;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
namespace CodeLiturgy.Views.Controllers
|
|
{
|
|
[Route("api/sites")]
|
|
[ApiController]
|
|
[Authorize]
|
|
|
|
public class SitesController : ControllerBase
|
|
{
|
|
private ApplicationUserManager _userManager;
|
|
private ILogger<UserController> _logger;
|
|
private readonly SiteDbContext _siteDbContext;
|
|
|
|
public SitesController(ApplicationUserManager userManager, ILogger<UserController> logger, SiteDbContext siteDbContext)
|
|
{
|
|
_logger = logger;
|
|
_userManager = userManager;
|
|
_siteDbContext = siteDbContext;
|
|
}
|
|
|
|
[HttpGet]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
|
|
public ActionResult GetSites(
|
|
|
|
int skip = 0, int take = 50, int orderDir = 1)
|
|
{
|
|
var (success, sites) = _siteDbContext.GetSites(skip, take, orderDir);
|
|
|
|
if (!success) return new NotFoundResult();
|
|
|
|
return Ok(sites);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get Country by Id
|
|
/// </summary>
|
|
/// <param name="countryId">ISO 3166-1 countryId numeric code</param>
|
|
/// <returns></returns>
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|
[HttpGet("{siteId}", Name = nameof(GetSiteById))]
|
|
public ActionResult GetSiteById(string siteId)
|
|
{
|
|
var (success, site) = _siteDbContext.GetOneSiteById(siteId);
|
|
|
|
if (success)
|
|
{
|
|
return Ok(site);
|
|
}
|
|
|
|
return new NotFoundResult();
|
|
}
|
|
|
|
/*
|
|
[ProducesResponseType(StatusCodes.Status201Created)]
|
|
[ProducesResponseType(StatusCodes.Status406NotAcceptable)]
|
|
[HttpPost]
|
|
public ActionResult AddSite(SiteCreate siteToCreate)
|
|
{
|
|
var (success, site) = _siteDbContext.AddSite(siteToCreate);
|
|
if (!success) return new BadRequestResult();
|
|
return CreatedAtRoute(nameof(GetSiteById), new {countryId = site.Id}, site);
|
|
}*/
|
|
|
|
}
|
|
}
|
|
|