restructure: flatten workspace nesting, move devcontainer to root
- backend/workspaces/backend/ → backend/ - backend/workspaces/frontend/ → frontend/ - backend/.devcontainer/ + .vscode/ → repo root (where VS Code expects them) - loose scripts/SQL files → scripts/ - replace nested git repo with single repo at project root - update docker-compose.yml build context and devcontainer.json path - add root .gitignore Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
72
frontend/src/routes/+page.server.ts
Normal file
72
frontend/src/routes/+page.server.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
import type { PageServerLoad } from './$types';
|
||||
|
||||
export const load: PageServerLoad = async ({ url, fetch }) => {
|
||||
|
||||
|
||||
// 1. Extract params
|
||||
const q = url.searchParams.get('q') || '';
|
||||
const from = url.searchParams.get('from') || '';
|
||||
const to = url.searchParams.get('to') || '';
|
||||
const senderId = url.searchParams.get('senderId') || '';
|
||||
const receiverId = url.searchParams.get('receiverId') || '';
|
||||
const tags = url.searchParams.getAll('tag') || '';
|
||||
|
||||
|
||||
|
||||
// 2. Build Search URL
|
||||
const searchUrl = new URL('http://localhost:8080/api/documents/search');
|
||||
if (q) searchUrl.searchParams.set('q', q);
|
||||
if (from) searchUrl.searchParams.set('from', from);
|
||||
if (to) searchUrl.searchParams.set('to', to);
|
||||
if (senderId) searchUrl.searchParams.set('senderId', senderId);
|
||||
if (receiverId) searchUrl.searchParams.set('receiverId', receiverId);
|
||||
if(tags) tags.forEach(tag => searchUrl.searchParams.append('tag', tag));
|
||||
|
||||
|
||||
// 3. Build Persons URL (to resolve names for the typeahead initial value)
|
||||
// Ideally, we would have endpoints like /api/persons/{id}, but for now we load the list or search.
|
||||
// To keep it simple and performant enough for now, we fetch all to find the names.
|
||||
const personsUrl = 'http://localhost:8080/api/persons';
|
||||
|
||||
try {
|
||||
const [docsRes, personsRes] = await Promise.all([
|
||||
fetch(searchUrl.toString()),
|
||||
fetch(personsUrl)
|
||||
]);
|
||||
|
||||
if (docsRes.status === 401 || personsRes.status === 401) {
|
||||
throw redirect(302, '/login');
|
||||
}
|
||||
|
||||
const documents = await docsRes.json();
|
||||
const allPersons = await personsRes.json();
|
||||
|
||||
// Resolve Names for the Typeahead Inputs
|
||||
const senderObj = allPersons.find((p: any) => p.id === senderId);
|
||||
const receiverObj = allPersons.find((p: any) => p.id === receiverId);
|
||||
|
||||
const senderName = senderObj ? `${senderObj.firstName} ${senderObj.lastName}` : '';
|
||||
const receiverName = receiverObj ? `${receiverObj.firstName} ${receiverObj.lastName}` : '';
|
||||
|
||||
return {
|
||||
documents,
|
||||
// We don't need to pass the full persons list to the frontend anymore,
|
||||
// as the Typeahead fetches it dynamically. We only pass the resolved names.
|
||||
initialValues: {
|
||||
senderName,
|
||||
receiverName
|
||||
},
|
||||
filters: { q, from, to, senderId, receiverId, tags }
|
||||
};
|
||||
|
||||
} catch (error) {
|
||||
console.error("Error loading data:", error);
|
||||
return {
|
||||
documents: [],
|
||||
initialValues: { senderName: '', receiverName: '' },
|
||||
filters: { q, from, to, senderId, receiverId },
|
||||
error: "Could not load data."
|
||||
};
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user