diff --git a/db/files.go b/db/files.go index 5c9c654..2e6125c 100644 --- a/db/files.go +++ b/db/files.go @@ -103,7 +103,12 @@ func UpdateCategoryByName(oldName, newName string) error { query := "update category set name = ? where name=?" log.Println(query) err := taskQuery(query, newName, oldName) - return err - +} + +//DeleteCommentByID will actually delete the comment from db +func DeleteCommentByID(id int) error { + query := "delete from comments where id=?" + err := taskQuery(query, id) + return err } diff --git a/db/tasks.go b/db/tasks.go index ca294c5..9c1f885 100644 --- a/db/tasks.go +++ b/db/tasks.go @@ -75,7 +75,11 @@ func GetTasks(status, category string) (types.Context, error) { var getTasksql string var rows *sql.Rows - comments := GetComments() + comments, err := GetComments() + + if err != nil { + return context, err + } basicSQL := "select id, title, content, created_date, priority from task t" if status == "pending" && category == "" { @@ -111,7 +115,7 @@ func GetTasks(status, category string) (types.Context, error) { } TaskCreated = TaskCreated.Local() - task.Created = TaskCreated.Format(time.UnixDate)[0:20] + task.Created = TaskCreated.Format("Jan 01 2006") tasks = append(tasks, task) } @@ -258,28 +262,32 @@ func SearchTask(query string) types.Context { //GetComments is used to get comments, all of them. //We do not want 100 different pages to show tasks, we want to use as few pages as possible //so we are going to populate everything on the damn home pages -func GetComments() map[int][]types.Comment { +func GetComments() (map[int][]types.Comment, error) { commentMap := make(map[int][]types.Comment) - var id int - var message types.Comment + var taskID int + var comment types.Comment + var created time.Time - stmt := "select taskID, content from comments;" + stmt := "select id, taskID, content, created from comments;" rows := database.query(stmt) for rows.Next() { - err := rows.Scan(&id, &message.Content) + err := rows.Scan(&comment.ID, &taskID, &comment.Content, &created) if err != nil { - + return commentMap, err } - commentMap[id] = append(commentMap[id], message) + // comment.Content = string(md.Markdown([]byte(comment.Content))) ## have to fix the
issue markdown support + created = created.Local() + comment.Created = created.Format("02 Jan 2006 15:04:05") + commentMap[taskID] = append(commentMap[taskID], comment) } - return commentMap + return commentMap, nil } //AddComments will be used to add comments in the database func AddComments(id int, comment string) error { - stmt := "insert into comments(taskID, content) values (?,?)" + stmt := "insert into comments(taskID, content, created) values (?,?,datetime())" err := taskQuery(stmt, id, comment) if err != nil { diff --git a/public/static/css/styles.css b/public/static/css/styles.css index 2f916ef..8969d88 100644 --- a/public/static/css/styles.css +++ b/public/static/css/styles.css @@ -22,13 +22,17 @@ Layout padding-left: 25px; padding-top: 5px; } + ul{ list-style-type: none; } +.timestamp{ + color: #aaa; +} + input { - border:none; - border-bottom:1px solid gray; + border:none; box-shadow:none; } diff --git a/schema.sql b/schema.sql index 5fb17c3..4f00680 100644 --- a/schema.sql +++ b/schema.sql @@ -12,4 +12,4 @@ CREATE TABLE files(name varchar(1000) not null, autoName varchar(255) not null); CREATE TABLE category( id integer primary key autoincrement ,name varchar(1000) not null); -CREATE TABLE comments(id integer primary key autoincrement, content ntext, taskID references task(id)); +CREATE TABLE comments(id integer primary key autoincrement, content ntext, taskID references task(id), created datetime); diff --git a/templates/home.html b/templates/home.html index 5e8d7e0..61af4e5 100644 --- a/templates/home.html +++ b/templates/home.html @@ -56,7 +56,11 @@ {{$value.Content}}