From fb7e9fdc042fa14656a6cdd21f4b002d92badb29 Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 17 Dec 2020 20:24:22 +0800 Subject: ... --- .../Controllers/HighlightTimelineController.cs | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 BackEnd/Timeline/Controllers/HighlightTimelineController.cs (limited to 'BackEnd/Timeline/Controllers/HighlightTimelineController.cs') diff --git a/BackEnd/Timeline/Controllers/HighlightTimelineController.cs b/BackEnd/Timeline/Controllers/HighlightTimelineController.cs new file mode 100644 index 00000000..3819bfc4 --- /dev/null +++ b/BackEnd/Timeline/Controllers/HighlightTimelineController.cs @@ -0,0 +1,63 @@ +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()); + } + } + } +} -- cgit v1.2.3