diff options
Diffstat (limited to 'BackEnd/Timeline')
-rw-r--r-- | BackEnd/Timeline/Controllers/TimelinePostController.cs | 35 | ||||
-rw-r--r-- | BackEnd/Timeline/Models/Http/HttpTimelinePostPatchRequest.cs | 20 |
2 files changed, 34 insertions, 21 deletions
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;
@@ -210,6 +209,40 @@ namespace Timeline.Controllers }
/// <summary>
+ /// Update a post except content.
+ /// </summary>
+ /// <param name="timeline">Timeline name.</param>
+ /// <param name="post">Post id.</param>
+ /// <param name="body">Request body.</param>
+ /// <returns>New info of post.</returns>
+ [HttpPatch("{post}")]
+ [Authorize]
+ [ProducesResponseType(StatusCodes.Status200OK)]
+ [ProducesResponseType(StatusCodes.Status400BadRequest)]
+ [ProducesResponseType(StatusCodes.Status401Unauthorized)]
+ [ProducesResponseType(StatusCodes.Status403Forbidden)]
+ public async Task<ActionResult<HttpTimelinePost>> 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());
+ }
+ }
+
+ /// <summary>
/// Delete a post.
/// </summary>
/// <param name="timeline">Timeline name.</param>
diff --git a/BackEnd/Timeline/Models/Http/HttpTimelinePostPatchRequest.cs b/BackEnd/Timeline/Models/Http/HttpTimelinePostPatchRequest.cs index 3dface29..2c6edf66 100644 --- a/BackEnd/Timeline/Models/Http/HttpTimelinePostPatchRequest.cs +++ b/BackEnd/Timeline/Models/Http/HttpTimelinePostPatchRequest.cs @@ -3,26 +3,6 @@ using Timeline.Models.Validation; namespace Timeline.Models.Http
{
- /// <summary>
- /// The model of changing post content.
- /// </summary>
- public class HttpTimelinePostPatchRequestContent
- {
- /// <summary>
- /// The new type of the post. If null, old type is used. This field can't be used alone. Use it with corresponding fields to change post content.
- /// </summary>
- [TimelinePostContentType]
- public string? Type { get; set; }
- /// <summary>
- /// The new text. Null for not change.
- /// </summary>
- public string? Text { get; set; }
- /// <summary>
- /// The new data. Null for not change.
- /// </summary>
- public string? Data { get; set; }
- }
-
public class HttpTimelinePostPatchRequest
{
/// <summary>
|