-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost.go
43 lines (35 loc) · 809 Bytes
/
post.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
package main
import "github.com/google/uuid"
type Post struct {
Url string
Title string
}
func NewPost(url string, title string) (*Post, error) {
// Remove query string to ensure proper url match in autoposter
url, err := stripQueryString(url)
if err != nil {
return nil, err
}
return &Post{
Url: url,
Title: title,
}, nil
}
func (p Post) ToSaved(twitterID string) SavedPost {
return SavedPost{
ID: uuid.NewString(),
TwitterID: twitterID,
Post: p,
}
}
// TODO: refactor to combine In() and InSaved()
func (p Post) In(posts []Post) bool {
return Some(posts, func(post Post) bool {
return post.Url == p.Url
})
}
func (p Post) InSaved(savedPosts []SavedPost) bool {
return Some(savedPosts, func(savedPost SavedPost) bool {
return savedPost.Url == p.Url
})
}