Implement friend APIs and target profile support
- Add friend search/list/request/requestCancel/response/expel handlers and schemas - Store friend relationships in user_friend and backfill default friend links at startup - Auto-add the default user as a friend for newly created accounts - Support target user_id in /api profile requests and return target profile data - Make profile accessory_info optional to avoid zero-value accessory payloads - Update login topInfo friend counters from friend relationship state Signed-off-by: Sean Du <do4suki@gmail.com>
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"honoka-chan/internal/middleware"
|
||||
usermodel "honoka-chan/internal/model/user"
|
||||
"honoka-chan/internal/router"
|
||||
friendschema "honoka-chan/internal/schema/friend"
|
||||
"honoka-chan/internal/session"
|
||||
honokautils "honoka-chan/internal/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func expel(ctx *gin.Context) {
|
||||
ss := session.Get(ctx)
|
||||
defer ss.Finalize()
|
||||
|
||||
req := friendschema.UserIDReq{}
|
||||
err := honokautils.ParseRequestData(ctx, &req)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
targetUserID, err := resolveActualFriendUserID(ss, req.UserID)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
_, err = ss.UserEng.Table(new(usermodel.UserFriend)).
|
||||
Where("user_id = ?", ss.UserID).
|
||||
Where("friend_user_id = ?", targetUserID).
|
||||
Delete()
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
_, err = ss.UserEng.Table(new(usermodel.UserFriend)).
|
||||
Where("user_id = ?", targetUserID).
|
||||
Where("friend_user_id = ?", ss.UserID).
|
||||
Delete()
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
ss.Respond(friendschema.ExpelResp{
|
||||
ResponseData: []any{},
|
||||
ReleaseInfo: []any{},
|
||||
StatusCode: 200,
|
||||
})
|
||||
}
|
||||
|
||||
func init() {
|
||||
router.AddHandler("main.php", "POST", "/friend/expel", middleware.Common, expel)
|
||||
}
|
||||
Reference in New Issue
Block a user