1010
1111 internal class AllStreamResource
1212 {
13- private const string StreamId = "stream" ;
14-
1513 private readonly IReadonlyStreamStore _streamStore ;
1614
1715 public AllStreamResource ( IReadonlyStreamStore streamStore )
@@ -38,10 +36,10 @@ public async Task<Response> GetPage(
3836 var response = new Response (
3937 new HALResponse ( new object ( ) )
4038 . AddLinks ( Links . SelfFeed ( options ) )
41- . AddLinks ( Links . Navigation ( page , options . Self ) )
42- . AddLinks ( Links . Feed )
39+ . AddLinks ( Links . Navigation ( page , options ) )
40+ . AddLinks ( Links . Feed ( options ) )
4341 . AddEmbeddedCollection (
44- Relations . Message ,
42+ Constants . Relations . Message ,
4543 page . Messages . Zip ( payloads ,
4644 ( message , payload ) => new HALResponse ( new
4745 {
@@ -79,7 +77,7 @@ public async Task<Response> GetMessage(
7977 {
8078 return new Response (
8179 new HALResponse ( new HALModelConfig ( ) )
82- . AddLinks ( Links . Feed ) ,
80+ . AddLinks ( Links . Feed ( options ) ) ,
8381 404 ) ;
8482 }
8583
@@ -97,46 +95,86 @@ public async Task<Response> GetMessage(
9795 payload
9896 } ) . AddLinks (
9997 Links . SelfAll ( message ) ,
100- Links . Feed ) ) ;
98+ Links . Feed ( options ) ) ) ;
10199 }
102100
103101 private static class Links
104102 {
105103 public static Link SelfFeed ( ReadAllStreamOptions options )
106- => new Link ( Relations . Self , options . Self ) ;
104+ => new Link ( Constants . Relations . Self , options . Self ) ;
107105
108106 public static Link Self ( StreamMessage message ) => new Link (
109- Relations . Self ,
107+ Constants . Relations . Self ,
110108 $ "streams/{ message . StreamId } /{ message . StreamVersion } ") ;
111109
112- public static Link SelfAll ( StreamMessage message ) => new Link ( Relations . Self , $ "/{ StreamId } /{ message . Position } ") ;
113-
114- public static Link First => new Link ( Relations . First ,
115- LinkFormatter . FormatForwardLink ( StreamId , 20 , Position . Start ) ) ;
116-
117- public static Link Last => new Link ( Relations . Last , LinkFormatter . FormatBackwardLink ( StreamId , 20 , Position . End ) ) ;
118-
119- public static Link Feed => new Link ( Relations . Feed , Last . Href ) ;
120-
121- public static Link Previous ( ReadAllPage page )
122- => new Link ( Relations . Previous ,
123- LinkFormatter . FormatBackwardLink ( StreamId , 20 , page . Messages . Min ( m => m . Position ) - 1 ) ) ;
124-
125- public static Link Next ( ReadAllPage page )
126- => new Link ( Relations . Next ,
127- LinkFormatter . FormatForwardLink ( StreamId , 20 , page . Messages . Max ( m => m . Position ) + 1 ) ) ;
128-
129- public static IEnumerable < Link > Navigation ( ReadAllPage page , string self )
110+ public static Link SelfAll ( StreamMessage message )
111+ => new Link ( Constants . Relations . Self , $ "/{ Constants . Streams . All } /{ message . Position } ") ;
112+
113+ public static Link First ( ReadAllStreamOptions options )
114+ => new Link (
115+ Constants . Relations . First ,
116+ LinkFormatter . FormatForwardLink (
117+ Constants . Streams . All ,
118+ options . MaxCount ,
119+ Position . Start ,
120+ options . EmbedPayload ) ) ;
121+
122+ public static Link Last ( ReadAllStreamOptions options )
123+ => new Link (
124+ Constants . Relations . Last ,
125+ LinkFormatter . FormatBackwardLink (
126+ Constants . Streams . All ,
127+ options . MaxCount ,
128+ Position . End ,
129+ options . EmbedPayload ) ) ;
130+
131+ public static Link Last ( ReadAllStreamMessageOptions options )
132+ => new Link (
133+ Constants . Relations . Last ,
134+ LinkFormatter . FormatBackwardLink (
135+ Constants . Streams . All ,
136+ Constants . MaxCount ,
137+ Position . End ,
138+ false ) ) ;
139+
140+ public static Link Feed ( ReadAllStreamOptions options )
141+ => new Link ( Constants . Relations . Feed , Last ( options ) . Href ) ;
142+
143+ public static Link Feed ( ReadAllStreamMessageOptions options )
144+ => new Link ( Constants . Relations . Feed , Last ( options ) . Href ) ;
145+
146+ public static Link Previous ( ReadAllPage page , ReadAllStreamOptions options )
147+ => new Link (
148+ Constants . Relations . Previous ,
149+ LinkFormatter . FormatBackwardLink (
150+ Constants . Streams . All ,
151+ options . MaxCount ,
152+ page . Messages . Min ( m => m . Position ) - 1 ,
153+ options . EmbedPayload ) ) ;
154+
155+ public static Link Next ( ReadAllPage page , ReadAllStreamOptions options )
156+ => new Link (
157+ Constants . Relations . Next ,
158+ LinkFormatter . FormatForwardLink (
159+ Constants . Streams . All ,
160+ options . MaxCount ,
161+ page . Messages . Max ( m => m . Position ) + 1 ,
162+ options . EmbedPayload ) ) ;
163+
164+ public static IEnumerable < Link > Navigation ( ReadAllPage page , ReadAllStreamOptions options )
130165 {
131- yield return First ;
166+ var first = First ( options ) ;
167+ var last = Last ( options ) ;
168+
169+ yield return first ;
132170
133- if ( self != First . Href && ! page . IsEnd )
134- yield return Previous ( page ) ;
171+ if ( options . Self != first . Href && ! page . IsEnd )
172+ yield return Previous ( page , options ) ;
135173
136- if ( self != Last . Href && ! page . IsEnd )
137- yield return Next ( page ) ;
174+ if ( options . Self != last . Href && ! page . IsEnd )
175+ yield return Next ( page , options ) ;
138176
139- yield return Last ;
177+ yield return last ;
140178 }
141179 }
142180 }
0 commit comments