feat(document-service): Unterstützung für die Abfrage von Dokumenten nach Attributen hinzugefügt

- Erforderlich für `DocAttribute.serilizedValue`.
- Erweitert `DocQuery` mit optionalem `attributes` Feld.
- Aktualisiert `getDocuments` um nach Attribut-Schlüssel-Wert-Paaren zu filtern.
- Hilfsfunktion `getDocumentByAttributes` hinzugefügt.
This commit is contained in:
tekh 2025-07-16 13:32:57 +02:00
parent bbb55e9746
commit c022b96a12
2 changed files with 14 additions and 4 deletions

View File

@ -7,8 +7,8 @@ import Typography from '@mui/material/Typography';
import Pagination from '@mui/material/Pagination';
import { DashboardContent } from 'src/layouts/dashboard';
import { Doc, getDocuments } from 'src/services/document-service';
import { Attribute, getAttributes } from 'src/services/attribute-service';
import { Doc, getDocumentByAttributes, getDocuments } from 'src/services/document-service';
import { Iconify } from 'src/components/iconify';
@ -49,7 +49,7 @@ export function DocSearchView() {
const [attributes, setAttributes] = useState<Record<string, string>>({});
useEffect(() => {
console.log(attributes);
getDocumentByAttributes(attributes).then(setDocs);
}, [attributes]);
function setAttribute(name: string, serilizedValue: string) {

View File

@ -24,7 +24,7 @@ const validExtensions: FileFormat[] = [
type DocAttribute = {
name: string;
serilizedValue?: string;
serilizedValue: string;
}
export class Doc {
@ -73,7 +73,8 @@ export class Doc {
export type DocQuery = {
id?: number | undefined,
name?: string | undefined
name?: string | undefined,
attributes?: Record<string, string>
}
export function getDocuments(query: DocQuery | undefined = undefined): Promise<Doc[]> {
@ -85,6 +86,11 @@ export function getDocuments(query: DocQuery | undefined = undefined): Promise<D
if (query?.name)
documents = documents.filter(d => d.name === query.name);
for (const name in query?.attributes) {
const attr = query.attributes[name];
documents = documents.filter(d => d.attributes.find(a => a.name === name)?.serilizedValue.toLowerCase().includes(attr.toLowerCase()));
}
return Promise.resolve(documents);
}
@ -95,3 +101,7 @@ export function getDocumentById(id: number): Promise<Doc[]> {
export function getDocumentByName(name: string): Promise<Doc[]> {
return getDocuments({ name: name });
}
export function getDocumentByAttributes(attributes: Record<string, string>): Promise<Doc[]> {
return getDocuments({ attributes: attributes });
}