diff --git a/client/src/generated/.openapi-generator/FILES b/client/src/generated/.openapi-generator/FILES index 5b49a97d..565ce88f 100644 --- a/client/src/generated/.openapi-generator/FILES +++ b/client/src/generated/.openapi-generator/FILES @@ -10,6 +10,7 @@ api/get-instrument-by-id-api.ts api/get-instrument-types-api.ts api/get-instruments-by-criteria-api.ts api/get-instruments-by-criteria-paginated-api.ts +api/get-manufacturers-api.ts api/get-user-profile-api.ts api/list-favorite-api.ts api/remove-favorite-api.ts @@ -28,12 +29,14 @@ model/get-instrument-by-criteria-page-response.ts model/get-instrument-criteria-request-body.ts model/get-instrument-types-response.ts model/get-instruments-by-criteria-response.ts +model/get-manufacturers-response.ts model/index.ts model/instrument-basic-material.ts model/instrument-detail.ts model/instrument-type.ts model/jwt-response.ts model/list-favorite-response-body.ts +model/manufacturer.ts model/profile-details.ts model/registration-request.ts model/remove-favorite-request-body.ts diff --git a/client/src/generated/api.ts b/client/src/generated/api.ts index 64ccc888..69e46d44 100644 --- a/client/src/generated/api.ts +++ b/client/src/generated/api.ts @@ -21,6 +21,7 @@ export * from "./api/get-instrument-by-id-api"; export * from "./api/get-instrument-types-api"; export * from "./api/get-instruments-by-criteria-api"; export * from "./api/get-instruments-by-criteria-paginated-api"; +export * from "./api/get-manufacturers-api"; export * from "./api/get-user-profile-api"; export * from "./api/list-favorite-api"; export * from "./api/remove-favorite-api"; diff --git a/client/src/generated/api/get-countries-api.ts b/client/src/generated/api/get-countries-api.ts new file mode 100644 index 00000000..343b9bbf --- /dev/null +++ b/client/src/generated/api/get-countries-api.ts @@ -0,0 +1,183 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Client Error + * Client Error + * + * The version of the OpenAPI document: 1.0.0 + * Contact: baskirill.an@gmail.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import type { Configuration } from "../configuration"; +import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from "axios"; +import globalAxios from "axios"; +// Some imports not used depending on template conditions +// @ts-ignore +import { + DUMMY_BASE_URL, + assertParamExists, + setApiKeyToObject, + setBasicAuthToObject, + setBearerAuthToObject, + setOAuthToObject, + setSearchParams, + serializeDataIfNeeded, + toPathString, + createRequestFunction, +} from "../common"; +// @ts-ignore +import { + BASE_PATH, + COLLECTION_FORMATS, + type RequestArgs, + BaseAPI, + RequiredError, + operationServerMap, +} from "../base"; +// @ts-ignore +import type { ClientError } from "../model"; +// @ts-ignore +import type { GetCountriesResponse } from "../model"; +// @ts-ignore +import type { ServerError } from "../model"; +/** + * GetCountriesApi - axios parameter creator + * @export + */ +export const GetCountriesApiAxiosParamCreator = function ( + configuration?: Configuration, +) { + return { + /** + * Get Countries + * @summary Get Countries + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getCountries: async ( + options: RawAxiosRequestConfig = {}, + ): Promise => { + const localVarPath = `/countries`; + // 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; + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = + baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = { + ...localVarHeaderParameter, + ...headersFromBaseOptions, + ...options.headers, + }; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + }; +}; + +/** + * GetCountriesApi - functional programming interface + * @export + */ +export const GetCountriesApiFp = function (configuration?: Configuration) { + const localVarAxiosParamCreator = + GetCountriesApiAxiosParamCreator(configuration); + return { + /** + * Get Countries + * @summary Get Countries + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async getCountries( + options?: RawAxiosRequestConfig, + ): Promise< + ( + axios?: AxiosInstance, + basePath?: string, + ) => AxiosPromise + > { + const localVarAxiosArgs = + await localVarAxiosParamCreator.getCountries(options); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = + operationServerMap["GetCountriesApi.getCountries"]?.[ + localVarOperationServerIndex + ]?.url; + return (axios, basePath) => + createRequestFunction( + localVarAxiosArgs, + globalAxios, + BASE_PATH, + configuration, + )(axios, localVarOperationServerBasePath || basePath); + }, + }; +}; + +/** + * GetCountriesApi - factory interface + * @export + */ +export const GetCountriesApiFactory = function ( + configuration?: Configuration, + basePath?: string, + axios?: AxiosInstance, +) { + const localVarFp = GetCountriesApiFp(configuration); + return { + /** + * Get Countries + * @summary Get Countries + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getCountries( + options?: RawAxiosRequestConfig, + ): AxiosPromise { + return localVarFp + .getCountries(options) + .then((request) => request(axios, basePath)); + }, + }; +}; + +/** + * GetCountriesApi - object-oriented interface + * @export + * @class GetCountriesApi + * @extends {BaseAPI} + */ +export class GetCountriesApi extends BaseAPI { + /** + * Get Countries + * @summary Get Countries + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof GetCountriesApi + */ + public getCountries(options?: RawAxiosRequestConfig) { + return GetCountriesApiFp(this.configuration) + .getCountries(options) + .then((request) => request(this.axios, this.basePath)); + } +} diff --git a/client/src/generated/api/get-manufacturers-api.ts b/client/src/generated/api/get-manufacturers-api.ts new file mode 100644 index 00000000..4e347e06 --- /dev/null +++ b/client/src/generated/api/get-manufacturers-api.ts @@ -0,0 +1,183 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Client Error + * Client Error + * + * The version of the OpenAPI document: 1.0.0 + * Contact: baskirill.an@gmail.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import type { Configuration } from "../configuration"; +import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from "axios"; +import globalAxios from "axios"; +// Some imports not used depending on template conditions +// @ts-ignore +import { + DUMMY_BASE_URL, + assertParamExists, + setApiKeyToObject, + setBasicAuthToObject, + setBearerAuthToObject, + setOAuthToObject, + setSearchParams, + serializeDataIfNeeded, + toPathString, + createRequestFunction, +} from "../common"; +// @ts-ignore +import { + BASE_PATH, + COLLECTION_FORMATS, + type RequestArgs, + BaseAPI, + RequiredError, + operationServerMap, +} from "../base"; +// @ts-ignore +import type { ClientError } from "../model"; +// @ts-ignore +import type { GetManufacturersResponse } from "../model"; +// @ts-ignore +import type { ServerError } from "../model"; +/** + * GetManufacturersApi - axios parameter creator + * @export + */ +export const GetManufacturersApiAxiosParamCreator = function ( + configuration?: Configuration, +) { + return { + /** + * Get Manufacturers + * @summary Get Manufacturers + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getManufacturers: async ( + options: RawAxiosRequestConfig = {}, + ): Promise => { + const localVarPath = `/manufacturer`; + // 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; + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = + baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = { + ...localVarHeaderParameter, + ...headersFromBaseOptions, + ...options.headers, + }; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + }; +}; + +/** + * GetManufacturersApi - functional programming interface + * @export + */ +export const GetManufacturersApiFp = function (configuration?: Configuration) { + const localVarAxiosParamCreator = + GetManufacturersApiAxiosParamCreator(configuration); + return { + /** + * Get Manufacturers + * @summary Get Manufacturers + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async getManufacturers( + options?: RawAxiosRequestConfig, + ): Promise< + ( + axios?: AxiosInstance, + basePath?: string, + ) => AxiosPromise + > { + const localVarAxiosArgs = + await localVarAxiosParamCreator.getManufacturers(options); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = + operationServerMap["GetManufacturersApi.getManufacturers"]?.[ + localVarOperationServerIndex + ]?.url; + return (axios, basePath) => + createRequestFunction( + localVarAxiosArgs, + globalAxios, + BASE_PATH, + configuration, + )(axios, localVarOperationServerBasePath || basePath); + }, + }; +}; + +/** + * GetManufacturersApi - factory interface + * @export + */ +export const GetManufacturersApiFactory = function ( + configuration?: Configuration, + basePath?: string, + axios?: AxiosInstance, +) { + const localVarFp = GetManufacturersApiFp(configuration); + return { + /** + * Get Manufacturers + * @summary Get Manufacturers + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getManufacturers( + options?: RawAxiosRequestConfig, + ): AxiosPromise { + return localVarFp + .getManufacturers(options) + .then((request) => request(axios, basePath)); + }, + }; +}; + +/** + * GetManufacturersApi - object-oriented interface + * @export + * @class GetManufacturersApi + * @extends {BaseAPI} + */ +export class GetManufacturersApi extends BaseAPI { + /** + * Get Manufacturers + * @summary Get Manufacturers + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof GetManufacturersApi + */ + public getManufacturers(options?: RawAxiosRequestConfig) { + return GetManufacturersApiFp(this.configuration) + .getManufacturers(options) + .then((request) => request(this.axios, this.basePath)); + } +} diff --git a/client/src/generated/model/country.ts b/client/src/generated/model/country.ts new file mode 100644 index 00000000..2262d098 --- /dev/null +++ b/client/src/generated/model/country.ts @@ -0,0 +1,27 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Client Error + * Client Error + * + * The version of the OpenAPI document: 1.0.0 + * Contact: baskirill.an@gmail.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +/** + * + * @export + * @interface Country + */ +export interface Country { + /** + * + * @type {string} + * @memberof Country + */ + country: string; +} diff --git a/client/src/generated/model/get-countries-response.ts b/client/src/generated/model/get-countries-response.ts new file mode 100644 index 00000000..b54397fb --- /dev/null +++ b/client/src/generated/model/get-countries-response.ts @@ -0,0 +1,31 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Client Error + * Client Error + * + * The version of the OpenAPI document: 1.0.0 + * Contact: baskirill.an@gmail.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +// May contain unused imports in some cases +// @ts-ignore +import type { Country } from "./country"; + +/** + * + * @export + * @interface GetCountriesResponse + */ +export interface GetCountriesResponse { + /** + * + * @type {Array} + * @memberof GetCountriesResponse + */ + content: Array; +} diff --git a/client/src/generated/model/get-manufacturers-response.ts b/client/src/generated/model/get-manufacturers-response.ts new file mode 100644 index 00000000..4b09ba2d --- /dev/null +++ b/client/src/generated/model/get-manufacturers-response.ts @@ -0,0 +1,31 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Client Error + * Client Error + * + * The version of the OpenAPI document: 1.0.0 + * Contact: baskirill.an@gmail.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +// May contain unused imports in some cases +// @ts-ignore +import type { Manufacturer } from "./manufacturer"; + +/** + * + * @export + * @interface GetManufacturersResponse + */ +export interface GetManufacturersResponse { + /** + * + * @type {Array} + * @memberof GetManufacturersResponse + */ + content: Array; +} diff --git a/client/src/generated/model/index.ts b/client/src/generated/model/index.ts index ca0abc96..aa0b9e8d 100644 --- a/client/src/generated/model/index.ts +++ b/client/src/generated/model/index.ts @@ -7,11 +7,13 @@ export * from "./get-instrument-by-criteria-page-response"; export * from "./get-instrument-criteria-request-body"; export * from "./get-instrument-types-response"; export * from "./get-instruments-by-criteria-response"; +export * from "./get-manufacturers-response"; export * from "./instrument-basic-material"; export * from "./instrument-detail"; export * from "./instrument-type"; export * from "./jwt-response"; export * from "./list-favorite-response-body"; +export * from "./manufacturer"; export * from "./profile-details"; export * from "./registration-request"; export * from "./remove-favorite-request-body"; diff --git a/client/src/generated/model/manufacturer.ts b/client/src/generated/model/manufacturer.ts new file mode 100644 index 00000000..2dadc54d --- /dev/null +++ b/client/src/generated/model/manufacturer.ts @@ -0,0 +1,27 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Client Error + * Client Error + * + * The version of the OpenAPI document: 1.0.0 + * Contact: baskirill.an@gmail.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +/** + * + * @export + * @interface Manufacturer + */ +export interface Manufacturer { + /** + * + * @type {string} + * @memberof Manufacturer + */ + manufacturer: string; +} diff --git a/client/src/pages/create-instrument/api/loader.ts b/client/src/pages/create-instrument/api/loader.ts index c934acf2..6a3a4907 100644 --- a/client/src/pages/create-instrument/api/loader.ts +++ b/client/src/pages/create-instrument/api/loader.ts @@ -1,24 +1,23 @@ import { LoaderFunction } from "react-router-dom"; -import { SERVER_URL } from "shared/config"; -import { API_MANUFACTURERS } from "shared/config/backend"; -import axios from "axios"; -import { ManufacturerNames } from "domain/model/manufacturer-name"; import { GetInstrumentTypesApi } from "generated/api/get-instrument-types-api"; import type { Country, InstrumentBasicMaterial, InstrumentType, + Manufacturer, } from "generated/model"; import { GetInstrumentBasicMaterialsApi } from "generated/api/get-instrument-basic-materials-api"; import { GetCountriesApi } from "generated/api/get-countries-api"; +import { GetManufacturersApi } from "generated/api/get-manufacturers-api"; const getInstrumentTypes = new GetInstrumentTypesApi(); const getInstrumentBasicMaterials = new GetInstrumentBasicMaterialsApi(); const getCountries = new GetCountriesApi(); +const getManufacturers = new GetManufacturersApi(); export interface CreateInstrumentLoader { instrumentTypes: InstrumentType[]; - manufacturerNames: ManufacturerNames; + manufacturers: Manufacturer[]; materials: InstrumentBasicMaterial[]; countries: Country[]; } @@ -33,19 +32,11 @@ export const loader: LoaderFunction = const countriesRequest = await getCountries.getCountries(); - let manufacturers: ManufacturerNames = []; - await axios - .get(`${SERVER_URL}${API_MANUFACTURERS}`) - .then((data) => { - manufacturers = data.data; - }) - .catch(() => { - throw new Error("Fail to retrieve manufacturer names"); - }); + const manufacturersRequest = await getManufacturers.getManufacturers(); return { instrumentTypes: instrumentTypesRequest.data.content, - manufacturerNames: manufacturers, + manufacturers: manufacturersRequest.data.content, materials: instrumentBasicMaterialsRequest.data.content, countries: countriesRequest.data.content, }; diff --git a/client/src/pages/create-instrument/ui/CreateInstrument.tsx b/client/src/pages/create-instrument/ui/CreateInstrument.tsx index 664e1b46..31db8805 100644 --- a/client/src/pages/create-instrument/ui/CreateInstrument.tsx +++ b/client/src/pages/create-instrument/ui/CreateInstrument.tsx @@ -24,8 +24,11 @@ export const CreateInstrument = () => { @@ -34,9 +37,12 @@ export const CreateInstrument = () => {
@@ -68,8 +74,8 @@ export const CreateInstrument = () => { @@ -79,8 +85,11 @@ export const CreateInstrument = () => { diff --git a/client/src/pages/edit-instrument/api/loader.ts b/client/src/pages/edit-instrument/api/loader.ts index 4999464c..4eef0834 100644 --- a/client/src/pages/edit-instrument/api/loader.ts +++ b/client/src/pages/edit-instrument/api/loader.ts @@ -1,28 +1,27 @@ -import { ManufacturerNames } from "domain/model/manufacturer-name"; import { LoaderFunction } from "react-router-dom"; -import axios from "axios"; -import { SERVER_URL } from "shared/config"; -import { API_MANUFACTURERS } from "shared/config/backend"; import { GetInstrumentByIdApi } from "generated/api/get-instrument-by-id-api"; import { Country, InstrumentBasicMaterial, InstrumentDetail, type InstrumentType, + Manufacturer, } from "generated/model"; import { GetInstrumentTypesApi } from "generated/api/get-instrument-types-api"; import { GetInstrumentBasicMaterialsApi } from "generated/api/get-instrument-basic-materials-api"; import { GetCountriesApi } from "generated/api/get-countries-api"; +import { GetManufacturersApi } from "generated/api/get-manufacturers-api"; const getInstrumentById = new GetInstrumentByIdApi(); const getInstrumentTypes = new GetInstrumentTypesApi(); const getInstrumentBasicMaterials = new GetInstrumentBasicMaterialsApi(); const getCountries = new GetCountriesApi(); +const getManufacturers = new GetManufacturersApi(); export interface EditInstrumentLoader { instrumentForEdit: InstrumentDetail; instrumentTypes: InstrumentType[]; - manufacturerNames: ManufacturerNames; + manufacturers: Manufacturer[]; materials: InstrumentBasicMaterial[]; countries: Country[]; } @@ -40,21 +39,12 @@ export const loader: LoaderFunction = async ({ await getInstrumentBasicMaterials.getInstrumentBasicMaterials(); const countriesRequest = await getCountries.getCountries(); - - let manufacturers: ManufacturerNames = []; - await axios - .get(`${SERVER_URL}${API_MANUFACTURERS}`) - .then((data) => { - manufacturers = data.data; - }) - .catch(() => { - throw new Error("Fail to retrieve manufacturer names"); - }); + const manufacturersRequest = await getManufacturers.getManufacturers(); return { instrumentForEdit: instrumentDetailRequest.data, instrumentTypes: instrumentTypesRequest.data.content, - manufacturerNames: manufacturers, + manufacturers: manufacturersRequest.data.content, materials: instrumentBasicMaterialsRequest.data.content, countries: countriesRequest.data.content, }; diff --git a/client/src/pages/edit-instrument/ui/EditInstrument.tsx b/client/src/pages/edit-instrument/ui/EditInstrument.tsx index 0c28e33f..715cc029 100644 --- a/client/src/pages/edit-instrument/ui/EditInstrument.tsx +++ b/client/src/pages/edit-instrument/ui/EditInstrument.tsx @@ -6,6 +6,7 @@ import { Form, useActionData, useLoaderData } from "react-router-dom"; import { EditInstrumentLoader } from "pages/edit-instrument/api/loader"; import { EditInstrumentAction } from "pages/edit-instrument/api/action"; import { InstrumentBasicMaterialFormField } from "./fields/InstrumentBasicMaterial"; +import { InstrumentBasicMaterial } from "generated/model"; export const EditInstrument = () => { const loader = useLoaderData() as EditInstrumentLoader; @@ -51,8 +52,11 @@ export const EditInstrument = () => { required > {loader.instrumentTypes.map((instrumentType) => ( - ))} @@ -70,7 +74,7 @@ export const EditInstrument = () => { defaultValue={loader.instrumentForEdit.name} required > - {loader.manufacturerNames.map((manufacturerName) => ( + {loader.manufacturers.map((manufacturerName) => ( @@ -90,7 +94,7 @@ export const EditInstrument = () => { name="manufacturer-date" min="0001-01-01" max="9999-12-31" - defaultValue={loader.instrumentForEdit.manufacturerDate} + defaultValue={loader.instrumentForEdit.manufacturer_date} required />
@@ -107,7 +111,7 @@ export const EditInstrument = () => { name="release-date" min="0001-01-01" max="9999-12-31" - defaultValue={loader.instrumentForEdit.releaseDate} + defaultValue={loader.instrumentForEdit.release_date} required /> @@ -125,8 +129,8 @@ export const EditInstrument = () => { required > {loader.countries.map((country) => ( - ))} @@ -135,7 +139,12 @@ export const EditInstrument = () => { + ({ + basic_material: material, + }) as InstrumentBasicMaterial, + )} /> diff --git a/client/src/shared/config/backend.ts b/client/src/shared/config/backend.ts index 6ad5d1eb..26ca79b2 100644 --- a/client/src/shared/config/backend.ts +++ b/client/src/shared/config/backend.ts @@ -2,4 +2,3 @@ export const SERVER_URL = "http://localhost:8080"; export const API = "/api"; export const API_CREATE_INSTRUMENT = `${API}/instrument/create`; -export const API_MANUFACTURERS = `${API}/manufacturers`; diff --git a/client/src/widgets/catalogue-filter/ui/ManufacturerNameFilter.tsx b/client/src/widgets/catalogue-filter/ui/ManufacturerNameFilter.tsx index 24cfb019..6f501e19 100644 --- a/client/src/widgets/catalogue-filter/ui/ManufacturerNameFilter.tsx +++ b/client/src/widgets/catalogue-filter/ui/ManufacturerNameFilter.tsx @@ -1,27 +1,24 @@ import React, { useEffect, useState } from "react"; import { ManufacturerNames } from "domain/model/manufacturer-name"; -import axios from "axios"; -import { SERVER_URL } from "shared/config"; -import { API_MANUFACTURERS } from "shared/config/backend"; +import { GetManufacturersApi } from "generated/api/get-manufacturers-api"; +import { Manufacturer } from "generated/model"; interface Props { onValueChange: (names: ManufacturerNames) => void; } +const getManufacturers = new GetManufacturersApi(); + export const ManufacturerNameFilter = ({ onValueChange }: Props) => { - const [manufacturerNames, setManufacturerNames] = useState( - [], - ); + const [manufacturers, setManufacturers] = useState([]); useEffect(() => { - axios - .get(`${SERVER_URL}${API_MANUFACTURERS}`) - .then((r) => { - setManufacturerNames(r.data); - }) - .catch((e) => { - throw new Error(`Failed to extract instrument types: '${e}'`); - }); + const fetchManufacturers = async () => { + const response = await getManufacturers.getManufacturers(); + setManufacturers(response.data.content); + }; + + fetchManufacturers(); }, []); function onChange() { @@ -39,16 +36,18 @@ export const ManufacturerNameFilter = ({ onValueChange }: Props) => { return (
Manufacturer: - {manufacturerNames.map((manufactureName) => ( -
+ {manufacturers.map((manufacturer) => ( +
- +
))}
diff --git a/openapi/openapi.yml b/openapi/openapi.yml index 8ae4ed07..6dbdb0c5 100644 --- a/openapi/openapi.yml +++ b/openapi/openapi.yml @@ -51,6 +51,9 @@ tags: - name: basicLogin description: Everything about user x-displayName: basicLogin + - name: getManufacturers + description: Get Manufacturers + x-displayName: getManufacturers - name: getUserProfile description: Get User Profile x-displayName: getUserProfile @@ -398,6 +401,32 @@ paths: application/json: schema: $ref: '#/components/schemas/ServerError' + /manufacturer: + get: + description: Get Manufacturers + summary: Get Manufacturers + operationId: getManufacturers + tags: + - getManufacturers + responses: + '200': + description: Manufacturers + content: + application/json: + schema: + $ref: '#/components/schemas/GetManufacturersResponse' + '400': + description: Client Error + content: + application/json: + schema: + $ref: '#/components/schemas/ClientError' + default: + description: Server Error + content: + application/json: + schema: + $ref: '#/components/schemas/ServerError' /profile: get: description: Get User Profile @@ -677,6 +706,22 @@ components: properties: jwt: type: string + Manufacturer: + type: object + required: + - manufacturer + properties: + manufacturer: + type: string + GetManufacturersResponse: + type: object + required: + - content + properties: + content: + type: array + items: + $ref: '#/components/schemas/Manufacturer' ProfileDetails: type: object required: @@ -737,6 +782,9 @@ x-tagGroups: - name: Basic Login tags: - basicLogin + - name: Get Manufacturers + tags: + - getManufacturers - name: Get Profile tags: - getUserProfile diff --git a/openapi/specs/manufacturer/GetManufacturersEndpoint.yml b/openapi/specs/manufacturer/GetManufacturersEndpoint.yml new file mode 100644 index 00000000..fced4ee3 --- /dev/null +++ b/openapi/specs/manufacturer/GetManufacturersEndpoint.yml @@ -0,0 +1,71 @@ +openapi: "3.0.0" # openApiGenerate gradle task do not support officially 3.1.0 openapi version + +info: + description: Get Manufacturers + version: 1.0.0 + title: Get Manufacturers + contact: + name: Kirill B + email: baskirill.an@gmail.com +servers: + - url: http://localhost:{port}/{basePath} + description: Local server (uses local data) + variables: + port: + default: "8080" + enum: + - "8080" + - "8000" + basePath: + default: "api" + +tags: + - name: getManufacturers + description: Get Manufacturers + +paths: + /manufacturer: + get: + description: Get Manufacturers + summary: Get Manufacturers + operationId: getManufacturers + tags: + - getManufacturers + responses: + "200": + description: Manufacturers + content: + application/json: + schema: + $ref: "#/components/schemas/GetManufacturersResponse" + "400": + description: Client Error + content: + application/json: + schema: + $ref: "./../common/ClientError.yml#/components/schemas/ClientError" + default: + description: Server Error + content: + application/json: + schema: + $ref: "./../common/ServerError.yml#/components/schemas/ServerError" + +components: + schemas: + Manufacturer: + type: object + required: [manufacturer] + properties: + manufacturer: + type: string + + GetManufacturersResponse: + type: object + required: [content] + properties: + content: + type: array + items: + $ref: "#/components/schemas/Manufacturer" + diff --git a/server/app/build/openapi/src/main/kotlin/mu/muse/rest/api/DeleteInstrumentByIdApi.kt b/server/app/build/openapi/src/main/kotlin/mu/muse/rest/api/DeleteInstrumentByIdApi.kt new file mode 100644 index 00000000..821a71b4 --- /dev/null +++ b/server/app/build/openapi/src/main/kotlin/mu/muse/rest/api/DeleteInstrumentByIdApi.kt @@ -0,0 +1,43 @@ +/** + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.8.0). + * https://openapi-generator.tech + * Do not edit the class manually. +*/ +package mu.muse.rest.api + +import mu.muse.rest.dto.ClientError +import mu.muse.rest.dto.ServerError +import org.springframework.http.HttpStatus +import org.springframework.http.MediaType +import org.springframework.http.ResponseEntity + +import org.springframework.web.bind.annotation.* +import org.springframework.validation.annotation.Validated +import org.springframework.web.context.request.NativeWebRequest +import org.springframework.beans.factory.annotation.Autowired + +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size +import jakarta.validation.Valid + +import kotlin.collections.List +import kotlin.collections.Map + +@RestController +@Validated +interface DeleteInstrumentByIdApi { + + + @RequestMapping( + method = [RequestMethod.GET], + value = ["/instrument/{instrumentId}/delete"], + produces = ["application/json"] + ) + fun deleteInstrumentById( @PathVariable("instrumentId") instrumentId: kotlin.Long): ResponseEntity +} diff --git a/server/app/build/openapi/src/main/kotlin/mu/muse/rest/api/GetCountriesApi.kt b/server/app/build/openapi/src/main/kotlin/mu/muse/rest/api/GetCountriesApi.kt new file mode 100644 index 00000000..d537641e --- /dev/null +++ b/server/app/build/openapi/src/main/kotlin/mu/muse/rest/api/GetCountriesApi.kt @@ -0,0 +1,44 @@ +/** + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.8.0). + * https://openapi-generator.tech + * Do not edit the class manually. +*/ +package mu.muse.rest.api + +import mu.muse.rest.dto.ClientError +import mu.muse.rest.dto.GetCountriesResponse +import mu.muse.rest.dto.ServerError +import org.springframework.http.HttpStatus +import org.springframework.http.MediaType +import org.springframework.http.ResponseEntity + +import org.springframework.web.bind.annotation.* +import org.springframework.validation.annotation.Validated +import org.springframework.web.context.request.NativeWebRequest +import org.springframework.beans.factory.annotation.Autowired + +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size +import jakarta.validation.Valid + +import kotlin.collections.List +import kotlin.collections.Map + +@RestController +@Validated +interface GetCountriesApi { + + + @RequestMapping( + method = [RequestMethod.GET], + value = ["/countries"], + produces = ["application/json"] + ) + fun getCountries(): ResponseEntity +} diff --git a/server/app/build/openapi/src/main/kotlin/mu/muse/rest/api/GetInstrumentBasicMaterialsApi.kt b/server/app/build/openapi/src/main/kotlin/mu/muse/rest/api/GetInstrumentBasicMaterialsApi.kt new file mode 100644 index 00000000..c363b2c3 --- /dev/null +++ b/server/app/build/openapi/src/main/kotlin/mu/muse/rest/api/GetInstrumentBasicMaterialsApi.kt @@ -0,0 +1,44 @@ +/** + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.8.0). + * https://openapi-generator.tech + * Do not edit the class manually. +*/ +package mu.muse.rest.api + +import mu.muse.rest.dto.ClientError +import mu.muse.rest.dto.GetInstrumentBasicMaterialsResponse +import mu.muse.rest.dto.ServerError +import org.springframework.http.HttpStatus +import org.springframework.http.MediaType +import org.springframework.http.ResponseEntity + +import org.springframework.web.bind.annotation.* +import org.springframework.validation.annotation.Validated +import org.springframework.web.context.request.NativeWebRequest +import org.springframework.beans.factory.annotation.Autowired + +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size +import jakarta.validation.Valid + +import kotlin.collections.List +import kotlin.collections.Map + +@RestController +@Validated +interface GetInstrumentBasicMaterialsApi { + + + @RequestMapping( + method = [RequestMethod.GET], + value = ["/instrument/materials"], + produces = ["application/json"] + ) + fun getInstrumentBasicMaterials(): ResponseEntity +} diff --git a/server/app/build/openapi/src/main/kotlin/mu/muse/rest/api/GetManufacturersApi.kt b/server/app/build/openapi/src/main/kotlin/mu/muse/rest/api/GetManufacturersApi.kt new file mode 100644 index 00000000..f733e610 --- /dev/null +++ b/server/app/build/openapi/src/main/kotlin/mu/muse/rest/api/GetManufacturersApi.kt @@ -0,0 +1,44 @@ +/** + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.8.0). + * https://openapi-generator.tech + * Do not edit the class manually. +*/ +package mu.muse.rest.api + +import mu.muse.rest.dto.ClientError +import mu.muse.rest.dto.GetManufacturersResponse +import mu.muse.rest.dto.ServerError +import org.springframework.http.HttpStatus +import org.springframework.http.MediaType +import org.springframework.http.ResponseEntity + +import org.springframework.web.bind.annotation.* +import org.springframework.validation.annotation.Validated +import org.springframework.web.context.request.NativeWebRequest +import org.springframework.beans.factory.annotation.Autowired + +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size +import jakarta.validation.Valid + +import kotlin.collections.List +import kotlin.collections.Map + +@RestController +@Validated +interface GetManufacturersApi { + + + @RequestMapping( + method = [RequestMethod.GET], + value = ["/manufacturer"], + produces = ["application/json"] + ) + fun getManufacturers(): ResponseEntity +} diff --git a/server/app/build/openapi/src/main/kotlin/mu/muse/rest/dto/Country.kt b/server/app/build/openapi/src/main/kotlin/mu/muse/rest/dto/Country.kt new file mode 100644 index 00000000..5ba386c6 --- /dev/null +++ b/server/app/build/openapi/src/main/kotlin/mu/muse/rest/dto/Country.kt @@ -0,0 +1,25 @@ +package mu.muse.rest.dto + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size +import jakarta.validation.Valid + +/** + * + * @param country + */ +data class Country( + + @get:JsonProperty("country", required = true) val country: kotlin.String + ) { + +} + diff --git a/server/app/build/openapi/src/main/kotlin/mu/muse/rest/dto/GetCountriesResponse.kt b/server/app/build/openapi/src/main/kotlin/mu/muse/rest/dto/GetCountriesResponse.kt new file mode 100644 index 00000000..a93f13ae --- /dev/null +++ b/server/app/build/openapi/src/main/kotlin/mu/muse/rest/dto/GetCountriesResponse.kt @@ -0,0 +1,27 @@ +package mu.muse.rest.dto + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +import mu.muse.rest.dto.Country +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size +import jakarta.validation.Valid + +/** + * + * @param content + */ +data class GetCountriesResponse( + + @field:Valid + @get:JsonProperty("content", required = true) val content: kotlin.collections.List + ) { + +} + diff --git a/server/app/build/openapi/src/main/kotlin/mu/muse/rest/dto/GetInstrumentBasicMaterialsResponse.kt b/server/app/build/openapi/src/main/kotlin/mu/muse/rest/dto/GetInstrumentBasicMaterialsResponse.kt new file mode 100644 index 00000000..451de98f --- /dev/null +++ b/server/app/build/openapi/src/main/kotlin/mu/muse/rest/dto/GetInstrumentBasicMaterialsResponse.kt @@ -0,0 +1,27 @@ +package mu.muse.rest.dto + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +import mu.muse.rest.dto.InstrumentBasicMaterial +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size +import jakarta.validation.Valid + +/** + * + * @param content + */ +data class GetInstrumentBasicMaterialsResponse( + + @field:Valid + @get:JsonProperty("content", required = true) val content: kotlin.collections.List + ) { + +} + diff --git a/server/app/build/openapi/src/main/kotlin/mu/muse/rest/dto/GetManufacturersResponse.kt b/server/app/build/openapi/src/main/kotlin/mu/muse/rest/dto/GetManufacturersResponse.kt new file mode 100644 index 00000000..46ebcaea --- /dev/null +++ b/server/app/build/openapi/src/main/kotlin/mu/muse/rest/dto/GetManufacturersResponse.kt @@ -0,0 +1,27 @@ +package mu.muse.rest.dto + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +import mu.muse.rest.dto.Manufacturer +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size +import jakarta.validation.Valid + +/** + * + * @param content + */ +data class GetManufacturersResponse( + + @field:Valid + @get:JsonProperty("content", required = true) val content: kotlin.collections.List + ) { + +} + diff --git a/server/app/build/openapi/src/main/kotlin/mu/muse/rest/dto/InstrumentBasicMaterial.kt b/server/app/build/openapi/src/main/kotlin/mu/muse/rest/dto/InstrumentBasicMaterial.kt new file mode 100644 index 00000000..505d3433 --- /dev/null +++ b/server/app/build/openapi/src/main/kotlin/mu/muse/rest/dto/InstrumentBasicMaterial.kt @@ -0,0 +1,25 @@ +package mu.muse.rest.dto + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size +import jakarta.validation.Valid + +/** + * + * @param basicMaterial + */ +data class InstrumentBasicMaterial( + + @get:JsonProperty("basic_material", required = true) val basicMaterial: kotlin.String + ) { + +} + diff --git a/server/app/build/openapi/src/main/kotlin/mu/muse/rest/dto/InstrumentType.kt b/server/app/build/openapi/src/main/kotlin/mu/muse/rest/dto/InstrumentType.kt new file mode 100644 index 00000000..3611834c --- /dev/null +++ b/server/app/build/openapi/src/main/kotlin/mu/muse/rest/dto/InstrumentType.kt @@ -0,0 +1,25 @@ +package mu.muse.rest.dto + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size +import jakarta.validation.Valid + +/** + * + * @param instrumentType + */ +data class InstrumentType( + + @get:JsonProperty("instrument_type") val instrumentType: kotlin.String? = null + ) { + +} + diff --git a/server/app/build/openapi/src/main/kotlin/mu/muse/rest/dto/Manufacturer.kt b/server/app/build/openapi/src/main/kotlin/mu/muse/rest/dto/Manufacturer.kt new file mode 100644 index 00000000..49efd8f0 --- /dev/null +++ b/server/app/build/openapi/src/main/kotlin/mu/muse/rest/dto/Manufacturer.kt @@ -0,0 +1,25 @@ +package mu.muse.rest.dto + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size +import jakarta.validation.Valid + +/** + * + * @param manufacturer + */ +data class Manufacturer( + + @get:JsonProperty("manufacturer", required = true) val manufacturer: kotlin.String + ) { + +} + diff --git a/server/app/build/openapi/src/main/kotlin/mu/muse/rest/dto/ProfileDetails.kt b/server/app/build/openapi/src/main/kotlin/mu/muse/rest/dto/ProfileDetails.kt new file mode 100644 index 00000000..84864b75 --- /dev/null +++ b/server/app/build/openapi/src/main/kotlin/mu/muse/rest/dto/ProfileDetails.kt @@ -0,0 +1,31 @@ +package mu.muse.rest.dto + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size +import jakarta.validation.Valid + +/** + * + * @param username + * @param role + * @param fullName + */ +data class ProfileDetails( + + @get:JsonProperty("username", required = true) val username: kotlin.String, + + @get:JsonProperty("role", required = true) val role: kotlin.String, + + @get:JsonProperty("full_name", required = true) val fullName: kotlin.String + ) { + +} + diff --git a/server/app/src/main/kotlin/mu/muse/application/muse/RestConfiguration.kt b/server/app/src/main/kotlin/mu/muse/application/muse/RestConfiguration.kt index c1b2f19d..b52209f3 100644 --- a/server/app/src/main/kotlin/mu/muse/application/muse/RestConfiguration.kt +++ b/server/app/src/main/kotlin/mu/muse/application/muse/RestConfiguration.kt @@ -9,7 +9,7 @@ import mu.muse.rest.instruments.CreateInstrumentEndpoint import mu.muse.rest.instruments.DeleteInstrumentByIdEndpoint import mu.muse.rest.instruments.EditInstrumentEndpoint import mu.muse.rest.instruments.GetInstrumentByIdEndpoint -import mu.muse.rest.instruments.GetInstrumentManufacturersEndpoint +import mu.muse.rest.instruments.GetManufacturersEndpoint import mu.muse.rest.instruments.GetInstrumentMaterialsEndpoint import mu.muse.rest.instruments.GetInstrumentTypesEndpoint import mu.muse.rest.instruments.GetInstrumentsByCriteriaEndpoint @@ -23,7 +23,7 @@ import mu.muse.usecase.DeleteInstrumentById import mu.muse.usecase.EditInstrument import mu.muse.usecase.GetCountries import mu.muse.usecase.GetInstrumentById -import mu.muse.usecase.GetInstrumentManufacturers +import mu.muse.usecase.GetManufacturers import mu.muse.usecase.GetInstrumentMaterials import mu.muse.usecase.GetInstrumentTypes import mu.muse.usecase.GetInstrumentsByCriteria @@ -79,8 +79,8 @@ class RestConfiguration { fun createInstrumentEndpoint(createInstrument: CreateInstrument) = CreateInstrumentEndpoint(createInstrument) @Bean - fun getInstrumentManufacturersEndpoint(getInstrumentManufacturers: GetInstrumentManufacturers) = - GetInstrumentManufacturersEndpoint(getInstrumentManufacturers) + fun getInstrumentManufacturersEndpoint(getManufacturers: GetManufacturers) = + GetManufacturersEndpoint(getManufacturers) @Bean fun editInstrumentEndpoint(editInstrument: EditInstrument) = EditInstrumentEndpoint(editInstrument) diff --git a/server/app/src/main/kotlin/mu/muse/application/muse/UseCaseConfiguration.kt b/server/app/src/main/kotlin/mu/muse/application/muse/UseCaseConfiguration.kt index bc94a6fa..1cc93f47 100644 --- a/server/app/src/main/kotlin/mu/muse/application/muse/UseCaseConfiguration.kt +++ b/server/app/src/main/kotlin/mu/muse/application/muse/UseCaseConfiguration.kt @@ -13,7 +13,7 @@ import mu.muse.usecase.scenario.instrument.CreateInstrumentUseCase import mu.muse.usecase.scenario.instrument.DeleteInstrumentByIdUseCase import mu.muse.usecase.scenario.instrument.EditInstrumentUseCase import mu.muse.usecase.scenario.instrument.GetInstrumentByIdUseCase -import mu.muse.usecase.scenario.instrument.GetInstrumentManufacturersUseCase +import mu.muse.usecase.scenario.instrument.GetManufacturersUseCase import mu.muse.usecase.scenario.instrument.GetInstrumentMaterialsUseCase import mu.muse.usecase.scenario.instrument.GetInstrumentTypesUseCase import mu.muse.usecase.scenario.instrument.GetInstrumentsByCriteriaPaginatedUseCase @@ -62,7 +62,7 @@ class UseCaseConfiguration { ) = CreateInstrumentUseCase(idGenerator, instrumentPersister) @Bean - fun getInstrumentManufacturers() = GetInstrumentManufacturersUseCase() + fun getInstrumentManufacturers() = GetManufacturersUseCase() @Bean fun editInstrument(instrumentExtractor: InstrumentExtractor, instrumentPersister: InstrumentPersister) = diff --git a/server/app/src/main/kotlin/mu/muse/rest/instruments/GetInstrumentManufacturersEndpoint.kt b/server/app/src/main/kotlin/mu/muse/rest/instruments/GetInstrumentManufacturersEndpoint.kt deleted file mode 100644 index 3e4d805a..00000000 --- a/server/app/src/main/kotlin/mu/muse/rest/instruments/GetInstrumentManufacturersEndpoint.kt +++ /dev/null @@ -1,18 +0,0 @@ -package mu.muse.rest.instruments - -import mu.muse.domain.instrument.Manufacturer -import mu.muse.rest.API_GET_MANUFACTURER_NAMES -import mu.muse.usecase.GetInstrumentManufacturers -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.RestController - -@RestController -class GetInstrumentManufacturersEndpoint( - private val getInstrumentManufacturers: GetInstrumentManufacturers, -) { - - @GetMapping(API_GET_MANUFACTURER_NAMES) - fun getManufacturers(): List { - return getInstrumentManufacturers.execute() - } -} diff --git a/server/app/src/main/kotlin/mu/muse/rest/instruments/GetInstrumentMaterialsEndpoint.kt b/server/app/src/main/kotlin/mu/muse/rest/instruments/GetInstrumentMaterialsEndpoint.kt index b702e664..0c96195f 100644 --- a/server/app/src/main/kotlin/mu/muse/rest/instruments/GetInstrumentMaterialsEndpoint.kt +++ b/server/app/src/main/kotlin/mu/muse/rest/instruments/GetInstrumentMaterialsEndpoint.kt @@ -15,11 +15,11 @@ class GetInstrumentMaterialsEndpoint( override fun getInstrumentBasicMaterials(): ResponseEntity { val basicMaterials = getInstrumentMaterials.execute() - return basicMaterials.toResponse() + return basicMaterials.toRestResponse() } } -fun List.toResponse(): ResponseEntity { +fun List.toRestResponse(): ResponseEntity { return ResponseEntity.ok( GetInstrumentBasicMaterialsResponse( content = this.map { InstrumentBasicMaterial(it.name) }, diff --git a/server/app/src/main/kotlin/mu/muse/rest/instruments/GetInstrumentTypesEndpoint.kt b/server/app/src/main/kotlin/mu/muse/rest/instruments/GetInstrumentTypesEndpoint.kt index b4926fca..ff0aaef9 100644 --- a/server/app/src/main/kotlin/mu/muse/rest/instruments/GetInstrumentTypesEndpoint.kt +++ b/server/app/src/main/kotlin/mu/muse/rest/instruments/GetInstrumentTypesEndpoint.kt @@ -3,7 +3,6 @@ package mu.muse.rest.instruments import mu.muse.domain.instrument.Instrument import mu.muse.rest.api.GetInstrumentTypesApi import mu.muse.rest.dto.GetInstrumentTypesResponse -import mu.muse.rest.dto.InstrumentBasicMaterial import mu.muse.rest.dto.InstrumentType import mu.muse.usecase.GetInstrumentTypes import org.springframework.http.ResponseEntity @@ -16,11 +15,11 @@ class GetInstrumentTypesEndpoint( override fun getInstrumentTypes(): ResponseEntity { val instrumentTypes = getInstrumentTypes.execute() - return instrumentTypes.toResponse() + return instrumentTypes.toRestResponse() } } -fun List.toResponse(): ResponseEntity { +fun List.toRestResponse(): ResponseEntity { return ResponseEntity.ok( GetInstrumentTypesResponse( content = this.map { InstrumentType(it.name) }, diff --git a/server/app/src/main/kotlin/mu/muse/rest/instruments/GetInstrumentsByCriteriaEndpoint.kt b/server/app/src/main/kotlin/mu/muse/rest/instruments/GetInstrumentsByCriteriaEndpoint.kt index f5a501c2..3b872aba 100644 --- a/server/app/src/main/kotlin/mu/muse/rest/instruments/GetInstrumentsByCriteriaEndpoint.kt +++ b/server/app/src/main/kotlin/mu/muse/rest/instruments/GetInstrumentsByCriteriaEndpoint.kt @@ -21,10 +21,10 @@ class GetInstrumentsByCriteriaEndpoint( val criteria = request.toInstrumentCriteria() val instruments = getInstrumentsByCriteria.execute(criteria = criteria) val instrumentsDto = instruments.map { it.toDto() } - return ResponseEntity.ok(instrumentsDto.toResponse()) + return ResponseEntity.ok(instrumentsDto.toRestResponse()) } } -fun List.toResponse(): GetInstrumentsByCriteriaResponse { +fun List.toRestResponse(): GetInstrumentsByCriteriaResponse { return GetInstrumentsByCriteriaResponse(content = this) } diff --git a/server/app/src/main/kotlin/mu/muse/rest/instruments/GetInstrumentsByCriteriaPaginatedEndpoint.kt b/server/app/src/main/kotlin/mu/muse/rest/instruments/GetInstrumentsByCriteriaPaginatedEndpoint.kt index f837153d..59e0ebb1 100644 --- a/server/app/src/main/kotlin/mu/muse/rest/instruments/GetInstrumentsByCriteriaPaginatedEndpoint.kt +++ b/server/app/src/main/kotlin/mu/muse/rest/instruments/GetInstrumentsByCriteriaPaginatedEndpoint.kt @@ -41,7 +41,7 @@ class GetInstrumentsByCriteriaPaginatedEndpoint( ) return ResponseEntity.ok( - instrumentsPaginated.toResponse(), + instrumentsPaginated.toRestResponse(), ) } } @@ -61,7 +61,7 @@ fun GetInstrumentCriteriaRequestBody.toInstrumentCriteria(): InstrumentExtractor ) } -fun Page.toResponse(): GetInstrumentByCriteriaPageResponse { +fun Page.toRestResponse(): GetInstrumentByCriteriaPageResponse { return GetInstrumentByCriteriaPageResponse( content = this.content.map { it.toDto() }, contentSize = this.contentSize, diff --git a/server/app/src/main/kotlin/mu/muse/rest/instruments/GetManufacturersEndpoint.kt b/server/app/src/main/kotlin/mu/muse/rest/instruments/GetManufacturersEndpoint.kt new file mode 100644 index 00000000..3af6cdbe --- /dev/null +++ b/server/app/src/main/kotlin/mu/muse/rest/instruments/GetManufacturersEndpoint.kt @@ -0,0 +1,27 @@ +package mu.muse.rest.instruments + +import mu.muse.domain.instrument.Manufacturer +import mu.muse.rest.api.GetManufacturersApi +import mu.muse.rest.dto.GetManufacturersResponse +import mu.muse.usecase.GetManufacturers +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.RestController + +@RestController +class GetManufacturersEndpoint( + private val getManufacturers: GetManufacturers, +) : GetManufacturersApi { + + override fun getManufacturers(): ResponseEntity { + val manufacturers = getManufacturers.execute() + return manufacturers.toRestResponse() + } +} + +fun List.toRestResponse(): ResponseEntity { + return ResponseEntity.ok( + GetManufacturersResponse( + content = this.map { mu.muse.rest.dto.Manufacturer(it.name) }, + ), + ) +} diff --git a/server/app/src/main/kotlin/mu/muse/usecase/GetInstrumentManufacturers.kt b/server/app/src/main/kotlin/mu/muse/usecase/GetManufacturers.kt similarity index 72% rename from server/app/src/main/kotlin/mu/muse/usecase/GetInstrumentManufacturers.kt rename to server/app/src/main/kotlin/mu/muse/usecase/GetManufacturers.kt index d042eddf..74b8fcc6 100644 --- a/server/app/src/main/kotlin/mu/muse/usecase/GetInstrumentManufacturers.kt +++ b/server/app/src/main/kotlin/mu/muse/usecase/GetManufacturers.kt @@ -2,6 +2,6 @@ package mu.muse.usecase import mu.muse.domain.instrument.Manufacturer -fun interface GetInstrumentManufacturers { +fun interface GetManufacturers { fun execute(): List } diff --git a/server/app/src/main/kotlin/mu/muse/usecase/scenario/instrument/GetInstrumentManufacturersUseCase.kt b/server/app/src/main/kotlin/mu/muse/usecase/scenario/instrument/GetManufacturersUseCase.kt similarity index 60% rename from server/app/src/main/kotlin/mu/muse/usecase/scenario/instrument/GetInstrumentManufacturersUseCase.kt rename to server/app/src/main/kotlin/mu/muse/usecase/scenario/instrument/GetManufacturersUseCase.kt index 7b0f74ca..06dcb0ec 100644 --- a/server/app/src/main/kotlin/mu/muse/usecase/scenario/instrument/GetInstrumentManufacturersUseCase.kt +++ b/server/app/src/main/kotlin/mu/muse/usecase/scenario/instrument/GetManufacturersUseCase.kt @@ -1,9 +1,9 @@ package mu.muse.usecase.scenario.instrument import mu.muse.domain.instrument.Manufacturer -import mu.muse.usecase.GetInstrumentManufacturers +import mu.muse.usecase.GetManufacturers -class GetInstrumentManufacturersUseCase : GetInstrumentManufacturers { +class GetManufacturersUseCase : GetManufacturers { override fun execute(): List { return Manufacturer.entries }