mirror of
https://github.com/hay-kot/homebox.git
synced 2025-07-18 00:20:29 +00:00
fix: inaccruate 401 & sql busy error (#679)
* fix inaccruate 401 error on SQL db error
* init golangci-lint config
* linter autofix
* testify auto fixes
* fix sqlite busy errors
* fix naming
* more linter errors
* fix rest of linter issues
Former-commit-id: e8449b3a73
This commit is contained in:
parent
5e83b28ff5
commit
03df23d97c
62 changed files with 389 additions and 292 deletions
|
@ -21,12 +21,12 @@ type LocationRepository struct {
|
|||
type (
|
||||
LocationCreate struct {
|
||||
Name string `json:"name"`
|
||||
ParentID uuid.UUID `json:"parentId" extensions:"x-nullable"`
|
||||
ParentID uuid.UUID `json:"parentId" extensions:"x-nullable"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
LocationUpdate struct {
|
||||
ParentID uuid.UUID `json:"parentId" extensions:"x-nullable"`
|
||||
ParentID uuid.UUID `json:"parentId" extensions:"x-nullable"`
|
||||
ID uuid.UUID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
|
@ -99,7 +99,7 @@ type LocationQuery struct {
|
|||
FilterChildren bool `json:"filterChildren" schema:"filterChildren"`
|
||||
}
|
||||
|
||||
// GetALlWithCount returns all locations with item count field populated
|
||||
// GetAll returns all locations with item count field populated
|
||||
func (r *LocationRepository) GetAll(ctx context.Context, GID uuid.UUID, filter LocationQuery) ([]LocationOutCount, error) {
|
||||
query := `--sql
|
||||
SELECT
|
||||
|
@ -135,7 +135,7 @@ func (r *LocationRepository) GetAll(ctx context.Context, GID uuid.UUID, filter L
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
defer func() { _ = rows.Close() }()
|
||||
|
||||
list := []LocationOutCount{}
|
||||
for rows.Next() {
|
||||
|
@ -265,7 +265,7 @@ type LocationPath struct {
|
|||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func (lr *LocationRepository) PathForLoc(ctx context.Context, GID, locID uuid.UUID) ([]LocationPath, error) {
|
||||
func (r *LocationRepository) PathForLoc(ctx context.Context, GID, locID uuid.UUID) ([]LocationPath, error) {
|
||||
query := `WITH RECURSIVE location_path AS (
|
||||
SELECT id, name, location_children
|
||||
FROM locations
|
||||
|
@ -282,11 +282,11 @@ func (lr *LocationRepository) PathForLoc(ctx context.Context, GID, locID uuid.UU
|
|||
SELECT id, name
|
||||
FROM location_path`
|
||||
|
||||
rows, err := lr.db.Sql().QueryContext(ctx, query, locID, GID)
|
||||
rows, err := r.db.Sql().QueryContext(ctx, query, locID, GID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
defer func() { _ = rows.Close() }()
|
||||
|
||||
var locations []LocationPath
|
||||
|
||||
|
@ -311,7 +311,7 @@ func (lr *LocationRepository) PathForLoc(ctx context.Context, GID, locID uuid.UU
|
|||
return locations, nil
|
||||
}
|
||||
|
||||
func (lr *LocationRepository) Tree(ctx context.Context, GID uuid.UUID, tq TreeQuery) ([]TreeItem, error) {
|
||||
func (r *LocationRepository) Tree(ctx context.Context, GID uuid.UUID, tq TreeQuery) ([]TreeItem, error) {
|
||||
query := `
|
||||
WITH recursive location_tree(id, NAME, parent_id, level, node_type) AS
|
||||
(
|
||||
|
@ -393,11 +393,11 @@ func (lr *LocationRepository) Tree(ctx context.Context, GID uuid.UUID, tq TreeQu
|
|||
query = strings.ReplaceAll(query, "{{ WITH_ITEMS_FROM }}", "")
|
||||
}
|
||||
|
||||
rows, err := lr.db.Sql().QueryContext(ctx, query, GID)
|
||||
rows, err := r.db.Sql().QueryContext(ctx, query, GID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
defer func() { _ = rows.Close() }()
|
||||
|
||||
var locations []FlatTreeItem
|
||||
for rows.Next() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue