refactor: tidy structure of source files

Fixes #79
This commit is contained in:
Karl-Philipp Wulfert
2019-06-19 15:04:59 +02:00
parent 5de9bf3794
commit ceab7cc7ef
99 changed files with 1395 additions and 1511 deletions

View File

@@ -0,0 +1,45 @@
/*
* Copyright (C) 2019 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {SCThingsField} from '../../meta';
/**
* A search facet
*/
export interface SCFacet {
/**
* Buckets for the aggregation
*/
buckets: SCFacetBucket[];
/**
* Field of the aggregation
*/
field: SCThingsField;
}
/**
* A bucket of a facet
*/
export interface SCFacetBucket {
/**
* Count of matching search results
*/
count: number;
/**
* Key of a bucket
*/
key: string;
}

View File

@@ -0,0 +1,60 @@
/*
* Copyright (C) 2019 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {SCMap} from '../../general/map';
/**
* All available filter types
*/
import {SCSearchAvailabilityFilter} from './filters/availability';
import {SCSearchBooleanFilter} from './filters/boolean';
import {SCSearchDistanceFilter} from './filters/distance';
import {SCSearchValueFilter} from './filters/value';
/**
* Filter instruction types
*/
export type SCSearchFilterType =
'availability'
| 'boolean'
| 'distance'
| 'value';
/**
* Structure of a filter instruction
*/
export interface SCSearchAbstractFilter<T extends SCSearchAbstractFilterArguments> {
/**
* Arguments of filter
*/
arguments: T;
/**
* Type of filter
*/
type: SCSearchFilterType;
}
/**
* Arguments for the filter instruction
*/
export type SCSearchAbstractFilterArguments = SCMap<unknown>;
/**
* Available filter instructions
*/
export type SCSearchFilter =
SCSearchAvailabilityFilter
| SCSearchBooleanFilter
| SCSearchDistanceFilter
| SCSearchValueFilter;

View File

@@ -0,0 +1,49 @@
/*
* Copyright (C) 2019 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {SCISO8601Date} from '../../../general/time';
import {SCThingsField} from '../../../meta';
import {SCSearchAbstractFilter, SCSearchAbstractFilterArguments} from '../filter';
/**
* An availability filter
*
* Filter for documents where it cannot be safely determined that they are not available
*/
export interface SCSearchAvailabilityFilter extends SCSearchAbstractFilter<SCAvailabilityFilterArguments> {
/**
* @see SCSearchAbstractFilter.type
*/
type: 'availability';
}
/**
* Arguments for filter instruction by availability
*/
export interface SCAvailabilityFilterArguments extends SCSearchAbstractFilterArguments {
/**
* Field which marks the start of the availability
*/
fromField: SCThingsField;
/**
* Time to check. Defaults to 'now'
*/
time?: SCISO8601Date | 'now';
/**
* Field which marks the end of the availability
*/
toField: SCThingsField;
}

View File

@@ -0,0 +1,42 @@
/*
* Copyright (C) 2019 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {SCSearchAbstractFilter, SCSearchAbstractFilterArguments, SCSearchFilter} from '../filter';
/**
* A boolean filter
*
* This filter can be used to combine multiple filters with boolean operations.
*/
export interface SCSearchBooleanFilter extends SCSearchAbstractFilter<SCBooleanFilterArguments> {
/**
* @see SCSearchAbstractFilter.type
*/
type: 'boolean';
}
/**
* Additional arguments for boolean filters
*/
export interface SCBooleanFilterArguments extends SCSearchAbstractFilterArguments {
/**
* A list of filter to apply the boolean operation to
*/
filters: SCSearchFilter[];
/**
* Boolean operation to apply to the filters
*/
operation: 'and' | 'not' | 'or';
}

View File

@@ -0,0 +1,50 @@
/*
* Copyright (C) 2019 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
// tslint:disable-next-line:no-implicit-dependencies
import {Position} from 'geojson';
import {SCThingsField} from '../../../meta';
import {SCSearchAbstractFilter, SCSearchAbstractFilterArguments} from '../filter';
/**
* A distance filter
*
* Filter for documents that are in the given distance of the given location
*/
export interface SCSearchDistanceFilter extends SCSearchAbstractFilter<SCSearchAbstractFilterArguments> {
/**
* @see SCSearchAbstractFilter.type
*/
type: 'distance';
}
/**
* Additional arguments for distance filters
*/
export interface SCDistanceFilterArguments extends SCSearchAbstractFilterArguments {
/**
* Distance in meters to filter from given location
*/
distance: number;
/**
* Field which contains the location you want to filter
*/
field: SCThingsField;
/**
* Position to calculate the distance to
*/
position: Position;
}

View File

@@ -0,0 +1,38 @@
/*
* Copyright (C) 2019 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {SCThingsField} from '../../../meta';
import {SCSearchAbstractFilter, SCSearchAbstractFilterArguments} from '../filter';
/**
* Filters for documents that match the value on the given field
*/
export interface SCSearchValueFilter extends SCSearchAbstractFilter<SCValueFilterArguments> {
/**
* @see SCSearchAbstractFilter.type
*/
type: 'value';
}
export interface SCValueFilterArguments extends SCSearchAbstractFilterArguments {
/**
* Field to filter for a value.
*/
field: SCThingsField;
/**
* Value to filter. Value has to match the field exactly.
*/
value: string;
}

View File

@@ -0,0 +1,52 @@
/*
* Copyright (C) 2019 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {SCSearchContext} from '../../config/backend';
import {SCSearchFilter} from './filter';
import {SCSearchSort} from './sort';
/**
* A search query
*/
export interface SCSearchQuery {
/**
* The context name from where the search query was initiated
*/
context?: SCSearchContext;
/**
* A filter structure that combines any number of filters with boolean methods ('AND', 'OR', 'NOT')
*/
filter?: SCSearchFilter;
/**
* Number of things to skip in result set (paging)
*/
from?: number;
/**
* A term to search for
*/
query?: string;
/**
* Number of things to have in the result set (paging)
*/
size?: number;
/**
* A list of sorting parameters to order the result set by
*/
sort?: SCSearchSort[];
}

View File

@@ -0,0 +1,71 @@
/*
* Copyright (C) 2019 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {SCThings} from '../../meta';
import {SCFacet} from './facet';
/**
* A search response
*/
export interface SCSearchResult {
/**
* Data (any data object)
*/
data: SCThings[];
/**
* Facets (aggregations over all matching data)
*/
facets: SCFacet[];
/**
* Pagination information
*/
pagination: SCSearchResultPagination;
/**
* Stats of the search engine
*/
stats: SCSearchResultSearchEngineStats;
}
/**
* Stores information about Pagination
*/
export interface SCSearchResultPagination {
/**
* Count of given data. Same as data.length
*/
count: number;
/**
* Offset of data on all matching data. Given by [[SCSearchQuery.from]]
*/
offset: number;
/**
* Number of total matching data
*/
total: number;
}
/**
* Statistics of search engine
*/
export interface SCSearchResultSearchEngineStats {
/**
* Response time of the search engine in ms
*/
time: number;
}

View File

@@ -0,0 +1,59 @@
/*
* Copyright (C) 2019 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {SCMap} from '../../general/map';
import {SCThingsField} from '../../meta';
import {SCDistanceSort} from './sorts/distance';
import {SCDucetSort} from './sorts/ducet';
import {SCPriceSort} from './sorts/price';
/**
* Abstract sort instruction
*/
export interface SCSearchAbstractSort<T extends SCSearchAbstractSortArguments> {
/**
* Map of arguments for the sort instruction
*/
arguments: T;
/**
* Direction of the sort instruction: `asc`ending or `desc`ending.
*/
order: 'asc' | 'desc';
/**
* Type of the sort instruction
*/
type: SCSearchSortType;
}
/**
* Map of arguments for the sort instruction
*/
export interface SCSearchAbstractSortArguments extends SCMap<unknown> {
/**
* Field to sort by
*/
field: SCThingsField;
}
/**
* Type of a sort instruction
*/
export type SCSearchSortType = 'distance' | 'price' | 'ducet';
/**
* A sort instruction
*/
export type SCSearchSort = SCDistanceSort | SCPriceSort | SCDucetSort;

View File

@@ -0,0 +1,37 @@
/*
* Copyright (C) 2019 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
// tslint:disable-next-line:no-implicit-dependencies
import {Position} from 'geojson';
import {SCSearchAbstractSort, SCSearchAbstractSortArguments} from '../sort';
/**
* Sort instruction to sort by distance
*/
export interface SCDistanceSort extends SCSearchAbstractSort<SCDistanceSortArguments> {
/**
* @see SCSearchAbstractSort.type
*/
type: 'distance';
}
/**
* Additional arguments for sort instruction to sort by distance
*/
export interface SCDistanceSortArguments extends SCSearchAbstractSortArguments {
/**
* Position to calculate distances to
*/
position: Position;
}

View File

@@ -0,0 +1,25 @@
/*
* Copyright (C) 2019 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {SCSearchAbstractSort, SCSearchAbstractSortArguments} from '../sort';
/**
* Sort instruction for ducet sort
*/
export interface SCDucetSort extends SCSearchAbstractSort<SCSearchAbstractSortArguments> {
/**
* @see SCSearchAbstractSort.type
*/
type: 'ducet';
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright (C) 2019 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {SCSportCoursePriceGroup} from '../../../things/date-series';
import {SCSearchAbstractSort, SCSearchAbstractSortArguments} from '../sort';
/**
* Sort instruction to sort by price
*/
export interface SCPriceSort extends SCSearchAbstractSort<SCPriceSortArguments> {
/**
* @see SCSearchAbstractSort.type
*/
type: 'price';
}
/**
* Additional arguments for sort instruction to sort by price
*/
export interface SCPriceSortArguments extends SCSearchAbstractSortArguments {
/**
* University role to sort price for
*/
universityRole: keyof SCSportCoursePriceGroup;
}