diff options
author | crupest <crupest@outlook.com> | 2020-12-17 23:49:16 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-17 23:49:16 +0800 |
commit | ebc2892d1546b8b59bd1c9adabe8a96a2e2a0754 (patch) | |
tree | f27b279237a6a7ab3b6a09206f3fec6a5524674b /BackEnd/Timeline/Controllers/HighlightTimelineController.cs | |
parent | b0ee9afddd4f7ecf8a183ab8d8e9e575324a2b68 (diff) | |
parent | d452781c81e6d19076cf9d356877e154b2e34e91 (diff) | |
download | timeline-ebc2892d1546b8b59bd1c9adabe8a96a2e2a0754.tar.gz timeline-ebc2892d1546b8b59bd1c9adabe8a96a2e2a0754.tar.bz2 timeline-ebc2892d1546b8b59bd1c9adabe8a96a2e2a0754.zip |
Merge pull request #192 from crupest/highlight-timeline
Highlight timeline.
Diffstat (limited to 'BackEnd/Timeline/Controllers/HighlightTimelineController.cs')
-rw-r--r-- | BackEnd/Timeline/Controllers/HighlightTimelineController.cs | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/BackEnd/Timeline/Controllers/HighlightTimelineController.cs b/BackEnd/Timeline/Controllers/HighlightTimelineController.cs new file mode 100644 index 00000000..0b6e1665 --- /dev/null +++ b/BackEnd/Timeline/Controllers/HighlightTimelineController.cs @@ -0,0 +1,107 @@ +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
+{
+ /// <summary>
+ /// Api related to highlight timeline.
+ /// </summary>
+ [ApiController]
+ [ProducesErrorResponseType(typeof(CommonResponse))]
+ public class HighlightTimelineController : Controller
+ {
+ private readonly IHighlightTimelineService _service;
+ private readonly IMapper _mapper;
+
+ public HighlightTimelineController(IHighlightTimelineService service, IMapper mapper)
+ {
+ _service = service;
+ _mapper = mapper;
+ }
+
+ /// <summary>
+ /// Get all highlight timelines.
+ /// </summary>
+ /// <returns>Highlight timeline list.</returns>
+ [HttpGet("highlights")]
+ [ProducesResponseType(200)]
+ public async Task<ActionResult<List<HttpTimeline>>> List()
+ {
+ var t = await _service.GetHighlightTimelines();
+ return _mapper.Map<List<HttpTimeline>>(t);
+ }
+
+ /// <summary>
+ /// Add a timeline to highlight list.
+ /// </summary>
+ /// <param name="timeline">The timeline name.</param>
+ [HttpPut("highlights/{timeline}")]
+ [PermissionAuthorize(UserPermission.HighlightTimelineManagement)]
+ [ProducesResponseType(200)]
+ [ProducesResponseType(400)]
+ public async Task<ActionResult> Put([GeneralTimelineName] string timeline)
+ {
+ try
+ {
+ await _service.AddHighlightTimeline(timeline, this.GetUserId());
+ return Ok();
+ }
+ catch (TimelineNotExistException)
+ {
+ return BadRequest(ErrorResponse.TimelineController.NotExist());
+ }
+ }
+
+ /// <summary>
+ /// Remove a timeline from highlight list.
+ /// </summary>
+ /// <param name="timeline">Timeline name.</param>
+ [HttpDelete("highlights/{timeline}")]
+ [PermissionAuthorize(UserPermission.HighlightTimelineManagement)]
+ [ProducesResponseType(200)]
+ [ProducesResponseType(400)]
+ public async Task<ActionResult> Delete([GeneralTimelineName] string timeline)
+ {
+ try
+ {
+ await _service.RemoveHighlightTimeline(timeline, this.GetUserId());
+ return Ok();
+ }
+ catch (TimelineNotExistException)
+ {
+ return BadRequest(ErrorResponse.TimelineController.NotExist());
+ }
+ }
+
+ /// <summary>
+ /// Move a highlight position.
+ /// </summary>
+ [HttpPost("highlightop/move")]
+ [PermissionAuthorize(UserPermission.HighlightTimelineManagement)]
+ [ProducesResponseType(200)]
+ [ProducesResponseType(400)]
+ public async Task<ActionResult> 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."));
+ }
+ }
+ }
+}
|