diff options
3 files changed, 64 insertions, 21 deletions
diff --git a/BackEnd/Timeline.Tests/IntegratedTests/TimelinePostTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/TimelinePostTest.cs index b4ddcb43..17c85f22 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/TimelinePostTest.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/TimelinePostTest.cs @@ -535,5 +535,35 @@ namespace Timeline.Tests.IntegratedTests await client.TestGetAssertNotFoundAsync($"timelines/{generator(1)}/posts/{post.Id}");
}
+
+ [Theory]
+ [MemberData(nameof(TimelineNameGeneratorTestData))]
+ public async Task PatchPost(TimelineNameGenerator generator)
+ {
+ using var client = await CreateClientAsUser();
+
+ var post = await client.TestPostAsync<HttpTimelinePost>($"timelines/{generator(1)}/posts", new HttpTimelinePostCreateRequest
+ {
+ Content = new()
+ {
+ Type = "text",
+ Text = "aaa"
+ }
+ });
+
+ var date = new DateTime(2000, 10, 1);
+
+ var post2 = await client.TestPatchAsync<HttpTimelinePost>($"timelines/{generator(1)}/posts/{post.Id}", new HttpTimelinePostPatchRequest
+ {
+ Time = date,
+ Color = "#aabbcc"
+ });
+ post2.Time.Should().Be(date);
+ post2.Color.Should().Be("#aabbcc");
+
+ var post3 = await client.TestGetAsync<HttpTimelinePost>($"timelines/{generator(1)}/posts/{post.Id}");
+ post3.Time.Should().Be(date);
+ post3.Color.Should().Be("#aabbcc");
+ }
}
}
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>
|