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

38 lines
941 B
Go
Raw Normal View History

package api
2024-02-01 16:53:22 +00:00
import (
"git.solsynth.dev/hydrogen/interactive/pkg/internal/database"
"git.solsynth.dev/hydrogen/interactive/pkg/internal/gap"
"git.solsynth.dev/hydrogen/interactive/pkg/internal/models"
2024-02-01 16:53:22 +00:00
"github.com/gofiber/fiber/v2"
)
func getUserinfo(c *fiber.Ctx) error {
if err := gap.H.EnsureAuthenticated(c); err != nil {
return err
}
user := c.Locals("user").(models.Account)
2024-02-01 16:53:22 +00:00
var data models.Account
if err := database.C.
Where(&models.Account{BaseModel: models.BaseModel{ID: user.ID}}).
First(&data).Error; err != nil {
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
}
return c.JSON(data)
}
2024-02-03 07:20:32 +00:00
2024-02-03 11:22:50 +00:00
func getOthersInfo(c *fiber.Ctx) error {
2024-02-05 07:51:31 +00:00
accountId := c.Params("accountId")
2024-02-03 11:22:50 +00:00
var data models.Account
if err := database.C.
2024-02-05 07:51:31 +00:00
Where(&models.Account{Name: accountId}).
2024-02-03 11:22:50 +00:00
First(&data).Error; err != nil {
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
}
return c.JSON(data)
}