diff --git a/create_tables.sql b/create_tables.sql index f9bed8a..fa18c9e 100644 --- a/create_tables.sql +++ b/create_tables.sql @@ -18,10 +18,9 @@ CREATE TABLE instructors ( CREATE TABLE briefings ( id INT AUTO_INCREMENT, - date DATE NOT NULL, - time TIME NOT NULL, + datetime DATETIME NOT NULL, location VARCHAR(32) NOT NULL, - document_name VARCHAR(16) NOT NULL, + document VARCHAR(16) NOT NULL, as_of DATE NOT NULL, instructor_id INT NOT NULL, @@ -65,22 +64,22 @@ CREATE TABLE given_answers ( INSERT INTO instructors (id, first_name, last_name) VALUES - ( '123456', 'Jason', 'Streifling' ), - ( '123457', 'Tim', 'Taler' ), - ( '123458', 'Georg', 'aus dem Jungel' ); - -INSERT INTO briefings ( - date, time, location, document_name, as_of, instructor_id -) VALUES - ( '2023-10-16', '17:00:00', 'Werk Langenhagen', 'ICS-2021-LGH', '2021-02-01', '123456' ), - ( '2023-10-16', '17:05:00', 'Werk Langenhagen', 'ICS-2021-LGH', '2021-02-01', '123457' ); - -INSERT INTO participants ( - first_name, last_name, company -) VALUES - ( 'Peter', 'Enis', 'Körber' ), - ( 'Dürüm', 'Döner', 'MP Technic' ); + ( '100000', 'Jason', 'Streifling' ), + ( '100001', 'Peter', 'Enis' ); +--INSERT INTO briefings ( +-- datetime, location, document, as_of, instructor_id +--) VALUES +-- ( '2023-10-16 17:00:00', 'Werk Langenhagen', 'ICL-1901-LGH', '2021-02-01', '100000' ), +-- ( '2023-10-16 17:05:00', 'Werk Langenhagen', 'ICL-1901-LGH', '2021-02-01', '100001' ); +-- +--INSERT INTO participants ( +-- first_name, last_name, company +--) VALUES +-- ( 'Max', 'Mustermann', 'ABC GmbH' ), +-- ( 'Gustav', 'Gans', 'ABC GmbH' ), +-- ( 'Klara', 'Kakerlake', 'DEF KG' ); +-- INSERT INTO questions ( question, answer_1, answer_2, answer_3, answer_4, correct_answer ) VALUES @@ -88,15 +87,19 @@ INSERT INTO questions ( ( 'Was ist 1+2?', '1', '2', '3', '4', '3' ), ( 'Was ist 2+2?', '1', '2', '3', '4', '4' ), ( 'Was ist 0+1?', '1', '2', '3', '4', '1' ); - -INSERT INTO given_answers ( - briefing_id, participant_id, question_id, given_answer -) VALUES - ( '1', '1', '1', '2' ), - ( '1', '1', '2', '3' ), - ( '1', '1', '3', '3' ), - ( '1', '1', '4', '1' ), - ( '2', '2', '1', '2' ), - ( '2', '2', '2', '3' ), - ( '2', '2', '3', '4' ), - ( '2', '2', '4', '1' ); +-- +--INSERT INTO given_answers ( +-- briefing_id, participant_id, question_id, given_answer +--) VALUES +-- ( '1', '1', '1', '2' ), +-- ( '1', '1', '2', '3' ), +-- ( '1', '1', '3', '3' ), +-- ( '1', '1', '4', '1' ), +-- ( '1', '2', '1', '2' ), +-- ( '1', '2', '2', '3' ), +-- ( '1', '2', '3', '3' ), +-- ( '1', '2', '4', '1' ), +-- ( '2', '3', '1', '2' ), +-- ( '2', '3', '2', '3' ), +-- ( '2', '3', '3', '4' ), +-- ( '2', '3', '4', '1' ); diff --git a/packages/data/dataStructs.go b/packages/data/dataStructs.go index d4998c7..d2e7c4e 100644 --- a/packages/data/dataStructs.go +++ b/packages/data/dataStructs.go @@ -21,10 +21,9 @@ type Participant struct { type Briefing struct { ID int64 - Date string - Time string + DateTime string Location string - DocumentName string + Document string AsOf string InstructorID int64 } @@ -51,10 +50,9 @@ type GivenAnswer struct { type OverviewTableData struct { InstructorFirstName string InstructorLastName string - BriefingDate string - BriefingTime string + BriefingDateTime string BriefingLocation string - BriefingDocumentName string + BriefingDocument string BriefingAsOf string ParticipantFirstName string ParticipantLastName string diff --git a/packages/data/dbFuncs.go b/packages/data/dbFuncs.go index 5cf80cf..227e2b0 100644 --- a/packages/data/dbFuncs.go +++ b/packages/data/dbFuncs.go @@ -33,12 +33,12 @@ func OpenDB(dbName string) (*DB, error) { func (db *DB) WriteBriefing(b *Briefing) error { query := ` INSERT INTO briefings - (date, time, location, document_name, as_of, instructor_id) + (datetime, location, document, as_of, instructor_id) VALUES - (?, ?, ?, ?, ?, ?) + (?, ?, ?, ?, ?) ` - result, err := db.Exec(query, b.Date, b.Time, b.Location, b.DocumentName, b.AsOf, b.InstructorID) + result, err := db.Exec(query, b.DateTime, b.Location, b.Document, b.AsOf, b.InstructorID) if err != nil { return fmt.Errorf("error: *DB.writeBriefing: db.Exec(): %v", err) } @@ -95,10 +95,9 @@ func (db *DB) GetAllOverviewTableData() ([]OverviewTableData, error) { SELECT i.first_name, i.last_name, - b.date, - b.time, + b.datetime, b.location, - b.document_name, + b.document, b.as_of, p.first_name, p.last_name, @@ -132,10 +131,9 @@ func (db *DB) GetAllOverviewTableData() ([]OverviewTableData, error) { err := rows.Scan( &otd.InstructorFirstName, &otd.InstructorLastName, - &otd.BriefingDate, - &otd.BriefingTime, + &otd.BriefingDateTime, &otd.BriefingLocation, - &otd.BriefingDocumentName, + &otd.BriefingDocument, &otd.BriefingAsOf, &otd.ParticipantFirstName, &otd.ParticipantLastName, @@ -156,10 +154,9 @@ func (db *DB) GetOverviewTableDataByName(n string) ([]OverviewTableData, error) SELECT i.first_name, i.last_name, - b.date, - b.time, + b.datetime, b.location, - b.document_name, + b.document, b.as_of, p.first_name, p.last_name, @@ -199,10 +196,9 @@ func (db *DB) GetOverviewTableDataByName(n string) ([]OverviewTableData, error) err := rows.Scan( &otd.InstructorFirstName, &otd.InstructorLastName, - &otd.BriefingDate, - &otd.BriefingTime, + &otd.BriefingDateTime, &otd.BriefingLocation, - &otd.BriefingDocumentName, + &otd.BriefingDocument, &otd.BriefingAsOf, &otd.ParticipantFirstName, &otd.ParticipantLastName, @@ -281,8 +277,12 @@ func (db *DB) GetQuestions(nums []string) ([]Question, error) { questions := make([]Question, 0) for rows.Next() { q := Question{Answers: make([]Answer, 4)} + q.Answers[0].ID = 1 + q.Answers[1].ID = 2 + q.Answers[2].ID = 3 + q.Answers[3].ID = 4 - if err := rows.Scan(&q.ID, &q.Text, &q.Answers[0], &q.Answers[1], &q.Answers[2], &q.Answers[3], &q.Correct); err != nil { + if err := rows.Scan(&q.ID, &q.Text, &q.Answers[0].Text, &q.Answers[1].Text, &q.Answers[2].Text, &q.Answers[3].Text, &q.Correct); err != nil { return nil, fmt.Errorf("error: *DB.GetQuestions: rows.Scan(): %v", err) } diff --git a/packages/session/handlerFuncs.go b/packages/session/handlerFuncs.go index aac90a9..dcbf38a 100644 --- a/packages/session/handlerFuncs.go +++ b/packages/session/handlerFuncs.go @@ -92,12 +92,9 @@ func (s *Session) HandleNewParticipant(cp chan<- *BriefingParticipant) http.Hand func (s *Session) HandleBriefingForm(db *data.DB) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - now := time.Now() - - s.Date = now.Format("2006-01-02") - s.Time = now.Format("15:04:05") + s.DateTime = time.Now().Format("2006-01-02 15:04:05") s.Location = r.PostFormValue("location") - s.DocumentName = r.PostFormValue("document") + s.Document = r.PostFormValue("document") s.AsOf = r.PostFormValue("as-of") err := db.WriteBriefing(s.Briefing) diff --git a/packages/session/helperFuncs.go b/packages/session/helperFuncs.go index ba937b4..081390d 100644 --- a/packages/session/helperFuncs.go +++ b/packages/session/helperFuncs.go @@ -60,6 +60,8 @@ func makeHTMLQuestions(sq []data.Question, givenAnswers []int) []resultQuestion questions[i].Answers = make([]resultAnswer, len(q.Answers)) for j := range q.Answers { + questions[i].Answers[j].Text = q.Answers[j].Text + if j+1 == q.Correct { questions[i].Answers[j].Correct = true } else { diff --git a/templates/summary.html b/templates/summary.html index 3e9f83d..25233c1 100644 --- a/templates/summary.html +++ b/templates/summary.html @@ -4,7 +4,7 @@ {{end}} {{define "retry"}} - + {{end}} {{define "participant"}} @@ -18,6 +18,7 @@ {{if lt .NoIncorrect 0}} {{template "refresh" .}} {{else if gt .NoIncorrect 0}} +

{{.NoIncorrect}} Fehler

{{template "retry" .}} {{template "refresh" .}} {{else}} diff --git a/templates/table.html b/templates/table.html index 173d179..bb38a73 100644 --- a/templates/table.html +++ b/templates/table.html @@ -3,10 +3,9 @@ {{.InstructorFirstName}} {{.InstructorLastName}} - {{.BriefingDate}} - {{.BriefingTime}} + {{.BriefingDateTime}} {{.BriefingLocation}} - {{.BriefingDocumentName}} + {{.BriefingDocument}} {{.BriefingAsOf}} {{.ParticipantFirstName}} {{.ParticipantLastName}} @@ -32,8 +31,7 @@ Unterweiser - Datum - Uhrzeit + Datum & Uhrzeit Ort Dokument Stand