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.
33 lines
719 B
Go
33 lines
719 B
Go
1 year ago
|
package repositories
|
||
|
|
||
|
import (
|
||
|
"grace/database"
|
||
|
|
||
|
"gorm.io/gorm"
|
||
|
)
|
||
|
|
||
|
type CollectionRepository struct {
|
||
|
DB *gorm.DB
|
||
|
}
|
||
|
|
||
|
func (r *CollectionRepository) Create(collection *database.Collection) error {
|
||
|
return r.DB.Create(collection).Error
|
||
|
}
|
||
|
|
||
|
func (r *CollectionRepository) Update(collection *database.Collection) error {
|
||
|
return r.DB.Save(collection).Error
|
||
|
}
|
||
|
|
||
|
func (r *CollectionRepository) Delete(collection *database.Collection) error {
|
||
|
return r.DB.Delete(collection).Error
|
||
|
}
|
||
|
|
||
|
func (r *CollectionRepository) FindByID(id uint) (*database.Collection, error) {
|
||
|
var collection database.Collection
|
||
|
err := r.DB.Preload("Books").First(&collection, id).Error
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return &collection, nil
|
||
|
}
|