emoticon_api/ARW.WebApi/Controllers/Api/Custom/GoodsBrowsingHistorys/GoodsBrowsingHistoryApiController.cs
2023-10-22 17:23:10 +08:00

100 lines
3.7 KiB
C#

using Infrastructure;
using Infrastructure.Attribute;
using Infrastructure.Enums;
using Infrastructure.Model;
using Mapster;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ARW.Admin.WebApi.Extensions;
using ARW.Admin.WebApi.Filters;
using ARW.Common;
using ARW.Admin.WebApi.Controllers;
using ARW.Model.Dto.Api.Custom.GoodsBrowsingHistorys;
using ARW.Service.Api.IBusinessService.Custom.GoodsBrowsingHistorys;
using ARW.Model.Models.Business.Custom.GoodsBrowsingHistorys;
using ARW.Model.Vo.Api.Custom.GoodsBrowsingHistorys;
using Microsoft.AspNetCore.Authorization;
using Geocoding;
using ARW.Model.Dto.Business.Custom.GoodsBrowsingHistorys;
using ARW.Service.Business.IBusinessService.Custom.GoodsBrowsingHistorys;
using ARW.Admin.WebApi.Framework;
namespace ARW.WebApi.Controllers.Api.Custom.GoodsBrowsingHistorys
{
/// <summary>
/// 商品浏览记录控制器Api
///
/// @author lwh
/// @date 2023-10-22
/// </summary>
[Verify]
[Route("api/[controller]")]
public class GoodsBrowsingHistoryApiController : BaseController
{
private readonly IGoodsBrowsingHistoryServiceApi _GoodsBrowsingHistoryServiceApi;
/// <summary>
/// 依赖注入
/// </summary>
/// <param name="GoodsBrowsingHistoryServiceApi">商品浏览记录商品浏览记录Api服务</param>
public GoodsBrowsingHistoryApiController(IGoodsBrowsingHistoryServiceApi GoodsBrowsingHistoryServiceApi)
{
_GoodsBrowsingHistoryServiceApi = GoodsBrowsingHistoryServiceApi;
}
/// <summary>
/// 获取商品浏览记录列表(Api)
/// </summary>
/// <param name="parm">查询参数</param>
/// <returns></returns>
[HttpGet("getGoodsBrowsingHistoryList")]
public async Task<IActionResult> GetGoodsBrowsingHistoryListApi([FromQuery] GoodsBrowsingHistoryQueryDtoApi parm)
{
var user = JwtUtil.GetLoginUser(App.HttpContext);
parm.CustomerGuid = user.UserId;
var res = await _GoodsBrowsingHistoryServiceApi.GetGoodsBrowsingHistoryListApi(parm);
return SUCCESS(res);
}
/// <summary>
/// 添加或修改商品浏览记录
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
[HttpPost("addOrUpdateGoodsBrowsingHistory")]
[Log(Title = "添加或修改商品浏览记录", BusinessType = BusinessType.ADDORUPDATE)]
public async Task<IActionResult> AddOrUpdateGoodsBrowsingHistory([FromBody] GoodsBrowsingHistoryDto parm)
{
if (parm == null) { throw new CustomException("请求参数错误"); }
var user = JwtUtil.GetLoginUser(App.HttpContext);
parm.CustomerGuid = user.UserId;
var modal = new GoodsBrowsingHistory();
if (parm.GoodsBrowsingHistoryId != 0) modal = parm.Adapt<GoodsBrowsingHistory>().ToUpdate(HttpContext);
else modal = parm.Adapt<GoodsBrowsingHistory>().ToCreate(HttpContext);
var res = await _GoodsBrowsingHistoryServiceApi.AddOrUpdateGoodsBrowsingHistory(modal);
return SUCCESS(res);
}
/// <summary>
/// 删除商品浏览记录
/// </summary>
/// <returns></returns>
[HttpDelete("{ids}")]
[Log(Title = "商品浏览记录删除", BusinessType = BusinessType.DELETE)]
public IActionResult Delete(string ids)
{
long[] idsArr = Tools.SpitLongArrary(ids);
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
var response = _GoodsBrowsingHistoryServiceApi.Delete(idsArr);
return SUCCESS("删除成功!");
}
}
}