snow/handlers/server.go

58 lines
1.7 KiB
Go
Raw Permalink Normal View History

2024-01-03 19:51:46 +00:00
package handlers
import (
"time"
"github.com/ectrc/snow/aid"
p "github.com/ectrc/snow/person"
"github.com/gofiber/fiber/v2"
)
var (
serverActions = map[string]func(c *fiber.Ctx, person *p.Person, profile *p.Profile, profileChanges, multiUpdate, notifications *[]aid.JSON) error{
"QueryProfile": serverQueryProfileAction,
}
)
func PostServerProfileAction(c *fiber.Ctx) error {
person := p.Find(c.Params("accountId"))
if person == nil {
return c.Status(404).JSON(aid.ErrorBadRequest("No Account Found"))
}
profile := person.GetProfileFromType(c.Query("profileId"))
if profile == nil {
return c.Status(404).JSON(aid.ErrorBadRequest("No Profile Found"))
}
profileChanges := []aid.JSON{}
multiUpdate := []aid.JSON{}
notifications := []aid.JSON{}
2024-02-19 16:26:13 +00:00
if action, ok := serverActions[c.Params("action")]; ok {
2024-01-03 19:51:46 +00:00
if err := action(c, person, profile, &profileChanges, &multiUpdate, &notifications); err != nil {
return c.Status(500).JSON(aid.ErrorBadRequest(err.Error()))
}
}
return c.Status(200).JSON(aid.JSON{
"profileId": c.Query("profileId"),
"profileRevision": profile.Revision,
"profileCommandRevision": profile.Revision,
"profileChangesBaseRevision": profile.Revision - 1,
2024-02-17 15:42:04 +00:00
"profileChanges": profileChanges,
"multiUpdate": multiUpdate,
"notifications": notifications,
2024-01-03 19:51:46 +00:00
"responseVersion": 1,
"serverTime": time.Now().Format("2006-01-02T15:04:05.999Z"),
})
}
func serverQueryProfileAction(c *fiber.Ctx, person *p.Person, profile *p.Profile, profileChanges, multiUpdate, notifications *[]aid.JSON) error {
*profileChanges = append(*profileChanges, aid.JSON{
"changeType": "fullProfileUpdate",
"profile": profile.GenerateFortniteProfileEntry(),
})
return nil
}