using AutoMapper; using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; using System.Threading.Tasks; using Timeline.Auth; using Timeline.Models.Http; using Timeline.Models.Validation; using Timeline.Services; using Timeline.Services.Exceptions; namespace Timeline.Controllers { /// /// Api related to highlight timeline. /// [ApiController] [ProducesErrorResponseType(typeof(CommonResponse))] [Route("highlights")] public class HighlightTimelineController : Controller { private readonly IHighlightTimelineService _service; private readonly IMapper _mapper; public HighlightTimelineController(IHighlightTimelineService service, IMapper mapper) { _service = service; _mapper = mapper; } /// /// Get all highlight timelines. /// /// Highlight timeline list. [HttpGet] [ProducesResponseType(200)] public async Task>> List() { var t = await _service.GetHighlightTimelines(); return _mapper.Map>(t); } /// /// Add a timeline to highlight list. /// /// [HttpPut("{timeline}")] [PermissionAuthorize(UserPermission.HighlightTimelineManagement)] [ProducesResponseType(200)] [ProducesResponseType(400)] public async Task Put([GeneralTimelineName] string timeline) { try { await _service.AddHighlightTimeline(timeline, this.GetUserId()); return Ok(); } catch (TimelineNotExistException) { return BadRequest(ErrorResponse.TimelineController.NotExist()); } } } }