User can pin multiple posts

This commit is contained in:
2024-07-25 22:58:47 +08:00
parent 761d73100b
commit a4d8a3b37f
6 changed files with 45 additions and 11 deletions

View File

@ -310,3 +310,16 @@ func ReactPost(user models.Account, reaction models.Reaction) (bool, models.Reac
return false, reaction, err
}
}
func PinPost(post models.Post) (bool, error) {
if post.PinnedAt != nil {
post.PinnedAt = nil
} else {
post.PinnedAt = lo.ToPtr(time.Now())
}
if err := database.C.Save(&post).Error; err != nil {
return post.PinnedAt != nil, err
}
return post.PinnedAt != nil, nil
}