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
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
0 deletions
+18
-0
script/core/handlers/reading_csv.py
+3
-0
script/service/main.py
+15
-0
No files found.
script/core/handlers/reading_csv.py
View file @
2322bc6c
...
@@ -5,6 +5,9 @@ from script.config.appconfig import csv_path
...
@@ -5,6 +5,9 @@ from script.config.appconfig import csv_path
# reading csv
# reading csv
def
csv_read
():
def
csv_read
():
try
:
dataset
=
pd
.
read_csv
(
csv_path
)
dataset
=
pd
.
read_csv
(
csv_path
)
dict_dataset
=
dataset
.
to_dict
(
orient
=
'records'
)
dict_dataset
=
dataset
.
to_dict
(
orient
=
'records'
)
return
dict_dataset
return
dict_dataset
except
Exception
as
e
:
print
(
"reading error"
,
e
)
script/service/main.py
View file @
2322bc6c
...
@@ -13,41 +13,56 @@ app = FastAPI()
...
@@ -13,41 +13,56 @@ app = FastAPI()
# read --> get
# read --> get
@app.get
(
"/get_all"
)
@app.get
(
"/get_all"
)
async
def
get_element
():
async
def
get_element
():
try
:
datas
=
table_1
.
objects
.
to_json
()
datas
=
table_1
.
objects
.
to_json
()
datas_list
=
json
.
loads
(
datas
)
datas_list
=
json
.
loads
(
datas
)
return
datas_list
return
datas_list
except
Exception
as
e
:
print
(
"error in get"
,
e
)
# insert many -->post
# insert many -->post
@app.post
(
"/insertall"
,
tags
=
[
'FIRST'
])
@app.post
(
"/insertall"
,
tags
=
[
'FIRST'
])
async
def
post_all_element
():
async
def
post_all_element
():
try
:
collection_name
.
insert_many
(
dict_from_file
)
collection_name
.
insert_many
(
dict_from_file
)
return
"data inserted"
return
"data inserted"
except
Exception
as
e
:
print
(
"error in post all"
,
e
)
#
#
# insert --> post
# insert --> post
@app.post
(
"/insert"
,
tags
=
[
'FIRST'
])
@app.post
(
"/insert"
,
tags
=
[
'FIRST'
])
async
def
post_element
(
body
:
insert_post
):
async
def
post_element
(
body
:
insert_post
):
try
:
new_data
=
insert_post
(
id
=
body
.
id
,
first_name
=
body
.
first_name
,
last_name
=
body
.
last_name
,
gender
=
body
.
gender
)
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
))
collection_name
.
insert_one
(
dict
(
new_data
))
return
{
"inserted data"
:
dict
(
new_data
)}
return
{
"inserted data"
:
dict
(
new_data
)}
except
Exception
as
e
:
print
(
"error in insert"
,
e
)
# update --> put
# update --> put
@app.put
(
"/update"
,
tags
=
[
'FIRST'
])
@app.put
(
"/update"
,
tags
=
[
'FIRST'
])
async
def
put_element
(
user_id
:
int
,
body
:
dict
):
async
def
put_element
(
user_id
:
int
,
body
:
dict
):
try
:
collection_name
.
update_one
({
"id"
:
user_id
},
{
"$set"
:
{
"first_name"
:
body
[
"first_name"
]}})
collection_name
.
update_one
({
"id"
:
user_id
},
{
"$set"
:
{
"first_name"
:
body
[
"first_name"
]}})
return
{
return
{
"data"
:
f
'name updated'
"data"
:
f
'name updated'
}
}
except
Exception
as
e
:
print
(
"error while update"
,
e
)
# delete
# delete
@app.delete
(
"/delete"
,
tags
=
[
'FIRST'
])
@app.delete
(
"/delete"
,
tags
=
[
'FIRST'
])
async
def
delete_element
(
user_id
:
int
):
async
def
delete_element
(
user_id
:
int
):
try
:
collection_name
.
delete_one
({
"id"
:
user_id
})
collection_name
.
delete_one
({
"id"
:
user_id
})
return
{
"data"
:
f
'details of {user_id} deleted'
}
return
{
"data"
:
f
'details of {user_id} deleted'
}
except
Exception
as
e
:
print
(
"delete error"
,
e
)
collection_name
=
mongo_connection
()
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