CollectionController.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System.Threading.Tasks;
  2. using GxPress.Auth;
  3. using GxPress.Common.Page;
  4. using GxPress.Request.App.Collection;
  5. using GxPress.Result.App.Collection;
  6. using GxPress.Service.Interface.Collection;
  7. using Microsoft.AspNetCore.Authorization;
  8. using Microsoft.AspNetCore.Mvc;
  9. using Microsoft.Extensions.Logging;
  10. using GxPress.Repository.Interface.Collection;
  11. namespace GxPress.Api.AppControllers
  12. {
  13. /// <summary>
  14. /// 收藏
  15. /// </summary>
  16. [Route("api/app/collection")]
  17. [ApiController]
  18. [Authorize]
  19. public class CollectionController : ControllerBase
  20. {
  21. private readonly ILogger<CollectionController> _logger;
  22. private readonly ICollectionService _collectionService;
  23. private readonly ILoginContext _loginContext;
  24. private readonly ICollectionRepository collectionRepository;
  25. public CollectionController(ILogger<CollectionController> logger, ICollectionService collectionService, ILoginContext loginContext, ICollectionRepository collectionRepository)
  26. {
  27. _logger = logger;
  28. _collectionService = collectionService;
  29. _loginContext = loginContext;
  30. this.collectionRepository = collectionRepository;
  31. }
  32. /// <summary>
  33. /// 添加收藏
  34. /// </summary>
  35. /// <param name="request"></param>
  36. /// <returns></returns>
  37. [HttpPut("add")]
  38. public async Task<bool> Insert(CollectionInRequest request)
  39. {
  40. request.UserId = _loginContext.AccountId;
  41. return await _collectionService.Insert(request);
  42. }
  43. /// <summary>
  44. /// 收藏
  45. /// </summary>
  46. /// <param name="request"></param>
  47. /// <returns></returns>
  48. [HttpPost("search")]
  49. public async Task<PagedList<CollectionListPageResult>> PageList(CollectionPageSearchRequest request)
  50. {
  51. request.UserId = _loginContext.AccountId;
  52. return await _collectionService.PageListAsync(request);
  53. }
  54. /// <summary>
  55. /// 获取收藏详情
  56. /// </summary>
  57. /// <param name="id"></param>
  58. /// <returns></returns>
  59. [HttpGet("{id}")]
  60. public async Task<CollectionResult> GetCollectionDetail(int id)
  61. {
  62. return await _collectionService.GetCollectionDetailAsync(id);
  63. }
  64. /// <summary>
  65. /// 收藏无文件夹分页列表
  66. /// </summary>
  67. /// <param name="request"></param>
  68. /// <returns></returns>
  69. [HttpPost("list")]
  70. public async Task<PagedList<CollectionNoFolderResult>> GetCollectionNoFolderPageListAsync(CollectionPageSearchRequest request)
  71. {
  72. request.UserId = _loginContext.AccountId;
  73. return await _collectionService.GetCollectionNoFolderPageListAsync(request);
  74. }
  75. /// <summary>
  76. /// 设置收藏置顶
  77. /// </summary>
  78. /// <param name="id"></param>
  79. /// <return></returns>
  80. [HttpPut("{id}")]
  81. public async Task<bool> SetTopAsync(int id)
  82. {
  83. return await collectionRepository.SetTopAsync(id);
  84. }
  85. [HttpGet("update-result")]
  86. [AllowAnonymous]
  87. public async Task<bool> UpdateResultJosnAsync()
  88. {
  89. return await _collectionService.UpdateResultJosnAsync();
  90. }
  91. }
  92. }