Skip to content

Commit

Permalink
feat: adiciona o service de words #32
Browse files Browse the repository at this point in the history
  • Loading branch information
ThamirisMaria committed Nov 20, 2023
1 parent 95d8bc1 commit 3bbdb44
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@fontsource/roboto": "^5.0.8",
"@mui/icons-material": "^5.14.18",
"@mui/material": "^5.14.18",
"axios": "^1.6.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.18.0"
Expand Down
13 changes: 13 additions & 0 deletions web/src/services/api/axios.config/ErrorInterceptor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { AxiosError } from "axios";

export const errorInterceptor = (error: AxiosError) => {
if(error.message === 'Network Error'){
return Promise.reject(new Error('Erro de conexão.'));
}

if(error.response?.status === 500){
return Promise.reject(new Error('Erro de servidor.'));
}

return Promise.reject(error);
}
5 changes: 5 additions & 0 deletions web/src/services/api/axios.config/ResponseInterceptor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { AxiosResponse } from "axios";

export const responseInterceptor = (response: AxiosResponse) => {
return response;
}
14 changes: 14 additions & 0 deletions web/src/services/api/axios.config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import axios from 'axios';
import { responseInterceptor } from './ResponseInterceptor';
import { errorInterceptor } from './ErrorInterceptor';

const Api = axios.create({
baseURL: 'http://localhost:8080'
});

Api.interceptors.response.use(
response => responseInterceptor(response),
error => errorInterceptor(error)
);

export { Api };
20 changes: 20 additions & 0 deletions web/src/services/api/words/WordsService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Api } from "../axios.config";

export interface IWord {
id: number,
word: String,
translation: String,
status: String
}

const updateStatus = async (id: number, wordStatus: string): Promise<void | Error> => {
try {
await Api.put(`/word/updateStatus?wordId=${id}&status=${wordStatus}`);
} catch (error) {
return new Error((error as { message: string }).message || 'Erro ao listar Gold List');
}
};

export const WordsService = {
updateStatus
}

0 comments on commit 3bbdb44

Please sign in to comment.