AdminDepartmentController.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using System.Threading.Tasks;
  4. using GxPress.Entity;
  5. using GxPress.Repository.Interface;
  6. using GxPress.Result.Department;
  7. using GxPress.Service.Interface.Department;
  8. using Microsoft.AspNetCore.Authorization;
  9. using Microsoft.AspNetCore.Mvc;
  10. namespace GxPress.Api.AdminControllers
  11. {
  12. /// <summary>
  13. /// 部门
  14. /// </summary>
  15. [Route("api/admin/department")]
  16. [ApiController]
  17. [Authorize]
  18. public class AdminDepartmentController : ControllerBase
  19. {
  20. private readonly IDepartmentRepository _departmentRepository;
  21. private readonly IDepartmentService _departmentService;
  22. public AdminDepartmentController(IDepartmentRepository departmentRepository,IDepartmentService departmentService)
  23. {
  24. _departmentRepository = departmentRepository;
  25. _departmentService = departmentService;
  26. }
  27. /// <summary>
  28. /// 添加
  29. /// </summary>
  30. /// <param name="request"></param>
  31. /// <returns></returns>
  32. [HttpPost]
  33. public async Task<Department> Add([FromBody]Department request)
  34. {
  35. return await _departmentRepository.AddAsync(request);
  36. }
  37. /// <summary>
  38. /// 详情
  39. /// </summary>
  40. /// <param name="id"></param>
  41. /// <returns></returns>
  42. [HttpGet("{id}")]
  43. public async Task<Department> GetDetail(int id)
  44. {
  45. return await _departmentRepository.GetAsync(id);
  46. }
  47. /// <summary>
  48. /// 删除
  49. /// </summary>
  50. /// <param name="id"></param>
  51. /// <returns></returns>
  52. [HttpDelete("{id}")]
  53. public async Task<bool> Delete(int id)
  54. {
  55. return await _departmentService.DeleteAsync(id);
  56. }
  57. /// <summary>
  58. /// 修改
  59. /// </summary>
  60. /// <param name="id"></param>
  61. /// <param name="request"></param>
  62. /// <returns></returns>
  63. [HttpPut("{id}")]
  64. public async Task<bool> Update(int id, [FromBody] Department request)
  65. {
  66. return await _departmentRepository.UpdateAsync(id, request);
  67. }
  68. /// <summary>
  69. /// 树形结构展示,懒加载
  70. /// </summary>
  71. /// <param name="id"></param>
  72. /// <returns></returns>
  73. [HttpGet("tree")]
  74. public async Task<List<DepartmentTreeResult>> GetTree(int id = 0)
  75. {
  76. return await _departmentRepository.GetTreeAsync(id);
  77. }
  78. }
  79. }