// GET admin get driver func AdminDriverGetOne(w http.ResponseWriter, r *http.Request, c *web.Context) { if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") { return } msgK, msgV := c.GetFlash() driver := service.FindOneDriver(c.GetPathVar("id")) ts.Render(w, "admin-driver-form.tmpl", tmpl.Model{ msgK: msgV, "driver": driver, "drivers": service.FindAllDriver(), "companies": service.CompanyNames(), "user": service.FindOneUser(driver.UserId), }) return }
// POST edit employee func AdminEmployeeEdit(w http.ResponseWriter, r *http.Request, c *web.Context) { if !c.CheckAuth(w, r, "/login", "admin", "developer") { return } if !service.CanUpdate(r.FormValue("userId"), r.FormValue("email")) { c.SetFlash("alertError", "Email already registered") http.Redirect(w, r, "/admin/employee/"+r.FormValue("id"), 303) return } r.ParseForm() employee := service.FindOneEmployee(r.FormValue("id")) util.FormToStruct(&employee, r.Form, "") user := service.FindOneUser(employee.UserId) util.FormToStruct(&user, r.Form, "") user.Id = employee.UserId service.SaveEmployee(employee) service.SaveUser(user) c.SetFlash("alertSuccess", "Successfully saved employee") http.Redirect(w, r, "/admin/employee", 303) return }
// POST admin save driver func AdminDriverSave(w http.ResponseWriter, r *http.Request, c *web.Context) { if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") { return } if !service.CanUpdate(r.FormValue("userId"), r.FormValue("email")) { c.SetFlash("alertError", "Email already registered") http.Redirect(w, r, "/admin/driver/"+c.GetPathVar("id"), 303) return } r.ParseForm() driver := service.FindOneDriver(r.FormValue("id")) util.FormToStruct(&driver, r.Form, "") user := service.FindOneUser(driver.UserId) util.FormToStruct(&user, r.Form, "") user.Id = driver.UserId service.SaveDriver(driver) service.SaveUser(user) c.SetFlash("alertSuccess", "Successfully saved driver") http.Redirect(w, r, "/admin/driver", 303) return }