Skip to content

Commit a8ba3c9

Browse files
committed
fix database errors
1 parent 7443db8 commit a8ba3c9

File tree

9 files changed

+39
-68
lines changed

9 files changed

+39
-68
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88
<img src="https://img.shields.io/github/go-mod/go-version/forest33/warthog?style=flat-square"/>
99
</p>
1010

11-
1211
## Features
1312

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

4847
### MacOS
4948

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

5252
### Windows
5353

adapter/database/gui.config.go

+9-24
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ import (
88

99
"github.com/forest33/warthog/business/entity"
1010
"github.com/forest33/warthog/pkg/database"
11-
"github.com/forest33/warthog/pkg/database/types"
1211
)
1312

1413
const (
1514
guiConfigTable = "gui_config"
16-
guiConfigTableFields = "window_width, window_height, window_x, window_y, created_at, updated_at"
15+
guiConfigTableFields = "window_width, window_height, window_x, window_y"
1716
)
1817

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

3332
type guiConfigDTO struct {
34-
WindowWidth int `db:"window_width"`
35-
WindowHeight int `db:"window_height"`
36-
WindowX int `db:"window_x"`
37-
WindowY int `db:"window_y"`
38-
CreatedAt string `db:"created_at"`
39-
UpdatedAt string `db:"updated_at"`
33+
WindowWidth int `db:"window_width"`
34+
WindowHeight int `db:"window_height"`
35+
WindowX int `db:"window_x"`
36+
WindowY int `db:"window_y"`
4037
}
4138

42-
func (dto *guiConfigDTO) entity() (*entity.GUIConfig, error) {
43-
out := &entity.GUIConfig{
39+
func (dto *guiConfigDTO) entity() *entity.GUIConfig {
40+
return &entity.GUIConfig{
4441
WindowWidth: dto.WindowWidth,
4542
WindowHeight: dto.WindowHeight,
4643
WindowX: &dto.WindowX,
4744
WindowY: &dto.WindowY,
4845
}
49-
50-
var err error
51-
out.CreatedAt, err = types.StrToDateTime(dto.CreatedAt)
52-
if err != nil {
53-
return nil, err
54-
}
55-
out.UpdatedAt, err = types.StrToDateTime(dto.UpdatedAt)
56-
if err != nil {
57-
return nil, err
58-
}
59-
60-
return out, nil
6146
}
6247

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

72-
return dto.entity()
57+
return dto.entity(), nil
7358
}
7459

7560
// Update updates GUIConfig
@@ -108,5 +93,5 @@ func (repo *GUIConfigRepository) Update(in *entity.GUIConfig) (*entity.GUIConfig
10893
return nil, err
10994
}
11095

111-
return dto.entity()
96+
return dto.entity(), nil
11297
}

adapter/database/workspace.go

+11-21
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919

2020
const (
2121
workspaceTable = "workspace"
22-
workspaceTableFields = "id, parent_id, has_child, type, title, data, sort, expanded, created_at, updated_at"
22+
workspaceTableFields = "id, parent_id, has_child, type, title, data, sort, expanded"
2323
)
2424

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

3939
type workspaceDTO struct {
40-
ID int64 `db:"id"`
41-
ParentID sql.NullInt64 `db:"parent_id"`
42-
HasChild bool `db:"has_child"`
43-
Type string `db:"type"`
44-
Title string `db:"title"`
45-
Data sql.NullString `db:"data"`
46-
Sort int64 `db:"sort"`
47-
Expanded bool `db:"expanded"`
48-
CreatedAt string `db:"created_at"`
49-
UpdatedAt string `db:"updated_at"`
40+
ID int64 `db:"id"`
41+
ParentID sql.NullInt64 `db:"parent_id"`
42+
HasChild bool `db:"has_child"`
43+
Type string `db:"type"`
44+
Title string `db:"title"`
45+
Data sql.NullString `db:"data"`
46+
Sort int64 `db:"sort"`
47+
Expanded bool `db:"expanded"`
5048
}
5149

5250
func newWorkspaceDTO(in *entity.Workspace) (dto *workspaceDTO, err error) {
@@ -77,7 +75,6 @@ func (dto *workspaceDTO) entity() (*entity.Workspace, error) {
7775
Expanded: &dto.Expanded,
7876
}
7977

80-
var err error
8178
if dto.Data.Valid {
8279
switch out.Type {
8380
case entity.WorkspaceTypeFolder:
@@ -93,14 +90,6 @@ func (dto *workspaceDTO) entity() (*entity.Workspace, error) {
9390
return nil, err
9491
}
9592
}
96-
out.CreatedAt, err = types.StrToDateTime(dto.CreatedAt)
97-
if err != nil {
98-
return nil, err
99-
}
100-
out.UpdatedAt, err = types.StrToDateTime(dto.UpdatedAt)
101-
if err != nil {
102-
return nil, err
103-
}
10493

10594
return out, nil
10695
}
@@ -124,9 +113,10 @@ func (repo *WorkspaceRepository) GetByID(id int64) (*entity.Workspace, error) {
124113
if err != nil {
125114
return nil, err
126115
}
116+
return dto.entity()
127117
}
128118

129-
return dto.entity()
119+
return nil, entity.ErrWorkspaceNotExists
130120
}
131121

132122
// GetByParentID returns workspace item by parent id

bin/version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.3.2
1+
0.3.8

business/entity/workspace.go

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ const (
1717
WorkspaceTypeQuery WorkspaceType = "r"
1818
)
1919

20+
var (
21+
// ErrWorkspaceNotExists error workspace not exists
22+
ErrWorkspaceNotExists = errors.New("workspace not exists")
23+
)
24+
2025
// Workspace workspace item
2126
type Workspace struct {
2227
ID int64 `json:"id"`

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ require (
1010
github.com/golang/protobuf v1.5.2
1111
github.com/jhump/protoreflect v1.14.0
1212
github.com/jmoiron/sqlx v1.3.5
13-
github.com/mattn/go-sqlite3 v1.14.15
1413
github.com/mitchellh/mapstructure v1.5.0
1514
github.com/pkg/errors v0.9.1
1615
github.com/rs/zerolog v1.28.0
@@ -28,6 +27,7 @@ require (
2827
github.com/hashicorp/go-multierror v1.1.1 // indirect
2928
github.com/mattn/go-colorable v0.1.12 // indirect
3029
github.com/mattn/go-isatty v0.0.14 // indirect
30+
github.com/mattn/go-sqlite3 v1.14.10 // indirect
3131
github.com/sam-kamerer/go-plister v1.2.0 // indirect
3232
go.uber.org/atomic v1.7.0 // indirect
3333
golang.org/x/sys v0.0.0-20220317061510-51cd9980dadf // indirect

go.sum

+1-2
Original file line numberDiff line numberDiff line change
@@ -807,9 +807,8 @@ github.com/mattn/go-shellwords v1.0.6/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vq
807807
github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=
808808
github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
809809
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
810+
github.com/mattn/go-sqlite3 v1.14.10 h1:MLn+5bFRlWMGoSRmJour3CL1w/qL96mvipqpwQW/Sfk=
810811
github.com/mattn/go-sqlite3 v1.14.10/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
811-
github.com/mattn/go-sqlite3 v1.14.15 h1:vfoHhTN1af61xCRSWzFIWzx2YskyMTwHLrExkBOjvxI=
812-
github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
813812
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
814813
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
815814
github.com/maxbrunsfeld/counterfeiter/v6 v6.2.2/go.mod h1:eD9eIE7cdwcMi9rYluz88Jz2VyhSmden33/aXg4oVIY=

resources/js/request.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function getRequestData(field, root, disableProtoFQN) {
7777
}
7878

7979
switch (field.type) {
80-
case protoTypeEnum: {
80+
case protoTypeEnum:
8181
let enumValues = [];
8282
root.find('[data-field-fqn="' + field.fqn + '"]').each(function () {
8383
enumValues.push($(this).find(":selected").val());
@@ -90,8 +90,7 @@ function getRequestData(field, root, disableProtoFQN) {
9090
}
9191
}
9292
break;
93-
}
94-
case protoTypeBool: {
93+
case protoTypeBool:
9594
let boolValues = [];
9695
root.find('[data-field-fqn="' + field.fqn + '"]').each(function () {
9796
boolValues.push($(this).is(":checked"));
@@ -104,8 +103,7 @@ function getRequestData(field, root, disableProtoFQN) {
104103
}
105104
}
106105
break;
107-
}
108-
case protoTypeMessage: {
106+
case protoTypeMessage:
109107
if (field.map !== undefined) {
110108
// todo validate dup keys
111109
if (field.map.fields === undefined) {
@@ -176,8 +174,7 @@ function getRequestData(field, root, disableProtoFQN) {
176174
}
177175
}
178176
break;
179-
}
180-
default: {
177+
default:
181178
let textValues = [];
182179
root.find('[data-field-fqn="' + field.fqn + '"]').each(function () {
183180
textValues.push($(this).val());
@@ -189,7 +186,6 @@ function getRequestData(field, root, disableProtoFQN) {
189186
data[field.fqn] = textValues;
190187
}
191188
}
192-
}
193189
}
194190

195191
return data;

resources/js/server.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ function getFieldTemplate(field, attr, showOneOf) {
263263
}
264264

265265
switch (field.type) {
266-
case protoTypeEnum: {
266+
case protoTypeEnum:
267267
if (!field.repeated) {
268268
tmpl = $(template["request-select-input"]);
269269
$(tmpl.find(".label-name")[0]).html(field.name);
@@ -288,8 +288,7 @@ function getFieldTemplate(field, attr, showOneOf) {
288288
);
289289
}
290290
break;
291-
}
292-
case protoTypeBool: {
291+
case protoTypeBool:
293292
if (!field.repeated) {
294293
tmpl = $(template["request-bool-input"]);
295294
$(tmpl.find(".label-name")[0]).attr("for", field.fqn).html(field.name);
@@ -304,8 +303,7 @@ function getFieldTemplate(field, attr, showOneOf) {
304303
);
305304
}
306305
break;
307-
}
308-
case protoTypeMessage: {
306+
case protoTypeMessage:
309307
let fieldType = field.type;
310308
if (field.map !== undefined) {
311309
fieldType =
@@ -412,8 +410,7 @@ function getFieldTemplate(field, attr, showOneOf) {
412410
currentInputCount++;
413411
});
414412
break;
415-
}
416-
default: {
413+
default:
417414
if (!field.repeated) {
418415
tmpl = $(template["request-text-input"]);
419416
$(tmpl.find(".label-name")[0]).html(field.name);
@@ -427,7 +424,6 @@ function getFieldTemplate(field, attr, showOneOf) {
427424
currentInputCount
428425
);
429426
}
430-
}
431427
}
432428

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

0 commit comments

Comments
 (0)