Return the index of the added element

This commit is contained in:
2024-10-20 12:57:24 +02:00
parent 764b143ff8
commit 8ce7d54d00
7 changed files with 65 additions and 59 deletions

View File

@@ -66,10 +66,10 @@ func NewEntry(title string) *Entry {
}
}
// AddAuthor adds the Person as an author to the Entry.
func (e *Entry) AddAuthor(p *Person) {
addToSlice(&e.Authors, p)
// AddAuthor adds the Person as an author to the Entry. It returns an int.
func (e *Entry) AddAuthor(p *Person) int {
e.Updated = NewDate(time.Now())
return addToSlice(&e.Authors, p)
}
// DeleteAuthor deletes the Person at index from the Entry. It return an error.
@@ -82,10 +82,10 @@ func (e *Entry) DeleteAuthor(index int) error {
return nil
}
// AddCategory adds the Category to the Entry.
func (e *Entry) AddCategory(c *Category) {
addToSlice(&e.Categories, c)
// AddCategory adds the Category to the Entry. It returns an int.
func (e *Entry) AddCategory(c *Category) int {
e.Updated = NewDate(time.Now())
return addToSlice(&e.Categories, c)
}
// DeleteCategory deletes the Category at index from the Entry. It return an
@@ -99,10 +99,11 @@ func (e *Entry) DeleteCategory(index int) error {
return nil
}
// AddContributor adds the Person as a contributor to the Entry.
func (e *Entry) AddContributor(c *Person) {
addToSlice(&e.Contributors, c)
// AddContributor adds the Person as a contributor to the Entry. It returns an
// int.
func (e *Entry) AddContributor(c *Person) int {
e.Updated = NewDate(time.Now())
return addToSlice(&e.Contributors, c)
}
// DeleteContributor deletes the Person at index from the Entry. It return an
@@ -116,10 +117,10 @@ func (e *Entry) DeleteContributor(index int) error {
return nil
}
// AddLink adds the Link to the Entry.
func (e *Entry) AddLink(l *Link) {
addToSlice(&e.Links, l)
// AddLink adds the Link to the Entry. It returns an int.
func (e *Entry) AddLink(l *Link) int {
e.Updated = NewDate(time.Now())
return addToSlice(&e.Links, l)
}
// DeleteLink deletes the Link at index from the Entry. It return an error.
@@ -132,10 +133,10 @@ func (e *Entry) DeleteLink(index int) error {
return nil
}
// AddExtension adds the ExtensionElement to the Entry.
func (e *Entry) AddExtension(x *ExtensionElement) {
addToSlice(&e.Extensions, x)
// AddExtension adds the ExtensionElement to the Entry. It returns an int.
func (e *Entry) AddExtension(x *ExtensionElement) int {
e.Updated = NewDate(time.Now())
return addToSlice(&e.Extensions, x)
}
// DeleteExtension deletes the Extension at index from the Entry. It return an