Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fastAPI-task
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mohammed.shibili
fastAPI-task
Commits
2322bc6c
Commit
2322bc6c
authored
Jan 25, 2023
by
mohammed.shibili
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
exception
parent
ce9b003c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
17 deletions
+35
-17
script/core/handlers/reading_csv.py
+6
-3
script/service/main.py
+29
-14
No files found.
script/core/handlers/reading_csv.py
View file @
2322bc6c
...
...
@@ -5,6 +5,9 @@ from script.config.appconfig import csv_path
# reading csv
def
csv_read
():
dataset
=
pd
.
read_csv
(
csv_path
)
dict_dataset
=
dataset
.
to_dict
(
orient
=
'records'
)
return
dict_dataset
try
:
dataset
=
pd
.
read_csv
(
csv_path
)
dict_dataset
=
dataset
.
to_dict
(
orient
=
'records'
)
return
dict_dataset
except
Exception
as
e
:
print
(
"reading error"
,
e
)
script/service/main.py
View file @
2322bc6c
...
...
@@ -13,41 +13,56 @@ app = FastAPI()
# read --> get
@app.get
(
"/get_all"
)
async
def
get_element
():
datas
=
table_1
.
objects
.
to_json
()
datas_list
=
json
.
loads
(
datas
)
return
datas_list
try
:
datas
=
table_1
.
objects
.
to_json
()
datas_list
=
json
.
loads
(
datas
)
return
datas_list
except
Exception
as
e
:
print
(
"error in get"
,
e
)
# insert many -->post
@app.post
(
"/insertall"
,
tags
=
[
'FIRST'
])
async
def
post_all_element
():
collection_name
.
insert_many
(
dict_from_file
)
return
"data inserted"
try
:
collection_name
.
insert_many
(
dict_from_file
)
return
"data inserted"
except
Exception
as
e
:
print
(
"error in post all"
,
e
)
#
# insert --> post
@app.post
(
"/insert"
,
tags
=
[
'FIRST'
])
async
def
post_element
(
body
:
insert_post
):
new_data
=
insert_post
(
id
=
body
.
id
,
first_name
=
body
.
first_name
,
last_name
=
body
.
last_name
,
gender
=
body
.
gender
)
collection_name
.
insert_one
(
dict
(
new_data
))
return
{
"inserted data"
:
dict
(
new_data
)}
try
:
new_data
=
insert_post
(
id
=
body
.
id
,
first_name
=
body
.
first_name
,
last_name
=
body
.
last_name
,
gender
=
body
.
gender
)
collection_name
.
insert_one
(
dict
(
new_data
))
return
{
"inserted data"
:
dict
(
new_data
)}
except
Exception
as
e
:
print
(
"error in insert"
,
e
)
# update --> put
@app.put
(
"/update"
,
tags
=
[
'FIRST'
])
async
def
put_element
(
user_id
:
int
,
body
:
dict
):
collection_name
.
update_one
({
"id"
:
user_id
},
{
"$set"
:
{
"first_name"
:
body
[
"first_name"
]}})
return
{
"data"
:
f
'name updated'
}
try
:
collection_name
.
update_one
({
"id"
:
user_id
},
{
"$set"
:
{
"first_name"
:
body
[
"first_name"
]}})
return
{
"data"
:
f
'name updated'
}
except
Exception
as
e
:
print
(
"error while update"
,
e
)
# delete
@app.delete
(
"/delete"
,
tags
=
[
'FIRST'
])
async
def
delete_element
(
user_id
:
int
):
collection_name
.
delete_one
({
"id"
:
user_id
})
return
{
"data"
:
f
'details of {user_id} deleted'
}
try
:
collection_name
.
delete_one
({
"id"
:
user_id
})
return
{
"data"
:
f
'details of {user_id} deleted'
}
except
Exception
as
e
:
print
(
"delete error"
,
e
)
collection_name
=
mongo_connection
()
...
...
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