-
Notifications
You must be signed in to change notification settings - Fork 2
feat: implementa leitura de eventos #541
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9e9979b
feat: implementa leitura de eventos
MariaGabriela-JR 027f118
fix: ajusta leitura de eventos conforme review
MariaGabriela-JR f689219
Merge branch '532-cadastro-expedicoes' into feature/eventos-leitura
EduTiyo 878b21e
Merge branch '532-cadastro-expedicoes' into feature/eventos-leitura
EduTiyo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,51 @@ | ||
| import { BuscarEventoPorIdUseCase } from '@/domain/evento/BuscarEventoPorIdUseCase' | ||
| import { | ||
| HttpRequest, HttpResponse, StatusCode | ||
| } from '@/library/http/common' | ||
| import { BadRequestError } from '@/library/http/error/BadRequestError' | ||
| import { HttpError } from '@/library/http/error/HttpError' | ||
| import { InternalServerError } from '@/library/http/error/InternalServerError' | ||
| import { NotFoundError } from '@/library/http/error/NotFoundError' | ||
| import { NextHandler, RequestHandler } from '@/library/http/Server' | ||
|
|
||
| interface Dependencies { | ||
| buscarEventoPorIdUseCase: BuscarEventoPorIdUseCase | ||
| } | ||
|
|
||
| export class BuscarEventoController implements RequestHandler { | ||
| private readonly buscarEventoPorIdUseCase: BuscarEventoPorIdUseCase | ||
|
|
||
| constructor(dependencies: Dependencies) { | ||
| this.buscarEventoPorIdUseCase = dependencies.buscarEventoPorIdUseCase | ||
| } | ||
|
|
||
| async handle(request: HttpRequest, _next: NextHandler): Promise<HttpResponse | HttpError> { | ||
| const { eventoId } = request.params as { eventoId?: string } | ||
|
|
||
| if ( | ||
| eventoId === undefined | ||
| || eventoId === null | ||
| || eventoId === '' | ||
| || !/^\d+$/.test(eventoId) | ||
| ) { | ||
| return new BadRequestError({ message: 'eventoId inválido' }) | ||
| } | ||
|
|
||
| const result = await this.buscarEventoPorIdUseCase.execute({ | ||
| id: Number(eventoId) | ||
| }) | ||
|
|
||
| if (result.left()) { | ||
| return new InternalServerError({ message: result.value.message }) | ||
| } | ||
|
|
||
| if (!result.value) { | ||
| return new NotFoundError({ message: 'Evento não encontrado' }) | ||
| } | ||
|
|
||
| return { | ||
| statusCode: StatusCode.Ok, | ||
| body: result.value | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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,72 @@ | ||
| import { EventoTipo } from '@/domain/evento/Evento' | ||
| import { ListaEventosUseCase } from '@/domain/evento/ListaEventosUseCase' | ||
| import { | ||
| HttpRequest, HttpResponse, StatusCode | ||
| } from '@/library/http/common' | ||
| import { BadRequestError } from '@/library/http/error/BadRequestError' | ||
| import { HttpError } from '@/library/http/error/HttpError' | ||
| import { InternalServerError } from '@/library/http/error/InternalServerError' | ||
| import { NextHandler, RequestHandler } from '@/library/http/Server' | ||
|
|
||
| interface Dependencies { | ||
| listaEventosUseCase: ListaEventosUseCase | ||
| } | ||
|
|
||
|
EduTiyo marked this conversation as resolved.
|
||
| export class ListaEventosController implements RequestHandler { | ||
| private readonly listaEventosUseCase: ListaEventosUseCase | ||
|
|
||
| constructor(dependencies: Dependencies) { | ||
| this.listaEventosUseCase = dependencies.listaEventosUseCase | ||
| } | ||
|
|
||
| async handle(request: HttpRequest, _next: NextHandler): Promise<HttpResponse | HttpError> { | ||
| const { | ||
| expedicaoId, | ||
| tipo, | ||
| capturado_de, | ||
| capturado_ate, | ||
| limite, | ||
| pagina | ||
| } = request.params as { | ||
| expedicaoId?: string | ||
| tipo?: string | ||
| capturado_de?: string | ||
| capturado_ate?: string | ||
| limite?: string | ||
| pagina?: string | ||
| } | ||
|
|
||
| if ( | ||
| expedicaoId === undefined | ||
| || expedicaoId === null | ||
| || expedicaoId === '' | ||
| || !/^\d+$/.test(expedicaoId) | ||
| ) { | ||
| return new BadRequestError({ message: 'expedicaoId inválido' }) | ||
| } | ||
|
|
||
| const filters = { | ||
| expedicao_id: Number(expedicaoId), | ||
| ...(limite && !Number.isNaN(Number(limite)) | ||
| ? { limite: Number(limite) } | ||
| : {}), | ||
| ...(pagina && !Number.isNaN(Number(pagina)) | ||
| ? { pagina: Number(pagina) } | ||
| : {}), | ||
| ...(tipo ? { tipo: tipo as EventoTipo } : {}), | ||
| ...(capturado_de ? { capturado_de: new Date(capturado_de) } : {}), | ||
| ...(capturado_ate ? { capturado_ate: new Date(capturado_ate) } : {}) | ||
| } | ||
|
|
||
| const result = await this.listaEventosUseCase.execute(filters) | ||
|
|
||
| if (result.left()) { | ||
| return new InternalServerError({ message: result.value.message }) | ||
| } | ||
|
|
||
| return { | ||
| statusCode: StatusCode.Ok, | ||
| body: result.value | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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,20 @@ | ||
| import { Either } from '@/library/either/Either' | ||
|
|
||
| import { Attributes } from './Evento' | ||
| import { EventoCollection } from './EventoCollection' | ||
|
|
||
| interface Dependencies { | ||
| eventoCollection: EventoCollection | ||
| } | ||
|
|
||
| export class BuscarEventoPorIdUseCase { | ||
| private readonly eventoCollection: EventoCollection | ||
|
|
||
| constructor(dependencies: Dependencies) { | ||
| this.eventoCollection = dependencies.eventoCollection | ||
| } | ||
|
|
||
| execute({ id }: { id: number }): Promise<Either<Error, Attributes | null>> { | ||
| return this.eventoCollection.findById(id) | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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,22 @@ | ||
| import { Either } from '@/library/either/Either' | ||
|
|
||
| import { Attributes } from './Evento' | ||
| import { | ||
| EventoCollection, EventoFilters, Paginated | ||
| } from './EventoCollection' | ||
|
|
||
| interface Dependencies { | ||
| eventoCollection: EventoCollection | ||
| } | ||
|
|
||
| export class ListaEventosUseCase { | ||
| private readonly eventoCollection: EventoCollection | ||
|
|
||
| constructor(dependencies: Dependencies) { | ||
| this.eventoCollection = dependencies.eventoCollection | ||
| } | ||
|
|
||
| execute(filters: EventoFilters): Promise<Either<Error, Paginated<Attributes>>> { | ||
| return this.eventoCollection.findAll(filters) | ||
|
EduTiyo marked this conversation as resolved.
|
||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.