From 45b683d582d4a7760ffd69c4cd47841ce0545119 Mon Sep 17 00:00:00 2001 From: crupest Date: Mon, 8 Feb 2021 21:24:42 +0800 Subject: ... --- .../Timeline/Controllers/TimelinePostController.cs | 35 +++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'BackEnd/Timeline/Controllers/TimelinePostController.cs') diff --git a/BackEnd/Timeline/Controllers/TimelinePostController.cs b/BackEnd/Timeline/Controllers/TimelinePostController.cs index 4dab2a44..44498c58 100644 --- a/BackEnd/Timeline/Controllers/TimelinePostController.cs +++ b/BackEnd/Timeline/Controllers/TimelinePostController.cs @@ -4,7 +4,6 @@ using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Threading.Tasks; -using Timeline.Entities; using Timeline.Filters; using Timeline.Helpers; using Timeline.Models; @@ -209,6 +208,40 @@ namespace Timeline.Controllers } } + /// + /// Update a post except content. + /// + /// Timeline name. + /// Post id. + /// Request body. + /// New info of post. + [HttpPatch("{post}")] + [Authorize] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + public async Task> Patch([FromRoute][GeneralTimelineName] string timeline, [FromRoute] long post, [FromBody] HttpTimelinePostPatchRequest body) + { + var timelineId = await _timelineService.GetTimelineIdByName(timeline); + + try + { + if (!UserHasAllTimelineManagementPermission && !await _postService.HasPostModifyPermission(timelineId, post, this.GetUserId(), true)) + { + return StatusCode(StatusCodes.Status403Forbidden, ErrorResponse.Common.Forbid()); + } + + var entity = await _postService.PatchPost(timelineId, post, new TimelinePostPatchRequest { Time = body.Time, Color = body.Color }); + var result = await _timelineMapper.MapToHttp(entity, timeline, Url); + return Ok(result); + } + catch (TimelinePostNotExistException) + { + return BadRequest(ErrorResponse.TimelineController.PostNotExist()); + } + } + /// /// Delete a post. /// -- cgit v1.2.3