✨ Support batch get userinfo by username
This commit is contained in:
parent
ed13d62110
commit
688d026d75
@ -39,14 +39,25 @@ func getOtherUserinfo(c *fiber.Ctx) error {
|
|||||||
|
|
||||||
func getOtherUserinfoBatch(c *fiber.Ctx) error {
|
func getOtherUserinfoBatch(c *fiber.Ctx) error {
|
||||||
idSet := strings.Split(c.Query("id"), ",")
|
idSet := strings.Split(c.Query("id"), ",")
|
||||||
if len(idSet) == 0 {
|
nameSet := strings.Split(c.Query("name"), ",")
|
||||||
return fiber.NewError(fiber.StatusBadRequest, "id list is required")
|
if len(idSet) == 0 && len(nameSet) == 0 {
|
||||||
|
return fiber.NewError(fiber.StatusBadRequest, "query filter is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(idSet)+len(nameSet) > 100 {
|
||||||
|
return fiber.NewError(fiber.StatusBadRequest, "only support 100 users in a single batch")
|
||||||
|
}
|
||||||
|
|
||||||
|
tx := database.C.Model(&models.Account{}).Limit(100)
|
||||||
|
if len(idSet) > 0 {
|
||||||
|
tx = tx.Where("id IN ?", idSet)
|
||||||
|
}
|
||||||
|
if len(nameSet) > 0 {
|
||||||
|
tx = tx.Where("name IN ?", nameSet)
|
||||||
}
|
}
|
||||||
|
|
||||||
var accounts []models.Account
|
var accounts []models.Account
|
||||||
if err := database.C.
|
if err := tx.Find(&accounts).Error; err != nil {
|
||||||
Where("id IN ?", idSet).
|
|
||||||
Find(&accounts).Error; err != nil {
|
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user