🐛 Fix publisher info did not marked used
This commit is contained in:
parent
f06bc2d382
commit
76c78e0c01
@ -191,6 +191,7 @@ func editPublisher(c *fiber.Ctx) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
og := publisher
|
||||||
publisher.Name = data.Name
|
publisher.Name = data.Name
|
||||||
publisher.Nick = data.Nick
|
publisher.Nick = data.Nick
|
||||||
publisher.Description = data.Description
|
publisher.Description = data.Description
|
||||||
@ -200,7 +201,7 @@ func editPublisher(c *fiber.Ctx) error {
|
|||||||
publisher.AccountID = data.AccountID
|
publisher.AccountID = data.AccountID
|
||||||
}
|
}
|
||||||
|
|
||||||
if publisher, err = services.EditPublisher(user, publisher); err != nil {
|
if publisher, err = services.EditPublisher(user, publisher, og); err != nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,8 +2,12 @@ package services
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.solsynth.dev/hypernet/interactive/pkg/internal/database"
|
"git.solsynth.dev/hypernet/interactive/pkg/internal/database"
|
||||||
|
"git.solsynth.dev/hypernet/interactive/pkg/internal/gap"
|
||||||
"git.solsynth.dev/hypernet/interactive/pkg/internal/models"
|
"git.solsynth.dev/hypernet/interactive/pkg/internal/models"
|
||||||
|
"git.solsynth.dev/hypernet/paperclip/pkg/filekit"
|
||||||
|
"git.solsynth.dev/hypernet/paperclip/pkg/proto"
|
||||||
authm "git.solsynth.dev/hypernet/passport/pkg/authkit/models"
|
authm "git.solsynth.dev/hypernet/passport/pkg/authkit/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -33,13 +37,23 @@ func CreatePersonalPublisher(user authm.Account, name, nick, desc, avatar, banne
|
|||||||
Banner: banner,
|
Banner: banner,
|
||||||
AccountID: &user.ID,
|
AccountID: &user.ID,
|
||||||
}
|
}
|
||||||
|
var attachments []string
|
||||||
if user.Avatar != nil && len(publisher.Avatar) == 0 {
|
if user.Avatar != nil && len(publisher.Avatar) == 0 {
|
||||||
|
attachments = append(attachments, *user.Avatar)
|
||||||
publisher.Avatar = *user.Avatar
|
publisher.Avatar = *user.Avatar
|
||||||
}
|
}
|
||||||
if user.Banner != nil && len(publisher.Banner) == 0 {
|
if user.Banner != nil && len(publisher.Banner) == 0 {
|
||||||
|
attachments = append(attachments, *user.Banner)
|
||||||
publisher.Banner = *user.Banner
|
publisher.Banner = *user.Banner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(attachments) > 0 {
|
||||||
|
filekit.CountAttachmentUsage(gap.Nx, &proto.UpdateUsageRequest{
|
||||||
|
Rid: attachments,
|
||||||
|
Delta: 1,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if err := database.C.Create(&publisher).Error; err != nil {
|
if err := database.C.Create(&publisher).Error; err != nil {
|
||||||
return publisher, err
|
return publisher, err
|
||||||
}
|
}
|
||||||
@ -57,26 +71,58 @@ func CreateOrganizationPublisher(user authm.Account, realm authm.Realm, name, ni
|
|||||||
RealmID: &realm.ID,
|
RealmID: &realm.ID,
|
||||||
AccountID: &user.ID,
|
AccountID: &user.ID,
|
||||||
}
|
}
|
||||||
|
var attachments []string
|
||||||
if realm.Avatar != nil && len(publisher.Avatar) == 0 {
|
if realm.Avatar != nil && len(publisher.Avatar) == 0 {
|
||||||
|
attachments = append(attachments, *realm.Avatar)
|
||||||
publisher.Avatar = *realm.Avatar
|
publisher.Avatar = *realm.Avatar
|
||||||
}
|
}
|
||||||
if realm.Banner != nil && len(publisher.Banner) == 0 {
|
if realm.Banner != nil && len(publisher.Banner) == 0 {
|
||||||
|
attachments = append(attachments, *realm.Banner)
|
||||||
publisher.Banner = *realm.Banner
|
publisher.Banner = *realm.Banner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(attachments) > 0 {
|
||||||
|
filekit.CountAttachmentUsage(gap.Nx, &proto.UpdateUsageRequest{
|
||||||
|
Rid: attachments,
|
||||||
|
Delta: 1,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if err := database.C.Create(&publisher).Error; err != nil {
|
if err := database.C.Create(&publisher).Error; err != nil {
|
||||||
return publisher, err
|
return publisher, err
|
||||||
}
|
}
|
||||||
return publisher, nil
|
return publisher, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func EditPublisher(user authm.Account, publisher models.Publisher) (models.Publisher, error) {
|
func EditPublisher(user authm.Account, publisher, og models.Publisher) (models.Publisher, error) {
|
||||||
if publisher.Type == models.PublisherTypePersonal {
|
if publisher.Type == models.PublisherTypePersonal {
|
||||||
if *publisher.AccountID != user.ID {
|
if *publisher.AccountID != user.ID {
|
||||||
return publisher, fmt.Errorf("you cannot transfer personal publisher")
|
return publisher, fmt.Errorf("you cannot transfer personal publisher")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var minusAttachments, plusAttachments []string
|
||||||
|
if publisher.Avatar != og.Avatar {
|
||||||
|
minusAttachments = append(minusAttachments, og.Avatar)
|
||||||
|
plusAttachments = append(plusAttachments, publisher.Avatar)
|
||||||
|
}
|
||||||
|
if publisher.Banner != og.Banner {
|
||||||
|
minusAttachments = append(minusAttachments, og.Banner)
|
||||||
|
plusAttachments = append(plusAttachments, publisher.Banner)
|
||||||
|
}
|
||||||
|
if len(minusAttachments) > 0 {
|
||||||
|
filekit.CountAttachmentUsage(gap.Nx, &proto.UpdateUsageRequest{
|
||||||
|
Rid: minusAttachments,
|
||||||
|
Delta: -1,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if len(plusAttachments) > 0 {
|
||||||
|
filekit.CountAttachmentUsage(gap.Nx, &proto.UpdateUsageRequest{
|
||||||
|
Rid: plusAttachments,
|
||||||
|
Delta: 1,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
err := database.C.Save(&publisher).Error
|
err := database.C.Save(&publisher).Error
|
||||||
return publisher, err
|
return publisher, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user