AdminCategoryController.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using GxPress.Repository.Interface.Category;
  4. using Microsoft.AspNetCore.Authorization;
  5. using Microsoft.AspNetCore.Mvc;
  6. // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
  7. namespace GxPress.Api.AdminControllers
  8. {
  9. [ApiController]
  10. [Authorize]
  11. [Route("api/admin/category")]
  12. public class AdminCategoryController : Controller
  13. {
  14. private readonly ICategoryRepository categoryRepository;
  15. public AdminCategoryController(ICategoryRepository categoryRepository)
  16. {
  17. this.categoryRepository = categoryRepository;
  18. }
  19. /// <summary>
  20. /// 详情
  21. /// </summary>
  22. /// <param name="id"></param>
  23. /// <returns></returns>
  24. [HttpGet("{id}")]
  25. public async Task<Entity.tede2.Category.Category> GetAsync(int id)
  26. {
  27. return await categoryRepository.GetAsync(id);
  28. }
  29. /// <summary>
  30. /// 删除
  31. /// </summary>
  32. /// <param name="id"></param>
  33. /// <returns></returns>
  34. [HttpDelete("{id}")]
  35. public async Task<bool> DeleteAsync(int id)
  36. {
  37. return await categoryRepository.DeleteAsync(id);
  38. }
  39. /// <summary>
  40. /// 添加
  41. /// </summary>
  42. /// <param name="note"></param>
  43. /// <returns></returns>
  44. [HttpPost]
  45. public async Task<int> InsertAsync(Entity.tede2.Category.Category note)
  46. {
  47. return await categoryRepository.InsertAsync(note);
  48. }
  49. /// <summary>
  50. /// 修改
  51. /// </summary>
  52. /// <param name="note"></param>
  53. /// <returns></returns>
  54. [HttpPut]
  55. public async Task<bool> UpdateAsync(Entity.tede2.Category.Category note)
  56. {
  57. return await categoryRepository.UpdateAsync(note);
  58. }
  59. /// <summary>
  60. /// 获取所有
  61. /// </summary>
  62. /// <returns></returns>
  63. [HttpGet]
  64. public async Task<IEnumerable<Entity.tede2.Category.Category>> GetAllAsync()
  65. {
  66. return await categoryRepository.GetAllAsync();
  67. }
  68. /// <summary>
  69. /// 查询子集
  70. /// </summary>
  71. /// <param name="parentId"></param>
  72. /// <returns></returns>
  73. [HttpGet("children/{parentId}")]
  74. public async Task<IEnumerable<Entity.tede2.Category.Category>> GetCategoryChildrenAsync(int parentId)
  75. {
  76. return await categoryRepository.GetCategoryChildrenAsync(parentId);
  77. }
  78. }
  79. }