fix: UpdateEvent now saves the event name, not just currency/rate
This commit is contained in:
parent
47fb82d109
commit
e9460a6a7d
2 changed files with 10 additions and 5 deletions
|
|
@ -528,9 +528,9 @@ func DeleteEvent(db *sql.DB, id string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateEvent updates the base currency and exchange rate of an existing event.
|
// UpdateEvent updates the name, base currency and exchange rate of an existing event.
|
||||||
func UpdateEvent(db *sql.DB, id, baseCurrency string, exchangeRate float64) error {
|
func UpdateEvent(db *sql.DB, id, name, baseCurrency string, exchangeRate float64) error {
|
||||||
_, err := db.Exec("UPDATE events SET base_currency = ?, exchange_rate = ? WHERE id = ?", baseCurrency, exchangeRate, id)
|
_, err := db.Exec("UPDATE events SET name = ?, base_currency = ?, exchange_rate = ? WHERE id = ?", name, baseCurrency, exchangeRate, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("ERROR [%s] database: UpdateEvent(%s): %v",
|
log.Printf("ERROR [%s] database: UpdateEvent(%s): %v",
|
||||||
time.Now().Format(time.RFC3339), id, err)
|
time.Now().Format(time.RFC3339), id, err)
|
||||||
|
|
|
||||||
|
|
@ -331,7 +331,7 @@ func (h *EventHandler) EditEvent(w http.ResponseWriter, r *http.Request) {
|
||||||
// PUT /months/{mid}/events/{eid} — UpdateEvent
|
// PUT /months/{mid}/events/{eid} — UpdateEvent
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
// UpdateEvent updates the event's base currency and exchange rate.
|
// UpdateEvent updates the event's name, base currency and exchange rate.
|
||||||
func (h *EventHandler) UpdateEvent(w http.ResponseWriter, r *http.Request) {
|
func (h *EventHandler) UpdateEvent(w http.ResponseWriter, r *http.Request) {
|
||||||
monthID := chi.URLParam(r, "mid")
|
monthID := chi.URLParam(r, "mid")
|
||||||
eventID := chi.URLParam(r, "eid")
|
eventID := chi.URLParam(r, "eid")
|
||||||
|
|
@ -342,6 +342,11 @@ func (h *EventHandler) UpdateEvent(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
name := r.FormValue("name")
|
||||||
|
if name == "" {
|
||||||
|
name = event.Name
|
||||||
|
}
|
||||||
|
|
||||||
baseCurrency := r.FormValue("base_currency")
|
baseCurrency := r.FormValue("base_currency")
|
||||||
if baseCurrency == "" {
|
if baseCurrency == "" {
|
||||||
baseCurrency = "USD"
|
baseCurrency = "USD"
|
||||||
|
|
@ -358,7 +363,7 @@ func (h *EventHandler) UpdateEvent(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := database.UpdateEvent(h.DB, eventID, baseCurrency, exchangeRate); err != nil {
|
if err := database.UpdateEvent(h.DB, eventID, name, baseCurrency, exchangeRate); err != nil {
|
||||||
log.Printf("ERROR [%s] handlers: UpdateEvent: %v", time.Now().Format(time.RFC3339), err)
|
log.Printf("ERROR [%s] handlers: UpdateEvent: %v", time.Now().Format(time.RFC3339), err)
|
||||||
http.Error(w, "Failed to update event", http.StatusInternalServerError)
|
http.Error(w, "Failed to update event", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue