💥 Passing relationship api arguments in body instead of querystring

This commit is contained in:
LittleSheep 2024-11-30 00:35:11 +08:00
parent 659548a544
commit 55b3a6f164
2 changed files with 32 additions and 27 deletions

9
.idea/workspace.xml generated
View File

@ -4,10 +4,9 @@
<option name="autoReloadType" value="ALL" /> <option name="autoReloadType" value="ALL" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":truck: Rename daily-sign to check-in"> <list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":sparkles: Result modifiers in check-in">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/authkit/models/check_in.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/authkit/models/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/check_in.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/check_in.go" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -160,7 +159,6 @@
</component> </component>
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" /> <option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
<MESSAGE value=":truck: Update package name from Hypdrogen to Hypernet" />
<MESSAGE value=":sparkles: Support users related rpc calls" /> <MESSAGE value=":sparkles: Support users related rpc calls" />
<MESSAGE value=":technologist: Improve DX by extending authkit" /> <MESSAGE value=":technologist: Improve DX by extending authkit" />
<MESSAGE value=":sparkles: Add list relative method into authkit" /> <MESSAGE value=":sparkles: Add list relative method into authkit" />
@ -185,7 +183,8 @@
<MESSAGE value=":bug: Fix group permission didn't extend properly" /> <MESSAGE value=":bug: Fix group permission didn't extend properly" />
<MESSAGE value=":mute: Remove authenticate result logging" /> <MESSAGE value=":mute: Remove authenticate result logging" />
<MESSAGE value=":truck: Rename daily-sign to check-in" /> <MESSAGE value=":truck: Rename daily-sign to check-in" />
<option name="LAST_COMMIT_MESSAGE" value=":truck: Rename daily-sign to check-in" /> <MESSAGE value=":sparkles: Result modifiers in check-in" />
<option name="LAST_COMMIT_MESSAGE" value=":sparkles: Result modifiers in check-in" />
<option name="GROUP_MULTIFILE_MERGE_BY_DIRECTORY" value="true" /> <option name="GROUP_MULTIFILE_MERGE_BY_DIRECTORY" value="true" />
</component> </component>
<component name="VgoProject"> <component name="VgoProject">

View File

@ -112,30 +112,33 @@ func makeFriendship(c *fiber.Ctx) error {
return err return err
} }
user := c.Locals("user").(models.Account) user := c.Locals("user").(models.Account)
relatedName := c.Query("related")
relatedId, _ := c.ParamsInt("relatedId", 0) var data struct {
Related string `json:"related" validate:"required"`
}
if err := exts.BindAndValidate(c, &data); err != nil {
return err
}
var err error var err error
var related models.Account var related models.Account
if relatedId > 0 { if numericId, err := strconv.Atoi(data.Related); err == nil {
related, err = services.GetAccount(uint(relatedId)) related, err = services.GetAccount(uint(numericId))
if err != nil {
return fiber.NewError(fiber.StatusNotFound, err.Error())
}
} else if len(relatedName) > 0 {
related, err = services.LookupAccount(relatedName)
if err != nil { if err != nil {
return fiber.NewError(fiber.StatusNotFound, err.Error()) return fiber.NewError(fiber.StatusNotFound, err.Error())
} }
} else { } else {
return fiber.NewError(fiber.StatusBadRequest, "must one of username or user id") related, err = services.LookupAccount(data.Related)
if err != nil {
return fiber.NewError(fiber.StatusNotFound, err.Error())
}
} }
friend, err := services.NewFriend(user, related) friend, err := services.NewFriend(user, related)
if err != nil { if err != nil {
return fiber.NewError(fiber.StatusBadRequest, err.Error()) return fiber.NewError(fiber.StatusBadRequest, err.Error())
} else { } else {
services.AddEvent(user.ID, "relationships.friends.new", strconv.Itoa(relatedId), c.IP(), c.Get(fiber.HeaderUserAgent)) services.AddEvent(user.ID, "relationships.friends.new", strconv.Itoa(int(related.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
return c.JSON(friend) return c.JSON(friend)
} }
} }
@ -145,30 +148,33 @@ func makeBlockship(c *fiber.Ctx) error {
return err return err
} }
user := c.Locals("user").(models.Account) user := c.Locals("user").(models.Account)
relatedName := c.Query("related")
relatedId, _ := c.ParamsInt("relatedId", 0) var data struct {
Related string `json:"related" validate:"required"`
}
if err := exts.BindAndValidate(c, &data); err != nil {
return err
}
var err error var err error
var related models.Account var related models.Account
if relatedId > 0 { if numericId, err := strconv.Atoi(data.Related); err == nil {
related, err = services.GetAccount(uint(relatedId)) related, err = services.GetAccount(uint(numericId))
if err != nil {
return fiber.NewError(fiber.StatusNotFound, err.Error())
}
} else if len(relatedName) > 0 {
related, err = services.LookupAccount(relatedName)
if err != nil { if err != nil {
return fiber.NewError(fiber.StatusNotFound, err.Error()) return fiber.NewError(fiber.StatusNotFound, err.Error())
} }
} else { } else {
return fiber.NewError(fiber.StatusBadRequest, "must one of username or user id") related, err = services.LookupAccount(data.Related)
if err != nil {
return fiber.NewError(fiber.StatusNotFound, err.Error())
}
} }
friend, err := services.NewBlockship(user, related) friend, err := services.NewBlockship(user, related)
if err != nil { if err != nil {
return fiber.NewError(fiber.StatusBadRequest, err.Error()) return fiber.NewError(fiber.StatusBadRequest, err.Error())
} else { } else {
services.AddEvent(user.ID, "relationships.blocks.new", strconv.Itoa(relatedId), c.IP(), c.Get(fiber.HeaderUserAgent)) services.AddEvent(user.ID, "relationships.blocks.new", strconv.Itoa(int(related.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
return c.JSON(friend) return c.JSON(friend)
} }
} }