diff --git a/packages/server/server.go b/packages/server/server.go index 4adc585..e526e9a 100644 --- a/packages/server/server.go +++ b/packages/server/server.go @@ -9,6 +9,7 @@ import ( "net/http" "strconv" "strings" + "time" "streifling.com/jason/sicherheitsunterweisung/packages/data" "streifling.com/jason/sicherheitsunterweisung/packages/types" @@ -57,7 +58,7 @@ func generateUUID() (string, error) { return hex.EncodeToString(bs), nil } -func AddParticipant(i *int64, ls *[]string) http.HandlerFunc { +func AddParticipant(i *int64, sl *[]string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { uuid, err := generateUUID() if err != nil { @@ -66,41 +67,29 @@ func AddParticipant(i *int64, ls *[]string) http.HandlerFunc { *i++ login := fmt.Sprintf("%d", *i) + "-" + uuid - (*ls) = append(*ls, login) + (*sl) = append(*sl, login) template.Must(template.ParseFiles("templates/briefing.html")).ExecuteTemplate(w, "new", login) } } -func SubmitForm(db *data.DB, i, j *int64) http.HandlerFunc { +// TODO: Hier weiter machen, irgendwie die b.ID herausgeben, +// am besten hier auch die p.IDs rausgeben, damit diese später verknüpft werden können +func SubmitBriefingForm(sb *[]types.Briefing) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - b := new(types.Briefing) + now := time.Now() + briefing := new(types.Briefing) - b.FirstName = r.PostFormValue("instructor-first") - b.LastName = r.PostFormValue("instructor-last") - b.Date = r.PostFormValue("date") - b.Time = r.PostFormValue("time") - b.State = r.PostFormValue("state") - b.Location = r.PostFormValue("location") + // TODO: Dropdownmenü + // instructorFirstName := r.PostFormValue("instructor-first") + // instructorLastName := r.PostFormValue("instructor-last") - for ; *j <= *i; *j++ { - b.Participants = append(b.Participants, &types.Participant{ - ID: *j, - Person: types.Person{ - FirstName: r.PostFormValue("participant-first-" + fmt.Sprint(*j)), - LastName: r.PostFormValue(("participant-last-" + fmt.Sprint(*j))), - }, - Company: r.PostFormValue(("participant-company-" + fmt.Sprint(*j))), - }) - } - - log.Println(b) - db.WriteBriefing(b) - bs, err := db.GetAllOverviewTableData() - if err != nil { - _ = fmt.Errorf("SubmitForm: db.GetAllOverviewTableData(): %v\n", err) - } - - template.Must(template.ParseFiles("templates/table.html")).Execute(w, bs) + briefing.Date = now.Format("2006-01-02") + briefing.Time = now.Format("15:04:05") + briefing.Location = r.PostFormValue("location") + briefing.DocumentName = r.PostFormValue("document") // TODO: in HTML einfügen + briefing.AsOf = r.PostFormValue("state") // TODO: Umbenennen + // briefing.InstructorID = r.PostFormValue("instructor-id") // TODO: aus Dropdown holen + (*sb) = append(*sb, *briefing) } }