♻️ Get users in batch supports name
This commit is contained in:
parent
11ca7c0ba6
commit
badae3aa0d
@ -23,9 +23,11 @@ import (
|
|||||||
func getUserInBatch(c *fiber.Ctx) error {
|
func getUserInBatch(c *fiber.Ctx) error {
|
||||||
id := c.Query("id")
|
id := c.Query("id")
|
||||||
list := strings.Split(id, ",")
|
list := strings.Split(id, ",")
|
||||||
|
var nameList []string
|
||||||
numericList := lo.Filter(lo.Map(list, func(str string, i int) int {
|
numericList := lo.Filter(lo.Map(list, func(str string, i int) int {
|
||||||
value, err := strconv.Atoi(str)
|
value, err := strconv.Atoi(str)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
nameList = append(nameList, str)
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return value
|
return value
|
||||||
@ -33,9 +35,16 @@ func getUserInBatch(c *fiber.Ctx) error {
|
|||||||
return vak > 0
|
return vak > 0
|
||||||
})
|
})
|
||||||
|
|
||||||
|
tx := database.C
|
||||||
|
if len(numericList) > 0 {
|
||||||
|
tx = tx.Where("id IN ?", numericList)
|
||||||
|
}
|
||||||
|
if len(nameList) > 0 {
|
||||||
|
tx = tx.Or("name IN ?", nameList)
|
||||||
|
}
|
||||||
|
|
||||||
var accounts []models.Account
|
var accounts []models.Account
|
||||||
if err := database.C.
|
if err := tx.
|
||||||
Where("id IN ?", numericList).
|
|
||||||
Preload("Profile").
|
Preload("Profile").
|
||||||
Preload("Badges", func(db *gorm.DB) *gorm.DB {
|
Preload("Badges", func(db *gorm.DB) *gorm.DB {
|
||||||
return db.Order("badges.type DESC")
|
return db.Order("badges.type DESC")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user