From 37405c57041c48ec1901e5db69d9d878ff95cffd Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Sun, 12 Apr 2026 20:43:44 -0400 Subject: [PATCH] feat(queries): Add processing issues management queries - Add CreateProcessingIssue with upsert for recording/renewing issues - Add ListProcessingIssuesByLibrary with severity ordering and media item details - Add GetProcessingIssueStats for error/warning/info counts - Add ResolveProcessingIssue for marking issues as resolved - Add DeleteProcessingIssue for removing resolved issues - Add GetLibraryWithType for fetching library with type info for validation --- internal/database/queries/queries.sql | 77 +++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/internal/database/queries/queries.sql b/internal/database/queries/queries.sql index 70da20e..70bdfbb 100644 --- a/internal/database/queries/queries.sql +++ b/internal/database/queries/queries.sql @@ -2016,3 +2016,80 @@ SET updated_at = NOW() WHERE id = $1 AND user_id = $5 RETURNING *; + +-- ============================================================================ +-- PROCESSING ISSUES QUERIES +-- ============================================================================ + +-- name: CreateProcessingIssue :one +INSERT INTO processing_issues (media_item_id, library_id, issue_type, issue_description, severity) +VALUES ($1, $2, $3, $4, $5) +ON CONFLICT (media_item_id, issue_type) +DO UPDATE SET issue_description = EXCLUDED.issue_description, + severity = EXCLUDED.severity, + resolved = false, + resolved_at = NULL +RETURNING *; + +-- name: ListProcessingIssuesByLibrary :many +SELECT + pi.id, + pi.media_item_id, + pi.issue_type, + pi.issue_description, + pi.severity, + pi.resolved, + pi.resolved_at, + pi.created_at, + mi.title, + mi.file_path, + mi.format_group, + lt.name as library_type_name +FROM processing_issues pi +JOIN media_items mi ON pi.media_item_id = mi.id +JOIN libraries l ON pi.library_id = l.id +JOIN library_types lt ON l.library_type_id = lt.id +WHERE pi.library_id = $1 + AND pi.resolved = false +ORDER BY + CASE pi.severity + WHEN 'error' THEN 1 + WHEN 'warning' THEN 2 + WHEN 'info' THEN 3 + END, + pi.created_at DESC; + +-- name: GetProcessingIssueStats :one +SELECT + COUNT(*) FILTER (WHERE severity = 'error' AND resolved = false) as error_count, + COUNT(*) FILTER (WHERE severity = 'warning' AND resolved = false) as warning_count, + COUNT(*) FILTER (WHERE severity = 'info' AND resolved = false) as info_count +FROM processing_issues +WHERE library_id = $1; + +-- name: ResolveProcessingIssue :one +UPDATE processing_issues +SET resolved = true, + resolved_at = NOW() +WHERE id = $1 + AND media_item_id = $2 +RETURNING *; + +-- name: DeleteProcessingIssue :one +DELETE FROM processing_issues +WHERE id = $1 +RETURNING *; + +-- ============================================================================ +-- LIBRARY WITH TYPE INFO QUERIES +-- ============================================================================ + +-- name: GetLibraryWithType :one +SELECT + l.*, + lt.name as type_name, + lt.description as type_description, + lt.allowed_extensions +FROM libraries l +JOIN library_types lt ON l.library_type_id = lt.id +WHERE l.id = $1;