Messaging/pkg/internal/server/api/users_api.go

39 lines
953 B
Go
Raw Normal View History

package api
2024-03-26 15:05:13 +00:00
import (
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
"git.solsynth.dev/hydrogen/messaging/pkg/internal/database"
2024-06-22 10:29:41 +00:00
"git.solsynth.dev/hydrogen/messaging/pkg/internal/gap"
"git.solsynth.dev/hydrogen/messaging/pkg/internal/models"
2024-03-26 15:05:13 +00:00
"github.com/gofiber/fiber/v2"
)
func getUserinfo(c *fiber.Ctx) error {
2024-06-22 10:29:41 +00:00
if err := gap.H.EnsureAuthenticated(c); err != nil {
return err
}
2024-06-22 12:15:01 +00:00
user := c.Locals("user").(models.Account)
2024-03-26 15:05:13 +00:00
var data models.Account
if err := database.C.
Where(&hyper.BaseModel{ID: user.ID}).
2024-03-26 15:05:13 +00:00
First(&data).Error; err != nil {
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
}
return c.JSON(data)
}
func getOthersInfo(c *fiber.Ctx) error {
accountId := c.Params("accountId")
var data models.Account
if err := database.C.
Where(&hyper.BaseUser{Name: accountId}).
2024-03-26 15:05:13 +00:00
First(&data).Error; err != nil {
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
}
return c.JSON(data)
}