aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline/Controllers/HighlightTimelineController.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-12-17 20:24:22 +0800
committercrupest <crupest@outlook.com>2020-12-17 20:24:22 +0800
commit1a56df5e91788f0e04cad7d94542ab0189033502 (patch)
treef0295e3e7290d4f814e340fcc40c3c6957d8c4b0 /BackEnd/Timeline/Controllers/HighlightTimelineController.cs
parentd934c1273bc20533683eaad858a1c499c7729a28 (diff)
downloadtimeline-1a56df5e91788f0e04cad7d94542ab0189033502.tar.gz
timeline-1a56df5e91788f0e04cad7d94542ab0189033502.tar.bz2
timeline-1a56df5e91788f0e04cad7d94542ab0189033502.zip
...
Diffstat (limited to 'BackEnd/Timeline/Controllers/HighlightTimelineController.cs')
-rw-r--r--BackEnd/Timeline/Controllers/HighlightTimelineController.cs63
1 files changed, 63 insertions, 0 deletions
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
+{
+ /// <summary>
+ /// Api related to highlight timeline.
+ /// </summary>
+ [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;
+ }
+
+ /// <summary>
+ /// Get all highlight timelines.
+ /// </summary>
+ /// <returns>Highlight timeline list.</returns>
+ [HttpGet]
+ [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"></param>
+ [HttpPut("{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());
+ }
+ }
+ }
+}