diff options
author | crupest <crupest@outlook.com> | 2022-04-11 22:16:19 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-04-11 22:16:19 +0800 |
commit | d4ccd980f6e3ae7ed7f1a8bedd5e3c10cf4df022 (patch) | |
tree | c9460faee34ac77b0bcdfdf0ebbc27507dd96fa0 /BackEnd/Timeline | |
parent | 671817e186d4f2c6209b8499f381068443a61793 (diff) | |
download | timeline-d4ccd980f6e3ae7ed7f1a8bedd5e3c10cf4df022.tar.gz timeline-d4ccd980f6e3ae7ed7f1a8bedd5e3c10cf4df022.tar.bz2 timeline-d4ccd980f6e3ae7ed7f1a8bedd5e3c10cf4df022.zip |
...
Diffstat (limited to 'BackEnd/Timeline')
3 files changed, 99 insertions, 0 deletions
diff --git a/BackEnd/Timeline/Controllers/TimelineBookmarkV2Controller.cs b/BackEnd/Timeline/Controllers/TimelineBookmarkV2Controller.cs index c9898b61..c2130b5a 100644 --- a/BackEnd/Timeline/Controllers/TimelineBookmarkV2Controller.cs +++ b/BackEnd/Timeline/Controllers/TimelineBookmarkV2Controller.cs @@ -84,6 +84,66 @@ namespace Timeline.Controllers return CreatedAtAction("Get", new { username, index = bookmark.Position }, bookmark); } + [Authorize] + [HttpPost("delete")] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status422UnprocessableEntity)] + public async Task<ActionResult> DeleteAsync([FromRoute][Username] string username, [FromBody] HttpTimelinebookmarkDeleteRequest body) + { + var userId = await _userService.GetUserIdByUsernameAsync(username); + if (!UserHasPermission(UserPermission.UserBookmarkManagement) && GetAuthUserId() != userId) + { + return Forbid(); + } + + long timelineId; + try + { + timelineId = await _timelineService.GetTimelineIdAsync(body.TimelineOwner, body.TimelineName); + } + catch (EntityNotExistException) + { + return UnprocessableEntity(); + } + + await _timelineBookmarkService.DeleteBookmarkAsync(userId, timelineId); + + return NoContent(); + } + + [Authorize] + [HttpPost("move")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status422UnprocessableEntity)] + public async Task<ActionResult<TimelineBookmark>> MoveAsync([FromRoute][Username] string username, [FromBody] HttpTimelineBookmarkMoveRequest body) + { + var userId = await _userService.GetUserIdByUsernameAsync(username); + if (!UserHasPermission(UserPermission.UserBookmarkManagement) && GetAuthUserId() != userId) + { + return Forbid(); + } + + long timelineId; + try + { + timelineId = await _timelineService.GetTimelineIdAsync(body.TimelineOwner, body.TimelineName); + } + catch (EntityNotExistException) + { + return UnprocessableEntity(); + } + + var bookmark = await _timelineBookmarkService.MoveBookmarkAsync(userId, timelineId, body.Position!.Value); + + return Ok(bookmark); + } + [HttpGet("visibility")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] diff --git a/BackEnd/Timeline/Models/Http/HttpTimelineBookmarkMoveRequest.cs b/BackEnd/Timeline/Models/Http/HttpTimelineBookmarkMoveRequest.cs new file mode 100644 index 00000000..5be7fd00 --- /dev/null +++ b/BackEnd/Timeline/Models/Http/HttpTimelineBookmarkMoveRequest.cs @@ -0,0 +1,21 @@ +using System; +using System.ComponentModel.DataAnnotations; +using Timeline.Models.Validation; + +namespace Timeline.Models.Http +{ + public class HttpTimelineBookmarkMoveRequest + { + [Required] + [Username] + public string TimelineOwner { get; set; } = default!; + + [Required] + [TimelineName] + public string TimelineName { get; set; } = default!; + + [Required] + public int? Position { get; set; } + } +} + diff --git a/BackEnd/Timeline/Models/Http/HttpTimelinebookmarkDeleteRequest.cs b/BackEnd/Timeline/Models/Http/HttpTimelinebookmarkDeleteRequest.cs new file mode 100644 index 00000000..ab45f976 --- /dev/null +++ b/BackEnd/Timeline/Models/Http/HttpTimelinebookmarkDeleteRequest.cs @@ -0,0 +1,18 @@ +using System; +using System.ComponentModel.DataAnnotations; +using Timeline.Models.Validation; + +namespace Timeline.Models.Http +{ + public class HttpTimelinebookmarkDeleteRequest + { + [Required] + [Username] + public string TimelineOwner { get; set; } = default!; + + [Required] + [TimelineName] + public string TimelineName { get; set; } = default!; + } +} + |