mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-02 20:30:10 +00:00
Add reported-issues, Goodreads sync & notifs
Introduce user-reported-issues and Goodreads shelf sync features and wire them into notifications. Adds Prisma migrations and schema changes (ReportedIssue, GoodreadsShelf, GoodreadsBookMapping), API endpoints for reporting (POST /audiobooks/[asin]/report-issue) and admin management (list, resolve/dismiss, replace), and an admin UI section to view/dismiss/replace reported issues. Adds a new notification event (issue_reported) with updates to notification schemas, docs and provider handling, plus a notification-events constants file. Refactors request creation to use createRequestForUser service, adds a Goodreads sync processor/service/hooks/UI modals, a scrape-resilience util, and related tests and minor integration updates.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "goodreads_shelves" (
|
||||
"id" TEXT NOT NULL,
|
||||
"user_id" TEXT NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"rss_url" TEXT NOT NULL,
|
||||
"last_sync_at" TIMESTAMP(3),
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "goodreads_shelves_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "goodreads_book_mappings" (
|
||||
"id" TEXT NOT NULL,
|
||||
"goodreads_book_id" TEXT NOT NULL,
|
||||
"title" TEXT NOT NULL,
|
||||
"author" TEXT NOT NULL,
|
||||
"audible_asin" TEXT,
|
||||
"cover_url" TEXT,
|
||||
"no_match" BOOLEAN NOT NULL DEFAULT false,
|
||||
"last_search_at" TIMESTAMP(3),
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "goodreads_book_mappings_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "goodreads_shelves_user_id_idx" ON "goodreads_shelves"("user_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "goodreads_shelves_user_id_rss_url_key" ON "goodreads_shelves"("user_id", "rss_url");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "goodreads_book_mappings_goodreads_book_id_key" ON "goodreads_book_mappings"("goodreads_book_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "goodreads_book_mappings_goodreads_book_id_idx" ON "goodreads_book_mappings"("goodreads_book_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "goodreads_book_mappings_audible_asin_idx" ON "goodreads_book_mappings"("audible_asin");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "goodreads_shelves" ADD CONSTRAINT "goodreads_shelves_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,3 @@
|
||||
-- Add cached book count and cover URLs to goodreads_shelves for rich UI display
|
||||
ALTER TABLE "goodreads_shelves" ADD COLUMN "book_count" INTEGER;
|
||||
ALTER TABLE "goodreads_shelves" ADD COLUMN "cover_urls" TEXT;
|
||||
@@ -0,0 +1,32 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "reported_issues" (
|
||||
"id" TEXT NOT NULL,
|
||||
"audiobook_id" TEXT NOT NULL,
|
||||
"reporter_id" TEXT NOT NULL,
|
||||
"reason" VARCHAR(250) NOT NULL,
|
||||
"status" TEXT NOT NULL DEFAULT 'open',
|
||||
"resolved_at" TIMESTAMP(3),
|
||||
"resolved_by_id" TEXT,
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "reported_issues_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "reported_issues_audiobook_id_idx" ON "reported_issues"("audiobook_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "reported_issues_reporter_id_idx" ON "reported_issues"("reporter_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "reported_issues_status_idx" ON "reported_issues"("status");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "reported_issues" ADD CONSTRAINT "reported_issues_audiobook_id_fkey" FOREIGN KEY ("audiobook_id") REFERENCES "audiobooks"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "reported_issues" ADD CONSTRAINT "reported_issues_reporter_id_fkey" FOREIGN KEY ("reporter_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "reported_issues" ADD CONSTRAINT "reported_issues_resolved_by_id_fkey" FOREIGN KEY ("resolved_by_id") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
+73
-1
@@ -64,6 +64,9 @@ model User {
|
||||
requests Request[]
|
||||
bookDateRecommendations BookDateRecommendation[]
|
||||
bookDateSwipes BookDateSwipe[]
|
||||
goodreadsShelves GoodreadsShelf[]
|
||||
reportedIssues ReportedIssue[] @relation("Reporter")
|
||||
resolvedIssues ReportedIssue[] @relation("Resolver")
|
||||
|
||||
@@index([plexId])
|
||||
@@index([role])
|
||||
@@ -197,7 +200,8 @@ model Audiobook {
|
||||
completedAt DateTime? @map("completed_at")
|
||||
|
||||
// Relations
|
||||
requests Request[]
|
||||
requests Request[]
|
||||
reportedIssues ReportedIssue[]
|
||||
|
||||
@@index([audibleAsin])
|
||||
@@index([plexGuid])
|
||||
@@ -456,3 +460,71 @@ model NotificationBackend {
|
||||
@@index([enabled])
|
||||
@@map("notification_backends")
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// REPORTED ISSUES TABLE
|
||||
// User-reported problems with available audiobooks (corrupted, wrong book, etc.)
|
||||
// ============================================================================
|
||||
|
||||
model ReportedIssue {
|
||||
id String @id @default(uuid())
|
||||
audiobookId String @map("audiobook_id")
|
||||
reporterId String @map("reporter_id")
|
||||
reason String @db.VarChar(250)
|
||||
status String @default("open") // open, dismissed, replaced
|
||||
resolvedAt DateTime? @map("resolved_at")
|
||||
resolvedById String? @map("resolved_by_id")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
// Relations
|
||||
audiobook Audiobook @relation(fields: [audiobookId], references: [id], onDelete: Cascade)
|
||||
reporter User @relation("Reporter", fields: [reporterId], references: [id], onDelete: Cascade)
|
||||
resolvedBy User? @relation("Resolver", fields: [resolvedById], references: [id], onDelete: SetNull)
|
||||
|
||||
@@index([audiobookId])
|
||||
@@index([reporterId])
|
||||
@@index([status])
|
||||
@@map("reported_issues")
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// GOODREADS SYNC TABLES
|
||||
// Per-user Goodreads shelf subscriptions + global book-to-ASIN mapping cache
|
||||
// ============================================================================
|
||||
|
||||
model GoodreadsShelf {
|
||||
id String @id @default(uuid())
|
||||
userId String @map("user_id")
|
||||
name String // Extracted from RSS <title>
|
||||
rssUrl String @map("rss_url") @db.Text
|
||||
lastSyncAt DateTime? @map("last_sync_at")
|
||||
bookCount Int? @map("book_count")
|
||||
coverUrls String? @map("cover_urls") @db.Text // JSON array of cover image URLs
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
// Relations
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([userId, rssUrl])
|
||||
@@index([userId])
|
||||
@@map("goodreads_shelves")
|
||||
}
|
||||
|
||||
model GoodreadsBookMapping {
|
||||
id String @id @default(uuid())
|
||||
goodreadsBookId String @unique @map("goodreads_book_id")
|
||||
title String
|
||||
author String
|
||||
audibleAsin String? @map("audible_asin")
|
||||
coverUrl String? @map("cover_url") @db.Text
|
||||
noMatch Boolean @default(false) @map("no_match")
|
||||
lastSearchAt DateTime? @map("last_search_at")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
@@index([goodreadsBookId])
|
||||
@@index([audibleAsin])
|
||||
@@map("goodreads_book_mappings")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user