mirror of
https://github.com/SamyRai/tercul-frontend.git
synced 2025-12-27 00:11:35 +00:00
Add capabilities to store and retrieve user content and analysis data
Implements data access methods for analysis results and annotations in JsonStorage, including get, filter, and create operations. Replit-Commit-Author: Agent Replit-Commit-Session-Id: cbacfb18-842a-4116-a907-18c0105ad8ec Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/39b5c689-6e8a-4d5a-9792-69cc81a56534/80f57837-9ae3-42b7-8c9f-0582d861d96f.jpg
This commit is contained in:
parent
fc3a941647
commit
d67963de51
@ -851,4 +851,72 @@ export class JsonStorage implements IStorage {
|
||||
|
||||
return filteredWorks;
|
||||
}
|
||||
|
||||
// Analysis methods
|
||||
async getAnalysisResultsByWorkId(workId: number): Promise<AnalysisResult[]> {
|
||||
return Array.from(this.data.analysisResults.values()).filter(
|
||||
result => result.workId === workId
|
||||
);
|
||||
}
|
||||
|
||||
async getAnalysisResultById(id: number): Promise<AnalysisResult | undefined> {
|
||||
return this.data.analysisResults.get(id);
|
||||
}
|
||||
|
||||
async getAnalysisResultByWorkAndType(workId: number, type: string): Promise<AnalysisResult | undefined> {
|
||||
return Array.from(this.data.analysisResults.values()).find(
|
||||
result => result.workId === workId && result.type === type
|
||||
);
|
||||
}
|
||||
|
||||
async createAnalysisResult(insertResult: InsertAnalysisResult): Promise<AnalysisResult> {
|
||||
const id = this.counters.analysisResultId++;
|
||||
const now = new Date();
|
||||
const result: AnalysisResult = {
|
||||
...insertResult,
|
||||
id,
|
||||
createdAt: now
|
||||
};
|
||||
this.data.analysisResults.set(id, result);
|
||||
this.saveDataToFile();
|
||||
return result;
|
||||
}
|
||||
|
||||
// Annotation methods
|
||||
async getAnnotationsByWorkId(workId: number): Promise<Annotation[]> {
|
||||
return Array.from(this.data.annotations.values()).filter(
|
||||
annotation => annotation.workId === workId
|
||||
);
|
||||
}
|
||||
|
||||
async getAnnotationsByTranslationId(translationId: number): Promise<Annotation[]> {
|
||||
return Array.from(this.data.annotations.values()).filter(
|
||||
annotation => annotation.translationId === translationId
|
||||
);
|
||||
}
|
||||
|
||||
async getAnnotationsByLine(workId: number, lineNumber: number, translationId?: number): Promise<Annotation[]> {
|
||||
return Array.from(this.data.annotations.values()).filter(
|
||||
annotation => annotation.workId === workId &&
|
||||
annotation.lineNumber === lineNumber &&
|
||||
(translationId === undefined || annotation.translationId === translationId)
|
||||
);
|
||||
}
|
||||
|
||||
async getAnnotationById(id: number): Promise<Annotation | undefined> {
|
||||
return this.data.annotations.get(id);
|
||||
}
|
||||
|
||||
async createAnnotation(insertAnnotation: InsertAnnotation): Promise<Annotation> {
|
||||
const id = this.counters.annotationId++;
|
||||
const now = new Date();
|
||||
const annotation: Annotation = {
|
||||
...insertAnnotation,
|
||||
id,
|
||||
createdAt: now
|
||||
};
|
||||
this.data.annotations.set(id, annotation);
|
||||
this.saveDataToFile();
|
||||
return annotation;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user