-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
93 lines (78 loc) · 2.21 KB
/
types.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
package main
import (
"time"
"github.com/google/uuid"
"github.com/wreckitral/RSS-feed-aggregator/internal/database"
)
type User struct {
ID uuid.UUID `json:"id"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Name string `json:"name"`
APIKey string `json:"apiKey"`
}
type CreateUserRequest struct {
Name string `json:"name"`
}
type Feed struct {
ID uuid.UUID `json:"id"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Name string `json:"name"`
Url string `json:"url"`
UserID uuid.UUID `json:"userId"`
}
type CreateFeedRequest struct {
Name string `json:"name"`
Url string `json:"url"`
}
type FeedFollow struct {
ID uuid.UUID `json:"id"`
FeedID uuid.UUID `json:"feedId"`
UserID uuid.UUID `json:"userId"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
type FeedFollowRequest struct {
FeedID uuid.UUID `json:"feedId"`
}
type Post struct {
ID uuid.UUID `json:"id"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Title string `json:"title"`
Url string `json:"url"`
Description *string `json:"description"`
PublishedAt time.Time `json:"publishedAt"`
FeedID uuid.UUID `json:"feedId"`
}
func NewUser(name string) (*database.User, error) {
id := uuid.New()
return &database.User{
ID: id,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
Name: name,
}, nil
}
func NewFeed(name, url string, userId uuid.UUID) (*database.Feed, error) {
id := uuid.New()
return &database.Feed{
ID: id,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
Name: name,
Url: url,
UserID: userId,
}, nil
}
func NewFeedFollow(userId, feedId uuid.UUID) (*database.FeedFollow) {
id := uuid.New()
return &database.FeedFollow{
ID: id,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
UserID: userId,
FeedID: feedId,
}
}