using FHT.Agency.CommonTypes; using FHT.Agency.Web.Filters; using FHT.ApiCommon; using FHT.DDD; using FHT.Management.Interfaces.DependentInterfaces.Services; using FHT.Management.Interfaces.InputModels; using FHT.Management.Interfaces.ViewModels; using Microsoft.AspNet.Identity; 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/feedbacks")] [EnableCors(origins: "*", headers: "*", methods: "*")] public class FeedBackApiController : ApiController { private readonly IManagementFeedbackService _managementFeedbackService; public FeedBackApiController(IManagementFeedbackService managementFeedbackService) { _managementFeedbackService = managementFeedbackService; } [HttpGet] [ClaimsAuthorize(FhtUserClaimType.FeedBack)] [ResponseType(typeof(QueryResult))] [Route("_search")] public async Task SearchAsync( bool isDeal, string q="", int? userId = null, int currPage = 1, int limit = 20) { int offset = (currPage < 2 ? 0 : currPage - 1) * limit; QueryResult feedBacks = await _managementFeedbackService.SearchAsync(userId, isDeal, q, limit, offset); return Ok(feedBacks); } [HttpGet] [ClaimsAuthorize(FhtUserClaimType.FeedBack)] [ResponseType(typeof(FeedbackViewModel))] [Route("{feedBackId:long:min(1)}")] public async Task GetDetailAsync(long feedBackId) { FeedbackViewModel model = await _managementFeedbackService.GetDetailAsync(feedBackId); return Ok(model); } [HttpGet] [ClaimsAuthorize(FhtUserClaimType.FeedBack)] [ResponseType(typeof(FeedbackDealInputModel))] [Route("_get")] public async Task GetAsync(long feedBackId) { FeedbackViewModel model = await _managementFeedbackService.GetDetailAsync(feedBackId); var inputModel = new FeedbackDealInputModel { FeedBackId = model.FeedBackId, Reply = model.Reply }; return Ok(inputModel); } [HttpPost] [ClaimsAuthorize(FhtUserClaimType.FeedBack)] [ValidateModel] [Route("_reply")] [ResponseType(typeof(void))] public async Task ReplyAsync(FeedbackDealInputModel model) { int operatorId = User.Identity.GetUserId(); await _managementFeedbackService.ReplyAsync(operatorId, model); return Ok(); } } }