TispContentGroupItemController.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using Microsoft.AspNetCore.Mvc;
  2. using Microsoft.Extensions.Logging;
  3. using Ropin.Inspection.Api.Common;
  4. using Ropin.Inspection.Model.ViewModel;
  5. using Ropin.Inspection.Service.Interface;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Threading.Tasks;
  10. namespace Ropin.Inspection.Api.Controllers
  11. {
  12. public class TispContentGroupItemController : BaseController
  13. {
  14. public ILogger<TispContentGroupItemController> _logger { get; }
  15. private readonly ITispContentGroupItemService _service;
  16. /// <summary>
  17. /// 构造函数
  18. /// </summary>
  19. /// <param name="service"></param>
  20. /// <param name="logger"></param>
  21. public TispContentGroupItemController(ITispContentGroupItemService service, ILogger<TispContentGroupItemController> logger)
  22. {
  23. _service = service;
  24. _logger = logger;
  25. }
  26. /// <summary>
  27. /// 根据分组Id取内容列表
  28. /// </summary>
  29. /// <param name="id"></param>
  30. /// <returns></returns>
  31. [HttpGet("GetContentGroupItemByGroupIdAsync/{id}")]
  32. public async Task<ApiResult> GetContentGroupItemByGroupIdAsync(Guid id)
  33. {
  34. try
  35. {
  36. var list = await _service.GetContentGroupItemByGroupIdAsync(id);
  37. return new ApiResult<IEnumerable<TispContentGroupItemViewModel>>(list);
  38. }
  39. catch (Exception ex)
  40. {
  41. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  42. }
  43. }
  44. /// <summary>
  45. /// 给内容分组
  46. /// </summary>
  47. /// <param name="items"></param>
  48. /// <returns></returns>
  49. [Route("CreateContentGroupItemsAsync")]
  50. [HttpPost]
  51. public async Task<ApiResult> CreateContentGroupItemsAsync(IEnumerable<TispContentGroupItemCreateViewModel> items)
  52. {
  53. if (items == null)
  54. {
  55. return new ApiResult(ReturnCode.ArgsError);
  56. }
  57. try
  58. {
  59. await _service.CreateContentGroupItemsAsync(items);
  60. }
  61. catch (Exception ex)
  62. {
  63. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  64. }
  65. return new ApiResult(ReturnCode.Success);
  66. }
  67. }
  68. }