64 lines
2.0 KiB
C#
64 lines
2.0 KiB
C#
using CodeLiturgy.Data.Auth.Context.Users;
|
|
using CodeLiturgy.Domain;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace CodeLiturgy.Views.Controllers
|
|
{
|
|
[ApiController]
|
|
[Authorize]
|
|
public class EnvironmentController : ControllerBase
|
|
{
|
|
private ApplicationUserManager _userManager;
|
|
private ILogger<SitesController> _logger;
|
|
private readonly SiteDbContext _siteDbContext;
|
|
public EnvironmentController(ApplicationUserManager userManager, ILogger<SitesController> logger, SiteDbContext siteDbContext)
|
|
{
|
|
_logger = logger;
|
|
_userManager = userManager;
|
|
_siteDbContext = siteDbContext;
|
|
}
|
|
|
|
[HttpGet("/api/environments")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
|
|
public ActionResult GetEnvironments(
|
|
|
|
int skip = 0, int take = 50, int orderDir = 1)
|
|
{
|
|
var (success, sites) = _siteDbContext.GetEnvironments(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)]
|
|
[ProducesResponseType(StatusCodes.Status403Forbidden)]
|
|
|
|
[HttpGet("/api/environments/{environmentId}", Name = nameof(GetEnvironmentById))]
|
|
public ActionResult GetEnvironmentById(string siteId)
|
|
{
|
|
var (success, environment) = _siteDbContext.GetOneSiteById(siteId);
|
|
|
|
if (success)
|
|
{
|
|
return Ok(environment);
|
|
}
|
|
|
|
return new NotFoundResult();
|
|
}
|
|
|
|
}
|
|
}
|