✨ Better relationships stauts query
This commit is contained in:
		
							
								
								
									
										10
									
								
								.idea/workspace.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										10
									
								
								.idea/workspace.xml
									
									
									
										generated
									
									
									
								
							| @@ -4,10 +4,10 @@ | ||||
|     <option name="autoReloadType" value="ALL" /> | ||||
|   </component> | ||||
|   <component name="ChangeListManager"> | ||||
|     <list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":boom: Passing relationship api arguments in body instead of querystring"> | ||||
|     <list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":sparkles: Better check in experience random algorithm"> | ||||
|       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> | ||||
|       <change beforePath="$PROJECT_DIR$/pkg/internal/http/api/check_in_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/http/api/check_in_api.go" afterDir="false" /> | ||||
|       <change beforePath="$PROJECT_DIR$/pkg/internal/services/check_in.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/check_in.go" afterDir="false" /> | ||||
|       <change beforePath="$PROJECT_DIR$/pkg/internal/http/api/relationships_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/http/api/relationships_api.go" afterDir="false" /> | ||||
|       <change beforePath="$PROJECT_DIR$/pkg/internal/services/relationships.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/relationships.go" afterDir="false" /> | ||||
|     </list> | ||||
|     <option name="SHOW_DIALOG" value="false" /> | ||||
|     <option name="HIGHLIGHT_CONFLICTS" value="true" /> | ||||
| @@ -160,7 +160,6 @@ | ||||
|   </component> | ||||
|   <component name="VcsManagerConfiguration"> | ||||
|     <option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" /> | ||||
|     <MESSAGE value=":technologist: Improve DX by extending authkit" /> | ||||
|     <MESSAGE value=":sparkles: Add list relative method into authkit" /> | ||||
|     <MESSAGE value=":sparkles: Realm operations now available in authkit" /> | ||||
|     <MESSAGE value=":bug: Fix grpc namespace conflict" /> | ||||
| @@ -185,7 +184,8 @@ | ||||
|     <MESSAGE value=":truck: Rename daily-sign to check-in" /> | ||||
|     <MESSAGE value=":sparkles: Result modifiers in check-in" /> | ||||
|     <MESSAGE value=":boom: Passing relationship api arguments in body instead of querystring" /> | ||||
|     <option name="LAST_COMMIT_MESSAGE" value=":boom: Passing relationship api arguments in body instead of querystring" /> | ||||
|     <MESSAGE value=":sparkles: Better check in experience random algorithm" /> | ||||
|     <option name="LAST_COMMIT_MESSAGE" value=":sparkles: Better check in experience random algorithm" /> | ||||
|     <option name="GROUP_MULTIFILE_MERGE_BY_DIRECTORY" value="true" /> | ||||
|   </component> | ||||
|   <component name="VgoProject"> | ||||
|   | ||||
| @@ -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()) | ||||
| 		} | ||||
| 	} | ||||
|   | ||||
| @@ -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 { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user