add more routes
This commit is contained in:
59
routes/api/user/param_userid/area/registeropentimearea.go
Normal file
59
routes/api/user/param_userid/area/registeropentimearea.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package area
|
||||
|
||||
import (
|
||||
"bdgrp_go/master"
|
||||
"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, handle)
|
||||
fmt.Println("Loaded:", path)
|
||||
})
|
||||
}
|
||||
|
||||
func handle(c *fiber.Ctx) error {
|
||||
userid := c.Params("userid")
|
||||
m := master.GetMaster()
|
||||
|
||||
areaMap := m["masterAreaMap"].(map[string]any)
|
||||
entries := areaMap["entries"].(map[string]any)
|
||||
|
||||
// .filter(area.areaType === "common").map(...)
|
||||
resultEntries := map[string]any{}
|
||||
for areaId, v := range entries {
|
||||
area := v.(map[string]any)
|
||||
if area["areaType"] != "common" {
|
||||
continue
|
||||
}
|
||||
resultEntries[areaId] = map[string]any{
|
||||
"userId": userid,
|
||||
"areaId": areaId,
|
||||
}
|
||||
}
|
||||
|
||||
data := map[string]any{
|
||||
"registerTimeOpenAreaIdList": nil,
|
||||
"userAreaStatusMap": map[string]any{
|
||||
"entries": resultEntries,
|
||||
},
|
||||
}
|
||||
|
||||
encoded, err := pbutil.Encode("RegisterTimeOpenAreaResponse", data)
|
||||
if err != nil {
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
encrypted, err := utils.Encrypt(encoded)
|
||||
if err != nil {
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
return c.Send(encrypted)
|
||||
}
|
||||
Reference in New Issue
Block a user