aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline/Controllers
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-12-19 20:12:00 +0800
committerGitHub <noreply@github.com>2020-12-19 20:12:00 +0800
commitd25b74fa167944a7701997e34810a2ffc3c39edd (patch)
tree03e2138077430562db17eab4fb0adfca1e16b80c /BackEnd/Timeline/Controllers
parent3b3c7c170f0070b0db85834b6c913b9060996d1d (diff)
parenta68670a3d87276ff73aa232d00a391d81407aced (diff)
downloadtimeline-d25b74fa167944a7701997e34810a2ffc3c39edd.tar.gz
timeline-d25b74fa167944a7701997e34810a2ffc3c39edd.tar.bz2
timeline-d25b74fa167944a7701997e34810a2ffc3c39edd.zip
Merge pull request #194 from crupest/bookmark-timeline
Bookmark timeline.
Diffstat (limited to 'BackEnd/Timeline/Controllers')
-rw-r--r--BackEnd/Timeline/Controllers/BookmarkTimelineController.cs114
-rw-r--r--BackEnd/Timeline/Controllers/HighlightTimelineController.cs8
2 files changed, 121 insertions, 1 deletions
diff --git a/BackEnd/Timeline/Controllers/BookmarkTimelineController.cs b/BackEnd/Timeline/Controllers/BookmarkTimelineController.cs
new file mode 100644
index 00000000..9dff95f3
--- /dev/null
+++ b/BackEnd/Timeline/Controllers/BookmarkTimelineController.cs
@@ -0,0 +1,114 @@
+using AutoMapper;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Timeline.Models.Http;
+using Timeline.Models.Validation;
+using Timeline.Services;
+using Timeline.Services.Exceptions;
+
+namespace Timeline.Controllers
+{
+ /// <summary>
+ /// Api related to timeline bookmarks.
+ /// </summary>
+ [ApiController]
+ [ProducesErrorResponseType(typeof(CommonResponse))]
+ public class BookmarkTimelineController : Controller
+ {
+ private readonly IBookmarkTimelineService _service;
+
+ private readonly IMapper _mapper;
+
+ public BookmarkTimelineController(IBookmarkTimelineService service, IMapper mapper)
+ {
+ _service = service;
+ _mapper = mapper;
+ }
+
+ /// <summary>
+ /// Get bookmark list in order.
+ /// </summary>
+ /// <returns>Bookmarks.</returns>
+ [HttpGet("bookmarks")]
+ [Authorize]
+ [ProducesResponseType(200)]
+ [ProducesResponseType(401)]
+ public async Task<ActionResult<List<HttpTimeline>>> List()
+ {
+ var bookmarks = await _service.GetBookmarks(this.GetUserId());
+ return Ok(_mapper.Map<List<HttpTimeline>>(bookmarks));
+ }
+
+ /// <summary>
+ /// Add a bookmark.
+ /// </summary>
+ /// <param name="timeline">Timeline name.</param>
+ [HttpPut("bookmarks/{timeline}")]
+ [Authorize]
+ [ProducesResponseType(200)]
+ [ProducesResponseType(400)]
+ [ProducesResponseType(401)]
+ public async Task<ActionResult> Put([GeneralTimelineName] string timeline)
+ {
+ try
+ {
+ await _service.AddBookmark(this.GetUserId(), timeline);
+ return Ok();
+ }
+ catch (TimelineNotExistException)
+ {
+ return BadRequest(ErrorResponse.TimelineController.NotExist());
+ }
+ }
+
+ /// <summary>
+ /// Remove a bookmark.
+ /// </summary>
+ /// <param name="timeline">Timeline name.</param>
+ [HttpDelete("bookmarks/{timeline}")]
+ [Authorize]
+ [ProducesResponseType(200)]
+ [ProducesResponseType(400)]
+ [ProducesResponseType(401)]
+ public async Task<ActionResult> Delete([GeneralTimelineName] string timeline)
+ {
+ try
+ {
+ await _service.RemoveBookmark(this.GetUserId(), timeline);
+ return Ok();
+ }
+ catch (TimelineNotExistException)
+ {
+ return BadRequest(ErrorResponse.TimelineController.NotExist());
+ }
+ }
+
+ /// <summary>
+ /// Move a bookmark to new posisition.
+ /// </summary>
+ /// <param name="request">Request body.</param>
+ [HttpPost("bookmarkop/move")]
+ [Authorize]
+ [ProducesResponseType(200)]
+ [ProducesResponseType(400)]
+ [ProducesResponseType(401)]
+ public async Task<ActionResult> Move([FromBody] HttpBookmarkTimelineMoveRequest request)
+ {
+ try
+ {
+ await _service.MoveBookmark(this.GetUserId(), request.Timeline, request.NewPosition!.Value);
+ return Ok();
+ }
+ catch (TimelineNotExistException)
+ {
+ return BadRequest(ErrorResponse.TimelineController.NotExist());
+ }
+ catch (InvalidBookmarkException)
+ {
+ return BadRequest(new CommonResponse(ErrorCodes.BookmarkTimelineController.NonBookmark, "You can't move a non-bookmark timeline."));
+ }
+ }
+ }
+}
diff --git a/BackEnd/Timeline/Controllers/HighlightTimelineController.cs b/BackEnd/Timeline/Controllers/HighlightTimelineController.cs
index 0b6e1665..519d6161 100644
--- a/BackEnd/Timeline/Controllers/HighlightTimelineController.cs
+++ b/BackEnd/Timeline/Controllers/HighlightTimelineController.cs
@@ -46,6 +46,8 @@ namespace Timeline.Controllers
[PermissionAuthorize(UserPermission.HighlightTimelineManagement)]
[ProducesResponseType(200)]
[ProducesResponseType(400)]
+ [ProducesResponseType(401)]
+ [ProducesResponseType(403)]
public async Task<ActionResult> Put([GeneralTimelineName] string timeline)
{
try
@@ -67,6 +69,8 @@ namespace Timeline.Controllers
[PermissionAuthorize(UserPermission.HighlightTimelineManagement)]
[ProducesResponseType(200)]
[ProducesResponseType(400)]
+ [ProducesResponseType(401)]
+ [ProducesResponseType(403)]
public async Task<ActionResult> Delete([GeneralTimelineName] string timeline)
{
try
@@ -81,12 +85,14 @@ namespace Timeline.Controllers
}
/// <summary>
- /// Move a highlight position.
+ /// Move a highlight to new position.
/// </summary>
[HttpPost("highlightop/move")]
[PermissionAuthorize(UserPermission.HighlightTimelineManagement)]
[ProducesResponseType(200)]
[ProducesResponseType(400)]
+ [ProducesResponseType(401)]
+ [ProducesResponseType(403)]
public async Task<ActionResult> Move([FromBody] HttpHighlightTimelineMoveRequest body)
{
try