Able get multiple userinfo in one request

This commit is contained in:
LittleSheep 2024-07-30 20:28:38 +08:00
parent e97f3b6047
commit d2beaa67b4
2 changed files with 18 additions and 0 deletions

View File

@ -63,6 +63,7 @@ func MapAPIs(app *fiber.App, baseURL string) {
directory.Get("/status", getStatus) directory.Get("/status", getStatus)
} }
api.Get("/users", getOtherUserinfoBatch)
api.Post("/users", doRegister) api.Post("/users", doRegister)
auth := api.Group("/auth").Name("Auth") auth := api.Group("/auth").Name("Auth")

View File

@ -2,6 +2,7 @@ package api
import ( import (
"fmt" "fmt"
"strings"
"git.solsynth.dev/hydrogen/passport/pkg/internal/database" "git.solsynth.dev/hydrogen/passport/pkg/internal/database"
"git.solsynth.dev/hydrogen/passport/pkg/internal/models" "git.solsynth.dev/hydrogen/passport/pkg/internal/models"
@ -35,3 +36,19 @@ func getOtherUserinfo(c *fiber.Ctx) error {
return c.JSON(account) 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)
}