81 lines
2.5 KiB
C#
81 lines
2.5 KiB
C#
using CodeLiturgy.Data.Application;
|
|
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);
|
|
}
|
|
|
|
|
|
[HttpPost("/api/environments")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
|
|
public ActionResult AddEnvironment(SiteEnvironmentCreate siteEnvironmentCreate)
|
|
{
|
|
var (success, result) = _siteDbContext.AddSiteEnvironment(siteEnvironmentCreate);
|
|
|
|
if (success)
|
|
{
|
|
return Ok(result);
|
|
}
|
|
|
|
return BadRequest();
|
|
}
|
|
|
|
|
|
/// <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();
|
|
}
|
|
|
|
}
|
|
}
|