Skip to content

Commit

Permalink
issues #64 mobile object mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
alekseyf12 committed Sep 13, 2019
1 parent 5cbfb8a commit df8e35d
Show file tree
Hide file tree
Showing 21 changed files with 503 additions and 167 deletions.
40 changes: 20 additions & 20 deletions adaptors/adaptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ type Adaptors struct {
DeviceAction *DeviceAction
DeviceState *DeviceState
Flow *Flow
FlowElement *FlowElement
Connection *Connection
Worker *Worker
Role *Role
Permission *Permission
User *User
UserMeta *UserMeta
Image *Image
Variable *Variable
Map *Map
MapLayer *MapLayer
MapText *MapText
MapImage *MapImage
MapDevice *MapDevice
MapElement *MapElement
MapDeviceState *MapDeviceState
MapDeviceAction *MapDeviceAction
Log *Log
ZoneTag *ZoneTag
FlowElement *FlowElement
Connection *Connection
Worker *Worker
Role *Role
Permission *Permission
User *User
UserMeta *UserMeta
Image *Image
Variable *Variable
Map *Map
MapLayer *MapLayer
MapText *MapText
MapImage *MapImage
MapDevice *MapDevice
MapElement *MapElement
MapDeviceState *MapDeviceState
MapDeviceAction *MapDeviceAction
Log *Log
MapZone *MapZone
}

func NewAdaptors(db *gorm.DB,
Expand Down Expand Up @@ -76,7 +76,7 @@ func NewAdaptors(db *gorm.DB,
MapDeviceState: GetMapDeviceStateAdaptor(db),
MapDeviceAction: GetMapDeviceActionAdaptor(db),
Log: GetLogAdaptor(db),
ZoneTag: GetZoneTagAdaptor(db),
MapZone: GetMapZoneAdaptor(db),
}

return
Expand Down
2 changes: 1 addition & 1 deletion adaptors/map_element.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func (n *MapElement) fromDb(dbVer *db.MapElement) (ver *m.MapElement) {

// Zone tag
if dbVer.Zone != nil {
zoneAdaptor := GetZoneTagAdaptor(n.db)
zoneAdaptor := GetMapZoneAdaptor(n.db)
ver.Zone = zoneAdaptor.fromDb(dbVer.Zone)
}

Expand Down
76 changes: 76 additions & 0 deletions adaptors/map_zone.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package adaptors

import (
"github.com/e154/smart-home/db"
m "github.com/e154/smart-home/models"
"github.com/jinzhu/gorm"
)

type MapZone struct {
table *db.MapZones
db *gorm.DB
}

func GetMapZoneAdaptor(d *gorm.DB) *MapZone {
return &MapZone{
table: &db.MapZones{Db: d},
db: d,
}
}

func (n *MapZone) Add(tag *m.MapZone) (id int64, err error) {

dbTag := n.toDb(tag)
id, err = n.table.Add(dbTag)

return
}


func (n *MapZone) GetByName(zoneName string) (ver *m.MapZone, err error) {

var dbVer *db.MapZone
if dbVer, err = n.table.GetByName(zoneName); err != nil {
return
}

ver = n.fromDb(dbVer)

return
}

func (n *MapZone) Delete(name string) (err error) {

err = n.table.Delete(name)

return
}

func (n *MapZone) Search(query string, limit, offset int) (list []*m.MapZone, total int64, err error) {
var dbList []*db.MapZone
if dbList, total, err = n.table.Search(query, limit, offset); err != nil {
return
}

list = make([]*m.MapZone, 0)
for _, dbTag := range dbList {
node := n.fromDb(dbTag)
list = append(list, node)
}

return
}

func (n *MapZone) toDb(tag *m.MapZone) *db.MapZone {
return &db.MapZone{
Id: tag.Id,
Name: tag.Name,
}
}

func (n *MapZone) fromDb(tag *db.MapZone) *m.MapZone {
return &m.MapZone{
Id: tag.Id,
Name: tag.Name,
}
}
63 changes: 0 additions & 63 deletions adaptors/zone_tag.go

This file was deleted.

5 changes: 5 additions & 0 deletions api/server/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ func (s *Server) setControllers() {
v1.GET("/map_elements", s.af.Auth, s.ControllersV1.MapElement.GetList)
v1.PUT("/map_elements/sort", s.af.Auth, s.ControllersV1.MapElement.Sort)

// map zone
v1.POST("/map_zone", s.af.Auth, s.ControllersV1.MapZone.Add)
v1.DELETE("/map_zone/:name", s.af.Auth, s.ControllersV1.MapZone.Delete)
v1.GET("/map_zone/search", s.af.Auth, s.ControllersV1.MapZone.Search)

// images
v1.POST("/image", s.af.Auth, s.ControllersV1.Image.Add)
v1.GET("/image/:id", s.af.Auth, s.ControllersV1.Image.GetById)
Expand Down
2 changes: 2 additions & 0 deletions api/server/v1/controllers/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type ControllersV1 struct {
Flow *ControllerFlow
Log *ControllerLog
Gate *ControllerGate
MapZone *ControllerMapZone
}

func NewControllersV1(adaptors *adaptors.Adaptors,
Expand Down Expand Up @@ -56,5 +57,6 @@ func NewControllersV1(adaptors *adaptors.Adaptors,
Flow: NewControllerFlow(common),
Log: NewControllerLog(common),
Gate: NewControllerGate(common),
MapZone: NewControllerMapZone(common),
}
}
Loading

0 comments on commit df8e35d

Please sign in to comment.