Skip to content

Commit

Permalink
Issue 120 - serviço de raças (devhatt#282)
Browse files Browse the repository at this point in the history
* feat: basecode getBreed

* feat: breeds service

* fix: service breed

* fix: remove wrong file

* fix: remove axios

* fix: new message bodty and url exported

* fix: pnpm lock

* fix: dependencies

* fix: better name

* fix: remove await of list breed

* fix: url in userservice and console in services

* fix: userService local

* fix: await in response
  • Loading branch information
juliaam authored Jul 18, 2024
1 parent fc9fe6b commit 72dbfc8
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 56 deletions.
6 changes: 6 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
"globals": {
"vi": true
}
},
{
"files": ["src/services/*.js"],
"rules": {
"no-console": "off"
}
}
]
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"eslint-plugin-vitest-globals": "1.5.0",
"husky": "^8.0.3",
"jsdom": "^23.2.0",
"json-server": "1.0.0-beta.1",
"lint-staged": "^15.2.2",
"prettier": "^3.2.5",
"reset-css": "^5.0.2",
Expand All @@ -82,8 +83,7 @@
"stylelint-order": "^6.0.4",
"stylelint-prettier": "^5.0.0",
"stylelint-scss": "^6.2.1",
"vitest": "^1.6.0",
"json-server": "1.0.0-beta.1"
"vitest": "^1.6.0"
},
"config": {
"commitizen": {
Expand Down
107 changes: 54 additions & 53 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/services/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const url = 'http://localhost:3000';
20 changes: 20 additions & 0 deletions src/services/breeds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { url } from './api';

export const BreedsService = {
list: async () => {
try {
const response = await fetch(`${url}/breed`);

if (!response.ok) {
throw new Error({
status: response.status,
message: response.statusText,
});
}
return response.json();
} catch (error) {
console.error(`An error occurred: ${error}`);
return error;
}
},
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { url } from './api';

export const UserService = {
getPets: async (userId) => {
try {
const response = await fetch(`http://localhost:3000/user/${userId}`);
const response = await fetch(`${url}/${userId}`);

if (!response.ok) {
throw new Error('Ocorreu um erro na requisição');
Expand Down

0 comments on commit 72dbfc8

Please sign in to comment.