using FHT.Agency.CommonTypes; using FHT.Agency.Web.Filters; using FHT.ApiCommon; using FHT.Core.CommonTypes; using FHT.Core.UI.ViewModels; using FHT.DDD; using FHT.Management.Interfaces.DependentInterfaces.Services; using FHT.Management.Interfaces.InputModels; using FHT.Management.Interfaces.ViewModels; using System.Threading.Tasks; using System.Web.Http; using System.Web.Http.Cors; using System.Web.Http.Description; namespace FHT.Agency.Web.ApiControllers { [Authorize] [RoutePrefix("api/appversions")] [EnableCors(origins: "*", headers: "*", methods: "*")] public class AppVersionApiController : ApiController { private readonly IManagementAppVersionService _managementAppVersionService; public AppVersionApiController(IManagementAppVersionService managementAppVersionService) { _managementAppVersionService = managementAppVersionService; } /// /// 检索数据 /// /// /// /// /// /// [HttpGet] [Route("_search")] [ResponseType(typeof(QueryResult))] [ApiClaimsAuthorize(FhtUserClaimType.AppVersion)] public async Task SearchAsync(DeviceType? deviceType = null, string q = "", int currPage = 1, int limit = 6) { int offset = (currPage < 2 ? 0 : currPage - 1) * limit; QueryResult results = await _managementAppVersionService.SearchAsync(q, deviceType, limit, offset); return Ok(results); } [HttpGet] [Route("{id:int:min(1)}")] [ResponseType(typeof(AppVersionInputModel))] [ApiClaimsAuthorize(FhtUserClaimType.AppVersion)] public async Task GetAsync(int id) { AppVersionInputModel model = await _managementAppVersionService.GetAsync(id); return Ok(model); } [HttpPost] [Route("_create", Name = nameof(CreateAppVersionAsync))] [ResponseType(typeof(CreatedViewModel))] [ValidateModel] [ApiClaimsAuthorize(FhtUserClaimType.AppVersion)] public async Task CreateAppVersionAsync(AppVersionInputModel model) { int appVersionId = await _managementAppVersionService.CreateOrUpdateAsync(model); string url = Url.Link(nameof(CreateAppVersionAsync), new { appVersionId }); return Created(url, new CreatedViewModel { Id = appVersionId, Location = url }); } [HttpPost] [Route("_update")] [ResponseType(typeof(void))] [ValidateModel] [ApiClaimsAuthorize(FhtUserClaimType.AppVersion)] public async Task UpdateAsync(AppVersionInputModel model) { await _managementAppVersionService.CreateOrUpdateAsync(model); return Ok(); } [HttpPost] [Route("_delete")] [ResponseType(typeof(void))] [ApiClaimsAuthorize(FhtUserClaimType.AppVersion)] public async Task DeleteByIdsAsync(int[] appVersionIds) { await _managementAppVersionService.DeleteByIdsAsync(appVersionIds); return Ok(); } } }