44 lines
1.0 KiB
C#
44 lines
1.0 KiB
C#
using API.Authentication.Interfaces;
|
|
using API.DTO.Base;
|
|
using API.DTO.Base.Update;
|
|
using API.Services;
|
|
using DAL.Models;
|
|
using DAL.Models.Audits;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using MUser = DAL.Models.User;
|
|
|
|
namespace API.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("api/v1/[controller]")]
|
|
public class GrantController : CRUDBase<GrantController, GrantDTO, GrantUpdateDTO, Grant, AuditGrant, IGrantAuthentication, GrantService>
|
|
{
|
|
public GrantController(ILogger<GrantController> logger, UserService userService, GrantService service) : base(logger, userService, service)
|
|
{
|
|
}
|
|
|
|
[HttpGet("mine")]
|
|
public ActionResult<List<GrantDTO>> getMine()
|
|
{
|
|
MUser? user = getUser(User);
|
|
if (user == null)
|
|
return Unauthorized();
|
|
|
|
IEnumerable<Grant>? result = Service.getMine(user);
|
|
if (result == null)
|
|
return Forbid();
|
|
|
|
List<GrantDTO> dtos = [];
|
|
|
|
Parallel.ForEach(result, item =>
|
|
{
|
|
GrantDTO dto = new GrantDTO();
|
|
dto.adaptFromModel(item);
|
|
dtos.Add(dto);
|
|
});
|
|
|
|
return Ok(dtos);
|
|
}
|
|
}
|
|
}
|