diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index a5a4431..08ecef9 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,13 +4,8 @@
-
+
-
-
-
-
-
@@ -142,7 +137,8 @@
-
+
+
true
diff --git a/pkg/server/friendships_api.go b/pkg/server/friendships_api.go
index 59c7ba4..fcc15ba 100644
--- a/pkg/server/friendships_api.go
+++ b/pkg/server/friendships_api.go
@@ -9,13 +9,21 @@ import (
func listFriendship(c *fiber.Ctx) error {
user := c.Locals("principal").(models.Account)
- status := c.QueryInt("status", int(models.FriendshipActive))
+ status := c.QueryInt("status", -1)
- if friends, err := services.ListFriend(user, models.FriendshipStatus(status)); err != nil {
- return fiber.NewError(fiber.StatusInternalServerError, err.Error())
+ var err error
+ var friends []models.AccountFriendship
+ if status < 0 {
+ if friends, err = services.ListAllFriend(user); err != nil {
+ return fiber.NewError(fiber.StatusInternalServerError, err.Error())
+ }
} else {
- return c.JSON(friends)
+ if friends, err = services.ListFriend(user, models.FriendshipStatus(status)); err != nil {
+ return fiber.NewError(fiber.StatusInternalServerError, err.Error())
+ }
}
+
+ return c.JSON(friends)
}
func getFriendship(c *fiber.Ctx) error {
diff --git a/pkg/server/startup.go b/pkg/server/startup.go
index 00f8ca6..3b0452e 100644
--- a/pkg/server/startup.go
+++ b/pkg/server/startup.go
@@ -1,6 +1,9 @@
package server
import (
+ "net/http"
+ "strings"
+
"git.solsynth.dev/hydrogen/passport/pkg"
"git.solsynth.dev/hydrogen/passport/pkg/i18n"
"git.solsynth.dev/hydrogen/passport/pkg/server/ui"
@@ -14,8 +17,6 @@ import (
jsoniter "github.com/json-iterator/go"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
- "net/http"
- "strings"
)
var A *fiber.App
diff --git a/pkg/services/friendships.go b/pkg/services/friendships.go
index a7a8389..4c0a039 100644
--- a/pkg/services/friendships.go
+++ b/pkg/services/friendships.go
@@ -3,11 +3,25 @@ package services
import (
"errors"
"fmt"
+
"git.solsynth.dev/hydrogen/passport/pkg/database"
"git.solsynth.dev/hydrogen/passport/pkg/models"
"gorm.io/gorm"
)
+func ListAllFriend(anyside models.Account) ([]models.AccountFriendship, error) {
+ var relationships []models.AccountFriendship
+ if err := database.C.
+ Where("account_id = ? OR related_id = ?", anyside.ID, anyside.ID).
+ Preload("Account").
+ Preload("Related").
+ Find(&relationships).Error; err != nil {
+ return relationships, err
+ }
+
+ return relationships, nil
+}
+
func ListFriend(anyside models.Account, status models.FriendshipStatus) ([]models.AccountFriendship, error) {
var relationships []models.AccountFriendship
if err := database.C.