forked from OrgGo/Tasks
tasks with blank category are allowed now
This commit is contained in:
parent
3c5e5460e8
commit
19c0b15132
|
@ -43,7 +43,7 @@ func GetCategories(username string) []types.CategoryCount {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
stmt := "select c.name, count(*) from category c left outer join task t join status s on c.id = t.cat_id and t.task_status_id=s.id where s.status!='DELETED' and c.user_id=? group by name union select name, 0 from category c, user u where c.user_id=? and name not in (select distinct name from task t join category c join status s on s.id = t.task_status_id and t.cat_id = c.id and s.status!='DELETED' and c.user_id=?)"
|
stmt := "select 'UNCATEGORIZED' as name, count(1) from task where cat_id=0 union select c.name, count(*) from category c left outer join task t join status s on c.id = t.cat_id and t.task_status_id=s.id where s.status!='DELETED' and c.user_id=? group by name union select name, 0 from category c, user u where c.user_id=? and name not in (select distinct name from task t join category c join status s on s.id = t.task_status_id and t.cat_id = c.id and s.status!='DELETED' and c.user_id=?)"
|
||||||
rows := database.query(stmt, userID, userID, userID)
|
rows := database.query(stmt, userID, userID, userID)
|
||||||
var categories []types.CategoryCount
|
var categories []types.CategoryCount
|
||||||
var category types.CategoryCount
|
var category types.CategoryCount
|
||||||
|
|
13
db/tasks.go
13
db/tasks.go
|
@ -100,9 +100,14 @@ func GetTasks(username, status, category string) (types.Context, error) {
|
||||||
rows = database.query(getTaskSQL, username)
|
rows = database.query(getTaskSQL, username)
|
||||||
} else {
|
} else {
|
||||||
status = category
|
status = category
|
||||||
getTaskSQL = basicSQL + " and name = ? and s.status='PENDING' order by priority desc, created_date asc, finish_date asc"
|
//This is a special case for showing tasks with null categories, we do a union query
|
||||||
rows, err = database.db.Query(getTaskSQL, username, category)
|
if category == "UNCATEGORIZED" {
|
||||||
log.Print(getTaskSQL)
|
getTaskSQL = "select t.id, title, content, created_date, priority, 'UNCATEGORIZED' from task t, status s, user u where u.username=? and s.id=t.task_status_id and u.id=t.user_id and t.cat_id=0 and s.status='PENDING' order by priority desc, created_date asc, finish_date asc"
|
||||||
|
rows, err = database.db.Query(getTaskSQL, username)
|
||||||
|
} else {
|
||||||
|
getTaskSQL = basicSQL + " and name = ? and s.status='PENDING' order by priority desc, created_date asc, finish_date asc"
|
||||||
|
rows, err = database.db.Query(getTaskSQL, username, category)
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("tasks.go: something went wrong while getting query fetch tasks by category")
|
log.Println("tasks.go: something went wrong while getting query fetch tasks by category")
|
||||||
|
@ -146,7 +151,7 @@ func GetTaskByID(username string, id int) (types.Context, error) {
|
||||||
var tasks []types.Task
|
var tasks []types.Task
|
||||||
var task types.Task
|
var task types.Task
|
||||||
|
|
||||||
getTaskSQL := "select t.id, t.title, t.content, t.priority, c.name from task t join user u left outer join category c where c.id = t.cat_id and t.id=? and u.username=?"
|
getTaskSQL := "select t.id, t.title, t.content, t.priority, 'UNCATEGORIZED' from task t join user u where t.user_id=u.id and t.cat_id=0 union select t.id, t.title, t.content, t.priority, c.name from task t join user u left outer join category c where c.id = t.cat_id and t.user_id=u.id and t.id=? and u.username=?;"
|
||||||
|
|
||||||
rows := database.query(getTaskSQL, id, username)
|
rows := database.query(getTaskSQL, id, username)
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
Loading…
Reference in New Issue