Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
crud-operations
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vipul.v
crud-operations
Commits
f983ca62
Commit
f983ca62
authored
Mar 13, 2023
by
vipul.v
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
10aa6d65
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
41 additions
and
22 deletions
+41
-22
conf/application.conf
conf/application.conf
+1
-1
script/constants/__init__.py
script/constants/__init__.py
+1
-0
script/core/db/mongo/interns2023/inventory.py
script/core/db/mongo/interns2023/inventory.py
+1
-1
script/core/handlers/inventory.py
script/core/handlers/inventory.py
+16
-9
script/core/schema/inventory.py
script/core/schema/inventory.py
+12
-0
script/service/inventory.py
script/service/inventory.py
+10
-11
No files found.
conf/application.conf
View file @
f983ca62
...
...
@@ -4,4 +4,4 @@ host=0.0.0.0
[
MONGO
-
DB
]
mongo_uri
=
mongodb
://
192
.
168
.
0
.
220
:
2717
/
\ No newline at end of file
mongo_uri
=
mongodb
://
192168
.
0
.
220
:
2717
/
\ No newline at end of file
script/constants/__init__.py
View file @
f983ca62
...
...
@@ -5,3 +5,4 @@ class APIEndpoints:
insert
=
"/insert"
update
=
"/update"
find
=
"/find"
script/core/db/mongo/interns2023/inventory.py
View file @
f983ca62
...
...
@@ -12,7 +12,7 @@ class InventoryCollection(MongoCollectionBaseClass):
def
insert_item
(
self
,
data
):
self
.
insert_one
(
data
)
def
list_item
s
(
self
,
data
):
def
list_item
(
self
,
data
):
self
.
find_one
(
data
)
def
delete_item
(
self
,
data
):
...
...
script/core/handlers/inventory.py
View file @
f983ca62
# class for CRUD operations
from
script.core.db.mongo.interns2023.inventory
import
InventoryCollection
from
script.core.errors
import
NameDoesNotExist
from
script.core.schema.inventory
import
Inventory
class
InventoryData
:
...
...
@@ -16,6 +18,7 @@ class InventoryData:
raise
ValueError
(
"ID"
)
except
Exception
as
e
:
print
(
e
,
"Error Detected in Deleion"
)
@
staticmethod
def
update_data
(
self
,
order_id
:
int
):
try
:
...
...
@@ -34,10 +37,14 @@ class InventoryData:
except
Exception
as
e
:
print
(
e
,
"Error Detected in Finding"
)
@
staticmethod
def
insert_data
(
self
,
order_id
:
int
):
def
insert_data
(
self
,
request_data
:
Inventory
):
try
:
d
=
{
"order_id"
:
5
}
d
=
{
"order_id"
:
request_data
.
order_id
,
"data"
:
request_data
.
date
,
"customer_name"
:
request_data
.
customer_name
,
"status"
:
request_data
.
status
,
"sales_order"
:
request_data
.
sales_order
}
self
.
inventory_col
.
insert_one
(
data
)
if
5
not
in
d
.
values
():
raise
NameDoesNotExist
except
Exception
as
e
:
...
...
script/core/schema/inventory.py
0 → 100644
View file @
f983ca62
from
typing
import
Optional
from
pydantic
import
BaseModel
# define a model for Item
class
Inventory
(
BaseModel
):
order_id
:
Optional
[
int
]
date
:
int
customer_name
:
str
status
:
str
sales_order
:
int
script/service/inventory.py
View file @
f983ca62
...
...
@@ -4,13 +4,13 @@ from fastapi.routing import APIRouter
from
script.constants
import
APIEndpoints
from
script.core.handlers.inventory
import
InventoryData
from
script.core.schema.inventory
import
Inventory
from
script.core.schema.responses
import
DefaultResponse
router
=
APIRouter
(
prefix
=
APIEndpoints
.
inventory_base
)
handler
=
InventoryData
()
@
router
.
post
(
APIEndpoints
.
delete
)
async
def
delete_item
(
order_id
:
int
):
"""This API deletes an item"""
...
...
@@ -23,6 +23,7 @@ async def delete_item(order_id: int):
logging
.
exception
(
e
)
return
DefaultResponse
(
message
=
"Deletion failed due to server error"
)
@
router
.
post
(
APIEndpoints
.
update
)
async
def
update_item
(
order_id
:
int
):
try
:
...
...
@@ -48,14 +49,12 @@ async def find_item(order_id: int):
@
router
.
post
(
APIEndpoints
.
insert
)
async
def
insert_item
(
order_id
:
int
):
async
def
insert_item
(
request_data
:
Inventory
):
try
:
handler
.
insert_data
(
order_id
,
int
)
handler
.
insert_data
(
request_data
)
return
DefaultResponse
(
message
=
"Successfully inserted"
,
status
=
"success"
)
except
ValueError
:
return
DefaultResponse
(
message
=
"Due to value error"
)
except
Exception
as
e
:
logging
.
exception
(
e
)
return
DefaultResponse
(
message
=
"inserted Failed due to server error"
)
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