gutendex processing implementation
This commit is contained in:
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -10,8 +10,22 @@ class Summary extends Model
|
||||
'content',
|
||||
'key_insights',
|
||||
'book_id',
|
||||
'processing_status',
|
||||
'processing_error',
|
||||
'processed_at',
|
||||
'model_used',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'processed_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the book that owns the summary.
|
||||
*/
|
||||
@@ -19,4 +33,79 @@ class Summary extends Model
|
||||
{
|
||||
return $this->belongsTo(Book::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to only include summaries with a specific status.
|
||||
*/
|
||||
public function scopeWithStatus($query, string $status)
|
||||
{
|
||||
return $query->where('processing_status', $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to only include pending summaries.
|
||||
*/
|
||||
public function scopePending($query)
|
||||
{
|
||||
return $query->where('processing_status', 'pending');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to only include processing summaries.
|
||||
*/
|
||||
public function scopeProcessing($query)
|
||||
{
|
||||
return $query->where('processing_status', 'processing');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to only include completed summaries.
|
||||
*/
|
||||
public function scopeCompleted($query)
|
||||
{
|
||||
return $query->where('processing_status', 'completed');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to only include failed summaries.
|
||||
*/
|
||||
public function scopeFailed($query)
|
||||
{
|
||||
return $query->where('processing_status', 'failed');
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the summary as processing.
|
||||
*/
|
||||
public function markAsProcessing(): void
|
||||
{
|
||||
$this->update([
|
||||
'processing_status' => 'processing',
|
||||
'processing_error' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the summary as completed.
|
||||
*/
|
||||
public function markAsCompleted(string $modelUsed): void
|
||||
{
|
||||
$this->update([
|
||||
'processing_status' => 'completed',
|
||||
'processing_error' => null,
|
||||
'processed_at' => now(),
|
||||
'model_used' => $modelUsed,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the summary as failed with an error message.
|
||||
*/
|
||||
public function markAsFailed(string $error): void
|
||||
{
|
||||
$this->update([
|
||||
'processing_status' => 'failed',
|
||||
'processing_error' => $error,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user