diff options
author | crupest <crupest@outlook.com> | 2020-12-17 23:09:24 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-12-17 23:09:24 +0800 |
commit | b9e55a05730cf4ede8dd5bd7a6f9befe5bc3580e (patch) | |
tree | f49daa201f1a3c34a3d9182839f1a3bae41dcdfa | |
parent | 1a56df5e91788f0e04cad7d94542ab0189033502 (diff) | |
download | timeline-b9e55a05730cf4ede8dd5bd7a6f9befe5bc3580e.tar.gz timeline-b9e55a05730cf4ede8dd5bd7a6f9befe5bc3580e.tar.bz2 timeline-b9e55a05730cf4ede8dd5bd7a6f9befe5bc3580e.zip |
...
-rw-r--r-- | BackEnd/Timeline.ErrorCodes/ErrorCodes.cs | 5 | ||||
-rw-r--r-- | BackEnd/Timeline/Controllers/HighlightTimelineController.cs | 52 | ||||
-rw-r--r-- | BackEnd/Timeline/Models/Http/HighlightTimeline.cs | 17 |
3 files changed, 70 insertions, 4 deletions
diff --git a/BackEnd/Timeline.ErrorCodes/ErrorCodes.cs b/BackEnd/Timeline.ErrorCodes/ErrorCodes.cs index 90c4ed99..a8519216 100644 --- a/BackEnd/Timeline.ErrorCodes/ErrorCodes.cs +++ b/BackEnd/Timeline.ErrorCodes/ErrorCodes.cs @@ -63,6 +63,11 @@ public const int PostNotExist = 1_104_05_01;
public const int PostNoData = 1_104_05_02;
}
+
+ public static class HighlightTimelineController
+ {
+ public const int NonHighlight = 1_105_01_01;
+ }
}
}
diff --git a/BackEnd/Timeline/Controllers/HighlightTimelineController.cs b/BackEnd/Timeline/Controllers/HighlightTimelineController.cs index 3819bfc4..0b6e1665 100644 --- a/BackEnd/Timeline/Controllers/HighlightTimelineController.cs +++ b/BackEnd/Timeline/Controllers/HighlightTimelineController.cs @@ -15,7 +15,6 @@ namespace Timeline.Controllers /// </summary>
[ApiController]
[ProducesErrorResponseType(typeof(CommonResponse))]
- [Route("highlights")]
public class HighlightTimelineController : Controller
{
private readonly IHighlightTimelineService _service;
@@ -31,7 +30,7 @@ namespace Timeline.Controllers /// Get all highlight timelines.
/// </summary>
/// <returns>Highlight timeline list.</returns>
- [HttpGet]
+ [HttpGet("highlights")]
[ProducesResponseType(200)]
public async Task<ActionResult<List<HttpTimeline>>> List()
{
@@ -42,8 +41,8 @@ namespace Timeline.Controllers /// <summary>
/// Add a timeline to highlight list.
/// </summary>
- /// <param name="timeline"></param>
- [HttpPut("{timeline}")]
+ /// <param name="timeline">The timeline name.</param>
+ [HttpPut("highlights/{timeline}")]
[PermissionAuthorize(UserPermission.HighlightTimelineManagement)]
[ProducesResponseType(200)]
[ProducesResponseType(400)]
@@ -59,5 +58,50 @@ namespace Timeline.Controllers 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."));
+ }
+ }
}
}
diff --git a/BackEnd/Timeline/Models/Http/HighlightTimeline.cs b/BackEnd/Timeline/Models/Http/HighlightTimeline.cs new file mode 100644 index 00000000..e5aed068 --- /dev/null +++ b/BackEnd/Timeline/Models/Http/HighlightTimeline.cs @@ -0,0 +1,17 @@ +using System.ComponentModel.DataAnnotations;
+using Timeline.Models.Validation;
+
+namespace Timeline.Models.Http
+{
+ /// <summary>
+ /// Move highlight timeline request body model.
+ /// </summary>
+ public class HttpHighlightTimelineMoveRequest
+ {
+ [GeneralTimelineName]
+ public string Timeline { get; set; } = default!;
+
+ [Required]
+ public long? NewPosition { get; set; }
+ }
+}
|