refactor: introduce domain model classes and mapper layer
Replace ad-hoc inline row casting (snake_case → camelCase) spread across services, routes, and the indexing pipeline with explicit model classes (Repository, IndexingJob, RepositoryVersion, Snippet, SearchResult) and dedicated mapper classes that own the DB → domain conversion. - Add src/lib/server/models/ with typed model classes for all domain entities - Add src/lib/server/mappers/ with mapper classes per entity - Remove duplicated RawRow interfaces and inline map functions from job-queue, repository.service, indexing.pipeline, and all API routes - Add dtoJsonResponse helper to standardise JSON responses via SvelteKit json() - Add api-contract.integration.test.ts as a regression baseline Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import type { RequestHandler } from './$types';
|
||||
import { getClient } from '$lib/server/db/client';
|
||||
import { RepositoryMapper } from '$lib/server/mappers/repository.mapper.js';
|
||||
import { RepositoryService } from '$lib/server/services/repository.service';
|
||||
import { handleServiceError } from '$lib/server/utils/validation';
|
||||
|
||||
@@ -22,8 +23,7 @@ export const GET: RequestHandler = ({ params }) => {
|
||||
return json({ error: 'Repository not found', code: 'NOT_FOUND' }, { status: 404 });
|
||||
}
|
||||
const versions = service.getVersions(id);
|
||||
const { githubToken: _token, ...safeRepo } = repo;
|
||||
return json({ ...safeRepo, versions });
|
||||
return json({ ...RepositoryMapper.toDto(repo), versions });
|
||||
} catch (err) {
|
||||
return handleServiceError(err);
|
||||
}
|
||||
@@ -40,8 +40,7 @@ export const PATCH: RequestHandler = async ({ params, request }) => {
|
||||
branch: body.branch,
|
||||
githubToken: body.githubToken
|
||||
});
|
||||
const { githubToken: _token, ...safeUpdated } = updated;
|
||||
return json(safeUpdated);
|
||||
return json(RepositoryMapper.toDto(updated));
|
||||
} catch (err) {
|
||||
return handleServiceError(err);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user