Skip to content

Commit 9ee8b62

Browse files
committed
Add responses and replies
1 parent e0cc052 commit 9ee8b62

File tree

2 files changed

+153
-73
lines changed

2 files changed

+153
-73
lines changed

pkg/posts/hot.go

Lines changed: 121 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -207,76 +207,13 @@ type PostDetails struct {
207207

208208
type Post struct {
209209
Post struct {
210-
IndexVotedByCurrentUser int `json:"indexVotedByCurrentUser"`
211-
IsFollowing bool `json:"isFollowing"`
212-
Responses []struct {
213-
ID string `json:"_id"`
214-
Content string `json:"content"`
215-
ContentMarkdown string `json:"contentMarkdown"`
216-
Author struct {
217-
ID string `json:"_id"`
218-
Username string `json:"username"`
219-
Name string `json:"name"`
220-
Photo string `json:"photo"`
221-
Tagline string `json:"tagline"`
222-
Role interface{} `json:"role"`
223-
CoverImage string `json:"coverImage"`
224-
NumReactions int `json:"numReactions"`
225-
IsEvangelist bool `json:"isEvangelist"`
226-
BadgesAwarded []interface{} `json:"badgesAwarded"`
227-
TotalUpvotesReceived int `json:"totalUpvotesReceived"`
228-
Appreciations []struct {
229-
Badge string `json:"badge"`
230-
ID string `json:"_id"`
231-
Count int `json:"count"`
232-
} `json:"appreciations"`
233-
DateJoined time.Time `json:"dateJoined"`
234-
SocialMedia struct {
235-
Linkedin string `json:"linkedin"`
236-
Stackoverflow string `json:"stackoverflow"`
237-
Google string `json:"google"`
238-
Facebook string `json:"facebook"`
239-
Twitter string `json:"twitter"`
240-
Github string `json:"github"`
241-
Website string `json:"website"`
242-
} `json:"socialMedia"`
243-
StoriesCreated []string `json:"storiesCreated"`
244-
NumFollowing int `json:"numFollowing"`
245-
NumFollowers int `json:"numFollowers"`
246-
IsDeactivated bool `json:"isDeactivated"`
247-
Location string `json:"location"`
248-
TotalAppreciationBadges int `json:"totalAppreciationBadges"`
249-
} `json:"author"`
250-
Stamp string `json:"stamp"`
251-
Post string `json:"post"`
252-
V int `json:"__v"`
253-
ReactionToCountMap struct {
254-
Reaction567453D0B73D6A82Ac8C5Abd int `json:"reaction_567453d0b73d6a82ac8c5abd"`
255-
Reaction5C090D96C2A9C2A674D35487 int `json:"reaction_5c090d96c2a9c2a674d35487"`
256-
Reaction5C090D96C2A9C2A674D35486 int `json:"reaction_5c090d96c2a9c2a674d35486"`
257-
} `json:"reactionToCountMap"`
258-
ReactionsByCurrentUser []interface{} `json:"reactionsByCurrentUser"`
259-
TotalReactions int `json:"totalReactions"`
260-
Reactions []string `json:"reactions"`
261-
Score int `json:"score"`
262-
BookmarkedIn []interface{} `json:"bookmarkedIn"`
263-
IsRewardWinner bool `json:"isRewardWinner"`
264-
TotalBadgesAwarded int `json:"totalBadgesAwarded"`
265-
BadgesAwarded []interface{} `json:"badgesAwarded"`
266-
IsCollapsed bool `json:"isCollapsed"`
267-
Downvotes int `json:"downvotes"`
268-
Upvotes int `json:"upvotes"`
269-
DownvotedBy []interface{} `json:"downvotedBy"`
270-
UpvotedBy []interface{} `json:"upvotedBy"`
271-
IsActive bool `json:"isActive"`
272-
DateAdded time.Time `json:"dateAdded"`
273-
Popularity float64 `json:"popularity"`
274-
Replies []interface{} `json:"replies"`
275-
} `json:"responses"`
276-
ID string `json:"_id"`
277-
IsRepublished bool `json:"isRepublished"`
278-
FollowersCount int `json:"followersCount"`
279-
Author struct {
210+
IndexVotedByCurrentUser int `json:"indexVotedByCurrentUser"`
211+
IsFollowing bool `json:"isFollowing"`
212+
Responses []Response `json:"responses"`
213+
ID string `json:"_id"`
214+
IsRepublished bool `json:"isRepublished"`
215+
FollowersCount int `json:"followersCount"`
216+
Author struct {
280217
BeingFollowed bool `json:"beingFollowed"`
281218
ID string `json:"_id"`
282219
Role interface{} `json:"role"`
@@ -405,3 +342,117 @@ type Post struct {
405342
IsAnonymous bool `json:"isAnonymous"`
406343
} `json:"post"`
407344
}
345+
type Response struct {
346+
ID string `json:"_id"`
347+
Content string `json:"content"`
348+
ContentMarkdown string `json:"contentMarkdown"`
349+
Author struct {
350+
ID string `json:"_id"`
351+
Username string `json:"username"`
352+
Name string `json:"name"`
353+
Photo string `json:"photo"`
354+
Tagline string `json:"tagline"`
355+
Role interface{} `json:"role"`
356+
CoverImage string `json:"coverImage"`
357+
NumReactions int `json:"numReactions"`
358+
IsEvangelist bool `json:"isEvangelist"`
359+
BadgesAwarded []interface{} `json:"badgesAwarded"`
360+
TotalUpvotesReceived int `json:"totalUpvotesReceived"`
361+
Appreciations []struct {
362+
Badge string `json:"badge"`
363+
ID string `json:"_id"`
364+
Count int `json:"count"`
365+
} `json:"appreciations"`
366+
DateJoined time.Time `json:"dateJoined"`
367+
SocialMedia struct {
368+
Linkedin string `json:"linkedin"`
369+
Stackoverflow string `json:"stackoverflow"`
370+
Google string `json:"google"`
371+
Facebook string `json:"facebook"`
372+
Twitter string `json:"twitter"`
373+
Github string `json:"github"`
374+
Website string `json:"website"`
375+
} `json:"socialMedia"`
376+
StoriesCreated []string `json:"storiesCreated"`
377+
NumFollowing int `json:"numFollowing"`
378+
NumFollowers int `json:"numFollowers"`
379+
IsDeactivated bool `json:"isDeactivated"`
380+
Location string `json:"location"`
381+
TotalAppreciationBadges int `json:"totalAppreciationBadges"`
382+
} `json:"author"`
383+
Stamp string `json:"stamp"`
384+
Post string `json:"post"`
385+
V int `json:"__v"`
386+
ReactionToCountMap struct {
387+
Reaction567453D0B73D6A82Ac8C5Abd int `json:"reaction_567453d0b73d6a82ac8c5abd"`
388+
Reaction5C090D96C2A9C2A674D35487 int `json:"reaction_5c090d96c2a9c2a674d35487"`
389+
Reaction5C090D96C2A9C2A674D35486 int `json:"reaction_5c090d96c2a9c2a674d35486"`
390+
} `json:"reactionToCountMap"`
391+
ReactionsByCurrentUser []interface{} `json:"reactionsByCurrentUser"`
392+
TotalReactions int `json:"totalReactions"`
393+
Reactions []string `json:"reactions"`
394+
Score int `json:"score"`
395+
BookmarkedIn []interface{} `json:"bookmarkedIn"`
396+
IsRewardWinner bool `json:"isRewardWinner"`
397+
TotalBadgesAwarded int `json:"totalBadgesAwarded"`
398+
BadgesAwarded []interface{} `json:"badgesAwarded"`
399+
IsCollapsed bool `json:"isCollapsed"`
400+
Downvotes int `json:"downvotes"`
401+
Upvotes int `json:"upvotes"`
402+
DownvotedBy []interface{} `json:"downvotedBy"`
403+
UpvotedBy []interface{} `json:"upvotedBy"`
404+
IsActive bool `json:"isActive"`
405+
DateAdded time.Time `json:"dateAdded"`
406+
Popularity float64 `json:"popularity"`
407+
Replies []Reply `json:"replies"`
408+
}
409+
410+
type Reply struct {
411+
ReactionToCountMap struct {
412+
Any int `json:"any"`
413+
} `json:"reactionToCountMap"`
414+
Content string `json:"content"`
415+
ContentMarkdown string `json:"contentMarkdown"`
416+
Author struct {
417+
ID string `json:"_id"`
418+
Username string `json:"username"`
419+
Name string `json:"name"`
420+
Photo string `json:"photo"`
421+
Tagline string `json:"tagline"`
422+
CoverImage string `json:"coverImage"`
423+
Role string `json:"role"`
424+
NumReactions int `json:"numReactions"`
425+
IsEvangelist bool `json:"isEvangelist"`
426+
BadgesAwarded []interface{} `json:"badgesAwarded"`
427+
TotalUpvotesReceived int `json:"totalUpvotesReceived"`
428+
Appreciations []struct {
429+
Badge string `json:"badge"`
430+
ID string `json:"_id"`
431+
Count int `json:"count"`
432+
} `json:"appreciations"`
433+
DateJoined time.Time `json:"dateJoined"`
434+
SocialMedia struct {
435+
Linkedin string `json:"linkedin"`
436+
Stackoverflow string `json:"stackoverflow"`
437+
Google string `json:"google"`
438+
Facebook string `json:"facebook"`
439+
Twitter string `json:"twitter"`
440+
Github string `json:"github"`
441+
Website string `json:"website"`
442+
} `json:"socialMedia"`
443+
StoriesCreated []string `json:"storiesCreated"`
444+
NumFollowing int `json:"numFollowing"`
445+
NumFollowers int `json:"numFollowers"`
446+
IsDeactivated bool `json:"isDeactivated"`
447+
Location string `json:"location"`
448+
TotalAppreciationBadges int `json:"totalAppreciationBadges"`
449+
} `json:"author"`
450+
Stamp string `json:"stamp"`
451+
ID string `json:"_id"`
452+
ReactionsByCurrentUser []interface{} `json:"reactionsByCurrentUser"`
453+
TotalReactions int `json:"totalReactions"`
454+
Reactions []interface{} `json:"reactions"`
455+
Upvotes int `json:"upvotes"`
456+
IsActive bool `json:"isActive"`
457+
DateAdded time.Time `json:"dateAdded"`
458+
}

pkg/posts/post.go

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,46 @@ func openPost(app *tview.Application, postcuid string, list *tview.List) {
3636

3737
title := fmt.Sprintf("Title: %s", singlePost.Post.Title)
3838
author := fmt.Sprintf("Author: %s", singlePost.Post.Author.Name)
39-
upvotes := fmt.Sprintf("Upvotes: %d", singlePost.Post.Upvotes)
39+
reactions := fmt.Sprintf("Reactions: %d", singlePost.Post.TotalReactions)
4040
ptype := fmt.Sprintf("Type: %s", singlePost.Post.Type)
4141
link := fmt.Sprintf("Link: https://hashnode.com/post/%s", singlePost.Post.Cuid)
42-
writeToTextView(textView, title,
42+
writeToTextView(textView,
43+
title,
4344
author,
44-
upvotes,
45+
reactions,
4546
ptype,
4647
link,
4748
"\n",
4849
singlePost.Post.ContentMarkdown,
50+
"\n[green]Responses[white]",
51+
"[green]==========[white]",
4952
)
53+
for ind, response := range singlePost.Post.Responses {
54+
writeToTextView(
55+
textView,
56+
fmt.Sprintf("\n%d", ind+1),
57+
fmt.Sprintf("---"),
58+
response.ContentMarkdown,
59+
)
60+
if len(response.Replies) > 0 {
61+
writeToTextView(textView,
62+
"\n\t[green]Replies[white]",
63+
"\t[green]=======[white]",
64+
)
65+
for indreply, reply := range response.Replies {
66+
writeToTextView(
67+
textView,
68+
fmt.Sprintf("\n\t%d", indreply+1),
69+
fmt.Sprintf("\t---"),
70+
fmt.Sprintf("\tAuthor: %s", reply.Author.Name),
71+
fmt.Sprintf("\t%s", reply.ContentMarkdown),
72+
)
73+
74+
}
75+
}
76+
77+
}
78+
5079
textView.Box = textView.Box.SetBorder(true).SetBorderPadding(1, 1, 2, 1)
5180
textView.SetBorder(true)
5281

0 commit comments

Comments
 (0)