Skip to content

Commit

Permalink
missions stub
Browse files Browse the repository at this point in the history
  • Loading branch information
kdudkov committed Oct 25, 2023
1 parent a889536 commit 8fa4a5e
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions cmd/goatak_server/marti_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"go.uber.org/zap"
)

const nodeId = "1"

func getMartiApi(app *App, addr string) *air.Air {
api := air.New()
api.Address = addr
Expand Down Expand Up @@ -54,6 +56,8 @@ func addMartiRoutes(app *App, api *air.Air, name string) {

api.GET("/Marti/api/device/profile/connection", getProfileConnectionHandler(app, name))

api.GET("/Marti/api/missions", getMissionsHandler(app, name))

api.GET("/Marti/sync/content", getMetadataGetHandler(app, name))
api.GET("/Marti/sync/search", getSearchHandler(app, name))
api.GET("/Marti/sync/missionquery", getMissionQueryHandler(app, name))
Expand All @@ -73,20 +77,15 @@ func getVersionHandler(app *App, name string) func(req *air.Request, res *air.Re
}

func getVersionConfigHandler(app *App, name string) func(req *air.Request, res *air.Response) error {
result := make(map[string]any)
data := make(map[string]any)
result["version"] = "2"
result["type"] = "ServerConfig"
result["nodeId"] = "1"
data["api"] = "2"
data["api"] = "3"
data["version"] = gitRevision + ":" + gitBranch
data["hostname"] = "0.0.0.0"
result["data"] = data
return func(req *air.Request, res *air.Response) error {
user := getUsernameFromReq(req)
logger := app.Logger.With(zap.String("api", name), zap.String("user", user))
logger.Infof("%s %s", req.Method, req.Path)
return res.WriteJSON(result)
return res.WriteJSON(makeAnswer("ServerConfig", data))
}
}

Expand All @@ -97,13 +96,7 @@ func getEndpointsHandler(app *App, name string) func(req *air.Request, res *air.
logger.Infof("%s %s", req.Method, req.Path)
//secAgo := getIntParam(req, "secAgo", 0)

result := make(map[string]any)
data := make([]map[string]any, 0)
result["Matcher"] = "com.bbn.marti.remote.ClientEndpoint"
result["BaseUrl"] = ""
result["ServerConnectString"] = ""
result["NotificationId"] = ""
result["type"] = "com.bbn.marti.remote.ClientEndpoint"

app.items.ForEach(func(item *model.Item) bool {
if item.GetClass() == model.CONTACT {
Expand All @@ -121,8 +114,7 @@ func getEndpointsHandler(app *App, name string) func(req *air.Request, res *air.

return true
})
result["data"] = data
return res.WriteJSON(result)
return res.WriteJSON(makeAnswer("com.bbn.marti.remote.ClientEndpoint", data))
}
}

Expand Down Expand Up @@ -305,16 +297,12 @@ func getAllGroupsHandler(app *App, name string) func(req *air.Request, res *air.
g := make(map[string]any)
g["name"] = "__ANON__"
g["direction"] = "OUT"
g["created"] = "2022-05-03"
g["created"] = "2023-01-01"
g["type"] = "SYSTEM"
g["bitpos"] = 2
g["active"] = true

result := make(map[string]any)
result["version"] = "3"
result["type"] = "com.bbn.marti.remote.groups.Group"
result["nodeId"] = "main"
result["data"] = []any{g}
result := makeAnswer("com.bbn.marti.remote.groups.Group", []map[string]any{g})

return func(req *air.Request, res *air.Response) error {
user := getUsernameFromReq(req)
Expand All @@ -324,6 +312,15 @@ func getAllGroupsHandler(app *App, name string) func(req *air.Request, res *air.
}
}

func getMissionsHandler(app *App, name string) func(req *air.Request, res *air.Response) error {
return func(req *air.Request, res *air.Response) error {
user := getUsernameFromReq(req)
logger := app.Logger.With(zap.String("api", name), zap.String("user", user))
logger.Infof("%s %s", req.Method, req.Path)
return res.WriteJSON(makeAnswer("Mission", []string{}))
}
}

func getProfileConnectionHandler(app *App, name string) func(req *air.Request, res *air.Response) error {
return func(req *air.Request, res *air.Response) error {
user := getUsernameFromReq(req)
Expand Down Expand Up @@ -390,6 +387,15 @@ func getVideoPostHandler(app *App, name string) func(req *air.Request, res *air.
}
}

func makeAnswer(typ string, data any) map[string]any {
result := make(map[string]any)
result["version"] = "3"
result["type"] = typ
result["nodeId"] = nodeId
result["data"] = data
return result
}

func getStringParam(req *air.Request, name string) string {
p := req.Param(name)
if p == nil {
Expand Down

0 comments on commit 8fa4a5e

Please sign in to comment.