using BlueWest.Data;
using BlueWest.WebApi.Context;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace BlueWest.WebApi.Controllers
{
[ApiController]
[Route("application/users")]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[Authorize(AuthenticationSchemes = CookieAuthenticationDefaults.AuthenticationScheme)]
[EnableCors(Constants.CorsPolicyName)]
public class ApplicationUserController : ControllerBase
{
private readonly ApplicationUserDbContext _dbContext;
public ApplicationUserController(ApplicationUserDbContext context)
{
_dbContext = context;
}
#region Users
///
/// Get Application users
///
///
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[HttpGet]
public ActionResult GetApplicationUsers(
int skip = 0,
int take = 50,
int orderDir = 1)
{
var (success, users) = _dbContext.GetUsers( skip, take, orderDir);
if (!success) return new NotFoundResult();
return Ok(users);
}
///
/// Updates a User
///
/// The UserId ISO 3166 code
/// User payload data
///
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[HttpPut("{UserCode}")]
public ActionResult UpdateApplicationUser(int UserCode, UserUnique UserToUpdate)
{
//var (success, User) = _dbContext.UpdateUser(UserToUpdate, UserCode);
/*
if (success)
{
return Ok(User);
}
*/
return new NotFoundResult();
}
#endregion
/*
#region GetUserById
///
/// Get User by Id
///
/// ISO 3166-1 UserId numeric code
///
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[HttpGet("{UserId}", Name = nameof(GetUserById))]
public ActionResult GetUserById(int UserId)
{
var (success, User) = _dbContext.GetOneUserById(UserId);
if (success)
{
return Ok(User);
}
return new NotFoundResult();
}
#endregion
*/
#region Roles
///
/// Get Application users
///
///
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[HttpGet("roles")]
public ActionResult GetApplicationRoles(
int skip = 0,
int take = 50,
int orderDir = 1)
{
var (success, users) = _dbContext.GetRoles( skip, take, orderDir);
if (!success) return new NotFoundResult();
return Ok(users);
}
#endregion
}
}
public static class Constants
{
public const string CorsPolicyName = "_myAllowSpecificOrigins";
}