🐛 Fix create post need cloned realm id

This commit is contained in:
LittleSheep 2024-05-05 19:09:44 +08:00
parent 1542507715
commit dc7e83eb61
2 changed files with 12 additions and 10 deletions

View File

@ -1,6 +1,7 @@
package server package server
import ( import (
"fmt"
"strings" "strings"
"time" "time"
@ -54,15 +55,15 @@ func createArticle(c *fiber.Ctx) error {
Title: data.Title, Title: data.Title,
Description: data.Description, Description: data.Description,
Content: data.Content, Content: data.Content,
RealmID: data.RealmID,
} }
var realm *models.Realm
if data.RealmID != nil { if data.RealmID != nil {
if err := database.C.Where(&models.Realm{ if realm, err := services.GetRealm(*data.RealmID); err != nil {
BaseModel: models.BaseModel{ID: *data.RealmID},
}).First(&realm).Error; err != nil {
return fiber.NewError(fiber.StatusBadRequest, err.Error()) return fiber.NewError(fiber.StatusBadRequest, err.Error())
} else if _, err := services.GetRealmMember(realm.ExternalID, user.ExternalID); err != nil {
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("you aren't a part of related realm: %v", err))
} else {
item.RealmID = &realm.ID
} }
} }

View File

@ -1,6 +1,7 @@
package server package server
import ( import (
"fmt"
"strings" "strings"
"time" "time"
@ -51,7 +52,6 @@ func createMoment(c *fiber.Ctx) error {
Categories: data.Categories, Categories: data.Categories,
Attachments: data.Attachments, Attachments: data.Attachments,
Content: data.Content, Content: data.Content,
RealmID: data.RealmID,
} }
var relatedCount int64 var relatedCount int64
@ -66,12 +66,13 @@ func createMoment(c *fiber.Ctx) error {
} }
} }
var realm *models.Realm
if data.RealmID != nil { if data.RealmID != nil {
if err := database.C.Where(&models.Realm{ if realm, err := services.GetRealm(*data.RealmID); err != nil {
BaseModel: models.BaseModel{ID: *data.RealmID},
}).First(&realm).Error; err != nil {
return fiber.NewError(fiber.StatusBadRequest, err.Error()) return fiber.NewError(fiber.StatusBadRequest, err.Error())
} else if _, err := services.GetRealmMember(realm.ExternalID, user.ExternalID); err != nil {
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("you aren't a part of related realm: %v", err))
} else {
item.RealmID = &realm.ID
} }
} }