-
Notifications
You must be signed in to change notification settings - Fork 0
/
star-system.go
39 lines (31 loc) · 896 Bytes
/
star-system.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package admin
import (
"context"
"net/http"
"github.com/dayaftereh/discover/server/api"
)
func (admin *adminRouter) starSystem(ctx context.Context, response http.ResponseWriter, request *http.Request, variables map[string]string) error {
// check if the user is admin
isAdmin, err := admin.IsAdmin(ctx)
if err != nil {
return err
}
// response Forbidden because not a admin
if !isAdmin {
return api.Forbidden(response)
}
// get the name of the star system
name, ok := variables["name"]
// return bad request because name missing
if !ok {
return api.BadRequest(response)
}
// get the star system for the given name
starSystem := admin.backend.GetStarSystem(name)
// check if a star system with the name exists
if starSystem == nil {
return api.NotFound(response)
}
// response all star systems
return api.WriteJSON(response, http.StatusOK, starSystem.Data)
}