4
4
"context"
5
5
"net/url"
6
6
"strconv"
7
+ "time"
7
8
8
9
"github.com/Southclaws/dt"
9
10
"github.com/Southclaws/fault"
@@ -13,10 +14,12 @@ import (
13
14
"github.com/rs/xid"
14
15
15
16
"github.com/Southclaws/storyden/app/resources/account/account_querier"
17
+ "github.com/Southclaws/storyden/app/resources/cachecontrol"
16
18
"github.com/Southclaws/storyden/app/resources/datagraph"
17
19
"github.com/Southclaws/storyden/app/resources/tag/tag_ref"
18
20
19
21
"github.com/Southclaws/storyden/app/resources/post/category"
22
+ "github.com/Southclaws/storyden/app/resources/post/thread_cache"
20
23
"github.com/Southclaws/storyden/app/resources/visibility"
21
24
"github.com/Southclaws/storyden/app/services/authentication/session"
22
25
thread_service "github.com/Southclaws/storyden/app/services/thread"
@@ -25,17 +28,19 @@ import (
25
28
)
26
29
27
30
type Threads struct {
31
+ thread_cache * thread_cache.Cache
28
32
thread_svc thread_service.Service
29
33
thread_mark_svc thread_mark.Service
30
34
accountQuery * account_querier.Querier
31
35
}
32
36
33
37
func NewThreads (
38
+ thread_cache * thread_cache.Cache ,
34
39
thread_svc thread_service.Service ,
35
40
thread_mark_svc thread_mark.Service ,
36
41
accountQuery * account_querier.Querier ,
37
42
) Threads {
38
- return Threads {thread_svc , thread_mark_svc , accountQuery }
43
+ return Threads {thread_cache , thread_svc , thread_mark_svc , accountQuery }
39
44
}
40
45
41
46
func (i * Threads ) ThreadCreate (ctx context.Context , request openapi.ThreadCreateRequestObject ) (openapi.ThreadCreateResponseObject , error ) {
@@ -211,6 +216,15 @@ func (i *Threads) ThreadGet(ctx context.Context, request openapi.ThreadGetReques
211
216
return nil , fault .Wrap (err , fctx .With (ctx ))
212
217
}
213
218
219
+ notModified , err := i .thread_cache .IsNotModified (ctx , cachecontrol .NewQuery (request .Params .IfNoneMatch , request .Params .IfModifiedSince ), xid .ID (postID ))
220
+ if err != nil {
221
+ return nil , fault .Wrap (err , fctx .With (ctx ))
222
+ }
223
+
224
+ if notModified {
225
+ return openapi.ThreadGet304Response {}, nil
226
+ }
227
+
214
228
pp := deserialisePageParams (request .Params .Page , 50 )
215
229
216
230
thread , err := i .thread_svc .Get (ctx , postID , pp )
@@ -219,7 +233,13 @@ func (i *Threads) ThreadGet(ctx context.Context, request openapi.ThreadGetReques
219
233
}
220
234
221
235
return openapi.ThreadGet200JSONResponse {
222
- ThreadGetJSONResponse : openapi .ThreadGetJSONResponse (serialiseThread (thread )),
236
+ ThreadGetJSONResponse : openapi.ThreadGetJSONResponse {
237
+ Body : serialiseThread (thread ),
238
+ Headers : openapi.ThreadGetResponseHeaders {
239
+ CacheControl : "max-age=1" ,
240
+ LastModified : thread .UpdatedAt .Format (time .RFC1123 ),
241
+ },
242
+ },
223
243
}, nil
224
244
}
225
245
0 commit comments