Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adição de funcionalidade de busca para feriados municipais, estaduais e nacionais. #555

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ module.exports = {
'react/react-in-jsx-scope': 'off',
'react/jsx-filename-extension': [1, { extensions: ['.js', '.jsx'] }],
'import/prefer-default-export': 'off',
'no-else-return': {
allowElseIf: true,
},
'no-else-return': [
2,
{
allowElseIf: true,
},
],
},
settings: {
'import/resolver': {
Expand Down
13 changes: 11 additions & 2 deletions package-lock.json

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

31 changes: 31 additions & 0 deletions pages/api/feriados/v2/[state]/[city].js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import app from '@/app';
import BadRequestError from '@/errors/BadRequestError';
import NotFoundError from '@/errors/NotFoundError';
import { getHolidaysByCity } from '@/services/holidays/v2';

async function holidaysByCity(request, response) {
try {
let { year } = request.query;

if (year === undefined) {
year = new Date().getFullYear();
}

const { state } = request.query;
const { city } = request.query;

const result = await getHolidaysByCity(state, city, year);

return response.json(result);
} catch (error) {
if (error.response.status === 400) {
throw new BadRequestError({ message: error.response.data.message });
}
if (error.response.status === 404) {
throw new NotFoundError({ message: error.response.data.message });
}
throw error;
}
}

export default app().get(holidaysByCity);
28 changes: 28 additions & 0 deletions pages/api/feriados/v2/[state]/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import app from '@/app';
import BadRequestError from '@/errors/BadRequestError';
import NotFoundError from '@/errors/NotFoundError';
import { getHolidaysByState } from '@/services/holidays/v2';

async function holidaysByState(request, response) {
try {
let { year } = request.query;

if (year === undefined) {
year = new Date().getFullYear();
}

const { state } = request.query;
const result = await getHolidaysByState(state, year);
return response.json(result);
} catch (error) {
if (error.response.status === 400) {
throw new BadRequestError({ message: error.response.data.message });
}
if (error.response.status === 404) {
throw new NotFoundError({ message: error.response.data.message });
}
throw error;
}
}

export default app().get(holidaysByState);
27 changes: 27 additions & 0 deletions pages/api/feriados/v2/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import app from '@/app';
import BadRequestError from '@/errors/BadRequestError';
import NotFoundError from '@/errors/NotFoundError';
import { getNationalHolidays } from '@/services/holidays/v2';

async function nationalHolidays(request, response) {
try {
let { year } = request.query;

if (year === undefined) {
year = new Date().getFullYear();
}

const result = await getNationalHolidays(year);
return response.json(result);
} catch (error) {
if (error.response.status === 400) {
throw new BadRequestError({ message: error.response.data.message });
}
if (error.response.status === 404) {
throw new NotFoundError({ message: error.response.data.message });
}
throw error;
}
}

export default app().get(nationalHolidays);
Loading
Loading