Change `/channels` API

Signed-off-by: Drasko DRASKOVIC <drasko.draskovic@gmail.com>
This commit is contained in:
Drasko DRASKOVIC 2016-09-20 23:03:54 +02:00
parent 52f0017be5
commit 57a4535bc4
3 changed files with 11 additions and 8 deletions

View File

@ -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)

View File

@ -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"`

View File

@ -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)
}