Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
FastAPI-CRUD
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
arjun.b
FastAPI-CRUD
Commits
9079c3c0
Commit
9079c3c0
authored
Feb 06, 2023
by
arjun.b
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
debug the project
parent
3c3c1ada
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
0 deletions
+58
-0
.idea/sonarlint/issuestore/1/e/1e9075f5bf079c01ef2c910709e91a497d262080
+0
-0
.idea/sonarlint/issuestore/4/9/496a238a6afa168dbaf6efd37bb459331589579c
+0
-0
scripts/services/main.py
+58
-0
No files found.
.idea/sonarlint/issuestore/1/e/1e9075f5bf079c01ef2c910709e91a497d262080
0 → 100644
View file @
9079c3c0
.idea/sonarlint/issuestore/4/9/496a238a6afa168dbaf6efd37bb459331589579c
0 → 100644
View file @
9079c3c0
scripts/services/main.py
0 → 100644
View file @
9079c3c0
import
logging
from
fastapi
import
FastAPI
,
UploadFile
from
mongoengine
import
connect
from
scripts.config.application_config
import
port_connect
from
scripts.constants.end_points
import
EndPoints
from
scripts.core.handlers.fastapi_handler
import
fastAPIHandler
from
scripts.database.model
import
employee_insert
,
employee_update
import
pandas
as
pd
app
=
FastAPI
()
connect
(
db
=
"employees"
,
host
=
"localhost"
,
port
=
int
(
port_connect
))
@app.get
(
"/"
)
async
def
root
():
return
{
"data"
:
"FastAPI CRUD Operations"
}
# upload and insert into database
@app.post
(
EndPoints
.
upload
,
tags
=
[
"upload file"
])
async
def
upload_file
(
file
:
UploadFile
):
try
:
file_content
=
pd
.
read_csv
(
file
.
file
)
fastAPIHandler
.
file_upload
(
file_content
)
return
{
"data"
:
"CSV data uploaded successfully"
}
except
Exception
as
e
:
logging
.
error
(
f
'upload file failed:{e}'
)
print
(
e
)
# insert data using post method
@app.post
(
EndPoints
.
send_data
,
tags
=
[
'send data'
])
def
send_data
(
emp
:
employee_insert
):
try
:
fastAPIHandler
.
insert_data
(
emp
)
return
{
"message"
:
"new data has been inserted"
}
except
Exception
as
e
:
logging
.
error
(
f
'inserting a document failed {e}'
)
# update data
@app.put
(
EndPoints
.
update
,
tags
=
[
"update database"
])
def
update_data
(
doc_id
:
int
,
details
:
employee_update
):
try
:
fastAPIHandler
.
update_data
(
doc_id
,
details
)
return
{
"data"
:
"data updated"
}
except
Exception
as
e
:
logging
.
error
(
f
'updating the data failed {e}'
)
# delete data
@app.delete
(
EndPoints
.
delete
,
tags
=
[
"delete data"
])
def
delete_data
(
doc_id
:
int
):
try
:
fastAPIHandler
.
delete_data
(
doc_id
)
return
{
"data"
:
"data deleted"
}
except
Exception
as
e
:
logging
.
error
(
f
'deleting a document failed {e}'
)
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