aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline/Controllers/HighlightTimelineController.cs
blob: 3819bfc4518a5642213e9e9fbedf951b01af23ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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());
            }
        }
    }
}