diff options
author | crupest <crupest@outlook.com> | 2020-08-31 22:39:18 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-08-31 22:39:18 +0800 |
commit | ff90e2819a1c0b7d1b605b45edaaaee7527c05b1 (patch) | |
tree | fdd69c951f68cda72ac1cbf017ca272ee1b783f5 | |
parent | c73388256aad039239cf3977d7b079e3f9323258 (diff) | |
download | timeline-ff90e2819a1c0b7d1b605b45edaaaee7527c05b1.tar.gz timeline-ff90e2819a1c0b7d1b605b45edaaaee7527c05b1.tar.bz2 timeline-ff90e2819a1c0b7d1b605b45edaaaee7527c05b1.zip |
Post info now contain data etag.
-rw-r--r-- | Timeline.Tests/IntegratedTests/TimelineTest.cs | 34 | ||||
-rw-r--r-- | Timeline/Models/Http/Timeline.cs | 7 | ||||
-rw-r--r-- | Timeline/Models/Timeline.cs | 4 |
3 files changed, 44 insertions, 1 deletions
diff --git a/Timeline.Tests/IntegratedTests/TimelineTest.cs b/Timeline.Tests/IntegratedTests/TimelineTest.cs index ac4f41a2..ec46b96a 100644 --- a/Timeline.Tests/IntegratedTests/TimelineTest.cs +++ b/Timeline.Tests/IntegratedTests/TimelineTest.cs @@ -1485,5 +1485,39 @@ namespace Timeline.Tests.IntegratedTests }
}
}
+
+ [Theory]
+ [MemberData(nameof(TimelineUrlGeneratorData))]
+ public async Task PostDataETag(TimelineUrlGenerator urlGenerator)
+ {
+ using var client = await CreateClientAsUser();
+
+ long id;
+ string etag;
+
+ {
+ var res = await client.PostAsJsonAsync(urlGenerator(1, "posts"), new TimelinePostCreateRequest
+ {
+ Content = new TimelinePostCreateRequestContent
+ {
+ Type = TimelinePostContentTypes.Image,
+ Data = Convert.ToBase64String(ImageHelper.CreatePngWithSize(100, 50))
+ }
+ });
+ res.Should().HaveStatusCode(200);
+ var body = await res.ReadBodyAsJsonAsync<TimelinePostInfo>();
+ body.Content.ETag.Should().NotBeNullOrEmpty();
+
+ id = body.Id;
+ etag = body.Content.ETag;
+ }
+
+ {
+ var res = await client.GetAsync(urlGenerator(1, $"posts/{id}/data"));
+ res.Should().HaveStatusCode(200);
+ res.Headers.ETag.Should().NotBeNull();
+ res.Headers.ETag.ToString().Should().Be(etag);
+ }
+ }
}
}
diff --git a/Timeline/Models/Http/Timeline.cs b/Timeline/Models/Http/Timeline.cs index 3596af18..a81b33f5 100644 --- a/Timeline/Models/Http/Timeline.cs +++ b/Timeline/Models/Http/Timeline.cs @@ -25,6 +25,10 @@ namespace Timeline.Models.Http /// If post is of image type. This is the image url.
/// </summary>
public string? Url { get; set; }
+ /// <summary>
+ /// If post has data (currently it means it's a image post), this is the data etag.
+ /// </summary>
+ public string? ETag { get; set; }
}
/// <summary>
@@ -192,7 +196,8 @@ namespace Timeline.Models.Http Url = urlHelper.ActionLink(
action: nameof(TimelineController.PostDataGet),
controller: nameof(TimelineController)[0..^nameof(Controller).Length],
- values: new { Name = source.TimelineName, Id = source.Id })
+ values: new { Name = source.TimelineName, Id = source.Id }),
+ ETag = $"\"{imageContent.DataTag}\""
};
}
else
diff --git a/Timeline/Models/Timeline.cs b/Timeline/Models/Timeline.cs index 42906053..a5987577 100644 --- a/Timeline/Models/Timeline.cs +++ b/Timeline/Models/Timeline.cs @@ -43,6 +43,10 @@ namespace Timeline.Models public ImageTimelinePostContent(string dataTag) { DataTag = dataTag; }
public string Type { get; } = TimelinePostContentTypes.Image;
+
+ /// <summary>
+ /// The tag of the data. The tag of the entry in DataManager. Also the etag (not quoted).
+ /// </summary>
public string DataTag { get; set; }
}
|