Compare commits
No commits in common. "1742f65fcd6fc2f69e72f31f563232d31aff3877" and "ce075d790a79ff93d2a60bcff60d5042dfa62461" have entirely different histories.
1742f65fcd
...
ce075d790a
4 changed files with 4 additions and 77 deletions
46
main.go
46
main.go
|
|
@ -242,7 +242,7 @@ func addTrainingAreaHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func fetchTrainings() ([]Training, error) {
|
func fetchTrainings() ([]Training, error) {
|
||||||
log.Println("Fetching trainings from the database")
|
log.Println("Fetching trainings from the database")
|
||||||
rows, err := db.Query("SELECT id, title, training_type, mode, strftime('%Y-%m-%d %H:%M:%S', start), strftime('%Y-%m-%d %H:%M:%S', end), status FROM trainings")
|
rows, err := db.Query("SELECT id, title, training_type, mode, start, end, status FROM trainings")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error fetching trainings: %v", err)
|
log.Printf("Error fetching trainings: %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -258,8 +258,8 @@ func fetchTrainings() ([]Training, error) {
|
||||||
log.Printf("Error scanning row for training: %v", err)
|
log.Printf("Error scanning row for training: %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
t.Start, _ = time.Parse(time.DateTime, start)
|
t.Start, _ = time.Parse("2006-01-02 15:04:05", start)
|
||||||
t.End, _ = time.Parse(time.DateTime, end)
|
t.End, _ = time.Parse("2006-01-02 15:04:05", end)
|
||||||
trainings = append(trainings, t)
|
trainings = append(trainings, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -525,49 +525,9 @@ func logoutHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
||||||
}
|
}
|
||||||
|
|
||||||
func addTrainingHandler(w http.ResponseWriter, r *http.Request) {
|
|
||||||
log.Println("Handling request to add a new training")
|
|
||||||
|
|
||||||
if r.Method == http.MethodPost {
|
|
||||||
title := r.FormValue("title")
|
|
||||||
trainingType := r.FormValue("training_type")
|
|
||||||
mode := r.FormValue("mode")
|
|
||||||
start := r.FormValue("start")
|
|
||||||
end := r.FormValue("end")
|
|
||||||
status := r.FormValue("status")
|
|
||||||
|
|
||||||
if title == "" || trainingType == "" || mode == "" || start == "" || end == "" || status == "" {
|
|
||||||
log.Println("Missing required training fields")
|
|
||||||
http.Error(w, "All fields are required", http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := db.Exec("INSERT INTO trainings (title, training_type, mode, start, end, status) VALUES (?, ?, ?, ?, ?, ?)",
|
|
||||||
title, trainingType, mode, start, end, status)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Error adding training: %v", err)
|
|
||||||
http.Error(w, "Database error", http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Println("New training added successfully")
|
|
||||||
http.Redirect(w, r, "/trainings", http.StatusSeeOther)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err := tmpl.ExecuteTemplate(w, "add_training.html", nil)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Error rendering add_training.html: %v", err)
|
|
||||||
http.Error(w, "Template error", http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func initServerHandlers() {
|
func initServerHandlers() {
|
||||||
http.Handle("/", redirectIfNoAdmin(http.HandlerFunc(homeHandler)))
|
http.Handle("/", redirectIfNoAdmin(http.HandlerFunc(homeHandler)))
|
||||||
|
|
||||||
http.Handle("/trainings", redirectIfNoAdmin(http.HandlerFunc(trainingListHandler)))
|
http.Handle("/trainings", redirectIfNoAdmin(http.HandlerFunc(trainingListHandler)))
|
||||||
http.Handle("/trainings/add", redirectIfNoAdmin(http.HandlerFunc(addTrainingHandler)))
|
|
||||||
|
|
||||||
http.Handle("/trainers", redirectIfNoAdmin(http.HandlerFunc(trainerListHandler)))
|
http.Handle("/trainers", redirectIfNoAdmin(http.HandlerFunc(trainerListHandler)))
|
||||||
http.Handle("/trainers/add", redirectIfNoAdmin(http.HandlerFunc(addTrainerHandler)))
|
http.Handle("/trainers/add", redirectIfNoAdmin(http.HandlerFunc(addTrainerHandler)))
|
||||||
http.Handle("/training-areas", redirectIfNoAdmin(http.HandlerFunc(trainingAreaListHandler)))
|
http.Handle("/training-areas", redirectIfNoAdmin(http.HandlerFunc(trainingAreaListHandler)))
|
||||||
|
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
{{ template "preamble.html" }}
|
|
||||||
<h1>Add Training</h1>
|
|
||||||
<form method="post" action="/trainings/add">
|
|
||||||
<label>Title: <input type="text" name="title" required></label><br>
|
|
||||||
<label>Type: <input type="text" name="training_type" required></label><br>
|
|
||||||
<label>Mode:
|
|
||||||
<select name="mode" required>
|
|
||||||
<option value="Online">Online</option>
|
|
||||||
<option value="Offline">Offline</option>
|
|
||||||
<option value="Hybrid">Hybrid</option>
|
|
||||||
</select>
|
|
||||||
</label><br>
|
|
||||||
<label>Start Time: <input type="datetime-local" name="start" required></label><br>
|
|
||||||
<label>End Time: <input type="datetime-local" name="end" required></label><br>
|
|
||||||
<label>Status:
|
|
||||||
<select name="status">
|
|
||||||
<option value="planned">Planned</option>
|
|
||||||
<option value="confirmed">Date Confirmed</option>
|
|
||||||
<option value="ongoing">Ongoing</option>
|
|
||||||
<option value="held">Held</option>
|
|
||||||
<option value="done">Done</option>
|
|
||||||
<option value="cancelled">Cancelled</option>
|
|
||||||
</select>
|
|
||||||
</label><br>
|
|
||||||
<button type="submit">Add Training</button>
|
|
||||||
</form>
|
|
||||||
{{ template "epilogue.html" }}
|
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
{{ template "preamble.html" }}
|
{{ template "preamble.html" }}
|
||||||
<h1>Training Areas</h1>
|
<h1>Training Areas</h1>
|
||||||
<p>
|
<a href="/training-areas/add"><button>Add Training Area</button></a>
|
||||||
<a href="/training-areas/add"><button> <div class="tile-icon"><i class="fas fa-map-marker-alt"></i></div> Add Training Area</button></a>
|
|
||||||
<a href="/trainers/add"><button><div class="tile-icon"><i class="fas fa-user-plus"></i></div> Add Trainer</button></a>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
{{ template "preamble.html" }}
|
{{ template "preamble.html" }}
|
||||||
<p><a href="/trainings/add"><button>Add New Training</button></a></p>
|
|
||||||
|
|
||||||
<h1>Trainings</h1>
|
<h1>Trainings</h1>
|
||||||
<table border="1">
|
<table border="1">
|
||||||
<tr>
|
<tr>
|
||||||
|
|
@ -22,5 +20,4 @@
|
||||||
</tr>
|
</tr>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
{{template "epilogue.html" }}
|
{{template "epilogue.html" }}
|
||||||
Loading…
Add table
Reference in a new issue