74 lines
2.5 KiB
C#
74 lines
2.5 KiB
C#
using DigitalData.Core.API;
|
|
using DigitalData.UserManager.Application.Contracts;
|
|
using DigitalData.UserManager.Application.DTOs.GroupOfUser;
|
|
using DigitalData.UserManager.Domain.Entities;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace DigitalData.UserManager.API.Controllers
|
|
{
|
|
[Authorize]
|
|
public class GroupOfUserController : CRUDControllerBaseWithErrorHandling<IGroupOfUserService, GroupOfUserCreateDto, GroupOfUserReadDto, GroupOfUserUpdateDto, GroupOfUser, int>
|
|
{
|
|
public GroupOfUserController(ILogger<GroupOfUserController> logger, IGroupOfUserService service) : base(logger, service)
|
|
{
|
|
}
|
|
|
|
[HttpDelete]
|
|
public async Task<IActionResult> Delete([FromQuery] int groupId, [FromQuery] int userId)
|
|
{
|
|
try
|
|
{
|
|
var result = await _service.DeleteAsyncByGroupUserId(groupId, userId);
|
|
if (result.IsSuccess)
|
|
{
|
|
return Ok(result);
|
|
}
|
|
|
|
return BadRequest(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "{Message}", ex.Message);
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
|
|
[NonAction]
|
|
public override Task<IActionResult> GetAll() => base.GetAll();
|
|
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetAll([FromQuery]bool withUser = false, [FromQuery]bool withGroup = false)
|
|
{
|
|
try
|
|
{
|
|
var result = await _service.ReadAllAsyncWith(withUser, withGroup);
|
|
if (result.IsSuccess)
|
|
{
|
|
return Ok(result);
|
|
}
|
|
|
|
return NotFound(result);
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
_logger.LogError(ex, "{Message}", ex.Message);
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
|
|
[HttpGet("Has")]
|
|
public async Task<IActionResult> HasGroup([FromQuery] string username, [FromQuery] string groupname)
|
|
{
|
|
try
|
|
{
|
|
return Ok(await _service.HasGroup(username, groupname));
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
_logger.LogError(ex, "{Message}", ex.Message);
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
}
|
|
} |