CodeLiturgy.Dashboard/BlueWest.Api/Controllers/ApplicationUserController.cs

132 lines
3.7 KiB
C#
Raw Normal View History

2022-09-12 17:57:37 +03:00
using BlueWest.Data;
2022-09-11 01:22:04 +03:00
using BlueWest.WebApi.Context;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
2022-09-12 17:57:37 +03:00
using Microsoft.AspNetCore.Cors;
2022-09-11 01:22:04 +03:00
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace BlueWest.WebApi.Controllers
{
[ApiController]
2022-09-12 17:57:37 +03:00
[Route("application/users")]
2022-09-11 01:22:04 +03:00
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
2022-09-12 17:57:37 +03:00
[Authorize(AuthenticationSchemes = CookieAuthenticationDefaults.AuthenticationScheme)]
[EnableCors(Constants.CorsPolicyName)]
2022-09-11 01:22:04 +03:00
public class ApplicationUserController : ControllerBase
{
2022-09-12 17:57:37 +03:00
private readonly ApplicationUserDbContext _dbContext;
2022-09-11 01:22:04 +03:00
public ApplicationUserController(ApplicationUserDbContext context)
{
2022-09-12 17:57:37 +03:00
_dbContext = context;
}
#region Users
/// <summary>
/// Get Application users
/// </summary>
/// <returns></returns>
[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);
2022-09-11 01:22:04 +03:00
}
2022-09-12 17:57:37 +03:00
2022-09-11 01:22:04 +03:00
2022-09-12 17:57:37 +03:00
/// <summary>
/// Updates a User
/// </summary>
/// <param name="UserCode">The UserId ISO 3166 code</param>
/// <param name="UserToUpdate">User payload data</param>
/// <returns></returns>
[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
/// <summary>
/// Get User by Id
/// </summary>
/// <param name="UserId">ISO 3166-1 UserId numeric code</param>
/// <returns></returns>
[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
/// <summary>
/// Get Application users
/// </summary>
/// <returns></returns>
[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
2022-09-11 01:22:04 +03:00
}
}
2022-09-12 17:57:37 +03:00
public static class Constants
{
public const string CorsPolicyName = "_myAllowSpecificOrigins";
}