c
This commit is contained in:
1 parent
b6014c6ffc
commit
f7037a6780
6 files changed
+11
-5
No files matched your search
@@ -60,10 +60,10 @@ func (h *Handlers) CreateCar(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var car models.Car
|
||||
err = h.dbGet(r.Context(), &car, `
|
||||
INSERT INTO cars (id, user_id, rego, make, model, year, color, odometer, rego_expiry, wof_expiry, service_interval_km, service_interval_months)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
INSERT INTO cars (id, user_id, rego, name, make, model, year, color, odometer, rego_expiry, wof_expiry, service_interval_km, service_interval_months)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
RETURNING *
|
||||
`, uuid.New().String(), userID, in.Rego, in.Make, in.Model, in.Year, in.Color, in.Odometer, regoExpiry, wofExpiry, in.ServiceIntervalKM, in.ServiceIntervalMonths)
|
||||
`, uuid.New().String(), userID, in.Rego, in.Name, in.Make, in.Model, in.Year, in.Color, in.Odometer, regoExpiry, wofExpiry, in.ServiceIntervalKM, in.ServiceIntervalMonths)
|
||||
if err != nil {
|
||||
if isUniqueConstraintErr(err) {
|
||||
writeError(w, http.StatusConflict, "could not create car (rego may already exist in your garage)")
|
||||
@@ -117,12 +117,12 @@ func (h *Handlers) UpdateCar(w http.ResponseWriter, r *http.Request) {
|
||||
var updated models.Car
|
||||
err = h.dbGet(r.Context(), &updated, `
|
||||
UPDATE cars
|
||||
SET rego = ?, make = ?, model = ?, year = ?, color = ?,
|
||||
SET rego = ?, name = ?, make = ?, model = ?, year = ?, color = ?,
|
||||
odometer = ?, rego_expiry = ?, wof_expiry = ?,
|
||||
service_interval_km = ?, service_interval_months = ?, updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = ?
|
||||
RETURNING *
|
||||
`, in.Rego, in.Make, in.Model, in.Year, in.Color, in.Odometer, regoExpiry, wofExpiry,
|
||||
`, in.Rego, in.Name, in.Make, in.Model, in.Year, in.Color, in.Odometer, regoExpiry, wofExpiry,
|
||||
in.ServiceIntervalKM, in.ServiceIntervalMonths, car.ID)
|
||||
if err != nil {
|
||||
if isUniqueConstraintErr(err) {
|
||||
|
||||
Reference in new issue
Block a user