Able to list all the friend without status filter

This commit is contained in:
LittleSheep 2024-04-25 22:08:49 +08:00
parent e0d496cc47
commit 3e9c84a284
4 changed files with 32 additions and 13 deletions

View File

@ -4,13 +4,8 @@
<option name="autoReloadType" value="ALL" />
</component>
<component name="ChangeListManager">
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":bug: Bug fixes of design">
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":sparkles: Bug fixes">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/server/auth_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/server/auth_api.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/server/oauth_api.go" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/server/startup.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/server/startup.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/views/users/directory/userinfo.gohtml" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/views/users/directory/userinfo.gohtml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/views/users/me.gohtml" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/views/users/me.gohtml" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -142,7 +137,8 @@
<MESSAGE value=":sparkles: Others userinfo" />
<MESSAGE value=":lipstick: Fix ui design" />
<MESSAGE value=":bug: Bug fixes of design" />
<option name="LAST_COMMIT_MESSAGE" value=":bug: Bug fixes of design" />
<MESSAGE value=":sparkles: Bug fixes" />
<option name="LAST_COMMIT_MESSAGE" value=":sparkles: Bug fixes" />
</component>
<component name="VgoProject">
<settings-migrated>true</settings-migrated>

View File

@ -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 {
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)
}
} else {
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 {

View File

@ -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

View File

@ -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.