|
|
|
@ -324,7 +324,7 @@ func (app *application) newMotionForm(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
app.render(w, http.StatusOK, "create_motion.html", data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (app *application) newMotionSubmit(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
func (form *NewMotionForm) Validate() {
|
|
|
|
|
const (
|
|
|
|
|
minimumTitleLength = 3
|
|
|
|
|
maximumTitleLength = 200
|
|
|
|
@ -335,28 +335,8 @@ func (app *application) newMotionSubmit(w http.ResponseWriter, r *http.Request)
|
|
|
|
|
oneWeek = 7
|
|
|
|
|
twoWeeks = 14
|
|
|
|
|
threeWeeks = 28
|
|
|
|
|
|
|
|
|
|
hoursInDay = 24
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
err := r.ParseForm()
|
|
|
|
|
if err != nil {
|
|
|
|
|
app.clientError(w, http.StatusBadRequest)
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var form NewMotionForm
|
|
|
|
|
|
|
|
|
|
err = app.formDecoder.Decode(&form, r.PostForm)
|
|
|
|
|
if err != nil {
|
|
|
|
|
app.errorLog.Printf("form decoding failed: %v", err)
|
|
|
|
|
|
|
|
|
|
app.clientError(w, http.StatusBadRequest)
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
form.CheckField(
|
|
|
|
|
validator.NotBlank(form.Title),
|
|
|
|
|
"title",
|
|
|
|
@ -391,6 +371,21 @@ func (app *application) newMotionSubmit(w http.ResponseWriter, r *http.Request)
|
|
|
|
|
form.CheckField(validator.PermittedInt(
|
|
|
|
|
form.Due, threeDays, oneWeek, twoWeeks, threeWeeks), "due", "invalid duration choice",
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (app *application) newMotionSubmit(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
const hoursInDay = 24
|
|
|
|
|
|
|
|
|
|
var form NewMotionForm
|
|
|
|
|
|
|
|
|
|
err := app.decodePostForm(r, &form)
|
|
|
|
|
if err != nil {
|
|
|
|
|
app.clientError(w, http.StatusBadRequest)
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
form.Validate()
|
|
|
|
|
|
|
|
|
|
if !form.Valid() {
|
|
|
|
|
form.User = &models.User{}
|
|
|
|
@ -441,7 +436,7 @@ func (app *application) newMotionSubmit(w http.ResponseWriter, r *http.Request)
|
|
|
|
|
|
|
|
|
|
// TODO: add flash message for new motion
|
|
|
|
|
|
|
|
|
|
http.Redirect(w, r, fmt.Sprintf("/motions/%s", decision.Tag), http.StatusFound)
|
|
|
|
|
http.Redirect(w, r, fmt.Sprintf("/motions/%s", decision.Tag), http.StatusSeeOther)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (app *application) editMotionForm(_ http.ResponseWriter, _ *http.Request) {
|
|
|
|
|