diff --git a/controllers/channels.go b/controllers/channels.go index fe0625ee..0df17cde 100644 --- a/controllers/channels.go +++ b/controllers/channels.go @@ -58,8 +58,11 @@ func CreateChannel(ctx *iris.Context) { c.Id = uuid.String() // Insert reference to DeviceId - did := ctx.Param("device_id") - c.Device = did + if c.Device = nil { + ctx.JSON(iris.StatusBadRequest, iris.Map{"response": "No device ID in request body"}) + } + + // TODO Check if Device ID is valid (in database) // Timestamp t := time.Now().UTC().Format(time.RFC3339) diff --git a/models/channel.go b/models/channel.go index 6dfcb492..52a11469 100644 --- a/models/channel.go +++ b/models/channel.go @@ -15,7 +15,7 @@ import ( type ( Channel struct { Id string `json:"id"` - Device string `json:"device"` + Device string `json:"device,omitempty"` Created string `json:"created"` Updated string `json:"updated"` diff --git a/servers/http_server.go b/servers/http_server.go index d2ee2751..456f45a0 100644 --- a/servers/http_server.go +++ b/servers/http_server.go @@ -59,11 +59,11 @@ func registerRoutes() { iris.Delete("/devices/:device_id", controllers.DeleteDevice) // CHANNELS - iris.Post("/devices/:device_id/channels", controllers.CreateChannel) - iris.Get("/devices/:device_id/channels", controllers.GetChannels) + iris.Post("/channels", controllers.CreateChannel) + iris.Get("/channels", controllers.GetChannels) - iris.Get("/devices/:device_id/channels/:channel_id", controllers.GetChannel) - iris.Put("/devices/:device_id/channels/:channel_id", controllers.UpdateChannel) + iris.Get("/channels/:channel_id", controllers.GetChannel) + iris.Put("/channels/:channel_id", controllers.UpdateChannel) - iris.Delete("/devices/:device_id/channels/:channel_id", controllers.DeleteChannel) + iris.Delete("/channels/:channel_id", controllers.DeleteChannel) }