Assignees optimizations #47

Merged
konrad merged 10 commits from enhancement/assignees-performance into master 2019-01-08 19:13:07 +00:00
4 changed files with 31 additions and 5 deletions
Showing only changes of commit 5a321a39ed - Show all commits

View File

@ -117,7 +117,7 @@ Sorry for some of them being in German, I'll tranlate them at some point.
* [x] Assignees
* [x] Check if something changed at all before running everything
* [x] Don't use `list.ReadOne()`, gets too much unnessecary shit
* [ ] Wegen Performance auf eigene endpoints umziehen, wie labels
* [x] Wegen Performance auf eigene endpoints umziehen, wie labels
* [ ] "One endpoint to rule them all" -> Array-addable
* [x] Labels
* [ ] Check if something changed at all before running everything

View File

@ -134,8 +134,13 @@ POST http://localhost:8080/api/v1/tasks/3565
Authorization: Bearer {{auth_token}}
Content-Type: application/json
{"assignees":[
]}
{
"assignees": [
{
"id": 1
}
]
}
###
@ -150,3 +155,8 @@ Content-Type: application/json
}
###
# Get all assignees
GET http://localhost:8080/api/v1/tasks/3565/assignees
Authorization: Bearer {{auth_token}}
###

View File

@ -16,7 +16,10 @@
package models
import "code.vikunja.io/web"
import (
"code.vikunja.io/web"
"fmt"
)
// ListTaskAssginee represents an assignment of a user to a task
type ListTaskAssginee struct {
@ -145,6 +148,7 @@ func (la *ListTaskAssginee) Create(a web.Auth) (err error) {
func (t *ListTask) addNewAssigneeByID(newAssigneeID int64, list *List) (err error) {
// Check if the user exists and has access to the list
fmt.Println("getuserbyid")
newAssignee, err := GetUserByID(newAssigneeID)
if err != nil {
return err
@ -160,3 +164,15 @@ func (t *ListTask) addNewAssigneeByID(newAssigneeID int64, list *List) (err erro
return
}
// ReadAll gets all assignees for a task
func (la *ListTaskAssginee) ReadAll(search string, a web.Auth, page int) (interface{}, error) {
taskAssignees := []*User{}
err := x.Table("task_assignees").
Select("users.*").
Join("INNER", "users", "task_assignees.user_id = users.id").
Where("task_id = ? AND users.username LIKE ?", la.TaskID, "%"+search+"%").
Limit(getLimitFromPageIndex(page)).
Find(&taskAssignees)
return taskAssignees, err
}

View File

@ -248,7 +248,7 @@ func RegisterRoutes(e *echo.Echo) {
}
a.PUT("/tasks/:listtask/assignees", assigneeTaskHandler.CreateWeb)
a.DELETE("/tasks/:listtask/assignees/:user", assigneeTaskHandler.DeleteWeb)
a.GET("/tasks/:listtask/labelassigneess", assigneeTaskHandler.ReadAllWeb)
a.GET("/tasks/:listtask/assignees", assigneeTaskHandler.ReadAllWeb)
labelTaskHandler := &handler.WebHandler{
EmptyStruct: func() handler.CObject {