diff --git a/docs/mammon-api.yml b/docs/mammon-api.yml index fea33a0..f71bca7 100644 --- a/docs/mammon-api.yml +++ b/docs/mammon-api.yml @@ -480,6 +480,42 @@ paths: Returned when: - the ids parameter is missing - an ids value is not a numeric id + /market/types/search: + get: + tags: + - market + summary: "Search marketable types whose name contains the given text, case-insensitively" + operationId: searchTypes + parameters: + - name: name + in: query + description: "Text to match against the type name, e.g. name=tritan" + required: true + schema: + type: string + - name: limit + in: query + description: "Maximum number of results to return, defaults to 50" + required: false + schema: + type: integer + format: int32 + default: 50 + responses: + "200": + description: "The marketable types matching the search, ordered by name\ + \ and capped at the requested limit" + content: + '*/*': + schema: + type: array + items: + $ref: "#/components/schemas/MarketTypeResponse" + "400": + description: |- + Returned when: + - the name parameter is missing + - the limit value is not a number /market/scan: get: tags: diff --git a/src/generated/mammon/api.ts b/src/generated/mammon/api.ts index ec97949..44b96ad 100644 --- a/src/generated/mammon/api.ts +++ b/src/generated/mammon/api.ts @@ -1490,6 +1490,48 @@ export const MarketApiAxiosParamCreator = function (configuration?: Configuratio let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * + * @summary Search marketable types whose name contains the given text, case-insensitively + * @param {string} name Text to match against the type name, e.g. name=tritan + * @param {number} [limit] Maximum number of results to return, defaults to 50 + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + searchTypes: async (name: string, limit?: number, options: RawAxiosRequestConfig = {}): Promise => { + // verify required parameter 'name' is not null or undefined + assertParamExists('searchTypes', 'name', name) + const localVarPath = `/market/types/search`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + if (name !== undefined) { + localVarQueryParameter['name'] = name; + } + + if (limit !== undefined) { + localVarQueryParameter['limit'] = limit; + } + + localVarHeaderParameter['Accept'] = '*/*'; + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + return { url: toPathString(localVarUrlObj), options: localVarRequestOptions, @@ -1575,6 +1617,20 @@ export const MarketApiFp = function(configuration?: Configuration) { const localVarOperationServerBasePath = operationServerMap['MarketApi.scanMarketType']?.[localVarOperationServerIndex]?.url; return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); }, + /** + * + * @summary Search marketable types whose name contains the given text, case-insensitively + * @param {string} name Text to match against the type name, e.g. name=tritan + * @param {number} [limit] Maximum number of results to return, defaults to 50 + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async searchTypes(name: string, limit?: number, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise>> { + const localVarAxiosArgs = await localVarAxiosParamCreator.searchTypes(name, limit, options); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = operationServerMap['MarketApi.searchTypes']?.[localVarOperationServerIndex]?.url; + return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); + }, } }; @@ -1640,6 +1696,17 @@ export const MarketApiFactory = function (configuration?: Configuration, basePat scanMarketType(marketTypeId: number, days?: number, brokerFee?: number, salesTax?: number, options?: RawAxiosRequestConfig): AxiosPromise { return localVarFp.scanMarketType(marketTypeId, days, brokerFee, salesTax, options).then((request) => request(axios, basePath)); }, + /** + * + * @summary Search marketable types whose name contains the given text, case-insensitively + * @param {string} name Text to match against the type name, e.g. name=tritan + * @param {number} [limit] Maximum number of results to return, defaults to 50 + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + searchTypes(name: string, limit?: number, options?: RawAxiosRequestConfig): AxiosPromise> { + return localVarFp.searchTypes(name, limit, options).then((request) => request(axios, basePath)); + }, }; }; @@ -1707,6 +1774,18 @@ export class MarketApi extends BaseAPI { public scanMarketType(marketTypeId: number, days?: number, brokerFee?: number, salesTax?: number, options?: RawAxiosRequestConfig) { return MarketApiFp(this.configuration).scanMarketType(marketTypeId, days, brokerFee, salesTax, options).then((request) => request(this.axios, this.basePath)); } + + /** + * + * @summary Search marketable types whose name contains the given text, case-insensitively + * @param {string} name Text to match against the type name, e.g. name=tritan + * @param {number} [limit] Maximum number of results to return, defaults to 50 + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + public searchTypes(name: string, limit?: number, options?: RawAxiosRequestConfig) { + return MarketApiFp(this.configuration).searchTypes(name, limit, options).then((request) => request(this.axios, this.basePath)); + } } diff --git a/src/market/type/MarketType.ts b/src/market/type/MarketType.ts index bbd8505..62f3173 100644 --- a/src/market/type/MarketType.ts +++ b/src/market/type/MarketType.ts @@ -30,6 +30,11 @@ export const getMarketTypes = async (types: (string | number)[]): Promise cache.get(id)).filter((t): t is MarketType => t !== undefined); } -export const searchMarketTypes = async (_search: string): Promise => { - return [] +export const searchMarketTypes = async (search: string): Promise => { + if (search.length === 0) { + return []; + } + const types = await marketApi.searchTypes(search).then(r => r.data); + types.forEach(t => cache.set(t.id, t)); + return types; } \ No newline at end of file