Some data handling changes

This commit is contained in:
mProjectsCode 2022-05-04 20:01:06 +02:00
parent 96d74a7732
commit c67a0bf590
12 changed files with 66 additions and 39 deletions

View file

@ -1,5 +1,5 @@
import {APIModel} from './APIModel';
import {APIRequestResult} from './APIRequestResult';
import {MediaTypeModel} from '../models/MediaTypeModel';
export class APIManager {
apis: APIModel[];
@ -8,10 +8,10 @@ export class APIManager {
this.apis = [];
}
async query(query: string, types: string[] = []): Promise<APIRequestResult[]> {
async query(query: string, types: string[] = []): Promise<MediaTypeModel[]> {
console.log('MDB | api manager queried');
let res: APIRequestResult[] = [];
let res: MediaTypeModel[] = [];
for (const api of this.apis) {
if (types.length === 0 || api.hasTypeOverlap(types)) {

View file

@ -1,7 +1,8 @@
import {APIRequestResult} from './APIRequestResult';
import {MediaTypeModel} from '../models/MediaTypeModel';
export abstract class APIModel {
name: string;
apiName: string;
apiUrl: string;
types: string[];
/**
@ -9,14 +10,7 @@ export abstract class APIModel {
*
* @param title the title to query for
*/
abstract getByTitle(title: string): Promise<APIRequestResult[]>;
/**
* This function should return the metadata corresponding to the api result. An implementation should check first, if the result is from this api.
*
* @param item
*/
abstract getMataDataFromResult(item: APIRequestResult): string;
abstract getByTitle(title: string): Promise<MediaTypeModel[]>;
hasType(type: string): boolean {
return this.types.contains(type);

View file

@ -1,7 +0,0 @@
export interface APIRequestResult {
title: string,
type: string,
description?: string,
apiName: string,
data: any,
}

View file

@ -1,24 +1,25 @@
import {APIModel} from '../APIModel';
import {APIRequestResult} from '../APIRequestResult';
import {MediaTypeModel} from '../../models/MediaTypeModel';
export class TestAPI extends APIModel {
constructor() {
super();
this.name = 'testAPI';
this.apiName = 'testAPI';
this.apiUrl = 'www.test.api';
this.types = ['test'];
}
async getByTitle(title: string): Promise<APIRequestResult[]> {
console.log(`MDB | api "${this.name}" queried`);
async getByTitle(title: string): Promise<MediaTypeModel[]> {
console.log(`MDB | api "${this.apiName}" queried`);
return [
{title: 'test1', type: this.types[0], apiName: this.name, data: {length: 126}} as APIRequestResult,
{title: 'test2', type: this.types[0], apiName: this.name, description: 'some test description', data: {}} as APIRequestResult,
{title: 'test1', type: this.types[0], dataSource: this.apiName} as MediaTypeModel,
{title: 'test2', type: this.types[0], dataSource: this.apiName} as MediaTypeModel,
];
}
getMataDataFromResult(item: APIRequestResult): string {
if (item.apiName !== this.name) {
getMataDataFromResult(item: MediaTypeModel): string {
if (item.dataSource !== this.apiUrl) {
return '';
}