Skip to content

Commit

Permalink
add tasks table
Browse files Browse the repository at this point in the history
  • Loading branch information
milwad-dev committed May 9, 2024
1 parent 8058f3b commit 8eed9f1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
7 changes: 7 additions & 0 deletions internal/handlers/task_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package handlers

import "net/http"

func (db *DBHandler) GetLatestTasks(w http.ResponseWriter, r *http.Request) {

}
2 changes: 1 addition & 1 deletion internal/routers/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func GetRouter(handler *handlers.DBHandler) *chi.Mux {
router.Post("/labels", handler.StoreLabel)

// TODOS
//router.Get("/todos", handler.GetLatestTodos)
router.Get("/tasks", handler.GetLatestTasks)

return router
}
15 changes: 15 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,21 @@ func runTables(db *sql.DB) {
FOREIGN KEY (user_id) REFERENCES users(id)
)`

tables["tasks"] = `CREATE TABLE IF NOT EXISTS tasks (
id INT NOT NULL AUTO_INCREMENT UNIQUE,
title VARCHAR(255) NOT NULL,
description LONGTEXT NOT NULL,
status VARCHAR(255) NOT NULL,
label_id INT NOT NULL,
user_id INT NOT NULL,
completed_at TIMESTAMP NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (label_id) REFERENCES labels(id)
)`

for _, table := range tables {
db.Exec(table)
}
Expand Down

0 comments on commit 8eed9f1

Please sign in to comment.