add user routes
This commit is contained in:
59
routes/api/user/param_userid.go
Normal file
59
routes/api/user/param_userid.go
Normal file
@@ -0,0 +1,59 @@
|
||||
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("")
|
||||
}
|
||||
Reference in New Issue
Block a user