/* * Sicherheitsunterweisung * Copyright (C) 2023 Jason Streifling * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see . */ package server import ( "html/template" "log" "net/http" "github.com/google/uuid" "streifling.com/jason/sicherheitsunterweisung/packages/data" ) type Session struct { UUID uuid.UUID Instructor data.Instructor Briefings []*Briefing } func (s *Session) handleSearch(db *data.DB) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var err error data := tableHTMLData{} data.SessionID = s.UUID data.OTD, err = db.GetOverviewTableDataByName(r.PostFormValue("search")) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) log.Panicln(err) } template.Must(template.ParseFiles("templates/table.html")).ExecuteTemplate(w, "rows", data) } } func (s *Session) handleNewBriefing(cb chan<- *Briefing) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { briefing := Briefing{Briefing: &data.Briefing{InstructorID: s.Instructor.ID}, UUID: uuid.New()} s.Briefings = append(s.Briefings, &briefing) cb <- &briefing template.Must(template.ParseFiles("templates/briefing.html")).ExecuteTemplate(w, "content", participantHTMLData{BriefingID: briefing.UUID}) } } func (s *Session) handleBriefingDone(db *data.DB) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { data := tableHTMLData{SessionID: s.UUID} var err error data.OTD, err = db.GetAllOverviewTableData() if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) log.Panicln(err) } template.Must(template.ParseFiles("templates/table.html")).ExecuteTemplate(w, "content", data) } }