Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Veiculos Via Montadora
Backend
Commits
54912334
Commit
54912334
authored
1 year ago
by
Pedro Carlucci
Committed by
Arthur Sudbrack Ibarra
1 year ago
Browse files
Options
Download
Email Patches
Plain Diff
feat: stopping with pdfs duplications
parent
78a692b2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/api/repositories/pdf_repository.py
+3
-14
app/api/repositories/pdf_repository.py
app/api/services/pdf_service.py
+17
-8
app/api/services/pdf_service.py
with
20 additions
and
22 deletions
+20
-22
app/api/repositories/pdf_repository.py
View file @
54912334
...
...
@@ -20,20 +20,9 @@ class PDFRepository:
return
pdfs
def
get_by_nome
(
self
,
nome
:
str
)
->
PDF
:
# This method returns the latest pdf with the given nome.
# It uses the 'criado' field to determine which pdf is the latest.
all_pdfs
=
self
.
get_all
()
latest_pdf
=
None
for
pdf
in
all_pdfs
:
if
pdf
.
nome
==
nome
:
if
latest_pdf
is
None
:
latest_pdf
=
pdf
else
:
if
is_date_after
(
pdf
.
criado
,
latest_pdf
.
criado
):
latest_pdf
=
pdf
if
latest_pdf
is
None
:
raise
Exception
(
f
"PDF com nome
{
nome
}
não encontrado."
)
return
latest_pdf
# This method returns pdf with the given nome.
pdf_dict
=
self
.
_collection
.
find_one
({
"nome"
:
nome
})
return
PDF
.
parse_obj
(
pdf_dict
)
def
create
(
self
,
pdf_data
:
PDF
)
->
InsertOneResult
:
# On create we need to convert car_data to dict and then insert it into the database.
...
...
This diff is collapsed.
Click to expand it.
app/api/services/pdf_service.py
View file @
54912334
...
...
@@ -24,17 +24,26 @@ class PDFService:
def
get_by_nome
(
self
,
nome
:
str
)
->
PDF
:
try
:
return
self
.
_repository
.
get_by_nome
(
nome
)
except
Exception
as
error
:
except
Exception
:
raise
HTTPException
(
status_code
=
404
,
detail
=
error
.
args
[
0
]
)
status_code
=
404
,
detail
=
"PDF não encontrado."
)
def
create
(
self
,
pdf_data
:
PDF
)
->
PDF
:
# Set date attributes.
created_date
=
current_date
()
pdf_data
.
criado
=
created_date
pdf_data
.
ultimo_visto
=
created_date
result
=
self
.
_repository
.
create
(
pdf_data
)
return
self
.
_repository
.
find_by_id
(
result
.
inserted_id
)
try
:
# get_by_nome raises a 404 error if the car is not found.
self
.
get_by_nome
(
pdf_data
.
nome
)
# If we got here, that means the pdf already exists in the database.
raise
ValueError
(
f
"PDF já existente por nome:
{
pdf_data
.
nome
}
."
)
except
HTTPException
as
e
:
if
e
.
status_code
==
404
:
created_date
=
current_date
()
pdf_data
.
criado
=
created_date
pdf_data
.
ultimo_visto
=
created_date
result
=
self
.
_repository
.
create
(
pdf_data
)
return
self
.
_repository
.
find_by_id
(
result
.
inserted_id
)
except
ValueError
as
e
:
raise
HTTPException
(
status_code
=
400
,
detail
=
e
.
args
[
0
])
def
update
(
self
,
nome
:
str
,
pdf_data
:
PDF
)
->
PDF
:
pdf_data
.
ultimo_visto
=
current_date
()
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help