/* * 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) } }