Compare commits
2 Commits
c6944cd3df
...
78e554577e
Author | SHA1 | Date | |
---|---|---|---|
78e554577e | |||
a58f44d50e |
@ -44,6 +44,16 @@ func ListBoostByAttachment(attachmentId uint) ([]models.AttachmentBoost, error)
|
||||
return boosts, nil
|
||||
}
|
||||
|
||||
func ListBoostByAttachmentWithStatus(attachmentId uint, status int) ([]models.AttachmentBoost, error) {
|
||||
var boosts []models.AttachmentBoost
|
||||
if err := database.C.
|
||||
Where("attachment_id = ? AND status = ?", attachmentId, status).
|
||||
Find(&boosts).Error; err != nil {
|
||||
return boosts, err
|
||||
}
|
||||
return boosts, nil
|
||||
}
|
||||
|
||||
func GetBoostByID(id uint) (models.AttachmentBoost, error) {
|
||||
var boost models.AttachmentBoost
|
||||
if err := database.C.
|
||||
@ -56,7 +66,12 @@ func GetBoostByID(id uint) (models.AttachmentBoost, error) {
|
||||
}
|
||||
|
||||
func CreateBoost(user *sec.UserInfo, source models.Attachment, destination int) (models.AttachmentBoost, error) {
|
||||
boost := models.AttachmentBoost{
|
||||
var boost models.AttachmentBoost
|
||||
if err := database.C.Where("attachment_id = ? AND destination = ?", source.ID, destination).First(&boost); err == nil {
|
||||
return boost, fmt.Errorf("boost already exists")
|
||||
}
|
||||
|
||||
boost = models.AttachmentBoost{
|
||||
Status: models.BoostStatusPending,
|
||||
Destination: destination,
|
||||
AttachmentID: source.ID,
|
||||
|
@ -52,13 +52,12 @@ func OpenAttachmentByRID(rid string, region ...string) (url string, mimetype str
|
||||
Preload("Pool").
|
||||
Preload("Thumbnail").
|
||||
Preload("Compressed").
|
||||
Preload("Boosts").
|
||||
First(&attachment).Error; err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var boosts []models.AttachmentBoost
|
||||
boosts, err = ListBoostByAttachment(attachment.ID)
|
||||
boosts, err = ListBoostByAttachmentWithStatus(attachment.ID, models.BoostStatusActive)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user