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
|
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) {
|
func GetBoostByID(id uint) (models.AttachmentBoost, error) {
|
||||||
var boost models.AttachmentBoost
|
var boost models.AttachmentBoost
|
||||||
if err := database.C.
|
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) {
|
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,
|
Status: models.BoostStatusPending,
|
||||||
Destination: destination,
|
Destination: destination,
|
||||||
AttachmentID: source.ID,
|
AttachmentID: source.ID,
|
||||||
|
@ -52,13 +52,12 @@ func OpenAttachmentByRID(rid string, region ...string) (url string, mimetype str
|
|||||||
Preload("Pool").
|
Preload("Pool").
|
||||||
Preload("Thumbnail").
|
Preload("Thumbnail").
|
||||||
Preload("Compressed").
|
Preload("Compressed").
|
||||||
Preload("Boosts").
|
|
||||||
First(&attachment).Error; err != nil {
|
First(&attachment).Error; err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var boosts []models.AttachmentBoost
|
var boosts []models.AttachmentBoost
|
||||||
boosts, err = ListBoostByAttachment(attachment.ID)
|
boosts, err = ListBoostByAttachmentWithStatus(attachment.ID, models.BoostStatusActive)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user