Implement admin media approval endpoints and add JWT role-based auth - NOT TESTED

This commit is contained in:
2025-05-16 14:56:13 +03:30
parent 1abc05ecd9
commit 2e4b97e4bc
7 changed files with 60 additions and 43 deletions
+14
View File
@@ -88,6 +88,8 @@ func (ps *PostService) InsertNewAccounts(newAccounts []models.Account) int {
return int(ps.db.Clauses(clause.OnConflict{UpdateAll: true}).Create(&newAccounts).RowsAffected)
}
// From this point on, its for the api endpoints
func (ps *PostService) GetRandomPost() models.Post {
var post models.Post
ps.db.
@@ -98,6 +100,18 @@ func (ps *PostService) GetRandomPost() models.Post {
return post
}
func (ps *PostService) ApproveMedia(mediaId string) bool {
return ps.db.Model(&models.MediaAttachment{}).
Where("id = ?", mediaId).
Update("approved", true).RowsAffected > 0
}
func (ps *PostService) RejectMedia(mediaId string) bool {
return ps.db.Model(&models.MediaAttachment{}).
Where("id = ?", mediaId).
Update("rejected", true).RowsAffected > 0
}
func arrayContains(arr []string, str string) bool {
for _, a := range arr {
if a == str {