7
7
"github.com/google/jsonapi"
8
8
)
9
9
10
+ // Blog is a model representing a blog site
10
11
type Blog struct {
11
12
ID int `jsonapi:"primary,blogs"`
12
13
Title string `jsonapi:"attr,title"`
@@ -17,6 +18,7 @@ type Blog struct {
17
18
ViewCount int `jsonapi:"attr,view_count"`
18
19
}
19
20
21
+ // Post is a model representing a post on a blog
20
22
type Post struct {
21
23
ID int `jsonapi:"primary,posts"`
22
24
BlogID int `jsonapi:"attr,blog_id"`
@@ -25,19 +27,21 @@ type Post struct {
25
27
Comments []* Comment `jsonapi:"relation,comments"`
26
28
}
27
29
30
+ // Comment is a model representing a user submitted comment
28
31
type Comment struct {
29
32
ID int `jsonapi:"primary,comments"`
30
33
PostID int `jsonapi:"attr,post_id"`
31
34
Body string `jsonapi:"attr,body"`
32
35
}
33
36
34
- // Blog Links
37
+ // JSONAPILinks implements the Linkable interface for a blog
35
38
func (blog Blog ) JSONAPILinks () * jsonapi.Links {
36
39
return & jsonapi.Links {
37
40
"self" : fmt .Sprintf ("https://example.com/blogs/%d" , blog .ID ),
38
41
}
39
42
}
40
43
44
+ // JSONAPIRelationshipLinks implements the RelationshipLinkable interface for a blog
41
45
func (blog Blog ) JSONAPIRelationshipLinks (relation string ) * jsonapi.Links {
42
46
if relation == "posts" {
43
47
return & jsonapi.Links {
@@ -52,13 +56,14 @@ func (blog Blog) JSONAPIRelationshipLinks(relation string) *jsonapi.Links {
52
56
return nil
53
57
}
54
58
55
- // Blog Meta
59
+ // JSONAPIMeta implements the Metable interface for a blog
56
60
func (blog Blog ) JSONAPIMeta () * jsonapi.Meta {
57
61
return & jsonapi.Meta {
58
62
"detail" : "extra details regarding the blog" ,
59
63
}
60
64
}
61
65
66
+ // JSONAPIRelationshipLinks implements the RelationshipMetable interface for a blog
62
67
func (blog Blog ) JSONAPIRelationshipMeta (relation string ) * jsonapi.Meta {
63
68
if relation == "posts" {
64
69
return & jsonapi.Meta {
0 commit comments