Compare commits
	
		
			4 Commits
		
	
	
		
			master
			...
			dateien_ho
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| ea8bf5e38e | |||
| 08fb23d0f5 | |||
| 6972948ee3 | |||
| fc7aae83d2 | 
							
								
								
									
										1
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								go.mod
									
									
									
									
									
								
							| @@ -4,6 +4,7 @@ go 1.21.1 | |||||||
|  |  | ||||||
| require ( | require ( | ||||||
| 	github.com/go-sql-driver/mysql v1.7.1 | 	github.com/go-sql-driver/mysql v1.7.1 | ||||||
|  | 	github.com/google/uuid v1.3.1 | ||||||
| 	golang.org/x/term v0.13.0 | 	golang.org/x/term v0.13.0 | ||||||
| ) | ) | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.sum
									
									
									
									
									
								
							| @@ -1,5 +1,7 @@ | |||||||
| github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI= | github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI= | ||||||
| github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= | github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= | ||||||
|  | github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= | ||||||
|  | github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||||||
| golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= | golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= | ||||||
| golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||||||
| golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek= | golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek= | ||||||
|   | |||||||
| @@ -2,10 +2,12 @@ package server | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  | 	"github.com/google/uuid" | ||||||
| 	"html/template" | 	"html/template" | ||||||
|  | 	"io" | ||||||
| 	"log" | 	"log" | ||||||
| 	"net/http" | 	"net/http" | ||||||
|  | 	"os" | ||||||
| 	"streifling.com/jason/sicherheitsunterweisung/packages/db" | 	"streifling.com/jason/sicherheitsunterweisung/packages/db" | ||||||
| 	"streifling.com/jason/sicherheitsunterweisung/packages/types" | 	"streifling.com/jason/sicherheitsunterweisung/packages/types" | ||||||
| ) | ) | ||||||
| @@ -15,6 +17,7 @@ func DisplayTable(db *db.DB) http.HandlerFunc { | |||||||
| 		bs, err := db.ReadAll() | 		bs, err := db.ReadAll() | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			_ = fmt.Errorf("DisplayTable: %v\n", err) | 			_ = fmt.Errorf("DisplayTable: %v\n", err) | ||||||
|  | 			return | ||||||
| 		} | 		} | ||||||
| 		template.Must(template.ParseFiles("templates/index.html", "templates/table.html")).Execute(w, bs) | 		template.Must(template.ParseFiles("templates/index.html", "templates/table.html")).Execute(w, bs) | ||||||
| 	} | 	} | ||||||
| @@ -25,6 +28,7 @@ func DisplayResults(db *db.DB) http.HandlerFunc { | |||||||
| 		bs, err := db.ReadByName(r.PostFormValue("search")) | 		bs, err := db.ReadByName(r.PostFormValue("search")) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			_ = fmt.Errorf("DisplayResults: db.ReadByName(r.PostFormValue()): %v\n", err) | 			_ = fmt.Errorf("DisplayResults: db.ReadByName(r.PostFormValue()): %v\n", err) | ||||||
|  | 			return | ||||||
| 		} | 		} | ||||||
| 		template.Must(template.ParseFiles("templates/table.html")).ExecuteTemplate(w, "rows", bs) | 		template.Must(template.ParseFiles("templates/table.html")).ExecuteTemplate(w, "rows", bs) | ||||||
| 	} | 	} | ||||||
| @@ -70,7 +74,33 @@ func SubmitForm(db *db.DB, i, j *int64) http.HandlerFunc { | |||||||
| 		bs, err := db.ReadAll() | 		bs, err := db.ReadAll() | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			_ = fmt.Errorf("SubmitForm: db.ReadAll(): %v\n", err) | 			_ = fmt.Errorf("SubmitForm: db.ReadAll(): %v\n", err) | ||||||
|  | 			return | ||||||
| 		} | 		} | ||||||
| 		template.Must(template.ParseFiles("templates/index.html", "templates/table.html")).Execute(w, bs) | 		template.Must(template.ParseFiles("templates/index.html", "templates/table.html")).Execute(w, bs) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func Upload(fn, ln, d, t string) http.HandlerFunc { | ||||||
|  | 	return func(w http.ResponseWriter, r *http.Request) { | ||||||
|  | 		r.ParseMultipartForm(10 << 20) // 10 MiB | ||||||
|  |  | ||||||
|  | 		tmpFile, _, err := r.FormFile("questionaire") | ||||||
|  | 		if err != nil { | ||||||
|  | 			http.Error(w, err.Error(), http.StatusInternalServerError) | ||||||
|  | 			return | ||||||
|  | 		} | ||||||
|  | 		defer tmpFile.Close() | ||||||
|  |  | ||||||
|  | 		file, err := os.Create(ln + fn + d + t + uuid.New().String() + ".png") | ||||||
|  | 		if err != nil { | ||||||
|  | 			http.Error(w, err.Error(), http.StatusInternalServerError) | ||||||
|  | 			return | ||||||
|  | 		} | ||||||
|  | 		defer file.Close() | ||||||
|  |  | ||||||
|  | 		if _, err := io.Copy(file, tmpFile); err != nil { | ||||||
|  | 			http.Error(w, err.Error(), http.StatusInternalServerError) | ||||||
|  | 			return | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
|   | |||||||
| @@ -1,5 +1,7 @@ | |||||||
| package types | package types | ||||||
|  |  | ||||||
|  | import "os" | ||||||
|  |  | ||||||
| type Person struct { | type Person struct { | ||||||
| 	FirstName string | 	FirstName string | ||||||
| 	LastName  string | 	LastName  string | ||||||
| @@ -11,6 +13,7 @@ type Participant struct { | |||||||
| 	ID int64 | 	ID int64 | ||||||
| 	Person | 	Person | ||||||
| 	Company      string | 	Company      string | ||||||
|  | 	Questionaire string | ||||||
| } | } | ||||||
|  |  | ||||||
| type Briefing struct { | type Briefing struct { | ||||||
|   | |||||||
| @@ -8,6 +8,8 @@ | |||||||
|  |  | ||||||
|   <label for="participant-company-input-{{ . }}">Firma</label> |   <label for="participant-company-input-{{ . }}">Firma</label> | ||||||
|   <input type="text" name="participant-company-{{ . }}" id="participant-company-input-{{ . }}" /> |   <input type="text" name="participant-company-{{ . }}" id="participant-company-input-{{ . }}" /> | ||||||
|  |  | ||||||
|  |   <button type="button" hx-post="/upload/">Fragebogen hochladen</button> | ||||||
| </div> | </div> | ||||||
| {{ end }} | {{ end }} | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user