Skip to content

Commit

Permalink
Develop (#255)
Browse files Browse the repository at this point in the history
* technical debt
  • Loading branch information
e154 authored Jan 8, 2024
1 parent 355dd9c commit 6ed8bd2
Show file tree
Hide file tree
Showing 244 changed files with 2,986 additions and 1,363 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.20.0
go-version: 1.21.0

- name: Set up Node
uses: actions/setup-node@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.20.0
go-version: 1.21.0

- name: Install linter
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.20.0
go-version: 1.21.0

- name: Set up Node
uses: actions/setup-node@v2
Expand Down
2 changes: 1 addition & 1 deletion Makefile.local
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ test:
go test -race $(go list ./... | grep -v /tests/)

install_linter:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.45.0
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.55.2

lint-todo:
@echo MARK: make lint todo
Expand Down
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# The program complex **Smart House**
<img width="100%" height="auto" src="doc/static/img/banner-v3.svg" alt="smart home logo">

# The **Smart Home**

[Project site](https://e154.github.io/smart-home/) |
[Node](https://github.com/e154/smart-home-node/)
Expand All @@ -14,11 +16,6 @@
|dev | ![Build Status](https://github.com/e154/smart-home/actions/workflows/test.yml/badge.svg?branch=develop) |
|docs | ![Build Status](https://github.com/e154/smart-home/actions/workflows/docs.yml/badge.svg?branch=docs) |

<img align="right" width="220" height="auto" src="doc/static/img/smarthome_logo.svg" alt="smart-home logo">

Attention! The project is under active development.
---------

### Overview

With the help of the software package **Smart Home** you can control many devices. Distributed network of devices based
Expand Down
17 changes: 17 additions & 0 deletions adaptors/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type IEntity interface {
GetByIdsSimple(ctx context.Context, ids []common.EntityId) (list []*m.Entity, err error)
Delete(ctx context.Context, id common.EntityId) (err error)
List(ctx context.Context, limit, offset int64, orderBy, sort string, autoLoad bool, query, plugin *string, areaId *int64) (list []*m.Entity, total int64, err error)
ListPlain(ctx context.Context, limit, offset int64, orderBy, sort string, autoLoad bool, query, plugin *string, areaId *int64) (list []*m.Entity, total int64, err error)
GetByType(ctx context.Context, t string, limit, offset int64) (list []*m.Entity, err error)
Update(ctx context.Context, ver *m.Entity) (err error)
Search(ctx context.Context, query string, limit, offset int64) (list []*m.Entity, total int64, err error)
Expand Down Expand Up @@ -270,6 +271,22 @@ func (n *Entity) List(ctx context.Context, limit, offset int64, orderBy, sort st
return
}

// ListPlain ...
func (n *Entity) ListPlain(ctx context.Context, limit, offset int64, orderBy, sort string, autoLoad bool, query, plugin *string, areaId *int64) (list []*m.Entity, total int64, err error) {

var dbList []*db.Entity
if dbList, total, err = n.table.ListPlain(ctx, int(limit), int(offset), orderBy, sort, autoLoad, query, plugin, areaId); err != nil {
return
}

list = make([]*m.Entity, len(dbList))
for i, dbVer := range dbList {
list[i] = n.fromDb(dbVer)
}

return
}

// GetByType ...
func (n *Entity) GetByType(ctx context.Context, t string, limit, offset int64) (list []*m.Entity, err error) {

Expand Down
16 changes: 16 additions & 0 deletions adaptors/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type ITrigger interface {
Update(ctx context.Context, ver *m.UpdateTrigger) error
Delete(ctx context.Context, deviceId int64) (err error)
List(ctx context.Context, limit, offset int64, orderBy, sort string, onlyEnabled bool) (list []*m.Trigger, total int64, err error)
ListPlain(ctx context.Context, limit, offset int64, orderBy, sort string, onlyEnabled bool) (list []*m.Trigger, total int64, err error)
Search(ctx context.Context, query string, limit, offset int) (list []*m.Trigger, total int64, err error)
Enable(ctx context.Context, id int64) (err error)
Disable(ctx context.Context, id int64) (err error)
Expand Down Expand Up @@ -182,6 +183,21 @@ func (n *Trigger) List(ctx context.Context, limit, offset int64, orderBy, sort s
return
}

// ListPlain ...
func (n *Trigger) ListPlain(ctx context.Context, limit, offset int64, orderBy, sort string, onlyEnabled bool) (list []*m.Trigger, total int64, err error) {
var dbList []*db.Trigger
if dbList, total, err = n.table.ListPlain(ctx, int(limit), int(offset), orderBy, sort, onlyEnabled); err != nil {
return
}

list = make([]*m.Trigger, len(dbList))
for i, dbVer := range dbList {
list[i] = n.fromDb(dbVer)
}

return
}

// Search ...
func (n *Trigger) Search(ctx context.Context, query string, limit, offset int) (list []*m.Trigger, total int64, err error) {
var dbList []*db.Trigger
Expand Down
1 change: 1 addition & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ func (a *Api) registerHandlers() {
v1.PUT("/plugin/:name/settings", a.echoFilter.Auth(wrapper.PluginServiceUpdatePluginSettings))
v1.GET("/plugins", a.echoFilter.Auth(wrapper.PluginServiceGetPluginList))
v1.GET("/plugins/search", a.echoFilter.Auth(wrapper.PluginServiceSearchPlugin))
v1.GET("/plugin/:name/readme", a.echoFilter.Auth(wrapper.PluginServiceGetPluginReadme))
v1.POST("/role", a.echoFilter.Auth(wrapper.RoleServiceAddRole))
v1.DELETE("/role/:name", a.echoFilter.Auth(wrapper.RoleServiceDeleteRoleByName))
v1.GET("/role/:name", a.echoFilter.Auth(wrapper.RoleServiceGetRoleByName))
Expand Down
35 changes: 35 additions & 0 deletions api/api.swagger3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2433,6 +2433,39 @@ paths:
$ref: '#/components/responses/HTTP-409'
security:
- ApiKeyAuth: [ ]
/v1/plugin/{name}/readme:
get:
tags:
- PluginService
summary: get plugin readme
operationId: PluginService_GetPluginReadme
parameters:
- name: name
in: path
required: true
schema:
type: string
- name: lang
in: query
required: false
schema:
type: string
- $ref: '#/components/parameters/Accept-JSON'
responses:
200:
description: A successful response.
content:
text/plain:
schema:
type: string
'400':
$ref: '#/components/responses/HTTP-400'
'401':
$ref: '#/components/responses/HTTP-401'
'404':
$ref: '#/components/responses/HTTP-404'
security:
- ApiKeyAuth: [ ]
/v1/plugins:
get:
tags:
Expand Down Expand Up @@ -4776,6 +4809,8 @@ components:
areaId:
type: integer
format: int64
area:
$ref: '#/components/schemas/apiArea'
createdAt:
type: string
format: date-time
Expand Down
11 changes: 11 additions & 0 deletions api/controllers/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,14 @@ func (c ControllerPlugin) PluginServiceUpdatePluginSettings(ctx echo.Context, na

return c.HTTP200(ctx, ResponseWithObj(ctx, struct{}{}))
}

// PluginServiceGetPluginReadme ...
func (c ControllerPlugin) PluginServiceGetPluginReadme(ctx echo.Context, name string, params stub.PluginServiceGetPluginReadmeParams) error {

html, err := c.endpoint.Plugin.Readme(ctx.Request().Context(), name, params.Lang)
if err != nil {
return c.ERROR(ctx, err)
}

return ctx.HTMLBlob(200, html)
}
15 changes: 13 additions & 2 deletions api/dto/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,19 @@ func (r Action) ToListResult(list []*m.Action) []stub.ApiAction {

items := make([]stub.ApiAction, 0, len(list))

for _, i := range list {
items = append(items, r.ToAction(i))
for _, action := range list {
items = append(items, stub.ApiAction{
Id: action.Id,
Name: action.Name,
Description: action.Description,
ScriptId: action.ScriptId,
AreaId: action.AreaId,
Area: GetStubArea(action.Area),
EntityId: action.EntityId.StringPtr(),
EntityActionName: action.EntityActionName,
CreatedAt: action.CreatedAt,
UpdatedAt: action.UpdatedAt,
})
}

return items
Expand Down
13 changes: 11 additions & 2 deletions api/dto/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,17 @@ func (r Condition) ToListResult(list []*m.Condition) []*stub.ApiCondition {

items := make([]*stub.ApiCondition, 0, len(list))

for _, i := range list {
items = append(items, ToCondition(i))
for _, cond := range list {
items = append(items, &stub.ApiCondition{
Id: cond.Id,
Name: cond.Name,
Description: cond.Description,
ScriptId: cond.ScriptId,
AreaId: cond.AreaId,
Area: GetStubArea(cond.Area),
CreatedAt: cond.CreatedAt,
UpdatedAt: cond.UpdatedAt,
})
}

return items
Expand Down
1 change: 1 addition & 0 deletions api/dto/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func ToDashboardShort(ver *m.Dashboard) (obj *stub.ApiDashboardShort) {
Description: ver.Description,
Enabled: ver.Enabled,
AreaId: ver.AreaId,
Area: GetStubArea(ver.Area),
CreatedAt: ver.CreatedAt,
UpdatedAt: ver.UpdatedAt,
}
Expand Down
11 changes: 9 additions & 2 deletions api/dto/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,15 @@ func (s Script) ToListResult(list []*m.Script) []*stub.ApiScript {

items := make([]*stub.ApiScript, 0, len(list))

for _, i := range list {
items = append(items, s.GetStubScript(i))
for _, script := range list {
items = append(items, &stub.ApiScript{
Id: script.Id,
Lang: string(script.Lang),
Name: script.Name,
Description: script.Description,
CreatedAt: script.CreatedAt,
UpdatedAt: script.UpdatedAt,
})
}

return items
Expand Down
17 changes: 15 additions & 2 deletions api/dto/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,21 @@ func (r Trigger) ToListResult(list []*m.Trigger) []*stub.ApiTrigger {

items := make([]*stub.ApiTrigger, 0, len(list))

for _, i := range list {
items = append(items, r.ToTrigger(i))
for _, trigger := range list {
items = append(items, &stub.ApiTrigger{
Id: trigger.Id,
Name: trigger.Name,
Description: trigger.Description,
EntityIds: make([]string, 0, len(trigger.Entities)),
ScriptId: trigger.ScriptId,
AreaId: trigger.AreaId,
Area: GetStubArea(trigger.Area),
PluginName: trigger.PluginName,
Enabled: trigger.Enabled,
IsLoaded: common.Bool(trigger.IsLoaded),
CreatedAt: trigger.CreatedAt,
UpdatedAt: trigger.UpdatedAt,
})
}

return items
Expand Down
48 changes: 48 additions & 0 deletions api/stub/server.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions api/stub/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion build/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ import "embed"
//go:embed public/assets/*
//go:embed public/index.html
//go:embed public/favicon.ico
//go:embed public/logo.png
var F embed.FS
Loading

0 comments on commit 6ed8bd2

Please sign in to comment.