Implement session module

Signed-off-by: Sean Du <do4suki@gmail.com>
This commit is contained in:
2025-08-15 19:24:36 +08:00
parent 985895a780
commit 80a686849f
29 changed files with 837 additions and 694 deletions
+11 -9
View File
@@ -1,31 +1,33 @@
package handler
import (
"encoding/json"
"honoka-chan/internal/model"
"honoka-chan/internal/session"
"honoka-chan/internal/tools"
"honoka-chan/internal/utils"
"net/http"
"github.com/gin-gonic/gin"
"github.com/tidwall/gjson"
)
func BackgroundSet(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
req := gjson.Parse(ctx.PostForm("request_data"))
pref := tools.UserPref{
BackgroundID: int(req.Get("background_id").Int()),
}
_, err := UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Update(&pref)
utils.CheckErr(err)
_, err := ss.UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Update(&pref)
if ss.CheckErr(err) {
return
}
backgroundResp := model.BackgroundSetResp{
ResponseData: []any{},
ReleaseInfo: []any{},
StatusCode: 200,
}
resp, err := json.Marshal(backgroundResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp))
ctx.String(http.StatusOK, string(resp))
ss.Respond(backgroundResp)
}