Skip to content

Commit

Permalink
technical debt (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
e154 authored Nov 2, 2023
1 parent bb18744 commit e5d136f
Show file tree
Hide file tree
Showing 19 changed files with 285 additions and 285 deletions.
4 changes: 2 additions & 2 deletions adaptors/metric_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ func (n *MetricBucket) List(ctx context.Context, from, to *time.Time, metricId i

var dbList []*db.MetricBucket
if dbList, err = n.table.List(ctx, metricId, optionItems, from, to, metricRange); err != nil {
return
}
return
}

list = make([]*m.MetricDataItem, len(dbList))
for i, dbVer := range dbList {
Expand Down
346 changes: 173 additions & 173 deletions api/stub/types.go

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions common/apperr/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,10 @@ var (
ErrUserDeviceDelete = ErrorWithCode("USER_DEVICE_DELETE_ERROR", "failed to delete user device", ErrInternal)
ErrUserDeviceAdd = ErrorWithCode("USER_DEVICE_ADD_ERROR", "failed to add user device", ErrInternal)

ErrBackupNotFound = ErrorWithCode("BACKUP_NOT_FOUND_ERROR", "backup not found", ErrNotFound)
ErrBackupNotFound = ErrorWithCode("BACKUP_NOT_FOUND_ERROR", "backup not found", ErrNotFound)
ErrBackupNameNotUnique = ErrorWithCode("BACKUP_NAME_NOT_UNIQUE", "backup name not unique", ErrInvalidRequest)

ErrScriptVersionAdd = ErrorWithCode("SCRIPT_VERSION_ADD_ERROR", "failed to add script version", ErrInternal)
ErrScriptVersionList = ErrorWithCode("SCRIPT_VERSION_LIST_ERROR", "failed to list script version", ErrInternal)
ErrScriptVersionDelete = ErrorWithCode("SCRIPT_VERSION_DELETE_ERROR", "failed to delete script version", ErrInternal)
ErrScriptVersionAdd = ErrorWithCode("SCRIPT_VERSION_ADD_ERROR", "failed to add script version", ErrInternal)
ErrScriptVersionList = ErrorWithCode("SCRIPT_VERSION_LIST_ERROR", "failed to list script version", ErrInternal)
ErrScriptVersionDelete = ErrorWithCode("SCRIPT_VERSION_DELETE_ERROR", "failed to delete script version", ErrInternal)
)
2 changes: 1 addition & 1 deletion endpoint/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (n *ActionEndpoint) Update(ctx context.Context, params *m.Action) (action *
}

n.eventBus.Publish(fmt.Sprintf("system/models/actions/%d", action.Id), events.EventUpdatedActionModel{
Id: action.Id,
Id: action.Id,
Action: action,
})

Expand Down
22 changes: 11 additions & 11 deletions models/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,34 @@ type AppConfig struct {
PgHost string `json:"pg_host" env:"PG_HOST"`
PgName string `json:"pg_name" env:"PG_NAME"`
PgPort string `json:"pg_port" env:"PG_PORT"`
PgDebug bool `json:"pg_debug" env:"PG_DEBUG"`
SnapshotDir string `json:"snapshot_dir" env:"SNAPSHOT_DIR"`
Mode common.RunMode `json:"mode" env:"MODE"`
AlexaHost string `json:"alexa_host" env:"ALEXA_HOST"`
MobileHost string `json:"mobile_host" env:"MOBILE_HOST"`
Lang string `json:"lang" env:"LANG"`
Domain string `json:"domain" env:"DOMAIN"`
PgMaxIdleConns int `json:"pg_max_idle_conns" env:"PG_MAX_IDLE_CONNS"`
PgMaxOpenConns int `json:"pg_max_open_conns" env:"PG_MAX_OPEN_CONNS"`
PgConnMaxLifeTime int `json:"pg_conn_max_life_time" env:"PG_CONN_MAX_LIFE_TIME"`
AutoMigrate bool `json:"auto_migrate" env:"AUTO_MIGRATE"`
SnapshotDir string `json:"snapshot_dir" env:"SNAPSHOT_DIR"`
Mode common.RunMode `json:"mode" env:"MODE"`
MqttPort int `json:"mqtt_port" env:"MQTT_PORT"`
MqttRetryInterval time.Duration `json:"mqtt_retry_interval" env:"MQTT_RETRY_INTERVAL"`
MqttRetryCheckInterval time.Duration `json:"mqtt_retry_check_interval" env:"MQTT_RETRY_CHECK_INTERVAL"`
MqttSessionExpiryInterval time.Duration `json:"mqtt_session_expiry_interval" env:"MQTT_SESSION_EXPIRY_INTERVAL"`
MqttSessionExpireCheckInterval time.Duration `json:"mqtt_session_expire_check_interval" env:"MQTT_SESSION_EXPIRE_CHECK_INTERVAL"`
MqttQueueQos0Messages bool `json:"mqtt_queue_qos_0_messages" env:"MQTT_QUEUE_QOS_0_MESSAGES"`
MqttMaxInflight int `json:"mqtt_max_inflight" env:"MQTT_MAX_INFLIGHT"`
MqttMaxAwaitRel int `json:"mqtt_max_await_rel" env:"MQTT_MAX_AWAIT_REL"`
MqttMaxMsgQueue int `json:"mqtt_max_msg_queue" env:"MQTT_MAX_MSG_QUEUE"`
MqttDeliverMode int `json:"mqtt_deliver_mode" env:"MQTT_DELIVER_MODE"`
Logging bool `json:"logging" env:"LOGGING"`
ColoredLogging bool `json:"colored_logging" env:"COLORED_LOGGING"`
AlexaHost string `json:"alexa_host" env:"ALEXA_HOST"`
AlexaPort int `json:"alexa_port" env:"ALEXA_PORT"`
MobileHost string `json:"mobile_host" env:"MOBILE_HOST"`
MobilePort int `json:"mobile_port" env:"MOBILE_PORT"`
ApiHttpPort int `json:"api_http_port" env:"API_HTTP_PORT"`
PgDebug bool `json:"pg_debug" env:"PG_DEBUG"`
AutoMigrate bool `json:"auto_migrate" env:"AUTO_MIGRATE"`
MqttQueueQos0Messages bool `json:"mqtt_queue_qos_0_messages" env:"MQTT_QUEUE_QOS_0_MESSAGES"`
Logging bool `json:"logging" env:"LOGGING"`
ColoredLogging bool `json:"colored_logging" env:"COLORED_LOGGING"`
ApiSwagger bool `json:"api_swagger" env:"API_SWAGGER"`
Lang string `json:"lang" env:"LANG"`
GodMode bool `json:"god_mode" env:"GOD_MODE"`
Domain string `json:"domain" env:"DOMAIN"`
Https bool `json:"https" env:"HTTPS"`
}

Expand Down
12 changes: 6 additions & 6 deletions models/area.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ import (

// Area ...
type Area struct {
Id int64 `json:"id"`
Polygon []Point `json:"polygon"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Name string `json:"name" validate:"required"`
Description string `json:"description"`
Polygon []Point `json:"polygon"`
Zoom float32 `json:"zoom"`
Center Point `json:"center"`
Id int64 `json:"id"`
Zoom float32 `json:"zoom"`
Resolution float32 `json:"resolution"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}

type AreaPayload struct {
Zoom float32 `json:"zoom"`
Center Point `json:"center"`
Zoom float32 `json:"zoom"`
Resolution float32 `json:"resolution"`
}
8 changes: 4 additions & 4 deletions models/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
package models

import (
"os"
"io/fs"
"time"
)

type Backup struct {
ModTime time.Time
Name string
Size int64
MimeType string
FileMode os.FileMode
ModTime time.Time
Size int64
FileMode fs.FileMode
}

type Backups []*Backup
Expand Down
10 changes: 5 additions & 5 deletions models/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ import (

// Dashboard ...
type Dashboard struct {
Id int64 `json:"id"`
Tabs []*DashboardTab `json:"tabs"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Name string `json:"name" validate:"required"`
Description string `json:"description"`
Enabled bool `json:"enabled"`
Id int64 `json:"id"`
AreaId *int64 `json:"area_id"`
Area *Area `json:"area"`
Tabs []*DashboardTab `json:"tabs"`
Entities map[common.EntityId]*Entity `json:"entities"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Enabled bool `json:"enabled"`
}
14 changes: 7 additions & 7 deletions models/dashboard_card.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ import (

// DashboardCard ...
type DashboardCard struct {
Id int64 `json:"id"`
Payload json.RawMessage `json:"payload"`
Items []*DashboardCardItem `json:"items"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Title string `json:"title" validate:"required"`
Id int64 `json:"id"`
Height int `json:"height" validate:"required"`
Width int `json:"width" validate:"required"`
Background *string `json:"background"`
Weight int `json:"weight"`
Enabled bool `json:"enabled"`
DashboardTabId int64 `json:"dashboard_tab_id" validate:"required"`
DashboardTab *DashboardTab `json:"dashboard_tab"`
Payload json.RawMessage `json:"payload"`
Items []*DashboardCardItem `json:"items"`
Entities map[common.EntityId]*Entity `json:"entities"`
Hidden bool `json:"hidden"`
EntityId *common.EntityId `json:"entity_id"`
Entity *Entity `json:"entity"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Enabled bool `json:"enabled"`
Hidden bool `json:"hidden"`
}
10 changes: 5 additions & 5 deletions models/dashboard_card_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ import (

// DashboardCardItem ...
type DashboardCardItem struct {
Id int64 `json:"id"`
Payload json.RawMessage `json:"payload"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Title string `json:"title" validate:"required"`
Type string `json:"type" validate:"required"`
Id int64 `json:"id"`
Weight int `json:"weight"`
Enabled bool `json:"enabled"`
DashboardCardId int64 `json:"dashboard_card_id" validate:"required"`
DashboardCard *DashboardCard `json:"dashboard_card"`
EntityId *common.EntityId `json:"entity_id"`
Entity *Entity `json:"entity"`
Payload json.RawMessage `json:"payload"`
Enabled bool `json:"enabled"`
Hidden bool `json:"hidden"`
Frozen bool `json:"frozen"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
14 changes: 7 additions & 7 deletions models/dashboard_tab.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ import (

// DashboardTab ...
type DashboardTab struct {
Id int64 `json:"id"`
Cards []*DashboardCard `json:"cards"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Name string `json:"name" validate:"required"`
Icon string `json:"icon"`
Id int64 `json:"id"`
ColumnWidth int `json:"column_width"`
Gap bool `json:"gap"`
Background *string `json:"background"`
Icon string `json:"icon"`
Enabled bool `json:"enabled"`
Weight int `json:"weight"`
DashboardId int64 `json:"dashboard_id" validate:"required"`
Dashboard *Dashboard `json:"dashboard"`
Cards []*DashboardCard `json:"cards"`
Entities map[common.EntityId]*Entity `json:"entities"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Gap bool `json:"gap"`
Enabled bool `json:"enabled"`
}
16 changes: 8 additions & 8 deletions models/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,24 @@ type EntitySettings struct {

// Entity ...
type Entity struct {
Actions []*EntityAction `json:"actions"`
States []*EntityState `json:"states"`
Metrics []*Metric `json:"metrics"`
Scripts []*Script `json:"scripts"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Id common.EntityId `json:"id"`
Description string `json:"description"`
PluginName string `json:"plugin_name" validate:"required"`
Icon *string `json:"icon"`
Image *Image `json:"image"`
ImageId *int64 `json:"image_id"`
Actions []*EntityAction `json:"actions"`
States []*EntityState `json:"states"`
Area *Area `json:"area"`
AreaId *int64 `json:"area_id"`
Metrics []*Metric `json:"metrics"`
Scripts []*Script `json:"scripts"`
Hidden bool `json:"hidden"`
Attributes Attributes `json:"attributes"`
Settings Attributes `json:"settings"`
ParentId *common.EntityId `json:"parent_id"`
Hidden bool `json:"hidden"`
AutoLoad bool `json:"auto_load"`
IsLoaded bool `json:"is_loaded"`
ParentId *common.EntityId `json:"parent_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
10 changes: 5 additions & 5 deletions models/geo_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,18 @@ type RegionInfo struct {
CountryCapital string `json:"country_capital"`
CountryTld string `json:"country_tld"`
ContinentCode string `json:"continent_code"`
InEu bool `json:"in_eu"`
Postal string `json:"postal"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
Timezone string `json:"timezone"`
UtcOffset string `json:"utc_offset"`
CountryCallingCode string `json:"country_calling_code"`
Currency string `json:"currency"`
CurrencyName string `json:"currency_name"`
Languages string `json:"languages"`
CountryArea float64 `json:"country_area"`
CountryPopulation float64 `json:"country_population"`
Asn string `json:"asn"`
Org string `json:"org"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
CountryArea float64 `json:"country_area"`
CountryPopulation float64 `json:"country_population"`
InEu bool `json:"in_eu"`
}
14 changes: 7 additions & 7 deletions models/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ type PluginSettings struct {
type Plugin struct {
Name string `json:"name"`
Version string `json:"version"`
Settings AttributeValue `json:"settings"`
Enabled bool `json:"enabled"`
System bool `json:"system"`
Actor bool `json:"actor"`
Settings AttributeValue `json:"settings"`
IsLoaded bool `json:"is_loaded"`
}

Expand Down Expand Up @@ -60,16 +60,16 @@ type PluginOptionsJs struct {

// PluginOptions ...
type PluginOptions struct {
Javascript PluginOptionsJs `json:"javascript"`
ActorAttrs Attributes `json:"actor_attrs"`
ActorActions map[string]EntityActionShort `json:"actor_actions"`
ActorStates map[string]EntityStateShort `json:"actor_states"`
ActorSetts Attributes `json:"actor_setts"`
Setts Attributes `json:"setts"`
Triggers bool `json:"triggers"`
Actors bool `json:"actors"`
ActorCustomAttrs bool `json:"actor_custom_attrs"`
ActorAttrs Attributes `json:"actor_attrs"`
ActorCustomActions bool `json:"actor_custom_actions"`
ActorActions map[string]EntityActionShort `json:"actor_actions"`
ActorCustomStates bool `json:"actor_custom_states"`
ActorStates map[string]EntityStateShort `json:"actor_states"`
ActorCustomSetts bool `json:"actor_custom_setts"`
ActorSetts Attributes `json:"actor_setts"`
Setts Attributes `json:"setts"`
Javascript PluginOptionsJs `json:"javascript"`
}
42 changes: 21 additions & 21 deletions models/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ import (

// Task ...
type Task struct {
Id int64 `json:"id"`
Name string `json:"name" validate:"required,lte=255"`
Description string `json:"description" validate:"lte=255"`
Enabled bool `json:"enabled"`
IsLoaded bool `json:"is_loaded"`
Condition common.ConditionType `json:"condition" validate:"required,oneof=or and"`
Triggers []*Trigger `json:"triggers" validate:"dive"`
Conditions []*Condition `json:"conditions" validate:"dive"`
Actions []*Action `json:"actions" validate:"dive"`
Area *Area `json:"area"`
AreaId *int64 `json:"area_id"`
Telemetry telemetry.Telemetry `json:"telemetry"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Name string `json:"name" validate:"required,lte=255"`
Description string `json:"description" validate:"lte=255"`
Condition common.ConditionType `json:"condition" validate:"required,oneof=or and"`
Id int64 `json:"id"`
Area *Area `json:"area"`
AreaId *int64 `json:"area_id"`
Enabled bool `json:"enabled"`
IsLoaded bool `json:"is_loaded"`
}

// AddTrigger ...
Expand All @@ -60,31 +60,31 @@ func (t *Task) AddAction(a *Action) {

// NewTask ...
type NewTask struct {
Name string `json:"name" validate:"required,lte=255"`
Description string `json:"description" validate:"lte=255"`
Enabled bool `json:"enabled"`
IsLoaded bool `json:"is_loaded"`
Condition common.ConditionType `json:"condition" validate:"required,oneof=or and"`
TriggerIds []int64 `json:"triggers" validate:"dive"`
ConditionIds []int64 `json:"conditions" validate:"dive"`
ActionIds []int64 `json:"actions" validate:"dive"`
Name string `json:"name" validate:"required,lte=255"`
Description string `json:"description" validate:"lte=255"`
Condition common.ConditionType `json:"condition" validate:"required,oneof=or and"`
Area *Area `json:"area"`
AreaId *int64 `json:"area_id"`
Enabled bool `json:"enabled"`
IsLoaded bool `json:"is_loaded"`
}

// UpdateTask ...
type UpdateTask struct {
Id int64 `json:"id"`
TriggerIds []int64 `json:"triggers" validate:"dive"`
ConditionIds []int64 `json:"conditions" validate:"dive"`
ActionIds []int64 `json:"actions" validate:"dive"`
CreatedAt time.Time
UpdatedAt time.Time
Name string `json:"name" validate:"required,lte=255"`
Description string `json:"description" validate:"lte=255"`
Enabled bool `json:"enabled"`
IsLoaded bool `json:"is_loaded"`
Condition common.ConditionType `json:"condition" validate:"required,oneof=or and"`
TriggerIds []int64 `json:"triggers" validate:"dive"`
ConditionIds []int64 `json:"conditions" validate:"dive"`
ActionIds []int64 `json:"actions" validate:"dive"`
Id int64 `json:"id"`
Area *Area `json:"area"`
AreaId *int64 `json:"area_id"`
CreatedAt time.Time
UpdatedAt time.Time
Enabled bool `json:"enabled"`
IsLoaded bool `json:"is_loaded"`
}
Loading

0 comments on commit e5d136f

Please sign in to comment.