diff --git a/src/assets/htmx/category.html b/src/assets/htmx/category.html index f551539..789aa26 100644 --- a/src/assets/htmx/category.html +++ b/src/assets/htmx/category.html @@ -5,7 +5,13 @@ CATEGORY FORM

-
+
+ {{ if eq .method "put" }} + + + {{ end }} + diff --git a/src/assets/htmx/terminal.html b/src/assets/htmx/terminal.html index 72cd98c..dcaf3b2 100644 --- a/src/assets/htmx/terminal.html +++ b/src/assets/htmx/terminal.html @@ -61,8 +61,6 @@ {{ template "categories" . }} {{ else if eq .content "category" }} {{ template "category" . }} - {{ else if eq .content "category" }} - {{ template "category" . }} {{ else if eq .content "overview" }} {{ template "overview" . }} {{ else if eq .content "stores" }} @@ -73,8 +71,8 @@ {{ template "storeNew" . }} {{ else if eq .content "types" }} {{ template "types" . }} - {{ else if eq .content "typeNew" }} - {{ template "typeNew" . }} + {{ else if eq .content "type" }} + {{ template "type" . }} {{ else }}
Unknown page
{{ end }} diff --git a/src/assets/htmx/type.html b/src/assets/htmx/type.html index 584a213..0ddb4e8 100644 --- a/src/assets/htmx/type.html +++ b/src/assets/htmx/type.html @@ -6,32 +6,40 @@

-

- - -

-
+ {{ if eq .method "put" }} + + + {{ end }} + + + -

- - -

-
- - - -
+ +
+ + {{ if eq .method "put" }} + + {{ end }}
+{{ template "deleteModal" }} {{ end }} diff --git a/src/assets/htmx/typeNew.html b/src/assets/htmx/typeNew.html deleted file mode 100644 index 7517c09..0000000 --- a/src/assets/htmx/typeNew.html +++ /dev/null @@ -1,23 +0,0 @@ -{{ define "typeNew" }} -
-
-
- TYPE FORM -
-

- - -

- - -
-
-
-
-
-{{ end }} diff --git a/src/expenses/types.go b/src/expenses/types.go index 9f1381e..b1fd6fe 100644 --- a/src/expenses/types.go +++ b/src/expenses/types.go @@ -4,7 +4,6 @@ import ( "database/sql" "fmt" "log" - "strconv" _ "github.com/mattn/go-sqlite3" ) @@ -58,12 +57,12 @@ func GetType(typID int) (Type, error) { query := "SELECT TypeID,TypeName " + "FROM expenseTypes " + - "WHERE TypeID = " + strconv.Itoa(typID) + "WHERE TypeID = ?" - var nType Type - err = db.QueryRow(query).Scan(&nType.TypeID, &nType.TypeName) + nType := Type{TypeID: -1} + err = db.QueryRow(query, typID).Scan(&nType.TypeID, &nType.TypeName) if err != nil { - return Type{}, nil + return Type{TypeID: -1}, nil } return nType, nil diff --git a/src/pages/types.go b/src/pages/types.go index 5875039..d44f3c1 100644 --- a/src/pages/types.go +++ b/src/pages/types.go @@ -39,6 +39,11 @@ func typePage(c *gin.Context) { typ, err := expenses.GetType(typeID) if err != nil { ServerErrorView(c, "failed to retrieve requested type") + return + } + if typ.TypeID == -1 { + NotFoundView(c, fmt.Sprintf("Couldn't find type `%d`", typeID)) + return } c.HTML(http.StatusOK, "terminal", gin.H{ @@ -46,6 +51,7 @@ func typePage(c *gin.Context) { "renderNavBar": false, "content": "type", "type": typ, + "method": "put", }) } @@ -53,7 +59,8 @@ func newTypePage(c *gin.Context) { c.HTML(http.StatusOK, "terminal", gin.H{ "page": "typeNew", "renderNavBar": false, - "content": "typeNew", + "content": "type", + "method": "post", }) }