TeamController.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using Microsoft.AspNetCore.Authorization;
  2. using Microsoft.AspNetCore.Http;
  3. using Microsoft.AspNetCore.Mvc;
  4. using MTWorkHR.Application.Filters;
  5. using MTWorkHR.Application.Identity;
  6. using MTWorkHR.Application.Models;
  7. using MTWorkHR.Application.Services.Interfaces;
  8. using MTWorkHR.Identity.Services;
  9. namespace MTWorkHR.API.Controllers
  10. {
  11. [Route("api/[controller]")]
  12. [ApiController]
  13. [AppAuthorize]
  14. public class TeamController : ControllerBase
  15. {
  16. private readonly ITeamService _TeamService;
  17. public TeamController(ITeamService UserTeamService)
  18. {
  19. this._TeamService = UserTeamService;
  20. }
  21. [HttpGet("GetAll")]
  22. [ProducesResponseType(StatusCodes.Status200OK)]
  23. [AppAuthorize(Permissions = "Team")]
  24. public async Task<ActionResult<List<TeamDto>>> GetAll([FromQuery] PagingInputDto pagingInput)
  25. {
  26. return Ok(await _TeamService.GetAll(pagingInput));
  27. }
  28. [HttpGet("Get")]
  29. [ProducesResponseType(StatusCodes.Status200OK)]
  30. [AppAuthorize(Permissions = "Team")]
  31. public async Task<ActionResult<TeamDto>> Get(long TeamId)
  32. {
  33. return Ok(await _TeamService.GetById(TeamId));
  34. }
  35. [HttpPost("Create")]
  36. [ProducesResponseType(StatusCodes.Status200OK)]
  37. [AppAuthorize(Permissions = "Team.Create")]
  38. public async Task<ActionResult<TeamDto>> Create([FromBody] TeamDto input)
  39. {
  40. return await _TeamService.Create(input);
  41. }
  42. [HttpPost("Update")]
  43. [ProducesResponseType(StatusCodes.Status200OK)]
  44. [AppAuthorize(Permissions = "Team.Update")]
  45. public async Task<ActionResult<TeamDto>> Update([FromBody] TeamDto input)
  46. {
  47. return await _TeamService.Update(input);
  48. }
  49. [HttpDelete("Delete")]
  50. [ProducesResponseType(StatusCodes.Status200OK)]
  51. [AppAuthorize(Permissions = "Team.Delete")]
  52. public async Task Delete([FromQuery] long id)
  53. {
  54. await _TeamService.Delete(id);
  55. }
  56. [HttpPost("AssignAdminManager")]
  57. [ProducesResponseType(StatusCodes.Status200OK)]
  58. [AppAuthorize(Permissions = "Team.Update")]
  59. public async Task<bool> AssignAdminManager([FromBody] TeamUserDto teamUser)
  60. {
  61. return await _TeamService.AssignAdminManager(teamUser);
  62. }
  63. }
  64. }