✨ Able get multiple userinfo in one request
This commit is contained in:
		| @@ -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") | ||||
|   | ||||
| @@ -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) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user