Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit 7e31275

Browse files
POST should return some additional information
1 parent a9b1ae9 commit 7e31275

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

src/SqlStreamStore.HAL.Tests/StreamAppendTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static IEnumerable<object[]> AppendCases()
6363
{
6464
body,
6565
ExpectedVersion.Any,
66-
HttpStatusCode.OK,
66+
HttpStatusCode.Created,
6767
messageId,
6868
jsonData,
6969
jsonMetadata
@@ -72,7 +72,7 @@ public static IEnumerable<object[]> AppendCases()
7272
{
7373
body,
7474
default(int?),
75-
HttpStatusCode.OK,
75+
HttpStatusCode.Created,
7676
messageId,
7777
jsonData,
7878
jsonMetadata

src/SqlStreamStore.HAL/ReadStreamMiddleware.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public static MidFunc UseStreamStore(IStreamStore streamStore)
3131
};
3232
}
3333

34-
3534
private static bool IsStream(IOwinContext context)
3635
=> context.IsGetOrHead() && context.Request.Path.IsStream();
3736

src/SqlStreamStore.HAL/StreamResource.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ public async Task<Response> AppendMessages(
2828
var result = await operation.Invoke(_streamStore, cancellationToken);
2929

3030
var response = new Response(
31-
new HALResponse(new object()),
32-
options.ExpectedVersion == ExpectedVersion.NoStream
31+
new HALResponse(result)
32+
.AddLinks(StreamLinks.Self(options))
33+
.AddLinks(StreamLinks.Feed(options)),
34+
result.CurrentVersion == 0
3335
? 201
3436
: 200);
3537
if(options.ExpectedVersion == ExpectedVersion.NoStream)
@@ -212,12 +214,20 @@ private static class StreamLinks
212214
Relations.Self,
213215
options.Self);
214216

217+
public static Link Self(AppendStreamOptions options) => new Link(
218+
Relations.Self,
219+
$"{options.StreamId}");
220+
215221
public static Link Feed(ReadStreamPage page) => new Link(Relations.Feed, Last(page).Href);
216222

217223
public static Link Feed(ReadStreamMessageOptions options) => new Link(
218224
Relations.Feed,
219225
LinkFormatter.FormatBackwardLink(options.StreamId, 20, StreamVersion.End));
220226

227+
public static Link Feed(AppendStreamOptions options) => new Link(
228+
Relations.Feed,
229+
LinkFormatter.FormatBackwardLink(options.StreamId, 20, StreamVersion.End));
230+
221231
public static IEnumerable<Link> Navigation(ReadStreamPage page, string self)
222232
{
223233
var first = First(page);

0 commit comments

Comments
 (0)