aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-02-11 22:21:12 +0800
committercrupest <crupest@outlook.com>2021-02-11 22:21:12 +0800
commitb5376f71157f68f06aa04bde79389f9ab291d84a (patch)
tree369d3a89588e752983a26baff9c225ce43ad3ef8 /BackEnd/Timeline
parentd1317bd9fe08a933a13df88ba692343cde549123 (diff)
downloadtimeline-b5376f71157f68f06aa04bde79389f9ab291d84a.tar.gz
timeline-b5376f71157f68f06aa04bde79389f9ab291d84a.tar.bz2
timeline-b5376f71157f68f06aa04bde79389f9ab291d84a.zip
...
Diffstat (limited to 'BackEnd/Timeline')
-rw-r--r--BackEnd/Timeline/Controllers/UserAvatarController.cs4
-rw-r--r--BackEnd/Timeline/Entities/TimelinePostEntity.cs2
-rw-r--r--BackEnd/Timeline/Formatters/ByteDataInputFormatter.cs6
-rw-r--r--BackEnd/Timeline/Models/Http/HttpTimelinePost.cs5
-rw-r--r--BackEnd/Timeline/Models/Http/HttpTimelinePostCreateRequest.cs2
-rw-r--r--BackEnd/Timeline/Models/Mapper/TimelineMapper.cs2
-rw-r--r--BackEnd/Timeline/Services/TimelinePostService.cs4
7 files changed, 21 insertions, 4 deletions
diff --git a/BackEnd/Timeline/Controllers/UserAvatarController.cs b/BackEnd/Timeline/Controllers/UserAvatarController.cs
index 8ac2d21a..180d1f9b 100644
--- a/BackEnd/Timeline/Controllers/UserAvatarController.cs
+++ b/BackEnd/Timeline/Controllers/UserAvatarController.cs
@@ -102,12 +102,12 @@ namespace Timeline.Controllers
try
{
- var etag = await _service.SetAvatar(id, body);
+ var digest = await _service.SetAvatar(id, body);
_logger.LogInformation(Log.Format(LogPutSuccess,
("Username", username), ("Mime Type", Request.ContentType)));
- Response.Headers.Append("ETag", new EntityTagHeaderValue($"\"{etag}\"").ToString());
+ Response.Headers.Append("ETag", new EntityTagHeaderValue($"\"{digest.ETag}\"").ToString());
return Ok();
}
diff --git a/BackEnd/Timeline/Entities/TimelinePostEntity.cs b/BackEnd/Timeline/Entities/TimelinePostEntity.cs
index c65ef929..1f0270cb 100644
--- a/BackEnd/Timeline/Entities/TimelinePostEntity.cs
+++ b/BackEnd/Timeline/Entities/TimelinePostEntity.cs
@@ -37,6 +37,8 @@ namespace Timeline.Entities
[Column("last_updated")]
public DateTime LastUpdated { get; set; }
+#pragma warning disable CA2227
public List<TimelinePostDataEntity> DataList { get; set; } = default!;
+#pragma warning restore CA2227
}
}
diff --git a/BackEnd/Timeline/Formatters/ByteDataInputFormatter.cs b/BackEnd/Timeline/Formatters/ByteDataInputFormatter.cs
index 2451ead6..49f8221a 100644
--- a/BackEnd/Timeline/Formatters/ByteDataInputFormatter.cs
+++ b/BackEnd/Timeline/Formatters/ByteDataInputFormatter.cs
@@ -44,6 +44,12 @@ namespace Timeline.Formatters
var logger = context.HttpContext.RequestServices.GetRequiredService<ILogger<ByteDataInputFormatter>>();
+ if (request.ContentType is null)
+ {
+ logger.LogInformation("Failed to read body as bytes. Content-Type is not set.");
+ return await InputFormatterResult.FailureAsync();
+ }
+
if (contentLength == null)
{
logger.LogInformation("Failed to read body as bytes. Content-Length is not set.");
diff --git a/BackEnd/Timeline/Models/Http/HttpTimelinePost.cs b/BackEnd/Timeline/Models/Http/HttpTimelinePost.cs
index 165c92da..26e1a92d 100644
--- a/BackEnd/Timeline/Models/Http/HttpTimelinePost.cs
+++ b/BackEnd/Timeline/Models/Http/HttpTimelinePost.cs
@@ -26,7 +26,12 @@ namespace Timeline.Models.Http
/// Post id.
/// </summary>
public long Id { get; set; }
+ /// <summary>
+ /// The data list.
+ /// </summary>
+#pragma warning disable CA2227
public List<HttpTimelinePostDataDigest> DataList { get; set; } = default!;
+#pragma warning restore CA2227
/// <summary>
/// True if post is deleted.
/// </summary>
diff --git a/BackEnd/Timeline/Models/Http/HttpTimelinePostCreateRequest.cs b/BackEnd/Timeline/Models/Http/HttpTimelinePostCreateRequest.cs
index 07d823ad..2a973c72 100644
--- a/BackEnd/Timeline/Models/Http/HttpTimelinePostCreateRequest.cs
+++ b/BackEnd/Timeline/Models/Http/HttpTimelinePostCreateRequest.cs
@@ -13,7 +13,9 @@ namespace Timeline.Models.Http
[Required]
[MinLength(1)]
[MaxLength(100)]
+#pragma warning disable CA2227
public List<HttpTimelinePostCreateRequestData> DataList { get; set; } = default!;
+#pragma warning restore CA2227
/// <summary>
/// Time of the post. If not set, current time will be used.
diff --git a/BackEnd/Timeline/Models/Mapper/TimelineMapper.cs b/BackEnd/Timeline/Models/Mapper/TimelineMapper.cs
index 33ee9593..1f10c123 100644
--- a/BackEnd/Timeline/Models/Mapper/TimelineMapper.cs
+++ b/BackEnd/Timeline/Models/Mapper/TimelineMapper.cs
@@ -66,6 +66,8 @@ namespace Timeline.Models.Mapper
public async Task<HttpTimelinePost> MapToHttp(TimelinePostEntity entity, string timelineName, IUrlHelper urlHelper)
{
+ _ = timelineName;
+
await _database.Entry(entity).Collection(p => p.DataList).LoadAsync();
await _database.Entry(entity).Reference(e => e.Author).LoadAsync();
diff --git a/BackEnd/Timeline/Services/TimelinePostService.cs b/BackEnd/Timeline/Services/TimelinePostService.cs
index 8afd0770..62bc43cc 100644
--- a/BackEnd/Timeline/Services/TimelinePostService.cs
+++ b/BackEnd/Timeline/Services/TimelinePostService.cs
@@ -1,6 +1,5 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
-using SixLabors.ImageSharp;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -12,7 +11,6 @@ using Timeline.Helpers.Cache;
using Timeline.Models;
using Timeline.Models.Validation;
using Timeline.Services.Exceptions;
-using static Timeline.Resources.Services.TimelineService;
namespace Timeline.Services
{
@@ -37,7 +35,9 @@ namespace Timeline.Services
/// <summary>If not set, current time is used.</summary>
public DateTime? Time { get; set; }
+#pragma warning disable CA2227
public List<TimelinePostCreateRequestData> DataList { get; set; } = new List<TimelinePostCreateRequestData>();
+#pragma warning restore CA2227
}
public class TimelinePostPatchRequest