Skip to content

Commit

Permalink
fix database errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Forest33 committed Nov 16, 2022
1 parent 7443db8 commit a8ba3c9
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 68 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
<img src="https://img.shields.io/github/go-mod/go-version/forest33/warthog?style=flat-square"/>
</p>


## Features

- Automatic parsing of proto definitions to render services and input messages
- `.proto` file discovery
- Selection of multiple services and methods
- Configuration of TLS, including disabling TLS (plain text)
- Input generation for all scalar types
- Input generation for nested messages
- Input generation for nested and looped messages
- Input generation for enums, including nested
- Input generation for repeated fields
- Input generation for oneof and map fields
Expand Down Expand Up @@ -47,7 +46,8 @@ Visit the [Releases](https://github.com/Forest33/warthog/releases) page for the

### MacOS

[Download](https://github.com/Forest33/warthog/releases) and open `Warthog*-darwin-x86-64.dmg`, drag `Warthog` to the `Applications` folder and run from `Applications`.
[Download](https://github.com/Forest33/warthog/releases) and open `Warthog*-darwin-x86-64.dmg`, drag `Warthog` to
the `Applications` folder and run from `Applications`.

### Windows

Expand Down
33 changes: 9 additions & 24 deletions adapter/database/gui.config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ import (

"github.com/forest33/warthog/business/entity"
"github.com/forest33/warthog/pkg/database"
"github.com/forest33/warthog/pkg/database/types"
)

const (
guiConfigTable = "gui_config"
guiConfigTableFields = "window_width, window_height, window_x, window_y, created_at, updated_at"
guiConfigTableFields = "window_width, window_height, window_x, window_y"
)

// GUIConfigRepository object capable of interacting with GUIConfigRepository
Expand All @@ -31,33 +30,19 @@ func NewGUIConfigRepository(ctx context.Context, db *database.Database) *GUIConf
}

type guiConfigDTO struct {
WindowWidth int `db:"window_width"`
WindowHeight int `db:"window_height"`
WindowX int `db:"window_x"`
WindowY int `db:"window_y"`
CreatedAt string `db:"created_at"`
UpdatedAt string `db:"updated_at"`
WindowWidth int `db:"window_width"`
WindowHeight int `db:"window_height"`
WindowX int `db:"window_x"`
WindowY int `db:"window_y"`
}

func (dto *guiConfigDTO) entity() (*entity.GUIConfig, error) {
out := &entity.GUIConfig{
func (dto *guiConfigDTO) entity() *entity.GUIConfig {
return &entity.GUIConfig{
WindowWidth: dto.WindowWidth,
WindowHeight: dto.WindowHeight,
WindowX: &dto.WindowX,
WindowY: &dto.WindowY,
}

var err error
out.CreatedAt, err = types.StrToDateTime(dto.CreatedAt)
if err != nil {
return nil, err
}
out.UpdatedAt, err = types.StrToDateTime(dto.UpdatedAt)
if err != nil {
return nil, err
}

return out, nil
}

// Get returns GUIConfig
Expand All @@ -69,7 +54,7 @@ func (repo *GUIConfigRepository) Get() (*entity.GUIConfig, error) {
return nil, err
}

return dto.entity()
return dto.entity(), nil
}

// Update updates GUIConfig
Expand Down Expand Up @@ -108,5 +93,5 @@ func (repo *GUIConfigRepository) Update(in *entity.GUIConfig) (*entity.GUIConfig
return nil, err
}

return dto.entity()
return dto.entity(), nil
}
32 changes: 11 additions & 21 deletions adapter/database/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

const (
workspaceTable = "workspace"
workspaceTableFields = "id, parent_id, has_child, type, title, data, sort, expanded, created_at, updated_at"
workspaceTableFields = "id, parent_id, has_child, type, title, data, sort, expanded"
)

// WorkspaceRepository object capable of interacting with WorkspaceRepository
Expand All @@ -37,16 +37,14 @@ func NewWorkspaceRepository(ctx context.Context, db *database.Database) *Workspa
}

type workspaceDTO struct {
ID int64 `db:"id"`
ParentID sql.NullInt64 `db:"parent_id"`
HasChild bool `db:"has_child"`
Type string `db:"type"`
Title string `db:"title"`
Data sql.NullString `db:"data"`
Sort int64 `db:"sort"`
Expanded bool `db:"expanded"`
CreatedAt string `db:"created_at"`
UpdatedAt string `db:"updated_at"`
ID int64 `db:"id"`
ParentID sql.NullInt64 `db:"parent_id"`
HasChild bool `db:"has_child"`
Type string `db:"type"`
Title string `db:"title"`
Data sql.NullString `db:"data"`
Sort int64 `db:"sort"`
Expanded bool `db:"expanded"`
}

func newWorkspaceDTO(in *entity.Workspace) (dto *workspaceDTO, err error) {
Expand Down Expand Up @@ -77,7 +75,6 @@ func (dto *workspaceDTO) entity() (*entity.Workspace, error) {
Expanded: &dto.Expanded,
}

var err error
if dto.Data.Valid {
switch out.Type {
case entity.WorkspaceTypeFolder:
Expand All @@ -93,14 +90,6 @@ func (dto *workspaceDTO) entity() (*entity.Workspace, error) {
return nil, err
}
}
out.CreatedAt, err = types.StrToDateTime(dto.CreatedAt)
if err != nil {
return nil, err
}
out.UpdatedAt, err = types.StrToDateTime(dto.UpdatedAt)
if err != nil {
return nil, err
}

return out, nil
}
Expand All @@ -124,9 +113,10 @@ func (repo *WorkspaceRepository) GetByID(id int64) (*entity.Workspace, error) {
if err != nil {
return nil, err
}
return dto.entity()
}

return dto.entity()
return nil, entity.ErrWorkspaceNotExists
}

// GetByParentID returns workspace item by parent id
Expand Down
2 changes: 1 addition & 1 deletion bin/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.3.2
0.3.8
5 changes: 5 additions & 0 deletions business/entity/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ const (
WorkspaceTypeQuery WorkspaceType = "r"
)

var (
// ErrWorkspaceNotExists error workspace not exists
ErrWorkspaceNotExists = errors.New("workspace not exists")
)

// Workspace workspace item
type Workspace struct {
ID int64 `json:"id"`
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
github.com/golang/protobuf v1.5.2
github.com/jhump/protoreflect v1.14.0
github.com/jmoiron/sqlx v1.3.5
github.com/mattn/go-sqlite3 v1.14.15
github.com/mitchellh/mapstructure v1.5.0
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.28.0
Expand All @@ -28,6 +27,7 @@ require (
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-sqlite3 v1.14.10 // indirect
github.com/sam-kamerer/go-plister v1.2.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
golang.org/x/sys v0.0.0-20220317061510-51cd9980dadf // indirect
Expand Down
3 changes: 1 addition & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -807,9 +807,8 @@ github.com/mattn/go-shellwords v1.0.6/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vq
github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=
github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mattn/go-sqlite3 v1.14.10 h1:MLn+5bFRlWMGoSRmJour3CL1w/qL96mvipqpwQW/Sfk=
github.com/mattn/go-sqlite3 v1.14.10/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mattn/go-sqlite3 v1.14.15 h1:vfoHhTN1af61xCRSWzFIWzx2YskyMTwHLrExkBOjvxI=
github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
github.com/maxbrunsfeld/counterfeiter/v6 v6.2.2/go.mod h1:eD9eIE7cdwcMi9rYluz88Jz2VyhSmden33/aXg4oVIY=
Expand Down
12 changes: 4 additions & 8 deletions resources/js/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function getRequestData(field, root, disableProtoFQN) {
}

switch (field.type) {
case protoTypeEnum: {
case protoTypeEnum:
let enumValues = [];
root.find('[data-field-fqn="' + field.fqn + '"]').each(function () {
enumValues.push($(this).find(":selected").val());
Expand All @@ -90,8 +90,7 @@ function getRequestData(field, root, disableProtoFQN) {
}
}
break;
}
case protoTypeBool: {
case protoTypeBool:
let boolValues = [];
root.find('[data-field-fqn="' + field.fqn + '"]').each(function () {
boolValues.push($(this).is(":checked"));
Expand All @@ -104,8 +103,7 @@ function getRequestData(field, root, disableProtoFQN) {
}
}
break;
}
case protoTypeMessage: {
case protoTypeMessage:
if (field.map !== undefined) {
// todo validate dup keys
if (field.map.fields === undefined) {
Expand Down Expand Up @@ -176,8 +174,7 @@ function getRequestData(field, root, disableProtoFQN) {
}
}
break;
}
default: {
default:
let textValues = [];
root.find('[data-field-fqn="' + field.fqn + '"]').each(function () {
textValues.push($(this).val());
Expand All @@ -189,7 +186,6 @@ function getRequestData(field, root, disableProtoFQN) {
data[field.fqn] = textValues;
}
}
}
}

return data;
Expand Down
12 changes: 4 additions & 8 deletions resources/js/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ function getFieldTemplate(field, attr, showOneOf) {
}

switch (field.type) {
case protoTypeEnum: {
case protoTypeEnum:
if (!field.repeated) {
tmpl = $(template["request-select-input"]);
$(tmpl.find(".label-name")[0]).html(field.name);
Expand All @@ -288,8 +288,7 @@ function getFieldTemplate(field, attr, showOneOf) {
);
}
break;
}
case protoTypeBool: {
case protoTypeBool:
if (!field.repeated) {
tmpl = $(template["request-bool-input"]);
$(tmpl.find(".label-name")[0]).attr("for", field.fqn).html(field.name);
Expand All @@ -304,8 +303,7 @@ function getFieldTemplate(field, attr, showOneOf) {
);
}
break;
}
case protoTypeMessage: {
case protoTypeMessage:
let fieldType = field.type;
if (field.map !== undefined) {
fieldType =
Expand Down Expand Up @@ -412,8 +410,7 @@ function getFieldTemplate(field, attr, showOneOf) {
currentInputCount++;
});
break;
}
default: {
default:
if (!field.repeated) {
tmpl = $(template["request-text-input"]);
$(tmpl.find(".label-name")[0]).html(field.name);
Expand All @@ -427,7 +424,6 @@ function getFieldTemplate(field, attr, showOneOf) {
currentInputCount
);
}
}
}

let fv = $(tmpl.find(".field-value")[0]);
Expand Down

0 comments on commit a8ba3c9

Please sign in to comment.