diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 3be5472..f21eba0 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,10 +4,7 @@
-
-
-
-
+
diff --git a/pkg/internal/server/api/accounts_api.go b/pkg/internal/server/api/accounts_api.go
index dbf6280..bce7758 100644
--- a/pkg/internal/server/api/accounts_api.go
+++ b/pkg/internal/server/api/accounts_api.go
@@ -18,7 +18,7 @@ import (
func lookupAccount(c *fiber.Ctx) error {
probe := c.Query("probe")
if len(probe) == 0 {
- return fiber.NewError(fiber.StatusBadRequest, "you must provide a probe")
+ return fiber.NewError(fiber.StatusBadRequest, "lookup probe is required")
}
user, err := services.LookupAccount(probe)
@@ -29,6 +29,20 @@ func lookupAccount(c *fiber.Ctx) error {
return c.JSON(user)
}
+func searchAccount(c *fiber.Ctx) error {
+ probe := c.Query("probe")
+ if len(probe) == 0 {
+ return fiber.NewError(fiber.StatusBadRequest, "search probe is required")
+ }
+
+ users, err := services.SearchAccount(probe)
+ if err != nil {
+ return fiber.NewError(fiber.StatusInternalServerError, err.Error())
+ }
+
+ return c.JSON(users)
+}
+
func getUserinfo(c *fiber.Ctx) error {
if err := exts.EnsureAuthenticated(c); err != nil {
return err
diff --git a/pkg/internal/server/api/index.go b/pkg/internal/server/api/index.go
index a5f3547..fe05c60 100644
--- a/pkg/internal/server/api/index.go
+++ b/pkg/internal/server/api/index.go
@@ -18,6 +18,7 @@ func MapAPIs(app *fiber.App, baseURL string) {
}
api.Get("/users/lookup", lookupAccount)
+ api.Get("/users/search", searchAccount)
me := api.Group("/users/me").Name("Myself Operations")
{
diff --git a/pkg/internal/services/accounts.go b/pkg/internal/services/accounts.go
index b266f20..60201e1 100644
--- a/pkg/internal/services/accounts.go
+++ b/pkg/internal/services/accounts.go
@@ -2,9 +2,10 @@ package services
import (
"fmt"
- "gorm.io/gorm/clause"
"time"
+ "gorm.io/gorm/clause"
+
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
"gorm.io/datatypes"
@@ -65,6 +66,15 @@ func LookupAccount(probe string) (models.Account, error) {
return account, fmt.Errorf("account was not found")
}
+func SearchAccount(probe string) ([]models.Account, error) {
+ probe = "%" + probe + "%"
+ var accounts []models.Account
+ if err := database.C.Where("name LIKE ? OR nick LIKE ?", probe).Find(&accounts).Error; err != nil {
+ return accounts, err
+ }
+ return accounts, nil
+}
+
func CreateAccount(name, nick, email, password string) (models.Account, error) {
user := models.Account{
Name: name,