-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
62 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export interface FileItem { | ||
url: string; | ||
} | ||
|
||
export interface UploadFilesResponse { | ||
files: FileItem[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { api } from '@/shared/api'; | ||
import { type UploadFilesResponse } from './contracts'; | ||
|
||
export const fileApi = api.injectEndpoints({ | ||
endpoints: builder => ({ | ||
uploadFiles: builder.mutation<UploadFilesResponse, FormData>({ | ||
query: body => ({ | ||
url: '/api/files', | ||
method: 'POST', | ||
body, | ||
}), | ||
}), | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './fileApi'; | ||
export * from './contracts'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './api'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { http, type HttpHandler } from 'msw'; | ||
import { type UploadFilesResponse } from '@/entities/file'; | ||
import { API_URL } from '@/shared/config'; | ||
import { DelayedHttpResponse } from '../DelayedHttpResponse'; | ||
|
||
const UPLOAD_FILE_FAKE_RESPONSE: UploadFilesResponse = { | ||
files: [ | ||
{ | ||
url: 'https://storage.yandexcloud.net/food-diary-images/oranges.png', | ||
}, | ||
], | ||
}; | ||
|
||
export const handlers: HttpHandler[] = [ | ||
http.post(`${API_URL}/api/files`, async ({ request }) => { | ||
const body = await request.formData(); | ||
const photos = body.getAll('photos'); | ||
|
||
if (photos.length < 1) { | ||
return await DelayedHttpResponse.badRequest(); | ||
} | ||
|
||
return await DelayedHttpResponse.json(UPLOAD_FILE_FAKE_RESPONSE); | ||
}), | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { handlers as filesHandlers } from './files.handlers'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters