diff --git a/pkg/internal/server/api/index.go b/pkg/internal/server/api/index.go index fe05c60..5f5eb14 100644 --- a/pkg/internal/server/api/index.go +++ b/pkg/internal/server/api/index.go @@ -63,6 +63,7 @@ func MapAPIs(app *fiber.App, baseURL string) { directory.Get("/status", getStatus) } + api.Get("/users", getOtherUserinfoBatch) api.Post("/users", doRegister) auth := api.Group("/auth").Name("Auth") diff --git a/pkg/internal/server/api/userinfo_api.go b/pkg/internal/server/api/userinfo_api.go index bf9471e..0b13c0e 100644 --- a/pkg/internal/server/api/userinfo_api.go +++ b/pkg/internal/server/api/userinfo_api.go @@ -2,6 +2,7 @@ package api import ( "fmt" + "strings" "git.solsynth.dev/hydrogen/passport/pkg/internal/database" "git.solsynth.dev/hydrogen/passport/pkg/internal/models" @@ -35,3 +36,19 @@ func getOtherUserinfo(c *fiber.Ctx) error { return c.JSON(account) } + +func getOtherUserinfoBatch(c *fiber.Ctx) error { + idSet := strings.Split(c.Query("id"), ",") + if len(idSet) == 0 { + return fiber.NewError(fiber.StatusBadRequest, "id list is required") + } + + var accounts []models.Account + if err := database.C. + Where("id IN ?", idSet). + Find(&accounts).Error; err != nil { + return fiber.NewError(fiber.StatusBadRequest, err.Error()) + } + + return c.JSON(accounts) +}