Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
abaldeweg authored Oct 26, 2024
1 parent 2dae5e8 commit 11cafec
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
5 changes: 0 additions & 5 deletions gateway/core/models/author.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,3 @@ type Author struct {
func (a *Author) Validate(v *validator.Validate) error {
return v.Struct(a)
}

// TableName specifies the table name for the Author model in the database.
func (Author) TableName() string {
return "authors"
}
12 changes: 6 additions & 6 deletions gateway/core/repository/author.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type AuthorRepository struct {
db *gorm.DB
}


const tableName = "author"

// NewAuthorRepository creates a new author repository.
func NewAuthorRepository(db *gorm.DB) *AuthorRepository {
Expand All @@ -20,31 +20,31 @@ func NewAuthorRepository(db *gorm.DB) *AuthorRepository {
// FindAllByTerm returns all authors by term.
func (r *AuthorRepository) FindAllByTerm(term string) ([]models.Author, error) {
var authors []models.Author
result := r.db.Where("firstname LIKE ? OR surname LIKE ? OR CONCAT(firstname, ' ', surname) LIKE ? OR CONCAT(surname, ' ', firstname) LIKE ? OR CONCAT(firstname, ',', surname) LIKE ? OR CONCAT(firstname, ', ', surname) LIKE ?", "%"+term+"%", "%"+term+"%", "%"+term+"%", "%"+term+"%", "%"+term+"%", "%"+term+"%").Find(&authors)
result := r.db.Table(tableName).Where("firstname LIKE ? OR surname LIKE ? OR CONCAT(firstname, ' ', surname) LIKE ? OR CONCAT(surname, ' ', firstname) LIKE ? OR CONCAT(firstname, ',', surname) LIKE ? OR CONCAT(firstname, ', ', surname) LIKE ?", "%"+term+"%", "%"+term+"%", "%"+term+"%", "%"+term+"%", "%"+term+"%", "%"+term+"%").Find(&authors)
return authors, result.Error
}

// FindOneById returns one author by id.
func (r *AuthorRepository) FindOneById(id uint64) (models.Author, error) {
var author models.Author
result := r.db.First(&author, id)
result := r.db.Table(tableName).First(&author, id)
return author, result.Error
}

// Create an author.
func (r *AuthorRepository) Create(author *models.Author) error {
result := r.db.Create(author)
result := r.db.Table(tableName).Create(author)
return result.Error
}

// Update an author.
func (r *AuthorRepository) Update(author *models.Author) error {
result := r.db.Save(author)
result := r.db.Table(tableName).Save(author)
return result.Error
}

// Delete an author.
func (r *AuthorRepository) Delete(id uint64) error {
result := r.db.Delete(&models.Author{}, id)
result := r.db.Table(tableName).Delete(&models.Author{}, id)
return result.Error
}

0 comments on commit 11cafec

Please sign in to comment.