Files
bdgrp_go/routes/api/user/param_userid.go
2026-09-04 23:03:50 +08:00

60 lines
1.2 KiB
Go

package user
import (
"bdgrp_go/db"
"bdgrp_go/pbutil"
"bdgrp_go/routes"
"bdgrp_go/utils"
"fmt"
"github.com/gofiber/fiber/v2"
)
func init() {
path := routes.PathOf()
routes.Register(func(app *fiber.App) {
app.Get(path, get)
app.Put(path, putUser)
fmt.Println("Loaded:", path)
})
}
func get(c *fiber.Ctx) error {
return c.SendString("")
}
func putUser(c *fiber.Ctx) error {
decrypted, _ := utils.Decrypt(c.Body())
decoded, err := pbutil.Decode("UserPutRequest", decrypted)
if err != nil {
fmt.Println(err)
}
userId := c.Params("userid")
user := db.FindUser(userId)
if v, ok := decoded["userName"].(string); ok && v != "" {
user["userName"] = v
}
if v, ok := decoded["birthMonth"].(string); ok && v != "" {
user["birthMonth"] = v
}
if v, ok := decoded["introduction"].(string); ok && v != "" {
user["introduction"] = v
}
if v, ok := decoded["tutorialStatus"].(string); ok && v != "" {
user["tutorialStatus"] = v
}
if v, ok := decoded["mainDeck"].(float64); ok && v != 0 {
user["mainDeck"] = uint64(v)
}
if v, ok := decoded["degree"].(float64); ok && v != 0 {
user["degree"] = uint32(v)
}
db.Save()
return c.SendString("")
}