Albirew/nyaa-pantsu
Albirew
/
nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/models/comments/interaction.go

30 lignes
1008 B
Go

package comments
import (
"errors"
"net/http"
"github.com/NyaaPantsu/nyaa/models"
)
// FindAll : Find all comments based on conditions
func FindAll(limit int, offset int, conditions string, values ...interface{}) ([]models.Comment, int) {
var comments []models.Comment
var nbComments int
models.ORM.Model(&comments).Where(conditions, values...).Count(&nbComments)
models.ORM.Limit(limit).Offset(offset).Order("comment_id DESC").Where(conditions, values...).Preload("User").Find(&comments)
return comments, nbComments
}
// Delete : Delete a comment
func Delete(id uint) (*models.Comment, int, error) {
var comment models.Comment
if models.ORM.Where("comment_id = ?", id).Preload("User").Preload("Torrent").Find(&comment).RecordNotFound() {
return &comment, http.StatusNotFound, errors.New("Comment is not found")
}
if models.ORM.Delete(&comment).Error != nil {
return &comment, http.StatusInternalServerError, errors.New("Comment is not deleted")
}
return &comment, http.StatusOK, nil
}