From 5a321a39ed4096922ff7df72fc5a3a2a9df039d3 Mon Sep 17 00:00:00 2001 From: kolaente Date: Sun, 6 Jan 2019 15:19:12 +0100 Subject: [PATCH] Add read all endpoint for assignees --- Featurecreep.md | 2 +- REST-Tests/lists.http | 14 ++++++++++++-- pkg/models/list_task_assignees.go | 18 +++++++++++++++++- pkg/routes/routes.go | 2 +- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/Featurecreep.md b/Featurecreep.md index 22aee0898..0ed53fd19 100644 --- a/Featurecreep.md +++ b/Featurecreep.md @@ -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 diff --git a/REST-Tests/lists.http b/REST-Tests/lists.http index b13d540d6..c3fd71e91 100644 --- a/REST-Tests/lists.http +++ b/REST-Tests/lists.http @@ -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}} + +### diff --git a/pkg/models/list_task_assignees.go b/pkg/models/list_task_assignees.go index 9c64fb45c..6c8ea7ffe 100644 --- a/pkg/models/list_task_assignees.go +++ b/pkg/models/list_task_assignees.go @@ -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 +} diff --git a/pkg/routes/routes.go b/pkg/routes/routes.go index e233520b3..e002bf50b 100644 --- a/pkg/routes/routes.go +++ b/pkg/routes/routes.go @@ -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 {