🐛 Use alias instead of id to link realm
This commit is contained in:
parent
dc7e83eb61
commit
fa87a8e838
@ -34,7 +34,7 @@ func createArticle(c *fiber.Ctx) error {
|
|||||||
Categories []models.Category `json:"categories" form:"categories"`
|
Categories []models.Category `json:"categories" form:"categories"`
|
||||||
Attachments []models.Attachment `json:"attachments" form:"attachments"`
|
Attachments []models.Attachment `json:"attachments" form:"attachments"`
|
||||||
PublishedAt *time.Time `json:"published_at" form:"published_at"`
|
PublishedAt *time.Time `json:"published_at" form:"published_at"`
|
||||||
RealmID *uint `json:"realm_id" form:"realm_id"`
|
RealmAlias string `json:"realm" form:"realm"`
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := BindAndValidate(c, &data); err != nil {
|
if err := BindAndValidate(c, &data); err != nil {
|
||||||
@ -57,8 +57,8 @@ func createArticle(c *fiber.Ctx) error {
|
|||||||
Content: data.Content,
|
Content: data.Content,
|
||||||
}
|
}
|
||||||
|
|
||||||
if data.RealmID != nil {
|
if len(data.RealmAlias) > 0 {
|
||||||
if realm, err := services.GetRealm(*data.RealmID); err != nil {
|
if realm, err := services.GetRealmWithAlias(data.RealmAlias); 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 {
|
} 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))
|
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("you aren't a part of related realm: %v", err))
|
||||||
|
@ -32,7 +32,7 @@ func createMoment(c *fiber.Ctx) error {
|
|||||||
Categories []models.Category `json:"categories" form:"categories"`
|
Categories []models.Category `json:"categories" form:"categories"`
|
||||||
Attachments []models.Attachment `json:"attachments" form:"attachments"`
|
Attachments []models.Attachment `json:"attachments" form:"attachments"`
|
||||||
PublishedAt *time.Time `json:"published_at" form:"published_at"`
|
PublishedAt *time.Time `json:"published_at" form:"published_at"`
|
||||||
RealmID *uint `json:"realm_id" form:"realm_id"`
|
RealmAlias string `json:"realm" form:"realm"`
|
||||||
RepostTo uint `json:"repost_to" form:"repost_to"`
|
RepostTo uint `json:"repost_to" form:"repost_to"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,8 +66,8 @@ func createMoment(c *fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if data.RealmID != nil {
|
if len(data.RealmAlias) > 0 {
|
||||||
if realm, err := services.GetRealm(*data.RealmID); err != nil {
|
if realm, err := services.GetRealmWithAlias(data.RealmAlias); 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 {
|
} 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))
|
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("you aren't a part of related realm: %v", err))
|
||||||
|
Loading…
Reference in New Issue
Block a user