diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 242e749..a4e1062 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,10 +4,10 @@
-
+
-
-
+
+
@@ -160,7 +160,6 @@
-
@@ -185,7 +184,8 @@
-
+
+
diff --git a/pkg/internal/http/api/relationships_api.go b/pkg/internal/http/api/relationships_api.go
index 486f098..47c3833 100644
--- a/pkg/internal/http/api/relationships_api.go
+++ b/pkg/internal/http/api/relationships_api.go
@@ -5,7 +5,9 @@ import (
"git.solsynth.dev/hypernet/passport/pkg/internal/http/exts"
"git.solsynth.dev/hypernet/passport/pkg/internal/services"
"github.com/gofiber/fiber/v2"
+ "github.com/samber/lo"
"strconv"
+ "strings"
)
func listRelationship(c *fiber.Ctx) error {
@@ -13,16 +15,24 @@ func listRelationship(c *fiber.Ctx) error {
return err
}
user := c.Locals("user").(models.Account)
- status := c.QueryInt("status", -1)
+ statusQuery := c.Query("status")
+
+ status := lo.Map(strings.Split(statusQuery, ","), func(s string, _ int) models.RelationshipStatus {
+ num, err := strconv.Atoi(s)
+ if err != nil {
+ return 0
+ }
+ return models.RelationshipStatus(num)
+ })
var err error
var friends []models.AccountRelationship
- if status < 0 {
+ if len(status) < 0 {
if friends, err = services.ListAllRelationship(user); err != nil {
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
}
} else {
- if friends, err = services.ListRelationshipWithFilter(user, models.RelationshipStatus(status)); err != nil {
+ if friends, err = services.ListRelationshipWithFilter(user, status...); err != nil {
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
}
}
diff --git a/pkg/internal/services/relationships.go b/pkg/internal/services/relationships.go
index 49080f8..2c6fb10 100644
--- a/pkg/internal/services/relationships.go
+++ b/pkg/internal/services/relationships.go
@@ -22,10 +22,10 @@ func ListAllRelationship(user models.Account) ([]models.AccountRelationship, err
return relationships, nil
}
-func ListRelationshipWithFilter(user models.Account, status models.RelationshipStatus) ([]models.AccountRelationship, error) {
+func ListRelationshipWithFilter(user models.Account, status ...models.RelationshipStatus) ([]models.AccountRelationship, error) {
var relationships []models.AccountRelationship
if err := database.C.
- Where("account_id = ? AND status = ?", user.ID, status).
+ Where("account_id = ? AND status IN ?", user.ID, status).
Preload("Account").
Preload("Related").
Find(&relationships).Error; err != nil {