Aus Date und Time wurde DateTime gemacht und kleine Bugs behoben

This commit is contained in:
Jason Streifling 2023-11-01 13:11:50 +01:00
parent 224a99dec6
commit c0f392938c
7 changed files with 62 additions and 63 deletions

View File

@ -18,10 +18,9 @@ CREATE TABLE instructors (
CREATE TABLE briefings ( CREATE TABLE briefings (
id INT AUTO_INCREMENT, id INT AUTO_INCREMENT,
date DATE NOT NULL, datetime DATETIME NOT NULL,
time TIME NOT NULL,
location VARCHAR(32) NOT NULL, location VARCHAR(32) NOT NULL,
document_name VARCHAR(16) NOT NULL, document VARCHAR(16) NOT NULL,
as_of DATE NOT NULL, as_of DATE NOT NULL,
instructor_id INT NOT NULL, instructor_id INT NOT NULL,
@ -65,22 +64,22 @@ CREATE TABLE given_answers (
INSERT INTO instructors INSERT INTO instructors
(id, first_name, last_name) (id, first_name, last_name)
VALUES VALUES
( '123456', 'Jason', 'Streifling' ), ( '100000', 'Jason', 'Streifling' ),
( '123457', 'Tim', 'Taler' ), ( '100001', 'Peter', 'Enis' );
( '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' );
--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 ( INSERT INTO questions (
question, answer_1, answer_2, answer_3, answer_4, correct_answer question, answer_1, answer_2, answer_3, answer_4, correct_answer
) VALUES ) VALUES
@ -88,15 +87,19 @@ INSERT INTO questions (
( 'Was ist 1+2?', '1', '2', '3', '4', '3' ), ( 'Was ist 1+2?', '1', '2', '3', '4', '3' ),
( 'Was ist 2+2?', '1', '2', '3', '4', '4' ), ( 'Was ist 2+2?', '1', '2', '3', '4', '4' ),
( 'Was ist 0+1?', '1', '2', '3', '4', '1' ); ( 'Was ist 0+1?', '1', '2', '3', '4', '1' );
--
INSERT INTO given_answers ( --INSERT INTO given_answers (
briefing_id, participant_id, question_id, given_answer -- briefing_id, participant_id, question_id, given_answer
) VALUES --) VALUES
( '1', '1', '1', '2' ), -- ( '1', '1', '1', '2' ),
( '1', '1', '2', '3' ), -- ( '1', '1', '2', '3' ),
( '1', '1', '3', '3' ), -- ( '1', '1', '3', '3' ),
( '1', '1', '4', '1' ), -- ( '1', '1', '4', '1' ),
( '2', '2', '1', '2' ), -- ( '1', '2', '1', '2' ),
( '2', '2', '2', '3' ), -- ( '1', '2', '2', '3' ),
( '2', '2', '3', '4' ), -- ( '1', '2', '3', '3' ),
( '2', '2', '4', '1' ); -- ( '1', '2', '4', '1' ),
-- ( '2', '3', '1', '2' ),
-- ( '2', '3', '2', '3' ),
-- ( '2', '3', '3', '4' ),
-- ( '2', '3', '4', '1' );

View File

@ -21,10 +21,9 @@ type Participant struct {
type Briefing struct { type Briefing struct {
ID int64 ID int64
Date string DateTime string
Time string
Location string Location string
DocumentName string Document string
AsOf string AsOf string
InstructorID int64 InstructorID int64
} }
@ -51,10 +50,9 @@ type GivenAnswer struct {
type OverviewTableData struct { type OverviewTableData struct {
InstructorFirstName string InstructorFirstName string
InstructorLastName string InstructorLastName string
BriefingDate string BriefingDateTime string
BriefingTime string
BriefingLocation string BriefingLocation string
BriefingDocumentName string BriefingDocument string
BriefingAsOf string BriefingAsOf string
ParticipantFirstName string ParticipantFirstName string
ParticipantLastName string ParticipantLastName string

View File

@ -33,12 +33,12 @@ func OpenDB(dbName string) (*DB, error) {
func (db *DB) WriteBriefing(b *Briefing) error { func (db *DB) WriteBriefing(b *Briefing) error {
query := ` query := `
INSERT INTO briefings INSERT INTO briefings
(date, time, location, document_name, as_of, instructor_id) (datetime, location, document, as_of, instructor_id)
VALUES 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 { if err != nil {
return fmt.Errorf("error: *DB.writeBriefing: db.Exec(): %v", err) return fmt.Errorf("error: *DB.writeBriefing: db.Exec(): %v", err)
} }
@ -95,10 +95,9 @@ func (db *DB) GetAllOverviewTableData() ([]OverviewTableData, error) {
SELECT SELECT
i.first_name, i.first_name,
i.last_name, i.last_name,
b.date, b.datetime,
b.time,
b.location, b.location,
b.document_name, b.document,
b.as_of, b.as_of,
p.first_name, p.first_name,
p.last_name, p.last_name,
@ -132,10 +131,9 @@ func (db *DB) GetAllOverviewTableData() ([]OverviewTableData, error) {
err := rows.Scan( err := rows.Scan(
&otd.InstructorFirstName, &otd.InstructorFirstName,
&otd.InstructorLastName, &otd.InstructorLastName,
&otd.BriefingDate, &otd.BriefingDateTime,
&otd.BriefingTime,
&otd.BriefingLocation, &otd.BriefingLocation,
&otd.BriefingDocumentName, &otd.BriefingDocument,
&otd.BriefingAsOf, &otd.BriefingAsOf,
&otd.ParticipantFirstName, &otd.ParticipantFirstName,
&otd.ParticipantLastName, &otd.ParticipantLastName,
@ -156,10 +154,9 @@ func (db *DB) GetOverviewTableDataByName(n string) ([]OverviewTableData, error)
SELECT SELECT
i.first_name, i.first_name,
i.last_name, i.last_name,
b.date, b.datetime,
b.time,
b.location, b.location,
b.document_name, b.document,
b.as_of, b.as_of,
p.first_name, p.first_name,
p.last_name, p.last_name,
@ -199,10 +196,9 @@ func (db *DB) GetOverviewTableDataByName(n string) ([]OverviewTableData, error)
err := rows.Scan( err := rows.Scan(
&otd.InstructorFirstName, &otd.InstructorFirstName,
&otd.InstructorLastName, &otd.InstructorLastName,
&otd.BriefingDate, &otd.BriefingDateTime,
&otd.BriefingTime,
&otd.BriefingLocation, &otd.BriefingLocation,
&otd.BriefingDocumentName, &otd.BriefingDocument,
&otd.BriefingAsOf, &otd.BriefingAsOf,
&otd.ParticipantFirstName, &otd.ParticipantFirstName,
&otd.ParticipantLastName, &otd.ParticipantLastName,
@ -281,8 +277,12 @@ func (db *DB) GetQuestions(nums []string) ([]Question, error) {
questions := make([]Question, 0) questions := make([]Question, 0)
for rows.Next() { for rows.Next() {
q := Question{Answers: make([]Answer, 4)} 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) return nil, fmt.Errorf("error: *DB.GetQuestions: rows.Scan(): %v", err)
} }

View File

@ -92,12 +92,9 @@ func (s *Session) HandleNewParticipant(cp chan<- *BriefingParticipant) http.Hand
func (s *Session) HandleBriefingForm(db *data.DB) http.HandlerFunc { func (s *Session) HandleBriefingForm(db *data.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
now := time.Now() s.DateTime = time.Now().Format("2006-01-02 15:04:05")
s.Date = now.Format("2006-01-02")
s.Time = now.Format("15:04:05")
s.Location = r.PostFormValue("location") s.Location = r.PostFormValue("location")
s.DocumentName = r.PostFormValue("document") s.Document = r.PostFormValue("document")
s.AsOf = r.PostFormValue("as-of") s.AsOf = r.PostFormValue("as-of")
err := db.WriteBriefing(s.Briefing) err := db.WriteBriefing(s.Briefing)

View File

@ -60,6 +60,8 @@ func makeHTMLQuestions(sq []data.Question, givenAnswers []int) []resultQuestion
questions[i].Answers = make([]resultAnswer, len(q.Answers)) questions[i].Answers = make([]resultAnswer, len(q.Answers))
for j := range q.Answers { for j := range q.Answers {
questions[i].Answers[j].Text = q.Answers[j].Text
if j+1 == q.Correct { if j+1 == q.Correct {
questions[i].Answers[j].Correct = true questions[i].Answers[j].Correct = true
} else { } else {

View File

@ -4,7 +4,7 @@
{{end}} {{end}}
{{define "retry"}} {{define "retry"}}
<button hx-post="/allow-retry/{{.SessionID}}/{{.Login}}/" type="button">Wiederholen erlauben</button> <button hx-post="/allow-retry/{{.SessionID}}/{{.Login}}/" hx-swap="delete" type="button">Wiederholen erlauben</button>
{{end}} {{end}}
{{define "participant"}} {{define "participant"}}
@ -18,6 +18,7 @@
{{if lt .NoIncorrect 0}} {{if lt .NoIncorrect 0}}
{{template "refresh" .}} {{template "refresh" .}}
{{else if gt .NoIncorrect 0}} {{else if gt .NoIncorrect 0}}
<p>{{.NoIncorrect}} Fehler</p>
{{template "retry" .}} {{template "retry" .}}
{{template "refresh" .}} {{template "refresh" .}}
{{else}} {{else}}

View File

@ -3,10 +3,9 @@
<tr> <tr>
<td>{{.InstructorFirstName}}</td> <td>{{.InstructorFirstName}}</td>
<td>{{.InstructorLastName}}</td> <td>{{.InstructorLastName}}</td>
<td>{{.BriefingDate}}</td> <td>{{.BriefingDateTime}}</td>
<td>{{.BriefingTime}}</td>
<td>{{.BriefingLocation}}</td> <td>{{.BriefingLocation}}</td>
<td>{{.BriefingDocumentName}}</td> <td>{{.BriefingDocument}}</td>
<td>{{.BriefingAsOf}}</td> <td>{{.BriefingAsOf}}</td>
<td>{{.ParticipantFirstName}}</td> <td>{{.ParticipantFirstName}}</td>
<td>{{.ParticipantLastName}}</td> <td>{{.ParticipantLastName}}</td>
@ -32,8 +31,7 @@
<thead> <thead>
<tr> <tr>
<th colspan="2">Unterweiser</th> <th colspan="2">Unterweiser</th>
<th>Datum</th> <th>Datum & Uhrzeit</th>
<th>Uhrzeit</th>
<th>Ort</th> <th>Ort</th>
<th>Dokument</th> <th>Dokument</th>
<th>Stand</th> <th>Stand</th>