Compare commits

..

No commits in common. "49c41681cedee25a7730ff91ad96c870bcc66d37" and "251080cbe556d46638b2ada505bd1277fa368f42" have entirely different histories.

3 changed files with 1 additions and 34 deletions

View File

@ -237,32 +237,3 @@ func HandleAddExpense(w http.ResponseWriter, r *http.Request, _ httprouter.Param
conn.MustExec(r.Context(), "select add_expense($1, $2, $3, $4, $5, $6, $7)", company.Id, form.InvoiceDate, form.Invoicer, form.InvoiceNumber, form.Amount, taxes, form.Tags) conn.MustExec(r.Context(), "select add_expense($1, $2, $3, $4, $5, $6, $7)", company.Id, form.InvoiceDate, form.Invoicer, form.InvoiceNumber, form.Amount, taxes, form.Tags)
htmxRedirect(w, r, companyURI(company, "/expenses")) htmxRedirect(w, r, companyURI(company, "/expenses"))
} }
func HandleUpdateExpense(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
conn := getConn(r)
locale := getLocale(r)
company := mustGetCompany(r)
form := newExpenseForm(r.Context(), conn, locale, company)
if err := form.Parse(r); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
if err := verifyCsrfTokenValid(r); err != nil {
http.Error(w, err.Error(), http.StatusForbidden)
return
}
slug := params[0].Value
if !form.Validate() {
if !IsHTMxRequest(r) {
w.WriteHeader(http.StatusUnprocessableEntity)
}
mustRenderEditExpenseForm(w, r, slug, form)
return
}
taxes := mustSliceAtoi(form.Tax.Selected)
if found := conn.MustGetText(r.Context(), "", "select edit_expense($1, $2, $3, $4, $5, $6, $7)", slug, form.InvoiceDate, form.Invoicer, form.InvoiceNumber, form.Amount, taxes, form.Tags); found == "" {
http.NotFound(w, r)
return
}
htmxRedirect(w, r, companyURI(company, "/expenses"))
}

View File

@ -137,16 +137,13 @@ func HandleUpdateProduct(w http.ResponseWriter, r *http.Request, params httprout
} }
slug := params[0].Value slug := params[0].Value
if !form.Validate() { if !form.Validate() {
if !IsHTMxRequest(r) { w.WriteHeader(http.StatusUnprocessableEntity)
w.WriteHeader(http.StatusUnprocessableEntity)
}
mustRenderEditProductForm(w, r, slug, form) mustRenderEditProductForm(w, r, slug, form)
return return
} }
taxes := mustSliceAtoi(form.Tax.Selected) taxes := mustSliceAtoi(form.Tax.Selected)
if ok := conn.MustGetBool(r.Context(), "select edit_product($1, $2, $3, $4, $5, $6)", slug, form.Name, form.Description, form.Price, taxes, form.Tags); !ok { if ok := conn.MustGetBool(r.Context(), "select edit_product($1, $2, $3, $4, $5, $6)", slug, form.Name, form.Description, form.Price, taxes, form.Tags); !ok {
http.NotFound(w, r) http.NotFound(w, r)
return
} }
htmxRedirect(w, r, companyURI(company, "/products")) htmxRedirect(w, r, companyURI(company, "/products"))
} }

View File

@ -37,7 +37,6 @@ func NewRouter(db *Db) http.Handler {
companyRouter.GET("/expenses", IndexExpenses) companyRouter.GET("/expenses", IndexExpenses)
companyRouter.POST("/expenses", HandleAddExpense) companyRouter.POST("/expenses", HandleAddExpense)
companyRouter.GET("/expenses/:slug", ServeExpenseForm) companyRouter.GET("/expenses/:slug", ServeExpenseForm)
companyRouter.PUT("/expenses/:slug", HandleUpdateExpense)
companyRouter.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { companyRouter.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
mustRenderMainTemplate(w, r, "dashboard.gohtml", nil) mustRenderMainTemplate(w, r, "dashboard.gohtml", nil)
}) })