diff --git a/app/Http/Controllers/DocumentController.php b/app/Http/Controllers/DocumentController.php new file mode 100644 index 00000000..5650abce --- /dev/null +++ b/app/Http/Controllers/DocumentController.php @@ -0,0 +1,34 @@ +file_path)) { + abort(404, 'Document file not found.'); + } + + // Stream the file to the browser + return Storage::download( + $document->file_path, + $document->original_filename, + [ + 'Content-Type' => $document->mime_type, + 'Content-Disposition' => 'inline; filename="' . $document->original_filename . '"', + ] + ); + } +} diff --git a/app/Http/Controllers/SubscriptionController.php b/app/Http/Controllers/SubscriptionController.php new file mode 100644 index 00000000..8575f51f --- /dev/null +++ b/app/Http/Controllers/SubscriptionController.php @@ -0,0 +1,86 @@ +all(), [ + 'email' => 'required|email|max:255', + ]); + + if ($validator->fails()) { + return response()->json([ + 'success' => false, + 'message' => 'Please provide a valid email address.', + 'errors' => $validator->errors(), + ], 422); + } + + $email = $request->input('email'); + + // Check if email already exists + $existing = Subscription::where('email', $email)->first(); + + if ($existing) { + if ($existing->is_active) { + return response()->json([ + 'success' => false, + 'message' => 'This email is already subscribed to notifications.', + ], 409); + } else { + // Reactivate subscription + $existing->is_active = true; + $existing->save(); + + return response()->json([ + 'success' => true, + 'message' => 'Your subscription has been reactivated! You will receive email notifications for new docket entries.', + ]); + } + } + + // Create new subscription + Subscription::create([ + 'email' => $email, + 'is_active' => true, + ]); + + return response()->json([ + 'success' => true, + 'message' => 'Successfully subscribed! You will receive email notifications for new docket entries.', + ]); + } + + /** + * Unsubscribe using token. + */ + public function unsubscribe(Request $request, string $token): JsonResponse + { + $subscription = Subscription::where('unsubscribe_token', $token)->first(); + + if (!$subscription) { + return response()->json([ + 'success' => false, + 'message' => 'Invalid unsubscribe token.', + ], 404); + } + + $subscription->is_active = false; + $subscription->save(); + + return response()->json([ + 'success' => true, + 'message' => 'You have been successfully unsubscribed from notifications.', + ]); + } +} diff --git a/database/seeders/DocketSeeder.php b/database/seeders/DocketSeeder.php new file mode 100644 index 00000000..24da8078 --- /dev/null +++ b/database/seeders/DocketSeeder.php @@ -0,0 +1,122 @@ + '2024-01-15', + 'title' => 'Complaint Filed', + 'summary' => 'Elizabeth Kragh filed a complaint against Montana Association of the Deaf alleging discrimination and wrongful termination. The complaint outlines multiple instances of workplace discrimination and seeks damages.', + 'notes' => 'Initial filing', + 'documents' => [ + [ + 'title' => 'Original Complaint', + 'original_filename' => 'complaint.pdf', + 'stored_filename' => 'complaint_001.pdf', + 'file_path' => 'documents/complaint_001.pdf', + 'file_size' => 245678, + 'mime_type' => 'application/pdf', + 'summary' => 'Initial complaint document', + 'display_order' => 1, + ], + ], + ], + [ + 'date' => '2024-02-01', + 'title' => 'Answer to Complaint', + 'summary' => 'Montana Association of the Deaf filed their answer to the complaint, denying all allegations and asserting various affirmative defenses.', + 'notes' => 'Defendant response', + 'documents' => [ + [ + 'title' => 'Answer to Complaint', + 'original_filename' => 'answer.pdf', + 'stored_filename' => 'answer_001.pdf', + 'file_path' => 'documents/answer_001.pdf', + 'file_size' => 189234, + 'mime_type' => 'application/pdf', + 'summary' => 'Defendant answer', + 'display_order' => 1, + ], + ], + ], + [ + 'date' => '2024-03-10', + 'title' => 'Motion for Summary Judgment', + 'summary' => 'Plaintiff filed a motion for summary judgment on certain claims, arguing that there are no genuine issues of material fact and that judgment should be entered as a matter of law.', + 'notes' => 'Key motion', + 'documents' => [ + [ + 'title' => 'Motion for Summary Judgment', + 'original_filename' => 'motion_summary_judgment.pdf', + 'stored_filename' => 'motion_001.pdf', + 'file_path' => 'documents/motion_001.pdf', + 'file_size' => 312456, + 'mime_type' => 'application/pdf', + 'summary' => 'Summary judgment motion', + 'display_order' => 1, + ], + [ + 'title' => 'Supporting Brief', + 'original_filename' => 'supporting_brief.pdf', + 'stored_filename' => 'brief_001.pdf', + 'file_path' => 'documents/brief_001.pdf', + 'file_size' => 456789, + 'mime_type' => 'application/pdf', + 'summary' => 'Brief in support of motion', + 'display_order' => 2, + ], + ], + ], + [ + 'date' => '2024-04-05', + 'title' => 'Discovery Order', + 'summary' => 'Court issued an order regarding discovery disputes, setting deadlines for document production and depositions.', + 'notes' => 'Discovery schedule', + 'documents' => [], + ], + [ + 'date' => '2024-05-20', + 'title' => 'Expert Witness Disclosure', + 'summary' => 'Plaintiff disclosed expert witnesses who will testify regarding workplace discrimination and damages calculations.', + 'notes' => 'Expert disclosures', + 'documents' => [ + [ + 'title' => 'Expert Report - Dr. Smith', + 'original_filename' => 'expert_report_smith.pdf', + 'stored_filename' => 'expert_001.pdf', + 'file_path' => 'documents/expert_001.pdf', + 'file_size' => 567890, + 'mime_type' => 'application/pdf', + 'summary' => 'Expert testimony on discrimination', + 'display_order' => 1, + ], + ], + ], + ]; + + foreach ($entries as $entryData) { + $documents = $entryData['documents'] ?? []; + unset($entryData['documents']); + + $entry = DocketEntry::create($entryData); + + foreach ($documents as $docData) { + $entry->documents()->create($docData); + } + } + + $this->command->info('Created ' . count($entries) . ' docket entries with sample documents.'); + } +} diff --git a/resources/js/Pages/Home.vue b/resources/js/Pages/Home.vue index c7f08b93..6f3490fe 100644 --- a/resources/js/Pages/Home.vue +++ b/resources/js/Pages/Home.vue @@ -38,11 +38,39 @@ const toggleEntry = (id: number) => { }; const subscribe = async () => { - // TODO: Implement subscription API call - subscribeMessage.value = 'Subscription feature coming soon!'; + if (!email.value) { + subscribeMessage.value = 'Please enter your email address.'; + setTimeout(() => { + subscribeMessage.value = ''; + }, 3000); + return; + } + + try { + const response = await fetch('/api/subscribe', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]')?.getAttribute('content') || '', + }, + body: JSON.stringify({ email: email.value }), + }); + + const data = await response.json(); + + if (data.success) { + subscribeMessage.value = data.message; + email.value = ''; // Clear the input + } else { + subscribeMessage.value = data.message; + } + } catch (error) { + subscribeMessage.value = 'An error occurred. Please try again.'; + } + setTimeout(() => { subscribeMessage.value = ''; - }, 3000); + }, 5000); }; @@ -152,16 +180,18 @@ const subscribe = async () => {