-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_timeline.go
60 lines (52 loc) · 1.79 KB
/
service_timeline.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
package main
import (
"context"
"htmxx/db"
"htmxx/model"
)
func shapeDBTimeline(tweets []db.GetTimelineRow) []*model.Tweet {
var shapedTweets []*model.Tweet
for _, tweet := range tweets {
shapedTweets = append(shapedTweets, &model.Tweet{
ID: tweet.Tweet.TweetID,
Author: tweet.Tweet.Author,
Content: tweet.Tweet.Content,
Created: tweet.Tweet.Created.Time,
LikeCount: tweet.Tweet.LikeCount,
LikedBySelf: tweet.Likedbyuser,
BookmarkedBySelf: tweet.Bookmarkedbyuser,
})
}
return shapedTweets
}
func shapeDBAllTimeline(tweets []db.GetAllTimelineRow) []*model.Tweet {
var shapedTweets []*model.Tweet
for _, tweet := range tweets {
shapedTweets = append(shapedTweets, &model.Tweet{
ID: tweet.Tweet.TweetID,
Author: tweet.Tweet.Author,
Content: tweet.Tweet.Content,
Created: tweet.Tweet.Created.Time,
LikeCount: tweet.Tweet.LikeCount,
LikedBySelf: tweet.Likedbyuser,
BookmarkedBySelf: tweet.Bookmarkedbyuser,
})
}
return shapedTweets
}
func (s *application) GetTimelineData(minid int64, ctx context.Context) ([]*model.Tweet, error) {
currentUser := ctx.Value("user").(string)
tweet, err := s.query.GetAllTimeline(ctx, db.GetAllTimelineParams{TweetID: minid, Username: currentUser, Username_2: currentUser})
if err != nil {
return nil, err
}
return shapeDBAllTimeline(tweet), nil
}
func (s *application) GetUserTimelineData(author string, minid int64, ctx context.Context) ([]*model.Tweet, error) {
currentUser := ctx.Value("user").(string)
tweet, err := s.query.GetTimeline(ctx, db.GetTimelineParams{TweetID: minid, Author: author, Username: currentUser, Username_2: currentUser})
if err != nil {
return nil, err
}
return shapeDBTimeline(tweet), nil
}