diff --git a/db/db.go b/db/db.go
index 1e6f06c..d9f30a1 100644
--- a/db/db.go
+++ b/db/db.go
@@ -2,7 +2,7 @@ package db
import (
"database/sql"
- "fmt"
+ "log"
_ "github.com/mattn/go-sqlite3" //we want to use sqlite natively
"github.com/thewhitetulip/Tasks/types"
"strings"
@@ -15,7 +15,7 @@ var err error
func init() {
database, err = sql.Open("sqlite3", "./tasks.db")
if err != nil {
- fmt.Println(err)
+ log.Println(err)
}
}
@@ -45,14 +45,14 @@ func GetTasks(status string) types.Context {
rows, err := database.Query(getTasksql)
if err != nil {
- fmt.Println(err)
+ log.Println(err)
}
defer rows.Close()
for rows.Next() {
err := rows.Scan(&TaskID, &TaskTitle, &TaskContent, &TaskCreated)
TaskContent = strings.Replace(TaskContent, "\n", "
", -1)
if err != nil {
- fmt.Println(err)
+ log.Println(err)
}
TaskCreated = TaskCreated.Local()
a := types.Task{Id: TaskID, Title: TaskTitle, Content: TaskContent, Created: TaskCreated.Format(time.UnixDate)[0:20]}
@@ -73,13 +73,13 @@ func GetTaskByID(id int) types.Context {
rows, err := database.Query(getTasksql, id)
if err != nil {
- fmt.Println(err)
+ log.Println(err)
}
defer rows.Close()
if rows.Next() {
err := rows.Scan(&TaskID, &TaskTitle, &TaskContent)
if err != nil {
- fmt.Println(err)
+ log.Println(err)
}
task = types.Task{Id: TaskID, Title: TaskTitle, Content: TaskContent}
}
@@ -92,15 +92,15 @@ func GetTaskByID(id int) types.Context {
func TrashTask(id int) error {
trashSQL, err := database.Prepare("update task set is_deleted='Y',last_modified_at=datetime() where id=?")
if err != nil {
- fmt.Println(err)
+ log.Println(err)
}
tx, err := database.Begin()
if err != nil {
- fmt.Println(err)
+ log.Println(err)
}
_, err = tx.Stmt(trashSQL).Exec(id)
if err != nil {
- fmt.Println("doing rollback")
+ log.Println("doing rollback")
tx.Rollback()
} else {
tx.Commit()
@@ -112,15 +112,15 @@ func TrashTask(id int) error {
func CompleteTask(id int) error {
stmt, err := database.Prepare("update task set is_deleted='Y', finish_date=datetime(),last_modified_at=datetime() where id=?")
if err != nil {
- fmt.Println(err)
+ log.Println(err)
}
tx, err := database.Begin()
if err != nil {
- fmt.Println(err)
+ log.Println(err)
}
_, err = tx.Stmt(stmt).Exec(id)
if err != nil {
- fmt.Println(err)
+ log.Println(err)
tx.Rollback()
} else {
tx.Commit()
@@ -132,15 +132,15 @@ func CompleteTask(id int) error {
func DeleteAll() error {
stmt, err := database.Prepare("delete from task where is_deleted='Y'")
if err != nil {
- fmt.Println(err)
+ log.Println(err)
}
tx, err := database.Begin()
if err != nil {
- fmt.Println(err)
+ log.Println(err)
}
_, err = tx.Stmt(stmt).Exec()
if err != nil {
- fmt.Println("doing rollback")
+ log.Println("doing rollback")
tx.Rollback()
} else {
tx.Commit()
@@ -152,15 +152,15 @@ func DeleteAll() error {
func RestoreTask(id int) error {
restoreSQL, err := database.Prepare("update task set is_deleted='N',last_modified_at=datetime() where id=?")
if err != nil {
- fmt.Println(err)
+ log.Println(err)
}
tx, err := database.Begin()
if err != nil {
- fmt.Println(err)
+ log.Println(err)
}
_, err = tx.Stmt(restoreSQL).Exec(id)
if err != nil {
- fmt.Println("doing rollback")
+ log.Println("doing rollback")
tx.Rollback()
} else {
tx.Commit()
@@ -168,19 +168,20 @@ func RestoreTask(id int) error {
return err
}
-//RestoreTaskFromComplete is used to restore tasks from the Trash
+
+//RestoreTask is used to restore tasks from the Trash
func RestoreTaskFromComplete(id int) error {
- restoreSQL, err := database.Prepare("update task set is_deleted='N',finish_date=null,last_modified_at=datetime() where id=?")
+ restoreSQL, err := database.Prepare("update task set finish_date=null,last_modified_at=datetime() where id=?")
if err != nil {
- fmt.Println(err)
+ log.Println(err)
}
tx, err := database.Begin()
if err != nil {
- fmt.Println(err)
+ log.Println(err)
}
_, err = tx.Stmt(restoreSQL).Exec(id)
if err != nil {
- fmt.Println("doing rollback")
+ log.Println("doing rollback")
tx.Rollback()
} else {
tx.Commit()
@@ -192,15 +193,15 @@ func RestoreTaskFromComplete(id int) error {
func DeleteTask(id int) error {
deleteSQL, err := database.Prepare("delete from task where id = ?")
if err != nil {
- fmt.Println(err)
+ log.Println(err)
}
tx, err := database.Begin()
if err != nil {
- fmt.Println(err)
+ log.Println(err)
}
_, err = tx.Stmt(deleteSQL).Exec(id)
if err != nil {
- fmt.Println(err)
+ log.Println(err)
tx.Rollback()
} else {
tx.Commit()
@@ -212,12 +213,12 @@ func DeleteTask(id int) error {
func AddTask(title, content string) error {
restoreSQL, err := database.Prepare("insert into task(title, content, created_date, last_modified_at) values(?,?,datetime(), datetime())")
if err != nil {
- fmt.Println(err)
+ log.Println(err)
}
tx, err := database.Begin()
_, err = tx.Stmt(restoreSQL).Exec(title, content)
if err != nil {
- fmt.Println(err)
+ log.Println(err)
tx.Rollback()
} else {
tx.Commit()
@@ -229,19 +230,19 @@ func AddTask(title, content string) error {
func UpdateTask(id int, title string, content string) error {
SQL, err := database.Prepare("update task set title=?, content=? where id=?")
if err != nil {
- fmt.Println(err)
+ log.Println(err)
}
tx, err := database.Begin()
if err != nil {
- fmt.Println(err)
+ log.Println(err)
}
_, err = tx.Stmt(SQL).Exec(title, content, id)
if err != nil {
- fmt.Println(err)
+ log.Println(err)
tx.Rollback()
} else {
- fmt.Println(tx.Commit())
+ log.Println(tx.Commit())
}
return err
}
@@ -258,12 +259,12 @@ func SearchTask(query string) types.Context {
rows, err := database.Query(stmt, query, query)
if err != nil {
- fmt.Println(err)
+ log.Println(err)
}
for rows.Next() {
err := rows.Scan(&TaskID, &TaskTitle, &TaskContent, &TaskCreated)
if err != nil {
- fmt.Println(err)
+ log.Println(err)
}
TaskTitle = strings.Replace(TaskTitle, query, ""+query+"", -1)
TaskContent = strings.Replace(TaskContent, query, ""+query+"", -1)
diff --git a/main.go b/main.go
index 9499db1..61ab231 100644
--- a/main.go
+++ b/main.go
@@ -5,7 +5,6 @@ package main
* License: MIT
**/
import (
- "fmt"
"github.com/thewhitetulip/Tasks/views"
"log"
"net/http"
@@ -27,6 +26,6 @@ func main() {
http.HandleFunc("/search/", views.SearchTaskFunc)
//http.HandleFunc("/static/", ServeStaticFunc)
http.Handle("/static/", http.FileServer(http.Dir("public")))
- fmt.Println("running on 8080")
+ log.Println("running server on 8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}
diff --git a/views/views.go b/views/views.go
index 7cfcd9c..7c9e9b3 100644
--- a/views/views.go
+++ b/views/views.go
@@ -2,7 +2,7 @@ package views
import (
"bufio"
- "fmt"
+ "log"
"github.com/thewhitetulip/Tasks/db"
"io/ioutil"
"net/http"
@@ -28,7 +28,7 @@ func PopulateTemplates() {
templatesDir := "./public/templates/"
files, err := ioutil.ReadDir(templatesDir)
if err != nil {
- fmt.Println("Error reading template dir")
+ log.Println("Error reading template dir")
}
for _, file := range files {
filename := file.Name()
@@ -38,12 +38,12 @@ func PopulateTemplates() {
}
if err != nil {
- fmt.Println(err)
+ log.Println(err)
os.Exit(1)
}
templates, err = template.ParseFiles(allFiles...)
if err != nil {
- fmt.Println(err)
+ log.Println(err)
os.Exit(1)
}
homeTemplate = templates.Lookup("home.html")
@@ -135,7 +135,7 @@ func EditTaskFunc(w http.ResponseWriter, r *http.Request) {
if r.Method == "GET" {
id, err := strconv.Atoi(r.URL.Path[len("/edit/"):])
if err != nil {
- fmt.Println(err)
+ log.Println(err)
} else {
task := db.GetTaskByID(id)
editTemplate.Execute(w, task)
@@ -151,7 +151,7 @@ func CompleteTaskFunc(w http.ResponseWriter, r *http.Request) {
if r.Method == "GET" {
id, err := strconv.Atoi(r.URL.Path[len("/complete/"):])
if err != nil {
- fmt.Println(err)
+ log.Println(err)
} else {
err = db.CompleteTask(id)
if err != nil {
@@ -177,7 +177,7 @@ func DeleteTaskFunc(w http.ResponseWriter, r *http.Request) {
} else {
id, err := strconv.Atoi(id)
if err != nil {
- fmt.Println(err)
+ log.Println(err)
} else {
err = db.DeleteTask(id)
if err != nil {
@@ -199,7 +199,7 @@ func TrashTaskFunc(w http.ResponseWriter, r *http.Request) {
if r.Method == "GET" {
id, err := strconv.Atoi(r.URL.Path[len("/trash/"):])
if err != nil {
- fmt.Println(err)
+ log.Println(err)
} else {
err = db.TrashTask(id)
if err != nil {
@@ -220,7 +220,7 @@ func RestoreTaskFunc(w http.ResponseWriter, r *http.Request) {
if r.Method == "GET" {
id, err := strconv.Atoi(r.URL.Path[len("/restore/"):])
if err != nil {
- fmt.Println(err)
+ log.Println(err)
} else {
err = db.RestoreTask(id)
if err != nil {
@@ -241,7 +241,7 @@ func RestoreFromCompleteFunc(w http.ResponseWriter, r *http.Request) {
if r.Method == "GET" {
id, err := strconv.Atoi(r.URL.Path[len("/incomplete/"):])
if err != nil {
- fmt.Println(err)
+ log.Println(err)
} else {
err = db.RestoreTaskFromComplete(id)
if err != nil {
@@ -263,7 +263,7 @@ func UpdateTaskFunc(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
id, err := strconv.Atoi(r.Form.Get("id"))
if err != nil {
- fmt.Println(err)
+ log.Println(err)
}
title := r.Form.Get("title")
content := r.Form.Get("content")