-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.go
116 lines (103 loc) · 2.78 KB
/
models.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package main
import (
"database/sql"
"time"
"github.com/muhtutorials/rss/db"
)
type User struct {
ID int64 `json:"id"`
Name string `json:"name"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt sql.NullTime `json:"updated_at"`
APIKey string `json:"APIKey"`
}
func dbUserToUser(dbUser db.User) User {
return User{
ID: dbUser.ID,
Name: dbUser.Name,
CreatedAt: dbUser.CreatedAt,
UpdatedAt: dbUser.UpdatedAt,
APIKey: dbUser.ApiKey,
}
}
type Feed struct {
ID int64 `json:"id"`
UserID int64 `json:"user_id"`
Name string `json:"name"`
Url string `json:"url"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt sql.NullTime `json:"updated_at"`
}
func dbFeedToFeed(dbFeed db.Feed) Feed {
return Feed{
ID: dbFeed.ID,
UserID: dbFeed.UserID,
Name: dbFeed.Name,
Url: dbFeed.Url,
CreatedAt: dbFeed.CreatedAt,
UpdatedAt: dbFeed.UpdatedAt,
}
}
func dbFeedsToFeeds(dbFeeds []db.Feed) []Feed {
feeds := []Feed{}
for _, dbFeed := range dbFeeds {
feeds = append(feeds, dbFeedToFeed(dbFeed))
}
return feeds
}
type FeedFollow struct {
ID int64 `json:"id"`
UserID int64 `json:"user_id"`
FeedID int64 `json:"feed_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt sql.NullTime `json:"updated_at"`
}
func dbFeedFollowToFeedFollow(dbFeedFollow db.FeedFollow) FeedFollow {
return FeedFollow{
ID: dbFeedFollow.ID,
UserID: dbFeedFollow.UserID,
FeedID: dbFeedFollow.FeedID,
CreatedAt: dbFeedFollow.CreatedAt,
UpdatedAt: dbFeedFollow.UpdatedAt,
}
}
func dbFeedFollowsToFeedFollows(dbFeedFollows []db.FeedFollow) []FeedFollow {
feedFollows := []FeedFollow{}
for _, dbFeedFollow := range dbFeedFollows {
feedFollows = append(feedFollows, dbFeedFollowToFeedFollow(dbFeedFollow))
}
return feedFollows
}
type Post struct {
ID int64 `json:"id"`
FeedID int64 `json:"feed_id"`
Title string `json:"title"`
Description *string `json:"description"`
Url string `json:"url"`
PublishedAt time.Time `json:"published_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt sql.NullTime `json:"updated_at"`
}
func dbPostToPost(dbPost db.Post) Post {
var description *string
if dbPost.Description.Valid {
description = &dbPost.Description.String
}
return Post{
ID: dbPost.ID,
FeedID: dbPost.FeedID,
Title: dbPost.Title,
Description: description,
Url: dbPost.Url,
PublishedAt: dbPost.PublishedAt,
CreatedAt: dbPost.CreatedAt,
UpdatedAt: dbPost.UpdatedAt,
}
}
func dbPostsToPosts(dbPosts []db.Post) []Post {
posts := []Post{}
for _, dbPost := range dbPosts {
posts = append(posts, dbPostToPost(dbPost))
}
return posts
}