🐛 Fix cannot get channel properly

This commit is contained in:
LittleSheep 2024-06-08 23:59:25 +08:00
parent bfd0c5e469
commit 4da282012d
2 changed files with 9 additions and 3 deletions

View File

@ -135,7 +135,7 @@ func removeChannelMember(c *fiber.Ctx) error {
} }
} }
func editChannelMembership(c *fiber.Ctx) error { func editMyChannelMembership(c *fiber.Ctx) error {
user := c.Locals("principal").(models.Account) user := c.Locals("principal").(models.Account)
alias := c.Params("channel") alias := c.Params("channel")
@ -148,7 +148,13 @@ func editChannelMembership(c *fiber.Ctx) error {
return err return err
} }
channel, err := services.GetChannelWithAlias(alias) var err error
var channel models.Channel
if val, ok := c.Locals("realm").(models.Realm); ok {
channel, err = services.GetChannelWithAlias(alias, val.ID)
} else {
channel, err = services.GetChannelWithAlias(alias)
}
if err != nil { if err != nil {
return fiber.NewError(fiber.StatusNotFound, err.Error()) return fiber.NewError(fiber.StatusNotFound, err.Error())
} }

View File

@ -80,8 +80,8 @@ func NewServer() {
channels.Delete("/:channelId", authMiddleware, deleteChannel) channels.Delete("/:channelId", authMiddleware, deleteChannel)
channels.Get("/:channel/members", listChannelMembers) channels.Get("/:channel/members", listChannelMembers)
channels.Put("/:channel/members/me", authMiddleware, editChannelMembership)
channels.Get("/:channel/members/me", authMiddleware, getMyChannelMembership) channels.Get("/:channel/members/me", authMiddleware, getMyChannelMembership)
channels.Put("/:channel/members/me", authMiddleware, editMyChannelMembership)
channels.Post("/:channel/members", authMiddleware, addChannelMember) channels.Post("/:channel/members", authMiddleware, addChannelMember)
channels.Post("/:channel/members/me", authMiddleware, joinChannel) channels.Post("/:channel/members/me", authMiddleware, joinChannel)
channels.Delete("/:channel/members", authMiddleware, removeChannelMember) channels.Delete("/:channel/members", authMiddleware, removeChannelMember)