Add admin views for quick replies, settings, and ticket details
- Created `quick-replies.blade.php` for managing quick replies. - Added `settings.blade.php` for admin settings management. - Implemented `ticket-show.blade.php` to display ticket details. - Introduced `timeline-card.blade.php` component for displaying timeline information. Enhance quick reply management functionality - Developed `quick-reply-manager.blade.php` for creating and editing quick replies. - Integrated Livewire for dynamic interaction and validation. Implement settings page for AI configuration - Created `settings-page.blade.php` for managing AI settings, including prompts and provider instances. - Added functionality for managing models and embeddings. Add ticket show functionality with real-time updates - Implemented ticket details view with processing status and tool call logs. - Added support for displaying article suggestions and error messages. Create unit tests for AI classifier and domain info tool - Added `AIClassifierServiceTest.php` to validate AI classifier functionality. - Implemented `DomainInfoToolTest.php` for domain parameter validation. - Created `OxxaClientTest.php` to test API interactions and password hashing.
This commit is contained in:
@@ -3,19 +3,88 @@
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Article;
|
||||
use App\Models\QuickReply;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class AdminArticleService
|
||||
{
|
||||
public function paginate(int $perPage = 10)
|
||||
public function paginate(int $perPage = 10): LengthAwarePaginator
|
||||
{
|
||||
return Article::query()->latest()->paginate($perPage);
|
||||
return Article::query()
|
||||
->with('quickReplies')
|
||||
->latest()
|
||||
->paginate($perPage);
|
||||
}
|
||||
|
||||
public function create(string $title, string $content): Article
|
||||
public function create(string $title, string $content, ?string $note = null, array $allowedActions = []): Article
|
||||
{
|
||||
return Article::query()->create([
|
||||
'title' => trim($title),
|
||||
'content' => trim($content),
|
||||
'note' => $note !== null && trim($note) !== '' ? trim($note) : null,
|
||||
'allowed_actions' => $this->sanitizeAllowedActions($allowedActions),
|
||||
'status' => 'published',
|
||||
'is_ai_draft' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
public function deleteById(int $articleId): bool
|
||||
{
|
||||
return (bool) Article::query()->whereKey($articleId)->delete();
|
||||
}
|
||||
|
||||
public function updateMetadata(int $articleId, ?string $note, array $allowedActions, array $quickReplyIds = []): bool
|
||||
{
|
||||
$article = Article::query()->find($articleId);
|
||||
if ($article === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DB::transaction(function () use ($article, $note, $allowedActions, $quickReplyIds): void {
|
||||
$article->note = $note !== null && trim($note) !== '' ? trim($note) : null;
|
||||
$article->allowed_actions = $this->sanitizeAllowedActions($allowedActions);
|
||||
$article->save();
|
||||
$article->quickReplies()->sync($this->existingQuickReplyIds($quickReplyIds));
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function approveDraft(int $articleId): bool
|
||||
{
|
||||
$article = Article::query()->find($articleId);
|
||||
if ($article === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$article->status = 'published';
|
||||
$article->is_ai_draft = false;
|
||||
$article->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function sanitizeAllowedActions(array $allowedActions): array
|
||||
{
|
||||
return array_values(array_intersect(array_unique($allowedActions), ['domain_inf']));
|
||||
}
|
||||
|
||||
private function existingQuickReplyIds(array $quickReplyIds): array
|
||||
{
|
||||
$ids = array_values(array_unique(array_filter(
|
||||
array_map(static fn ($id) => (int) $id, $quickReplyIds),
|
||||
static fn ($id) => $id > 0
|
||||
)));
|
||||
|
||||
if ($ids === []) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return QuickReply::query()
|
||||
->whereIn('id', $ids)
|
||||
->pluck('id')
|
||||
->map(static fn ($id) => (int) $id)
|
||||
->all();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user