server.SubmitForm() zu server.SubmitBriefingForm() umbenannt und weitgehend an neues DB-Layout angepasst

This commit is contained in:
Jason Streifling 2023-10-18 16:22:39 +02:00
parent b42f739581
commit 3e9cfb49eb

View File

@ -9,6 +9,7 @@ import (
"net/http" "net/http"
"strconv" "strconv"
"strings" "strings"
"time"
"streifling.com/jason/sicherheitsunterweisung/packages/data" "streifling.com/jason/sicherheitsunterweisung/packages/data"
"streifling.com/jason/sicherheitsunterweisung/packages/types" "streifling.com/jason/sicherheitsunterweisung/packages/types"
@ -57,7 +58,7 @@ func generateUUID() (string, error) {
return hex.EncodeToString(bs), nil 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) { return func(w http.ResponseWriter, r *http.Request) {
uuid, err := generateUUID() uuid, err := generateUUID()
if err != nil { if err != nil {
@ -66,41 +67,29 @@ func AddParticipant(i *int64, ls *[]string) http.HandlerFunc {
*i++ *i++
login := fmt.Sprintf("%d", *i) + "-" + uuid 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) 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) { 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") // TODO: Dropdownmenü
b.LastName = r.PostFormValue("instructor-last") // instructorFirstName := r.PostFormValue("instructor-first")
b.Date = r.PostFormValue("date") // instructorLastName := r.PostFormValue("instructor-last")
b.Time = r.PostFormValue("time")
b.State = r.PostFormValue("state")
b.Location = r.PostFormValue("location")
for ; *j <= *i; *j++ { briefing.Date = now.Format("2006-01-02")
b.Participants = append(b.Participants, &types.Participant{ briefing.Time = now.Format("15:04:05")
ID: *j, briefing.Location = r.PostFormValue("location")
Person: types.Person{ briefing.DocumentName = r.PostFormValue("document") // TODO: in HTML einfügen
FirstName: r.PostFormValue("participant-first-" + fmt.Sprint(*j)), briefing.AsOf = r.PostFormValue("state") // TODO: Umbenennen
LastName: r.PostFormValue(("participant-last-" + fmt.Sprint(*j))), // briefing.InstructorID = r.PostFormValue("instructor-id") // TODO: aus Dropdown holen
}, (*sb) = append(*sb, *briefing)
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)
} }
} }