renamed GetTaskById to GetTaskByID

This commit is contained in:
thewhitetulip 2015-11-21 16:33:34 +05:30
parent 65dd3713d1
commit 8eea6f51f5
3 changed files with 20 additions and 25 deletions

View File

@ -60,8 +60,8 @@ func GetTasks(status string) []types.Task {
return task
}
//GetTaskById function gets the tasks from the ID passed to the function
func GetTaskById(id int) types.Task {
//GetTaskByID function gets the tasks from the ID passed to the function
func GetTaskByID(id int) types.Task {
var task types.Task
var TaskID int
var TaskTitle string
@ -223,24 +223,25 @@ func UpdateTask(id int, title string, content string) error {
//SearchTask is used to return the search results depending on the query
func SearchTask(query string) []types.Task {
stmt := "select id, title, content from task where title like '%" + query + "%' or content like '%" + query + "%'"
stmt := "select id, title, content, created_date from task where title like '%" + query + "%' or content like '%" + query + "%'"
var task []types.Task
var TaskID int
var TaskTitle string
var TaskContent string
var TaskCreated time.Time
rows, err := database.Query(stmt, query, query)
if err != nil {
fmt.Println(err)
}
for rows.Next() {
err := rows.Scan(&TaskID, &TaskTitle, &TaskContent)
err := rows.Scan(&TaskID, &TaskTitle, &TaskContent, &TaskCreated)
if err != nil {
fmt.Println(err)
}
TaskTitle = strings.Replace(TaskTitle, query, "<span class='highlight'>"+query+"</span>", -1)
TaskContent = strings.Replace(TaskContent, query, "<span class='highlight'>"+query+"</span>", -1)
a := types.Task{Id: TaskID, Title: TaskTitle, Content: TaskContent}
a := types.Task{Id: TaskID, Title: TaskTitle, Content: TaskContent, Created: TaskCreated.Format(time.UnixDate)[0:20]}
task = append(task, a)
}
return task

View File

@ -1,8 +1,4 @@
{{template "_head.html"}}
<!--end mainHeader -->
<button class=" btn-danger btn glyphicon glyphicon-plus floating-action-icon floating-action-icon-add"></button>
<div class="timeline">
{{ if .}} {{range .}}
<div class="note">
@ -11,26 +7,24 @@
<p class="noteContent">{{.Content}}</p>
<span class="notefooter">
<ul class="menu">
<li role="presentation">
<span class="glyphicon glyphicon-time"></span> {{.Created}}</li>
<!-- <li role="presentation">
<a role="menuitem" tabindex="-1" href="/share/{{.Id}}">
<span class="glyphicon glyphicon-share"></span> Share</a>
<a role="menuitem" tabindex="-1" href="/mask/{{.Id}}">
<span class="glyphicon glyphicon-lock"></span> Mask</a></li> !-->
<li role="presentation">
<a role="menuitem" tabindex="-1" href="/trash/{{.Id}}">
<span class="glyphicon glyphicon-trash"></span> Trash</a>
</li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="/mask/{{.Id}}">
<span class="glyphicon glyphicon-lock"></span> Mask</a>
</li> !-->
<a role="menuitem" tabindex="-1" href="/complete/{{.Id}}">
<span class="glyphicon glyphicon-check"></span> Complete</a>
</li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="/edit/{{.Id}}">
<span class="glyphicon glyphicon-pencil"></span> Edit</a>
</li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="/archive/{{.Id}}">
<span class="glyphicon glyphicon-inbox"></span> Complete</a>
</li>
<!--
<li role="presentation"><a role="menuitem" tabindex="-1" href="/delete/{{.Id}}">
<span class="glyphicon glyphicon-trash"></span> Delete</a></li>
-->
</ul>
</span>
</div>

View File

@ -105,7 +105,7 @@ func EditTaskFunc(w http.ResponseWriter, r *http.Request) {
if err != nil {
fmt.Println(err)
} else {
task := db.GetTaskById(id)
task := db.GetTaskByID(id)
editTemplate.Execute(w, task)
}
}