1
0

List item creation is now done via handler

This commit is contained in:
konrad
2018-07-11 02:13:53 +02:00
committed by kolaente
parent b067425dc3
commit 592dc20af4
12 changed files with 114 additions and 18 deletions

View File

@ -38,3 +38,38 @@ func CreateOrUpdateListItem(item *ListItem) (newItem *ListItem, err error) {
return &finalItem, err
}
// Create is the implementation to create a list item
func (i *ListItem) Create(doer *User, lID int64) (err error) {
i.ListID = lID
// Check rights
user, _, err := GetUserByID(doer.ID)
if err != nil {
return
}
i.CreatedBy = user // Needed because we return the full item object
i.CreatedByID = user.ID
// Get the list to check if the user has the right to write to that list
list, err := GetListByID(lID)
if err != nil {
return
}
if !list.CanWrite(&user) {
return ErrNeedToBeListWriter{ListID: lID, UserID: user.ID}
}
// Check if we have at least a text
if i.Text == "" {
return ErrListItemCannotBeEmpty{}
}
_, err = x.Insert(i)
if err != nil {
return
}
return
}