gutendex processing implementation

This commit is contained in:
Doar Mihai
2026-03-29 15:23:02 +03:00
parent 7be6af781b
commit 93fef1512a
7 changed files with 542 additions and 0 deletions
+47
View File
@@ -14,8 +14,23 @@ class Book extends Model
'publication_date',
'description',
'category_id',
'gutenberg_id',
'source',
'full_text_url',
'language',
];
/**
* Get the attributes that should be cast.
*/
protected function casts(): array
{
return [
'publication_date' => 'date',
'gutenberg_id' => 'integer',
];
}
/**
* Use slug for route model binding and URL generation.
*/
@@ -24,6 +39,38 @@ class Book extends Model
return 'slug';
}
/**
* Scope a query to only include books from a specific source.
*/
public function scopeFromSource($query, string $source)
{
return $query->where('source', $source);
}
/**
* Scope a query to only include manually added books.
*/
public function scopeManual($query)
{
return $query->where('source', 'manual');
}
/**
* Scope a query to only include Gutendex imported books.
*/
public function scopeGutendex($query)
{
return $query->where('source', 'gutendex');
}
/**
* Scope a query to only include books in a specific language.
*/
public function scopeInLanguage($query, string $language)
{
return $query->where('language', $language);
}
/**
* Get the category that owns the book.
*/