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

Commit 91c182a

Browse files
adding link to browse streams from more places
1 parent 437b458 commit 91c182a

12 files changed

Lines changed: 54 additions & 23 deletions

File tree

src/SqlStreamStore.HAL/AllStream/AllStreamResource.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public async Task<Response> Get(
5757
.FromOperation(operation)
5858
.Index()
5959
.Find()
60+
.Browse()
6061
.AllStreamNavigation(page, operation))
6162
.AddEmbeddedCollection(
6263
Constants.Relations.Message,

src/SqlStreamStore.HAL/AllStreamMessage/AllStreamMessageResource.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public async Task<Response> Get(
2929
.FromOperation(operation)
3030
.Index()
3131
.Find()
32+
.Browse()
3233
.Add(
3334
Constants.Relations.Message,
3435
$"stream/{message.Position}",

src/SqlStreamStore.HAL/Constants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static class Relations
6060
public const string DeleteStream = StreamStorePrefix + ":delete-stream";
6161
public const string DeleteMessage = StreamStorePrefix + ":delete-message";
6262
public const string Find = StreamStorePrefix + ":find";
63-
public const string ListStreams = StreamStorePrefix + ":feed-browser";
63+
public const string Browse = StreamStorePrefix + ":feed-browser";
6464
}
6565

6666
public static class Streams

src/SqlStreamStore.HAL/Index/IndexResource.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ namespace SqlStreamStore.HAL.Index
44
using System.Reflection;
55
using Halcyon.HAL;
66
using Microsoft.AspNetCore.Http;
7-
using Newtonsoft.Json;
87
using Newtonsoft.Json.Linq;
98

109
internal class IndexResource : IResource
@@ -43,8 +42,7 @@ private static string GetVersion(Type type)
4342
.FromPath(PathString.Empty)
4443
.Index().Self()
4544
.Find()
45+
.Browse()
4646
.Add(Constants.Relations.Feed, Constants.Streams.All)));
47-
48-
public override string ToString() => _data.ToString(Formatting.None);
4947
}
5048
}

src/SqlStreamStore.HAL/LinksExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ public static Links Find(this Links links)
99
=> links.Add(Constants.Relations.Find, "streams/{streamId}", "Find a Stream");
1010

1111
public static Links Browse(this Links links)
12-
=> links.Add(Constants.Relations.Browse, "stream/browse{?p,t,m}");
12+
=> links.Add(Constants.Relations.Browse, "stream/browse{?p,t,m}", "Browse Streams");
1313
}
1414
}

src/SqlStreamStore.HAL/SqlStreamStoreHalMiddleware.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
using SqlStreamStore.HAL.Docs;
1212
using SqlStreamStore.HAL.Index;
1313
using SqlStreamStore.HAL.Logging;
14-
using SqlStreamStore.HAL.Resources;
1514
using SqlStreamStore.HAL.StreamBrowser;
1615
using SqlStreamStore.HAL.StreamMessage;
1716
using SqlStreamStore.HAL.StreamMetadata;

src/SqlStreamStore.HAL/StreamBrowser/ListStreamsMiddleware.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ namespace SqlStreamStore.HAL.StreamBrowser
44
using System.Net.Http;
55
using Microsoft.AspNetCore.Builder;
66
using Microsoft.AspNetCore.Http;
7-
using SqlStreamStore.HAL.Resources;
87
using MidFunc = System.Func<
98
Microsoft.AspNetCore.Http.HttpContext,
109
System.Func<System.Threading.Tasks.Task>,
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
namespace SqlStreamStore.HAL.StreamBrowser
2+
{
3+
using SqlStreamStore.Streams;
4+
5+
internal static class StreamBrowserLinkExtensions
6+
{
7+
public static Links StreamBrowserNavigation(
8+
this Links links,
9+
ListStreamsPage listStreamsPage,
10+
ListStreamsOperation operation)
11+
{
12+
if(operation.ContinuationToken != null)
13+
{
14+
links.Add(
15+
Constants.Relations.Next,
16+
FormatLink(operation, listStreamsPage.ContinuationToken));
17+
}
18+
19+
if(listStreamsPage.ContinuationToken != null)
20+
{
21+
links.Add(
22+
Constants.Relations.Next,
23+
FormatLink(operation, listStreamsPage.ContinuationToken));
24+
}
25+
26+
27+
return links
28+
.Add(
29+
Constants.Relations.Browse,
30+
FormatLink(operation, listStreamsPage.ContinuationToken))
31+
.Self();
32+
}
33+
34+
private static string FormatLink(ListStreamsOperation operation, string continuationToken) =>
35+
$"stream/browser?p={operation.Pattern.Value}&t={operation.PatternType}&c={continuationToken}&m={operation.MaxCount}";
36+
}
37+
}
Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace SqlStreamStore.HAL.Resources
1+
namespace SqlStreamStore.HAL.StreamBrowser
22
{
33
using System;
44
using System.Threading;
@@ -19,7 +19,7 @@ public async Task<Response> Get(ListStreamsOperation operation, CancellationToke
1919
{
2020
var listStreamsPage = await operation.Invoke(_streamStore, cancellationToken);
2121

22-
var halResponse = new HALResponse(new
22+
return new HalJsonResponse(new HALResponse(new
2323
{
2424
listStreamsPage.ContinuationToken
2525
})
@@ -29,23 +29,15 @@ public async Task<Response> Get(ListStreamsOperation operation, CancellationToke
2929
listStreamsPage.StreamIds,
3030
streamId =>
3131
{
32-
var href = $"../../streams/{streamId}";
3332
return new HALResponse(null)
3433
.AddLinks(
35-
new Link(Constants.Relations.Self, href, streamId),
36-
new Link(Constants.Relations.Feed, href, streamId));
34+
Links
35+
.FromOperation(operation)
36+
.Index()
37+
.Find()
38+
.StreamBrowserNavigation(listStreamsPage, operation));
3739
}
38-
));
39-
40-
if(listStreamsPage.ContinuationToken != null)
41-
{
42-
halResponse.AddLinks(
43-
new Link(
44-
Constants.Relations.Next,
45-
$"browser?p={operation.Pattern.Value}&t={operation.PatternType}&c={listStreamsPage.ContinuationToken}&m={operation.MaxCount}"));
46-
}
47-
48-
return new HalJsonResponse(halResponse);
40+
)));
4941
}
5042
}
5143
}

src/SqlStreamStore.HAL/StreamMessage/StreamMessageResource.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public async Task<Response> Get(
3131
.FromPath(operation.Path)
3232
.Index()
3333
.Find()
34+
.Browse()
3435
.StreamMessageNavigation(message, operation);
3536

3637
if(message.MessageId == Guid.Empty)

0 commit comments

Comments
 (0)