feat(api): consolidate user profile update endpoints
Add delete_user, reset_user_password, and update_user endpoints to replace individual update operations. Update database schema to include deleted_at column for soft deletion. Add DeleteUser, ResetUserPassword, and UpdateUserAdmin queries. Update Querier with new methods for user management.
This commit is contained in:
@@ -337,6 +337,10 @@ UPDATE users SET password_hash = $2, updated_at = NOW() WHERE id = $1;
|
||||
UPDATE users SET max_devices = $2, updated_at = NOW() WHERE id = $1
|
||||
RETURNING *;
|
||||
|
||||
-- name: UpdateUserRole :one
|
||||
UPDATE users SET role = $2, updated_at = NOW() WHERE id = $1
|
||||
RETURNING id, email, username, role;
|
||||
|
||||
-- name: CountUserDevices :one
|
||||
SELECT COUNT(*) FROM devices WHERE user_id = $1;
|
||||
|
||||
@@ -1621,7 +1625,8 @@ RETURNING *;
|
||||
-- Dashboard collections queries
|
||||
-- name: GetSystemCollectionsForDashboard :many
|
||||
SELECT * FROM collections
|
||||
WHERE user_id IS NULL
|
||||
WHERE user_id = $1
|
||||
AND is_system_collection = true
|
||||
AND show_on_dashboard = true
|
||||
ORDER BY priority ASC;
|
||||
|
||||
@@ -1638,14 +1643,33 @@ WHERE user_id = $1
|
||||
AND name = $2
|
||||
AND is_system_collection = true;
|
||||
|
||||
-- name: CreateSystemCollection :one
|
||||
INSERT INTO collections (user_id, name, description, icon, color, show_on_dashboard, query_type, priority, is_system_collection, auto_assign_rules)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, true, 'null'::jsonb)
|
||||
RETURNING *;
|
||||
|
||||
-- name: ResetSystemCollectionMetadata :exec
|
||||
UPDATE collections
|
||||
SET description = $3,
|
||||
icon = $4,
|
||||
color = $5,
|
||||
priority = $6
|
||||
WHERE user_id = $1
|
||||
AND name = $2
|
||||
AND is_system_collection = true;
|
||||
|
||||
-- Smart section queries (for system collections)
|
||||
-- name: GetContinueReadingItems :many
|
||||
SELECT DISTINCT mi.* FROM media_items mi
|
||||
INNER JOIN reading_progress rp ON rp.media_item_id = mi.id
|
||||
SELECT mi.* FROM media_items mi
|
||||
INNER JOIN (
|
||||
SELECT DISTINCT ON (media_item_id) media_item_id, last_read_at
|
||||
FROM reading_progress
|
||||
WHERE user_id = $2
|
||||
AND percentage > 0
|
||||
AND percentage < 1
|
||||
ORDER BY media_item_id, last_read_at DESC
|
||||
) rp ON rp.media_item_id = mi.id
|
||||
WHERE mi.library_id = $1
|
||||
AND rp.user_id = $2
|
||||
AND rp.percentage > 0
|
||||
AND rp.percentage < 1
|
||||
ORDER BY rp.last_read_at DESC
|
||||
LIMIT $3;
|
||||
|
||||
@@ -1656,11 +1680,15 @@ ORDER BY mi.created_at DESC
|
||||
LIMIT $2;
|
||||
|
||||
-- name: GetRecentlyReadItems :many
|
||||
SELECT DISTINCT mi.* FROM media_items mi
|
||||
INNER JOIN reading_progress rp ON rp.media_item_id = mi.id
|
||||
SELECT mi.* FROM media_items mi
|
||||
INNER JOIN (
|
||||
SELECT DISTINCT ON (media_item_id) media_item_id, last_read_at
|
||||
FROM reading_progress
|
||||
WHERE user_id = $2
|
||||
AND percentage >= 1
|
||||
ORDER BY media_item_id, last_read_at DESC
|
||||
) rp ON rp.media_item_id = mi.id
|
||||
WHERE mi.library_id = $1
|
||||
AND rp.user_id = $2
|
||||
AND rp.percentage >= 1
|
||||
ORDER BY rp.last_read_at DESC
|
||||
LIMIT $3;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user