Add random post selection
This commit is contained in:
@@ -22,7 +22,7 @@ func NewPostService(db *gorm.DB) *PostService {
|
|||||||
return &PostService{db: db}
|
return &PostService{db: db}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ps *PostService) GetPostsFromApi(ctx context.Context, tag string, instance string) (error, []models.Post) {
|
func (*PostService) GetPostsFromApi(ctx context.Context, tag string, instance string) (error, []models.Post) {
|
||||||
var requestUrl = instance + "/api/v1/timelines/tag/" + tag + "?limit=40"
|
var requestUrl = instance + "/api/v1/timelines/tag/" + tag + "?limit=40"
|
||||||
req, err := http.NewRequestWithContext(ctx, "GET", requestUrl, nil)
|
req, err := http.NewRequestWithContext(ctx, "GET", requestUrl, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -93,6 +93,12 @@ func (ps *PostService) InsertNewAccounts(newAccounts []models.Account) int {
|
|||||||
return int(ps.db.Clauses(clause.OnConflict{UpdateAll: true}).Create(&newAccounts).RowsAffected)
|
return int(ps.db.Clauses(clause.OnConflict{UpdateAll: true}).Create(&newAccounts).RowsAffected)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ps *PostService) GetRandomPost() models.Post {
|
||||||
|
var post models.Post
|
||||||
|
ps.db.Order("RANDOM()").First(&post) // TODO: only approved posts
|
||||||
|
return post
|
||||||
|
}
|
||||||
|
|
||||||
func arrayContains(arr []string, str string) bool {
|
func arrayContains(arr []string, str string) bool {
|
||||||
for _, a := range arr {
|
for _, a := range arr {
|
||||||
if a == str {
|
if a == str {
|
||||||
|
Reference in New Issue
Block a user