Added docs via swagger
This commit is contained in:
@ -159,7 +159,6 @@ func (err ErrNeedToBeListOwner) Error() string {
|
||||
return fmt.Sprintf("You need to be list owner to do that [ListID: %d, UserID: %d]", err.ListID, err.UserID)
|
||||
}
|
||||
|
||||
|
||||
// ================
|
||||
// List item errors
|
||||
// ================
|
||||
@ -178,7 +177,7 @@ func (err ErrListItemCannotBeEmpty) Error() string {
|
||||
}
|
||||
|
||||
// ErrListItemCannotBeEmpty represents a "ErrListDoesNotExist" kind of error. Used if the list does not exist.
|
||||
type ErrListItemDoesNotExist struct{
|
||||
type ErrListItemDoesNotExist struct {
|
||||
ID int64
|
||||
}
|
||||
|
||||
@ -206,4 +205,4 @@ func IsErrNeedToBeItemOwner(err error) bool {
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ func DeleteListByID(listID int64, doer *User) (err error) {
|
||||
}
|
||||
|
||||
if list.Owner.ID != doer.ID {
|
||||
return ErrNeedToBeListOwner{ListID:listID, UserID:doer.ID}
|
||||
return ErrNeedToBeListOwner{ListID: listID, UserID: doer.ID}
|
||||
}
|
||||
|
||||
// Delete the list
|
||||
|
@ -95,7 +95,7 @@ func DeleteListItemByID(itemID int64, doer *User) (err error) {
|
||||
|
||||
// Check if the user hat the right to delete that item
|
||||
if listitem.CreatedByID != doer.ID {
|
||||
return ErrNeedToBeItemOwner{ItemID:itemID, UserID: doer.ID}
|
||||
return ErrNeedToBeItemOwner{ItemID: itemID, UserID: doer.ID}
|
||||
}
|
||||
|
||||
_, err = x.ID(itemID).Delete(ListItem{})
|
||||
|
@ -17,21 +17,23 @@ func CreateOrUpdateListItem(item *ListItem) (newItem *ListItem, err error) {
|
||||
item.CreatedByID = item.CreatedBy.ID
|
||||
item.CreatedBy = user
|
||||
|
||||
// TODO: Check if the user has the right to add/update an item to that list
|
||||
|
||||
if item.ID != 0 {
|
||||
_, err = x.ID(item.ID).Update(item)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
_, err = x.Insert(item)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Check if we have at least a text
|
||||
if item.Text == "" {
|
||||
return newItem, ErrListItemCannotBeEmpty{}
|
||||
}
|
||||
|
||||
_, err = x.Insert(item)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Get the new/updated item
|
||||
|
@ -27,6 +27,23 @@ func (User) TableName() string {
|
||||
return "users"
|
||||
}
|
||||
|
||||
// ApiUserPassword represents a user object without timestamps and a json password field.
|
||||
type ApiUserPassword struct {
|
||||
ID int64 `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
Email string `json:"email"`
|
||||
}
|
||||
|
||||
func (apiUser *ApiUserPassword) APIFormat() User {
|
||||
return User{
|
||||
ID: apiUser.ID,
|
||||
Username: apiUser.Username,
|
||||
Password: apiUser.Password,
|
||||
Email: apiUser.Email,
|
||||
}
|
||||
}
|
||||
|
||||
// GetUserByID gets informations about a user by its ID
|
||||
func GetUserByID(id int64) (user User, exists bool, err error) {
|
||||
// Apparently xorm does otherwise look for all users but return only one, which leads to returing one even if the ID is 0
|
||||
|
Reference in New Issue
Block a user