Remove kanban links from main.go, delete tables.go

This commit removes unnecessary endpoints from the HTTP server and
deletes the tables.go file, consolidating the relevant code under
main.go. The kanban and update-task-status handlers are no longer
needed, as well as the createTableDB function.  No major consequences or
considerations arise from these changes.
This commit is contained in:
James Musselman 2023-11-29 17:07:36 -06:00
parent a311be9630
commit 808f3f3772
2 changed files with 0 additions and 117 deletions

View file

@ -97,7 +97,6 @@ func main() {
createUserTable() createUserTable()
createFilesTable() createFilesTable()
createTableDB()
createUser(adminUsername, adminPassword, adminName, adminEmail) createUser(adminUsername, adminPassword, adminName, adminEmail)
log.Println("Done with database checks, starting webserver!") log.Println("Done with database checks, starting webserver!")
@ -123,8 +122,6 @@ func initHTTPServer() {
http.HandleFunc("/delete", DeleteFiles) http.HandleFunc("/delete", DeleteFiles)
http.HandleFunc("/export", exportFiles) http.HandleFunc("/export", exportFiles)
http.HandleFunc("/checkusername", handleUsernameCheck) http.HandleFunc("/checkusername", handleUsernameCheck)
http.HandleFunc("/kanban", kanban)
http.HandleFunc("/update-task-status", updateTaskStatus)
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static")))) http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))

114
tables.go
View file

@ -1,114 +0,0 @@
package main
import (
"encoding/json"
"log"
"net/http"
"time"
)
type Task struct {
ID int
Title string
Description string
Status string
}
func kanban(w http.ResponseWriter, r *http.Request) {
userSession, err := validateSession(w, r)
if err != nil {
handleError(w, "Error validating session", err)
return
}
if r.Method == "GET" {
var tasks []Task
rows, err := db.Query("SELECT id, title, description, status FROM tasks")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
defer rows.Close()
for rows.Next() {
var task Task
err := rows.Scan(&task.ID, &task.Title, &task.Description, &task.Status)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
tasks = append(tasks, task)
}
err = rows.Err()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
data := struct {
Tasks []Task
}{
Tasks: tasks,
}
renderTemplate(w, "kanban.html", data)
} else if r.Method == "POST" {
title := r.FormValue("title")
description := r.FormValue("description")
status := r.FormValue("status")
_, err := db.Exec("INSERT INTO tasks (title, description, status, owner,date) VALUES ($1, $2, $3, $4, $5)", title, description, status, userSession.username, time.Now())
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.Redirect(w, r, "/kanban", http.StatusSeeOther)
}
}
func createTableDB() {
// Create Task Table
createTaskTable := `
CREATE TABLE IF NOT EXISTS tasks (
id SERIAL PRIMARY KEY,
title TEXT NOT NULL,
description TEXT NOT NULL,
status TEXT NOT NULL,
owner TEXT NOT NULL,
date TIMESTAMP NOT NULL
);`
_, err := db.Exec(createTaskTable)
if err != nil {
log.Fatal(err)
}
}
func updateTaskStatus(w http.ResponseWriter, r *http.Request) {
if r.Method == "POST" {
var task struct {
ID int `json:"id"`
Status string `json:"status"`
}
err := json.NewDecoder(r.Body).Decode(&task)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Update the task status in the database
_, err = db.Exec("UPDATE tasks SET status = $1 WHERE id = $2", task.Status, task.ID)
if err != nil {
log.Println("Error updating task status:", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Return a success response
w.WriteHeader(http.StatusOK)
} else {
http.Error(w, "Invalid request method", http.StatusMethodNotAllowed)
}
}