Renamed list items to tasks
This commit is contained in:
parent
d5758e0444
commit
d31f16aff1
18 changed files with 249 additions and 249 deletions
|
@ -5,7 +5,7 @@ Authorization: Bearer {{auth_token}}
|
|||
###
|
||||
|
||||
# Get one list
|
||||
GET http://localhost:8080/api/v1/lists/28
|
||||
GET http://localhost:8080/api/v1/lists/10
|
||||
Authorization: Bearer {{auth_token}}
|
||||
|
||||
###
|
||||
|
|
|
@ -201,55 +201,55 @@ func IsErrListTitleCannotBeEmpty(err error) bool {
|
|||
}
|
||||
|
||||
func (err ErrListTitleCannotBeEmpty) Error() string {
|
||||
return fmt.Sprintf("List item text cannot be empty.")
|
||||
return fmt.Sprintf("List task text cannot be empty.")
|
||||
}
|
||||
|
||||
// ================
|
||||
// List item errors
|
||||
// List task errors
|
||||
// ================
|
||||
|
||||
// ErrListItemCannotBeEmpty represents a "ErrListDoesNotExist" kind of error. Used if the list does not exist.
|
||||
type ErrListItemCannotBeEmpty struct{}
|
||||
// ErrListTaskCannotBeEmpty represents a "ErrListDoesNotExist" kind of error. Used if the list does not exist.
|
||||
type ErrListTaskCannotBeEmpty struct{}
|
||||
|
||||
// IsErrListItemCannotBeEmpty checks if an error is a ErrListDoesNotExist.
|
||||
func IsErrListItemCannotBeEmpty(err error) bool {
|
||||
_, ok := err.(ErrListItemCannotBeEmpty)
|
||||
// IsErrListTaskCannotBeEmpty checks if an error is a ErrListDoesNotExist.
|
||||
func IsErrListTaskCannotBeEmpty(err error) bool {
|
||||
_, ok := err.(ErrListTaskCannotBeEmpty)
|
||||
return ok
|
||||
}
|
||||
|
||||
func (err ErrListItemCannotBeEmpty) Error() string {
|
||||
return fmt.Sprintf("List item text cannot be empty.")
|
||||
func (err ErrListTaskCannotBeEmpty) Error() string {
|
||||
return fmt.Sprintf("List task text cannot be empty.")
|
||||
}
|
||||
|
||||
// ErrListItemDoesNotExist represents a "ErrListDoesNotExist" kind of error. Used if the list does not exist.
|
||||
type ErrListItemDoesNotExist struct {
|
||||
// ErrListTaskDoesNotExist represents a "ErrListDoesNotExist" kind of error. Used if the list does not exist.
|
||||
type ErrListTaskDoesNotExist struct {
|
||||
ID int64
|
||||
}
|
||||
|
||||
// IsErrListItemDoesNotExist checks if an error is a ErrListDoesNotExist.
|
||||
func IsErrListItemDoesNotExist(err error) bool {
|
||||
_, ok := err.(ErrListItemDoesNotExist)
|
||||
// IsErrListTaskDoesNotExist checks if an error is a ErrListDoesNotExist.
|
||||
func IsErrListTaskDoesNotExist(err error) bool {
|
||||
_, ok := err.(ErrListTaskDoesNotExist)
|
||||
return ok
|
||||
}
|
||||
|
||||
func (err ErrListItemDoesNotExist) Error() string {
|
||||
return fmt.Sprintf("List item does not exist. [ID: %d]", err.ID)
|
||||
func (err ErrListTaskDoesNotExist) Error() string {
|
||||
return fmt.Sprintf("List task does not exist. [ID: %d]", err.ID)
|
||||
}
|
||||
|
||||
// ErrNeedToBeItemOwner represents an error, where the user is not the owner of that item (used i.e. when deleting a list)
|
||||
type ErrNeedToBeItemOwner struct {
|
||||
ItemID int64
|
||||
// ErrNeedToBeTaskOwner represents an error, where the user is not the owner of that task (used i.e. when deleting a list)
|
||||
type ErrNeedToBeTaskOwner struct {
|
||||
TaskID int64
|
||||
UserID int64
|
||||
}
|
||||
|
||||
// IsErrNeedToBeItemOwner checks if an error is a ErrNeedToBeItemOwner.
|
||||
func IsErrNeedToBeItemOwner(err error) bool {
|
||||
_, ok := err.(ErrNeedToBeItemOwner)
|
||||
// IsErrNeedToBeTaskOwner checks if an error is a ErrNeedToBeTaskOwner.
|
||||
func IsErrNeedToBeTaskOwner(err error) bool {
|
||||
_, ok := err.(ErrNeedToBeTaskOwner)
|
||||
return ok
|
||||
}
|
||||
|
||||
func (err ErrNeedToBeItemOwner) Error() string {
|
||||
return fmt.Sprintf("You need to be item owner to do that [ItemID: %d, UserID: %d]", err.ItemID, err.UserID)
|
||||
func (err ErrNeedToBeTaskOwner) Error() string {
|
||||
return fmt.Sprintf("You need to be task owner to do that [TaskID: %d, UserID: %d]", err.TaskID, err.UserID)
|
||||
}
|
||||
|
||||
// =================
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package models
|
||||
|
||||
// List represents a list of items
|
||||
// List represents a list of tasks
|
||||
type List struct {
|
||||
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id" param:"list"`
|
||||
Title string `xorm:"varchar(250)" json:"title"`
|
||||
|
@ -9,7 +9,7 @@ type List struct {
|
|||
NamespaceID int64 `xorm:"int(11)" json:"-" param:"namespace"`
|
||||
|
||||
Owner User `xorm:"-" json:"owner"`
|
||||
Items []*ListItem `xorm:"-" json:"items"`
|
||||
Tasks []*ListTask `xorm:"-" json:"tasks"`
|
||||
|
||||
Created int64 `xorm:"created" json:"created"`
|
||||
Updated int64 `xorm:"updated" json:"updated"`
|
||||
|
@ -18,14 +18,14 @@ type List struct {
|
|||
Rights `xorm:"-" json:"-"`
|
||||
}
|
||||
|
||||
// AfterLoad loads the owner and list items
|
||||
// AfterLoad loads the owner and list tasks
|
||||
func (l *List) AfterLoad() {
|
||||
|
||||
// Get the owner
|
||||
l.Owner, _, _ = GetUserByID(l.OwnerID)
|
||||
|
||||
// Get the list items
|
||||
l.Items, _ = GetItemsByListID(l.ID)
|
||||
// Get the list tasks
|
||||
l.Tasks, _ = GetTasksByListID(l.ID)
|
||||
}
|
||||
|
||||
// GetListByID returns a list by its ID
|
||||
|
|
|
@ -14,7 +14,7 @@ func (l *List) Delete() (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
// Delete all todoitems on that list
|
||||
_, err = x.Where("list_id = ?", l.ID).Delete(&ListItem{})
|
||||
// Delete all todotasks on that list
|
||||
_, err = x.Where("list_id = ?", l.ID).Delete(&ListTask{})
|
||||
return
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package models
|
||||
|
||||
// ListItem represents an item in a todolist
|
||||
type ListItem struct {
|
||||
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id" param:"listitem"`
|
||||
// ListTask represents an task in a todolist
|
||||
type ListTask struct {
|
||||
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id" param:"listtask"`
|
||||
Text string `xorm:"varchar(250)" json:"text"`
|
||||
Description string `xorm:"varchar(250)" json:"description"`
|
||||
Done bool `json:"done"`
|
||||
DueDateUnix int64 `xorm:"int(11)" json:"dueDate"`
|
||||
ReminderUnix int64 `xorm:"int(11)" json:"reminderDate"`
|
||||
CreatedByID int64 `xorm:"int(11)" json:"-"` // ID of the user who put that item on the list
|
||||
CreatedByID int64 `xorm:"int(11)" json:"-"` // ID of the user who put that task on the list
|
||||
ListID int64 `xorm:"int(11)" json:"listID" param:"list"`
|
||||
Created int64 `xorm:"created" json:"created"`
|
||||
Updated int64 `xorm:"updated" json:"updated"`
|
||||
|
@ -19,26 +19,26 @@ type ListItem struct {
|
|||
Rights `xorm:"-" json:"-"`
|
||||
}
|
||||
|
||||
// TableName returns the table name for listitems
|
||||
func (ListItem) TableName() string {
|
||||
return "items"
|
||||
// TableName returns the table name for listtasks
|
||||
func (ListTask) TableName() string {
|
||||
return "tasks"
|
||||
}
|
||||
|
||||
// GetItemsByListID gets all todoitems for a list
|
||||
func GetItemsByListID(listID int64) (items []*ListItem, err error) {
|
||||
err = x.Where("list_id = ?", listID).Find(&items)
|
||||
// GetTasksByListID gets all todotasks for a list
|
||||
func GetTasksByListID(listID int64) (tasks []*ListTask, err error) {
|
||||
err = x.Where("list_id = ?", listID).Find(&tasks)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// No need to iterate over users if the list doesn't has items
|
||||
if len(items) == 0 {
|
||||
// No need to iterate over users if the list doesn't has tasks
|
||||
if len(tasks) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
// Get all users and put them into the array
|
||||
var userIDs []int64
|
||||
for _, i := range items {
|
||||
for _, i := range tasks {
|
||||
found := false
|
||||
for _, u := range userIDs {
|
||||
if i.CreatedByID == u {
|
||||
|
@ -58,37 +58,37 @@ func GetItemsByListID(listID int64) (items []*ListItem, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
for in, item := range items {
|
||||
for in, task := range tasks {
|
||||
for _, user := range users {
|
||||
if item.CreatedByID == user.ID {
|
||||
items[in].CreatedBy = user
|
||||
if task.CreatedByID == user.ID {
|
||||
tasks[in].CreatedBy = user
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// obsfucate the user password
|
||||
items[in].CreatedBy.Password = ""
|
||||
tasks[in].CreatedBy.Password = ""
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// GetListItemByID returns all items a list has
|
||||
func GetListItemByID(listItemID int64) (listItem ListItem, err error) {
|
||||
exists, err := x.ID(listItemID).Get(&listItem)
|
||||
// GetListTaskByID returns all tasks a list has
|
||||
func GetListTaskByID(listTaskID int64) (listTask ListTask, err error) {
|
||||
exists, err := x.ID(listTaskID).Get(&listTask)
|
||||
if err != nil {
|
||||
return ListItem{}, err
|
||||
return ListTask{}, err
|
||||
}
|
||||
|
||||
if !exists {
|
||||
return ListItem{}, ErrListItemDoesNotExist{listItemID}
|
||||
return ListTask{}, ErrListTaskDoesNotExist{listTaskID}
|
||||
}
|
||||
|
||||
user, _, err := GetUserByID(listItem.CreatedByID)
|
||||
user, _, err := GetUserByID(listTask.CreatedByID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
listItem.CreatedBy = user
|
||||
listTask.CreatedBy = user
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
@ -1,30 +1,30 @@
|
|||
package models
|
||||
|
||||
// Create is the implementation to create a list item
|
||||
func (i *ListItem) Create(doer *User) (err error) {
|
||||
// Create is the implementation to create a list task
|
||||
func (i *ListTask) Create(doer *User) (err error) {
|
||||
//i.ListID = lID
|
||||
i.ID = 0
|
||||
|
||||
return createOrUpdateListItem(i, doer)
|
||||
return createOrUpdateListTask(i, doer)
|
||||
}
|
||||
|
||||
// Update updates a list item
|
||||
func (i *ListItem) Update() (err error) {
|
||||
// Check if the item exists
|
||||
_, err = GetListItemByID(i.ID)
|
||||
// Update updates a list task
|
||||
func (i *ListTask) Update() (err error) {
|
||||
// Check if the task exists
|
||||
_, err = GetListTaskByID(i.ID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return createOrUpdateListItem(i, &User{})
|
||||
return createOrUpdateListTask(i, &User{})
|
||||
}
|
||||
|
||||
// Helper function for creation or updating of new lists as both methods share most of their logic
|
||||
func createOrUpdateListItem(i *ListItem, doer *User) (err error) {
|
||||
func createOrUpdateListTask(i *ListTask, doer *User) (err error) {
|
||||
|
||||
// Check if we have at least a text
|
||||
if i.Text == "" {
|
||||
return ErrListItemCannotBeEmpty{}
|
||||
return ErrListTaskCannotBeEmpty{}
|
||||
}
|
||||
|
||||
// Check if the list exists
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package models
|
||||
|
||||
// Delete implements the delete method for listItem
|
||||
func (i *ListItem) Delete() (err error) {
|
||||
// Delete implements the delete method for listTask
|
||||
func (i *ListTask) Delete() (err error) {
|
||||
|
||||
// Check if it exists
|
||||
_, err = GetListItemByID(i.ID)
|
||||
_, err = GetListTaskByID(i.ID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
_, err = x.ID(i.ID).Delete(ListItem{})
|
||||
_, err = x.ID(i.ID).Delete(ListTask{})
|
||||
return
|
||||
}
|
||||
|
|
|
@ -1,28 +1,28 @@
|
|||
package models
|
||||
|
||||
// CanDelete checks if the user can delete an item
|
||||
func (i *ListItem) CanDelete(doer *User) bool {
|
||||
// Get the item
|
||||
lI, _ := GetListItemByID(i.ID)
|
||||
// CanDelete checks if the user can delete an task
|
||||
func (i *ListTask) CanDelete(doer *User) bool {
|
||||
// Get the task
|
||||
lI, _ := GetListTaskByID(i.ID)
|
||||
|
||||
// A user can delete an item if he has write acces to its list
|
||||
// A user can delete an task if he has write acces to its list
|
||||
list, _ := GetListByID(lI.ListID)
|
||||
return list.CanWrite(doer)
|
||||
}
|
||||
|
||||
// CanUpdate determines if a user has the right to update a list item
|
||||
func (i *ListItem) CanUpdate(doer *User) bool {
|
||||
// Get the item
|
||||
lI, _ := GetListItemByID(i.ID)
|
||||
// CanUpdate determines if a user has the right to update a list task
|
||||
func (i *ListTask) CanUpdate(doer *User) bool {
|
||||
// Get the task
|
||||
lI, _ := GetListTaskByID(i.ID)
|
||||
|
||||
// A user can update an item if he has write acces to its list
|
||||
// A user can update an task if he has write acces to its list
|
||||
list, _ := GetListByID(lI.ListID)
|
||||
return list.CanWrite(doer)
|
||||
}
|
||||
|
||||
// CanCreate determines if a user has the right to create a list item
|
||||
func (i *ListItem) CanCreate(doer *User) bool {
|
||||
// A user can create an item if he has write acces to its list
|
||||
// CanCreate determines if a user has the right to create a list task
|
||||
func (i *ListTask) CanCreate(doer *User) bool {
|
||||
// A user can create an task if he has write acces to its list
|
||||
list, _ := GetListByID(i.ListID)
|
||||
return list.CanWrite(doer)
|
||||
}
|
||||
|
|
|
@ -5,11 +5,11 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
func TestListItem_Create(t *testing.T) {
|
||||
func TestListTask_Create(t *testing.T) {
|
||||
//assert.NoError(t, PrepareTestDatabase())
|
||||
|
||||
// Fake list item
|
||||
listitem := ListItem{
|
||||
// Fake list task
|
||||
listtask := ListTask{
|
||||
Text: "Lorem",
|
||||
Description: "Lorem Ipsum BACKERY",
|
||||
ListID: 1,
|
||||
|
@ -19,56 +19,56 @@ func TestListItem_Create(t *testing.T) {
|
|||
doer, _, err := GetUserByID(1)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.True(t, listitem.CanCreate(&doer))
|
||||
assert.True(t, listtask.CanCreate(&doer))
|
||||
|
||||
err = listitem.Create(&doer)
|
||||
err = listtask.Create(&doer)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Update it
|
||||
listitem.Text = "Test34"
|
||||
assert.True(t, listitem.CanUpdate(&doer))
|
||||
err = listitem.Update()
|
||||
listtask.Text = "Test34"
|
||||
assert.True(t, listtask.CanUpdate(&doer))
|
||||
err = listtask.Update()
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Check if it was updated
|
||||
li, err := GetListItemByID(listitem.ID)
|
||||
li, err := GetListTaskByID(listtask.ID)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, li.Text, "Test34")
|
||||
|
||||
// Delete the item
|
||||
assert.True(t, listitem.CanDelete(&doer))
|
||||
err = listitem.Delete()
|
||||
// Delete the task
|
||||
assert.True(t, listtask.CanDelete(&doer))
|
||||
err = listtask.Delete()
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Delete a nonexistant item
|
||||
listitem.ID = 0
|
||||
err = listitem.Delete()
|
||||
// Delete a nonexistant task
|
||||
listtask.ID = 0
|
||||
err = listtask.Delete()
|
||||
assert.Error(t, err)
|
||||
assert.True(t, IsErrListItemDoesNotExist(err))
|
||||
assert.True(t, IsErrListTaskDoesNotExist(err))
|
||||
|
||||
// Try adding a list item with an empty text
|
||||
listitem.Text = ""
|
||||
err = listitem.Create(&doer)
|
||||
// Try adding a list task with an empty text
|
||||
listtask.Text = ""
|
||||
err = listtask.Create(&doer)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, IsErrListItemCannotBeEmpty(err))
|
||||
assert.True(t, IsErrListTaskCannotBeEmpty(err))
|
||||
|
||||
// Try adding one to a nonexistant list
|
||||
listitem.ListID = 99993939
|
||||
listitem.Text = "Lorem Ipsum"
|
||||
err = listitem.Create(&doer)
|
||||
listtask.ListID = 99993939
|
||||
listtask.Text = "Lorem Ipsum"
|
||||
err = listtask.Create(&doer)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, IsErrListDoesNotExist(err))
|
||||
|
||||
// Try updating a nonexistant item
|
||||
listitem.ID = 94829352
|
||||
err = listitem.Update()
|
||||
// Try updating a nonexistant task
|
||||
listtask.ID = 94829352
|
||||
err = listtask.Update()
|
||||
assert.Error(t, err)
|
||||
assert.True(t, IsErrListItemDoesNotExist(err))
|
||||
assert.True(t, IsErrListTaskDoesNotExist(err))
|
||||
|
||||
// Try inserting an item with a nonexistant user
|
||||
// Try inserting an task with a nonexistant user
|
||||
nUser := &User{ID: 9482385}
|
||||
listitem.ListID = 1
|
||||
err = listitem.Create(nUser)
|
||||
listtask.ListID = 1
|
||||
err = listtask.Create(nUser)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, IsErrUserDoesNotExist(err))
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ func init() {
|
|||
tables = append(tables,
|
||||
new(User),
|
||||
new(List),
|
||||
new(ListItem),
|
||||
new(ListTask),
|
||||
new(Team),
|
||||
new(TeamMember),
|
||||
new(TeamList),
|
||||
|
|
|
@ -15,18 +15,18 @@ func (n *Namespace) Delete() (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
// Delete all lists with their items
|
||||
// Delete all lists with their tasks
|
||||
lists, err := GetListsByNamespaceID(n.ID)
|
||||
var listIDs []int64
|
||||
// We need to do that for here because we need the list ids to delete two times:
|
||||
// 1) to delete the lists itself
|
||||
// 2) to delete the list items
|
||||
// 2) to delete the list tasks
|
||||
for _, list := range lists {
|
||||
listIDs = append(listIDs, list.ID)
|
||||
}
|
||||
|
||||
// Delete items
|
||||
_, err = x.In("list_id", listIDs).Delete(&ListItem{})
|
||||
// Delete tasks
|
||||
_, err = x.In("list_id", listIDs).Delete(&ListTask{})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ const (
|
|||
const (
|
||||
// Can read lists in a Team
|
||||
TeamRightRead TeamRight = iota
|
||||
// Can write items in a Team like lists and todo items. Cannot create new lists.
|
||||
// Can write tasks in a Team like lists and todo tasks. Cannot create new lists.
|
||||
TeamRightWrite
|
||||
// Can manage a list/namespace, can do everything
|
||||
TeamRightAdmin
|
||||
|
|
|
@ -2,87 +2,6 @@
|
|||
"swagger": "2.0",
|
||||
"info": {},
|
||||
"paths": {
|
||||
"/items/{itemID}": {
|
||||
"post": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"lists"
|
||||
],
|
||||
"summary": "Updates a list item",
|
||||
"operationId": "updateListItem",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "ID of the item to update",
|
||||
"name": "itemID",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/ListItem"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/responses/ListItem"
|
||||
},
|
||||
"400": {
|
||||
"$ref": "#/responses/Message"
|
||||
},
|
||||
"500": {
|
||||
"$ref": "#/responses/Message"
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"lists"
|
||||
],
|
||||
"summary": "Deletes a list item",
|
||||
"operationId": "deleteListItem",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "ID of the list item to delete",
|
||||
"name": "itemID",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/responses/Message"
|
||||
},
|
||||
"400": {
|
||||
"$ref": "#/responses/Message"
|
||||
},
|
||||
"403": {
|
||||
"$ref": "#/responses/Message"
|
||||
},
|
||||
"404": {
|
||||
"$ref": "#/responses/Message"
|
||||
},
|
||||
"500": {
|
||||
"$ref": "#/responses/Message"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/lists": {
|
||||
"get": {
|
||||
"consumes": [
|
||||
|
@ -117,7 +36,7 @@
|
|||
"tags": [
|
||||
"lists"
|
||||
],
|
||||
"summary": "gets one list with all todo items",
|
||||
"summary": "gets one list with all todo tasks",
|
||||
"operationId": "getList",
|
||||
"parameters": [
|
||||
{
|
||||
|
@ -150,8 +69,8 @@
|
|||
"tags": [
|
||||
"lists"
|
||||
],
|
||||
"summary": "Adds an item to a list",
|
||||
"operationId": "addListItem",
|
||||
"summary": "Adds an task to a list",
|
||||
"operationId": "addListTask",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
|
@ -164,13 +83,13 @@
|
|||
"name": "body",
|
||||
"in": "body",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/ListItem"
|
||||
"$ref": "#/definitions/ListTask"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/responses/ListItem"
|
||||
"$ref": "#/responses/ListTask"
|
||||
},
|
||||
"400": {
|
||||
"$ref": "#/responses/Message"
|
||||
|
@ -233,7 +152,7 @@
|
|||
"tags": [
|
||||
"lists"
|
||||
],
|
||||
"summary": "Deletes a list with all items on it",
|
||||
"summary": "Deletes a list with all tasks on it",
|
||||
"operationId": "deleteList",
|
||||
"parameters": [
|
||||
{
|
||||
|
@ -485,7 +404,7 @@
|
|||
"tags": [
|
||||
"namespaces"
|
||||
],
|
||||
"summary": "gets one namespace with all todo items",
|
||||
"summary": "gets one namespace with all todo tasks",
|
||||
"operationId": "getNamespace",
|
||||
"parameters": [
|
||||
{
|
||||
|
@ -829,6 +748,87 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/tasks/{taskID}": {
|
||||
"post": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"lists"
|
||||
],
|
||||
"summary": "Updates a list task",
|
||||
"operationId": "updateListTask",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "ID of the task to update",
|
||||
"name": "taskID",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/ListTask"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/responses/ListTask"
|
||||
},
|
||||
"400": {
|
||||
"$ref": "#/responses/Message"
|
||||
},
|
||||
"500": {
|
||||
"$ref": "#/responses/Message"
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"lists"
|
||||
],
|
||||
"summary": "Deletes a list task",
|
||||
"operationId": "deleteListTask",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "ID of the list task to delete",
|
||||
"name": "taskID",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/responses/Message"
|
||||
},
|
||||
"400": {
|
||||
"$ref": "#/responses/Message"
|
||||
},
|
||||
"403": {
|
||||
"$ref": "#/responses/Message"
|
||||
},
|
||||
"404": {
|
||||
"$ref": "#/responses/Message"
|
||||
},
|
||||
"500": {
|
||||
"$ref": "#/responses/Message"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/teams": {
|
||||
"get": {
|
||||
"consumes": [
|
||||
|
@ -1125,7 +1125,7 @@
|
|||
"x-go-package": "code.vikunja.io/api/models"
|
||||
},
|
||||
"List": {
|
||||
"description": "List represents a list of items",
|
||||
"description": "List represents a list of tasks",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"created": {
|
||||
|
@ -1142,16 +1142,16 @@
|
|||
"format": "int64",
|
||||
"x-go-name": "ID"
|
||||
},
|
||||
"items": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/ListItem"
|
||||
},
|
||||
"x-go-name": "Items"
|
||||
},
|
||||
"owner": {
|
||||
"$ref": "#/definitions/User"
|
||||
},
|
||||
"tasks": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/ListTask"
|
||||
},
|
||||
"x-go-name": "Tasks"
|
||||
},
|
||||
"title": {
|
||||
"type": "string",
|
||||
"x-go-name": "Title"
|
||||
|
@ -1164,8 +1164,8 @@
|
|||
},
|
||||
"x-go-package": "code.vikunja.io/api/models"
|
||||
},
|
||||
"ListItem": {
|
||||
"description": "ListItem represents an item in a todolist",
|
||||
"ListTask": {
|
||||
"description": "ListTask represents an task in a todolist",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"created": {
|
||||
|
@ -1479,10 +1479,10 @@
|
|||
"$ref": "#/definitions/List"
|
||||
}
|
||||
},
|
||||
"ListItem": {
|
||||
"description": "ListItem",
|
||||
"ListTask": {
|
||||
"description": "ListTask",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/ListItem"
|
||||
"$ref": "#/definitions/ListTask"
|
||||
}
|
||||
},
|
||||
"Message": {
|
||||
|
|
|
@ -18,7 +18,7 @@ type swaggerParameterBodies struct {
|
|||
List models.List
|
||||
|
||||
// in:body
|
||||
ListItem models.ListItem
|
||||
ListTask models.ListTask
|
||||
|
||||
// in:body
|
||||
Namespace models.Namespace
|
||||
|
|
|
@ -44,11 +44,11 @@ type swaggerResponseLIst struct {
|
|||
Body models.List `json:"body"`
|
||||
}
|
||||
|
||||
// ListItem
|
||||
// swagger:response ListItem
|
||||
type swaggerResponseLIstItem struct {
|
||||
// ListTask
|
||||
// swagger:response ListTask
|
||||
type swaggerResponseLIstTask struct {
|
||||
// in:body
|
||||
Body models.ListItem `json:"body"`
|
||||
Body models.ListTask `json:"body"`
|
||||
}
|
||||
|
||||
// ================
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
package v1
|
||||
|
||||
// swagger:operation DELETE /items/{itemID} lists deleteListItem
|
||||
// swagger:operation DELETE /tasks/{taskID} lists deleteListTask
|
||||
// ---
|
||||
// summary: Deletes a list item
|
||||
// summary: Deletes a list task
|
||||
// consumes:
|
||||
// - application/json
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: itemID
|
||||
// - name: taskID
|
||||
// in: path
|
||||
// description: ID of the list item to delete
|
||||
// description: ID of the list task to delete
|
||||
// type: string
|
||||
// required: true
|
||||
// responses:
|
||||
|
@ -27,7 +27,7 @@ package v1
|
|||
|
||||
// swagger:operation DELETE /lists/{listID} lists deleteList
|
||||
// ---
|
||||
// summary: Deletes a list with all items on it
|
||||
// summary: Deletes a list with all tasks on it
|
||||
// consumes:
|
||||
// - application/json
|
||||
// produces:
|
||||
|
@ -50,9 +50,9 @@ package v1
|
|||
// "500":
|
||||
// "$ref": "#/responses/Message"
|
||||
|
||||
// swagger:operation PUT /lists/{listID} lists addListItem
|
||||
// swagger:operation PUT /lists/{listID} lists addListTask
|
||||
// ---
|
||||
// summary: Adds an item to a list
|
||||
// summary: Adds an task to a list
|
||||
// consumes:
|
||||
// - application/json
|
||||
// produces:
|
||||
|
@ -66,35 +66,35 @@ package v1
|
|||
// - name: body
|
||||
// in: body
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ListItem"
|
||||
// "$ref": "#/definitions/ListTask"
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/ListItem"
|
||||
// "$ref": "#/responses/ListTask"
|
||||
// "400":
|
||||
// "$ref": "#/responses/Message"
|
||||
// "500":
|
||||
// "$ref": "#/responses/Message"
|
||||
|
||||
// swagger:operation POST /items/{itemID} lists updateListItem
|
||||
// swagger:operation POST /tasks/{taskID} lists updateListTask
|
||||
// ---
|
||||
// summary: Updates a list item
|
||||
// summary: Updates a list task
|
||||
// consumes:
|
||||
// - application/json
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: itemID
|
||||
// - name: taskID
|
||||
// in: path
|
||||
// description: ID of the item to update
|
||||
// description: ID of the task to update
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: body
|
||||
// in: body
|
||||
// schema:
|
||||
// "$ref": "#/definitions/ListItem"
|
||||
// "$ref": "#/definitions/ListTask"
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/ListItem"
|
||||
// "$ref": "#/responses/ListTask"
|
||||
// "400":
|
||||
// "$ref": "#/responses/Message"
|
||||
// "500":
|
||||
|
@ -102,7 +102,7 @@ package v1
|
|||
|
||||
// swagger:operation GET /lists/{listID} lists getList
|
||||
// ---
|
||||
// summary: gets one list with all todo items
|
||||
// summary: gets one list with all todo tasks
|
||||
// consumes:
|
||||
// - application/json
|
||||
// produces:
|
||||
|
@ -321,7 +321,7 @@ package v1
|
|||
|
||||
// swagger:operation GET /namespaces/{namespaceID} namespaces getNamespace
|
||||
// ---
|
||||
// summary: gets one namespace with all todo items
|
||||
// summary: gets one namespace with all todo tasks
|
||||
// consumes:
|
||||
// - application/json
|
||||
// produces:
|
||||
|
|
|
@ -38,8 +38,8 @@ func (c *WebHandler) CreateWeb(ctx echo.Context) error {
|
|||
if models.IsErrListTitleCannotBeEmpty(err) {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "You must provide at least a list title.")
|
||||
}
|
||||
if models.IsErrListItemCannotBeEmpty(err) {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "You must provide at least a list item text.")
|
||||
if models.IsErrListTaskCannotBeEmpty(err) {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "You must provide at least a list task text.")
|
||||
}
|
||||
if models.IsErrUserDoesNotExist(err) {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "The user does not exist.")
|
||||
|
|
|
@ -96,12 +96,12 @@ func RegisterRoutes(e *echo.Echo) {
|
|||
a.DELETE("/lists/:list", listHandler.DeleteWeb)
|
||||
a.PUT("/namespaces/:namespace/lists", listHandler.CreateWeb)
|
||||
|
||||
itemHandler := &crud.WebHandler{
|
||||
CObject: &models.ListItem{},
|
||||
taskHandler := &crud.WebHandler{
|
||||
CObject: &models.ListTask{},
|
||||
}
|
||||
a.PUT("/lists/:list", itemHandler.CreateWeb)
|
||||
a.DELETE("/items/:listitem", itemHandler.DeleteWeb)
|
||||
a.POST("/items/:listitem", itemHandler.UpdateWeb)
|
||||
a.PUT("/lists/:list", taskHandler.CreateWeb)
|
||||
a.DELETE("/tasks/:listtask", taskHandler.DeleteWeb)
|
||||
a.POST("/tasks/:listtask", taskHandler.UpdateWeb)
|
||||
|
||||
listTeamHandler := &crud.WebHandler{
|
||||
CObject: &models.TeamList{},
|
||||
|
|
Loading…
Reference in a new issue