diff options
| author | Kevin Hoerr <kjhoerr@noreply.cybr.es> | 2022-08-14 21:35:45 +0000 |
|---|---|---|
| committer | Kevin Hoerr <kjhoerr@noreply.cybr.es> | 2022-08-14 21:35:45 +0000 |
| commit | c04674fa74c2e43535181431aef5d891f8839619 (patch) | |
| tree | 2f7ce3b61590b39254bc22ac96272b7533ed96d2 /src/conf | |
| parent | 461b1fa053bcc86d06156574ab59fa7000dbf69e (diff) | |
| download | pantry-c04674fa74c2e43535181431aef5d891f8839619.tar.gz pantry-c04674fa74c2e43535181431aef5d891f8839619.tar.bz2 pantry-c04674fa74c2e43535181431aef5d891f8839619.zip | |
Merge planner code (#3)
Reviewed-on: https://git.submelon.dev/kjhoerr/pantry/pulls/3
Diffstat (limited to 'src/conf')
| -rw-r--r-- | src/conf/mutator.ts | 29 | ||||
| -rw-r--r-- | src/conf/openapi-pantry.yaml | 87 |
2 files changed, 116 insertions, 0 deletions
diff --git a/src/conf/mutator.ts b/src/conf/mutator.ts new file mode 100644 index 0000000..74f29e3 --- /dev/null +++ b/src/conf/mutator.ts @@ -0,0 +1,29 @@ +import Axios, { AxiosError, AxiosRequestConfig } from "axios"; + +export const AXIOS_PANTRY_INSTANCE = Axios.create({ + baseURL: process.env.REACT_APP_API_SERVER!, +}); + +export const useMutator = <T>(): (( + config: AxiosRequestConfig +) => Promise<T>) => { + return (config: AxiosRequestConfig) => { + const source = Axios.CancelToken.source(); + const promise = AXIOS_PANTRY_INSTANCE({ + ...config, + cancelToken: source.token, + }).then(({ data }) => data); + + // @ts-ignore + promise.cancel = () => { + source.cancel("Query was cancelled by React Query!"); + }; + + return promise; + }; +}; + +export default useMutator; + +// In some case with react-query and swr you want to be able to override the return error type so you can also do it here like this +export type ErrorType<Error> = AxiosError<Error>; diff --git a/src/conf/openapi-pantry.yaml b/src/conf/openapi-pantry.yaml new file mode 100644 index 0000000..8409064 --- /dev/null +++ b/src/conf/openapi-pantry.yaml @@ -0,0 +1,87 @@ +--- +openapi: 3.0.3 +info: + title: pantry API + version: 1.0.0-SNAPSHOT +paths: + /items: + get: + tags: + - Pantry Item Resource + responses: + "200": + description: OK + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/PantryItem' + post: + tags: + - Pantry Item Resource + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/PantryItem' + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/PantryItem' + /items/{id}: + put: + tags: + - Pantry Item Resource + parameters: + - name: id + in: path + required: true + schema: + format: int64 + type: integer + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/PantryItem' + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/PantryItem' + delete: + tags: + - Pantry Item Resource + parameters: + - name: id + in: path + required: true + schema: + format: int64 + type: integer + responses: + "204": + description: No Content +components: + schemas: + PantryItem: + type: object + properties: + id: + format: int64 + type: integer + name: + type: string + description: + type: string + quantity: + format: double + type: number + quantityUnitType: + type: string |
