You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
717 B
Go
24 lines
717 B
Go
1 year ago
|
package repositories
|
||
|
|
||
|
import (
|
||
|
"grace/database"
|
||
|
|
||
|
"gorm.io/gorm"
|
||
|
)
|
||
|
|
||
|
type CollectionBookRepository struct {
|
||
|
DB *gorm.DB
|
||
|
}
|
||
|
|
||
|
func (r *CollectionBookRepository) AddBookToCollection(book *database.Book, collection *database.Collection) error {
|
||
|
return r.DB.Model(collection).Association("Books").Append(book)
|
||
|
}
|
||
|
|
||
|
func (r *CollectionBookRepository) RemoveBookFromCollection(book *database.Book, collection *database.Collection) error {
|
||
|
return r.DB.Model(collection).Association("Books").Delete(book)
|
||
|
}
|
||
|
|
||
|
func (r *CollectionBookRepository) RemoveCollectionBook(book *database.Book, collection *database.Collection) error {
|
||
|
return r.DB.Delete(&database.CollectionBook{CollectionID: collection.ID, BookID: book.ID}).Error
|
||
|
}
|