diff --git a/pkg/internal/http/api/accounts_api.go b/pkg/internal/http/api/accounts_api.go index 20203ab..1a2c18f 100644 --- a/pkg/internal/http/api/accounts_api.go +++ b/pkg/internal/http/api/accounts_api.go @@ -7,6 +7,7 @@ import ( "time" "git.solsynth.dev/hypernet/nexus/pkg/nex/sec" + "gorm.io/gorm" "git.solsynth.dev/hypernet/passport/pkg/internal/http/exts" @@ -15,9 +16,37 @@ import ( "git.solsynth.dev/hypernet/passport/pkg/internal/services" "github.com/gofiber/fiber/v2" jsoniter "github.com/json-iterator/go" + "github.com/samber/lo" "github.com/spf13/viper" ) +func getUserInBatch(c *fiber.Ctx) error { + id := c.Query("id") + list := strings.Split(id, ",") + numericList := lo.Filter(lo.Map(list, func(str string, i int) int { + value, err := strconv.Atoi(str) + if err != nil { + return 0 + } + return value + }), func(vak int, idx int) bool { + return vak > 0 + }) + + var accounts []models.Account + if err := database.C. + Where("id IN ?", numericList). + Preload("Profile"). + Preload("Badges", func(db *gorm.DB) *gorm.DB { + return db.Order("badges.type DESC") + }). + First(&accounts).Error; err != nil { + return fiber.NewError(fiber.StatusBadRequest, err.Error()) + } + + return c.JSON(accounts) +} + func lookupAccount(c *fiber.Ctx) error { probe := c.Query("probe") if len(probe) == 0 { diff --git a/pkg/internal/http/api/index.go b/pkg/internal/http/api/index.go index bf5ace7..82a93d3 100644 --- a/pkg/internal/http/api/index.go +++ b/pkg/internal/http/api/index.go @@ -48,6 +48,7 @@ func MapAPIs(app *fiber.App, baseURL string) { } } + api.Get("/users", getUserInBatch) api.Get("/users/lookup", lookupAccount) api.Get("/users/search", searchAccount)