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
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user