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

Commit 62cade6

Browse files
removed last vestiges of static link classes
1 parent 3bceab2 commit 62cade6

4 files changed

Lines changed: 29 additions & 69 deletions

File tree

src/SqlStreamStore.HAL/AllStream/AllStreamResource.cs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,12 @@ public async Task<Response> Get(
7272
metadata = message.JsonMetadata
7373
})
7474
.AddLinks(
75-
Links.Message.Self(message),
76-
Links.Message.Feed(message)))));
75+
TheLinks.RootedAt(string.Empty)
76+
.Add(
77+
Constants.Relations.Message,
78+
$"streams/{message.StreamId}/{message.StreamVersion}")
79+
.Self()
80+
.Add(Constants.Relations.Feed, $"streams/{message.StreamId}")))));
7781

7882
if(operation.FromPositionInclusive == Position.End)
7983
{
@@ -96,19 +100,5 @@ public async Task<Response> Get(
96100

97101
return response;
98102
}
99-
100-
private static class Links
101-
{
102-
public static class Message
103-
{
104-
public static Link Self(StreamMessage message) => new Link(
105-
Constants.Relations.Self,
106-
$"streams/{message.StreamId}/{message.StreamVersion}");
107-
108-
public static Link Feed(StreamMessage message) => new Link(
109-
Constants.Relations.Feed,
110-
$"streams/{message.StreamId}");
111-
}
112-
}
113103
}
114104
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace SqlStreamStore.HAL
2+
{
3+
internal static class LinkExtensions
4+
{
5+
public static TheLinks Index(this TheLinks links) =>
6+
links.Add(Constants.Relations.Index, string.Empty, "Index");
7+
8+
public static TheLinks Find(this TheLinks links)
9+
=> links.Add(Constants.Relations.Find, "streams/{streamId}", "Find a Stream");
10+
}
11+
}

src/SqlStreamStore.HAL/Links.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,6 @@ namespace SqlStreamStore.HAL
44
using System.Collections.Generic;
55
using Halcyon.HAL;
66

7-
internal static class Links
8-
{
9-
public static Link Find(string href) =>
10-
new Link(Constants.Relations.Find, href, "Find a Stream", replaceParameters: false);
11-
12-
public static Link Index(string href) =>
13-
new Link(Constants.Relations.Index, href, "Index", replaceParameters: false);
14-
}
15-
16-
internal static class LinkExtensions
17-
{
18-
public static TheLinks Index(this TheLinks links) =>
19-
links.Add(Constants.Relations.Index, string.Empty, "Index");
20-
21-
public static TheLinks Find(this TheLinks links)
22-
=> links.Add(Constants.Relations.Find, "streams/{streamId}", "Find a Stream");
23-
}
24-
257
internal class TheLinks
268
{
279
private readonly List<(string rel, string href, string title)> _links;

src/SqlStreamStore.HAL/Streams/StreamResource.cs

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ namespace SqlStreamStore.HAL.Streams
55
using System.Threading;
66
using System.Threading.Tasks;
77
using Halcyon.HAL;
8-
using SqlStreamStore.HAL.Resources;
98
using SqlStreamStore.Streams;
109

1110
internal class StreamResource : IResource
@@ -32,11 +31,14 @@ public async Task<Response> Post(
3231
{
3332
var result = await operation.Invoke(_streamStore, cancellationToken);
3433

34+
var links = TheLinks.RootedAt(_relativePathToRoot)
35+
.Index()
36+
.Find()
37+
.Add(Constants.Relations.Feed, $"streams/{operation.StreamId}").Self();
38+
3539
var response = new Response(
3640
new HALResponse(result)
37-
.AddLinks(Links.Self(operation))
38-
.AddLinks(Links.Feed(operation))
39-
.AddLinks(Links.Find()),
41+
.AddLinks(links),
4042
result.CurrentVersion == 0
4143
? 201
4244
: 200);
@@ -106,8 +108,12 @@ public async Task<Response> Get(ReadStreamOperation operation, CancellationToken
106108
metadata = message.JsonMetadata
107109
})
108110
.AddLinks(
109-
Links.Message.Self(message),
110-
Links.Message.Feed(message)))),
111+
TheLinks.RootedAt(_relativePathToRoot)
112+
.Add(
113+
Constants.Relations.Message,
114+
$"{message.StreamId}/{message.StreamVersion}")
115+
.Self()
116+
.Add(Constants.Relations.Feed, message.StreamId)))),
111117
page.Status == PageReadStatus.StreamNotFound ? 404 : 200);
112118

113119
if(page.TryGetETag(out var eTag))
@@ -124,34 +130,5 @@ public async Task<Response> Delete(DeleteStreamOperation operation, Cancellation
124130

125131
return new Response(new HALResponse(new object()));
126132
}
127-
128-
private static class Links
129-
{
130-
public static Link Find() => SqlStreamStore.HAL.Links.Find("../streams/{streamId}");
131-
132-
public static Link Self(AppendStreamOperation operation) => new Link(
133-
Constants.Relations.Self,
134-
$"{operation.StreamId}");
135-
136-
public static Link Feed(AppendStreamOperation operation)
137-
=> new Link(
138-
Constants.Relations.Feed,
139-
LinkFormatter.FormatBackwardLink(
140-
operation.StreamId,
141-
Constants.MaxCount,
142-
StreamVersion.End,
143-
false));
144-
145-
public static class Message
146-
{
147-
public static Link Self(StreamMessage message) => new Link(
148-
Constants.Relations.Self,
149-
$"{message.StreamId}/{message.StreamVersion}");
150-
151-
public static Link Feed(StreamMessage message) => new Link(
152-
Constants.Relations.Feed,
153-
message.StreamId);
154-
}
155-
}
156133
}
157134
}

0 commit comments

Comments
 (0)