using FHT.Agency.CommonTypes; using FHT.Agency.Web.Filters; using FHT.Core.CommonTypes; using FHT.DDD; using FHT.Management.Interfaces.DependentInterfaces.Services; using System.Threading.Tasks; using System.Web.Http; using System.Web.Http.Description; using FHT.Management.Interfaces.ViewModels; using FHT.ApiCommon; using FHT.Management.Interfaces.InputModels; using Microsoft.AspNet.Identity; using System.Web.Http.Cors; namespace FHT.Agency.Web.ApiControllers { [Authorize] [RoutePrefix("api/applies")] [EnableCors(origins: "*", headers: "*", methods: "*")] public class ApplyApiController : ApiController { private readonly IManagementJoinApplyService _managementJoinApplyService; public ApplyApiController(IManagementJoinApplyService managementJoinApplyService) { _managementJoinApplyService = managementJoinApplyService; } [HttpGet] [Route("_search")] [ResponseType(typeof(QueryResult))] [ClaimsAuthorize(FhtUserClaimType.JoinApply, FhtUserClaimType.MemberApply)] public async Task SearchAsync(ApplyType applyType, bool isDeal, string q, int currPage, int limit = 20) { int offset = (currPage < 2 ? 0 : currPage - 1) * limit; QueryResult result = await _managementJoinApplyService.SearchAsync(applyType, isDeal, q, limit, offset); return Ok(result); } [HttpGet] [Route("{id:int:min(1)}")] [ResponseType(typeof(JoinApplyViewModel))] [ClaimsAuthorize(FhtUserClaimType.JoinApply, FhtUserClaimType.MemberApply)] public async Task GetDetailAsync(long id) { JoinApplyViewModel model = await _managementJoinApplyService.GetDetailAsync(id); return Ok(model); } [HttpPost] [ValidateModel] [ResponseType(typeof(void))] [Route("_deal")] [ClaimsAuthorize(FhtUserClaimType.JoinApply, FhtUserClaimType.MemberApply)] public async Task DealAsync(JoinApplyDealInputModel model) { int operatorId = User.Identity.GetUserId(); await _managementJoinApplyService.DealAsync(operatorId, model.JoinId); return Ok(); } } }