🐛 Fix cannot join realm related channel

This commit is contained in:
LittleSheep 2024-05-06 23:28:15 +08:00
parent 1603d9f438
commit 7c5c9d03d1
2 changed files with 6 additions and 4 deletions

View File

@ -19,7 +19,9 @@ type Channel struct {
Type ChannelType `json:"type"`
Account Account `json:"account"`
AccountID uint `json:"account_id"`
RealmID *uint `json:"realm_id"`
Realm Realm `json:"realm"`
RealmID *uint `json:"realm_id"`
}
type NotifyLevel = int8

View File

@ -132,7 +132,7 @@ func joinChannel(c *fiber.Ctx) error {
var channel models.Channel
if err := database.C.Where(&models.Channel{
Alias: alias,
}).First(&channel).Error; err != nil {
}).Preload("Realm").First(&channel).Error; err != nil {
return fiber.NewError(fiber.StatusNotFound, err.Error())
} else if _, _, err := services.GetAvailableChannel(channel.ID, user); err == nil {
return fiber.NewError(fiber.StatusBadRequest, "you already joined the channel")
@ -140,9 +140,9 @@ func joinChannel(c *fiber.Ctx) error {
return fiber.NewError(fiber.StatusBadRequest, "you was impossible to join a channel without related realm")
}
if realm, err := services.GetRealm(channel.ID); err != nil {
if realm, err := services.GetRealm(channel.Realm.ExternalID); err != nil {
return fiber.NewError(fiber.StatusInternalServerError, fmt.Sprintf("invalid channel, related realm was not found: %v", err))
} else if _, err := services.GetRealmMember(realm.ID, user.ExternalID); err != nil {
} else if _, err := services.GetRealmMember(realm.ExternalID, user.ExternalID); err != nil {
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("you are not a part of the realm: %v", err))
}