Phase 1: Email subscription and document download features
- Created SubscriptionController with subscribe/unsubscribe endpoints
- Added subscription API routes (POST /api/subscribe, GET /api/unsubscribe/{token})
- Updated Vue Home component with working subscription form
- Created DocumentController with download endpoint
- Added document download route (GET /api/documents/{id}/download)
- Updated Vue component to link PDF buttons to download route
- Created DocketSeeder with 5 sample docket entries and documents
- Seeded database with test data for development
Features working:
- Email subscription with validation and duplicate checking
- Subscription reactivation for previously unsubscribed emails
- Document download functionality (ready for actual PDFs)
- Sample data for testing UI
Next: Admin dashboard for CRUD operations
This commit is contained in:
parent
80657cc209
commit
06a620406c
5 changed files with 287 additions and 6 deletions
34
app/Http/Controllers/DocumentController.php
Normal file
34
app/Http/Controllers/DocumentController.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Document;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
class DocumentController extends Controller
|
||||
{
|
||||
/**
|
||||
* Download a document by ID.
|
||||
*/
|
||||
public function download(int $id): StreamedResponse
|
||||
{
|
||||
$document = Document::findOrFail($id);
|
||||
|
||||
// Check if file exists
|
||||
if (!Storage::exists($document->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 . '"',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
86
app/Http/Controllers/SubscriptionController.php
Normal file
86
app/Http/Controllers/SubscriptionController.php
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Subscription;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class SubscriptionController extends Controller
|
||||
{
|
||||
/**
|
||||
* Subscribe an email address to notifications.
|
||||
*/
|
||||
public function subscribe(Request $request): JsonResponse
|
||||
{
|
||||
$validator = Validator::make($request->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.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
122
database/seeders/DocketSeeder.php
Normal file
122
database/seeders/DocketSeeder.php
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\DocketEntry;
|
||||
use App\Models\Document;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class DocketSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// Sample docket entries with documents
|
||||
$entries = [
|
||||
[
|
||||
'date' => '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.');
|
||||
}
|
||||
}
|
||||
|
|
@ -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 = '';
|
||||
}, 5000);
|
||||
};
|
||||
</script>
|
||||
|
||||
|
|
@ -152,16 +180,18 @@ const subscribe = async () => {
|
|||
</div>
|
||||
|
||||
<div v-if="entry.documents.length > 0">
|
||||
<button
|
||||
<a
|
||||
v-for="doc in entry.documents"
|
||||
:key="doc.id"
|
||||
:href="`/api/documents/${doc.id}/download`"
|
||||
target="_blank"
|
||||
class="inline-block px-4 py-2 rounded-lg text-white font-semibold mr-2 mb-2 transition-colors"
|
||||
style="background-color: #6b9080;"
|
||||
@mouseover="$event.target.style.backgroundColor = '#5a8070'"
|
||||
@mouseout="$event.target.style.backgroundColor = '#6b9080'"
|
||||
>
|
||||
📄 View PDF
|
||||
</button>
|
||||
📄 {{ doc.title }}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
<?php
|
||||
|
||||
use App\Http\Controllers\DocumentController;
|
||||
use App\Http\Controllers\HomeController;
|
||||
use App\Http\Controllers\ProfileController;
|
||||
use App\Http\Controllers\SubscriptionController;
|
||||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Inertia\Inertia;
|
||||
|
|
@ -9,6 +11,13 @@ use Inertia\Inertia;
|
|||
// Public home page - Court Docket
|
||||
Route::get('/', [HomeController::class, 'index'])->name('home');
|
||||
|
||||
// Subscription API routes
|
||||
Route::post('/api/subscribe', [SubscriptionController::class, 'subscribe'])->name('api.subscribe');
|
||||
Route::get('/api/unsubscribe/{token}', [SubscriptionController::class, 'unsubscribe'])->name('api.unsubscribe');
|
||||
|
||||
// Document download route
|
||||
Route::get('/api/documents/{id}/download', [DocumentController::class, 'download'])->name('api.documents.download');
|
||||
|
||||
Route::get('/dashboard', function () {
|
||||
return Inertia::render('Dashboard');
|
||||
})->middleware(['auth', 'verified'])->name('dashboard');
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue