From b9e55a05730cf4ede8dd5bd7a6f9befe5bc3580e Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 17 Dec 2020 23:09:24 +0800 Subject: ... --- .../Controllers/HighlightTimelineController.cs | 52 ++++++++++++++++++++-- 1 file changed, 48 insertions(+), 4 deletions(-) (limited to 'BackEnd/Timeline/Controllers') diff --git a/BackEnd/Timeline/Controllers/HighlightTimelineController.cs b/BackEnd/Timeline/Controllers/HighlightTimelineController.cs index 3819bfc4..0b6e1665 100644 --- a/BackEnd/Timeline/Controllers/HighlightTimelineController.cs +++ b/BackEnd/Timeline/Controllers/HighlightTimelineController.cs @@ -15,7 +15,6 @@ namespace Timeline.Controllers /// [ApiController] [ProducesErrorResponseType(typeof(CommonResponse))] - [Route("highlights")] public class HighlightTimelineController : Controller { private readonly IHighlightTimelineService _service; @@ -31,7 +30,7 @@ namespace Timeline.Controllers /// Get all highlight timelines. /// /// Highlight timeline list. - [HttpGet] + [HttpGet("highlights")] [ProducesResponseType(200)] public async Task>> List() { @@ -42,8 +41,8 @@ namespace Timeline.Controllers /// /// Add a timeline to highlight list. /// - /// - [HttpPut("{timeline}")] + /// The timeline name. + [HttpPut("highlights/{timeline}")] [PermissionAuthorize(UserPermission.HighlightTimelineManagement)] [ProducesResponseType(200)] [ProducesResponseType(400)] @@ -59,5 +58,50 @@ namespace Timeline.Controllers return BadRequest(ErrorResponse.TimelineController.NotExist()); } } + + /// + /// Remove a timeline from highlight list. + /// + /// Timeline name. + [HttpDelete("highlights/{timeline}")] + [PermissionAuthorize(UserPermission.HighlightTimelineManagement)] + [ProducesResponseType(200)] + [ProducesResponseType(400)] + public async Task Delete([GeneralTimelineName] string timeline) + { + try + { + await _service.RemoveHighlightTimeline(timeline, this.GetUserId()); + return Ok(); + } + catch (TimelineNotExistException) + { + return BadRequest(ErrorResponse.TimelineController.NotExist()); + } + } + + /// + /// Move a highlight position. + /// + [HttpPost("highlightop/move")] + [PermissionAuthorize(UserPermission.HighlightTimelineManagement)] + [ProducesResponseType(200)] + [ProducesResponseType(400)] + public async Task Move([FromBody] HttpHighlightTimelineMoveRequest body) + { + try + { + await _service.MoveHighlightTimeline(body.Timeline, body.NewPosition!.Value); + return Ok(); + } + catch (TimelineNotExistException) + { + return BadRequest(ErrorResponse.TimelineController.NotExist()); + } + catch (InvalidHighlightTimelineException) + { + return BadRequest(new CommonResponse(ErrorCodes.HighlightTimelineController.NonHighlight, "Can't move a non-highlight timeline.")); + } + } } } -- cgit v1.2.3