Rename /commands to /command

Make it a verb not a GET fetch
This commit is contained in:
Marc Di Luzio 2020-06-05 22:29:51 +01:00
parent 9d57f48f98
commit 9ae1f50f46
5 changed files with 27 additions and 27 deletions

View file

@ -39,9 +39,9 @@ var Routes = []Route{
handler: HandleSpawn,
},
{
path: "/commands",
path: "/command",
method: http.MethodPost,
handler: HandleCommands,
handler: HandleCommand,
},
{
path: "/radar",
@ -122,13 +122,13 @@ func HandleSpawn(s *Server, b io.ReadCloser, w io.Writer) (interface{}, error) {
}
// HandleSpawn will spawn the player entity for the associated account
func HandleCommands(s *Server, b io.ReadCloser, w io.Writer) (interface{}, error) {
var response = rove.CommandsResponse{
func HandleCommand(s *Server, b io.ReadCloser, w io.Writer) (interface{}, error) {
var response = rove.CommandResponse{
Success: false,
}
// Decode the commands, verify them and the account, and execute the commands
var data rove.CommandsData
var data rove.CommandData
if err := json.NewDecoder(b).Decode(&data); err != nil {
fmt.Printf("Failed to decode json: %s\n", err)
response.Error = err.Error()
@ -162,7 +162,7 @@ func HandleRadar(s *Server, b io.ReadCloser, w io.Writer) (interface{}, error) {
}
// Decode the radar message, verify it, and respond with the radar info
var data rove.CommandsData
var data rove.CommandData
if err := json.NewDecoder(b).Decode(&data); err != nil {
fmt.Printf("Failed to decode json: %s\n", err)
response.Error = err.Error()

View file

@ -74,7 +74,7 @@ func TestHandleSpawn(t *testing.T) {
}
}
func TestHandleCommands(t *testing.T) {
func TestHandleCommand(t *testing.T) {
s := NewServer()
a, err := s.accountant.RegisterAccount("test")
assert.NoError(t, err, "Error registering account")
@ -85,7 +85,7 @@ func TestHandleCommands(t *testing.T) {
pos, err := s.world.RoverPosition(inst)
assert.NoError(t, err, "Couldn't get rover position")
data := rove.CommandsData{
data := rove.CommandData{
Id: a.Id.String(),
Commands: []rove.Command{
{
@ -99,16 +99,16 @@ func TestHandleCommands(t *testing.T) {
b, err := json.Marshal(data)
assert.NoError(t, err, "Error marshalling data")
request, _ := http.NewRequest(http.MethodPost, "/commands", bytes.NewReader(b))
request, _ := http.NewRequest(http.MethodPost, "/command", bytes.NewReader(b))
response := httptest.NewRecorder()
s.wrapHandler(http.MethodPost, HandleCommands)(response, request)
s.wrapHandler(http.MethodPost, HandleCommand)(response, request)
var status rove.CommandsResponse
var status rove.CommandResponse
json.NewDecoder(response.Body).Decode(&status)
if status.Success != true {
t.Errorf("got false for /commands")
t.Errorf("got false for /command")
}
attrib, err := s.world.RoverAttributes(inst)