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:
36
src/lib/server/mappers/indexing-job.mapper.ts
Normal file
36
src/lib/server/mappers/indexing-job.mapper.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { IndexingJob, IndexingJobDto, IndexingJobEntity } from '$lib/server/models/indexing-job.js';
|
||||
|
||||
export class IndexingJobMapper {
|
||||
static fromEntity(entity: IndexingJobEntity): IndexingJob {
|
||||
return new IndexingJob({
|
||||
id: entity.id,
|
||||
repositoryId: entity.repository_id,
|
||||
versionId: entity.version_id,
|
||||
status: entity.status,
|
||||
progress: entity.progress,
|
||||
totalFiles: entity.total_files,
|
||||
processedFiles: entity.processed_files,
|
||||
error: entity.error,
|
||||
startedAt: entity.started_at != null ? new Date(entity.started_at * 1000) : null,
|
||||
completedAt:
|
||||
entity.completed_at != null ? new Date(entity.completed_at * 1000) : null,
|
||||
createdAt: new Date(entity.created_at * 1000)
|
||||
});
|
||||
}
|
||||
|
||||
static toDto(domain: IndexingJob): IndexingJobDto {
|
||||
return new IndexingJobDto({
|
||||
id: domain.id,
|
||||
repositoryId: domain.repositoryId,
|
||||
versionId: domain.versionId,
|
||||
status: domain.status,
|
||||
progress: domain.progress,
|
||||
totalFiles: domain.totalFiles,
|
||||
processedFiles: domain.processedFiles,
|
||||
error: domain.error,
|
||||
startedAt: domain.startedAt,
|
||||
completedAt: domain.completedAt,
|
||||
createdAt: domain.createdAt
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user