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
Hide 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
...
@@ -4,4 +4,4 @@ host=0.0.0.0
[
MONGO
-
DB
]
[
MONGO
-
DB
]
mongo_uri
=
mongodb
://
192
.
168
.
0
.
220
:
2717
/
mongo_uri
=
mongodb
://
192168
.
0
.
220
:
2717
/
\ No newline at end of file
\ No newline at end of file
script/constants/__init__.py
View file @
f983ca62
...
@@ -5,3 +5,4 @@ class APIEndpoints:
...
@@ -5,3 +5,4 @@ class APIEndpoints:
insert
=
"/insert"
insert
=
"/insert"
update
=
"/update"
update
=
"/update"
find
=
"/find"
find
=
"/find"
script/core/db/mongo/interns2023/inventory.py
View file @
f983ca62
...
@@ -12,7 +12,7 @@ class InventoryCollection(MongoCollectionBaseClass):
...
@@ -12,7 +12,7 @@ class InventoryCollection(MongoCollectionBaseClass):
def
insert_item
(
self
,
data
):
def
insert_item
(
self
,
data
):
self
.
insert_one
(
data
)
self
.
insert_one
(
data
)
def
list_item
s
(
self
,
data
):
def
list_item
(
self
,
data
):
self
.
find_one
(
data
)
self
.
find_one
(
data
)
def
delete_item
(
self
,
data
):
def
delete_item
(
self
,
data
):
...
...
script/core/handlers/inventory.py
View file @
f983ca62
# class for CRUD operations
# class for CRUD operations
from
script.core.db.mongo.interns2023.inventory
import
InventoryCollection
from
script.core.db.mongo.interns2023.inventory
import
InventoryCollection
from
script.core.errors
import
NameDoesNotExist
from
script.core.errors
import
NameDoesNotExist
from
script.core.schema.inventory
import
Inventory
class
InventoryData
:
class
InventoryData
:
...
@@ -16,6 +18,7 @@ class InventoryData:
...
@@ -16,6 +18,7 @@ class InventoryData:
raise
ValueError
(
"ID"
)
raise
ValueError
(
"ID"
)
except
Exception
as
e
:
except
Exception
as
e
:
print
(
e
,
"Error Detected in Deleion"
)
print
(
e
,
"Error Detected in Deleion"
)
@
staticmethod
@
staticmethod
def
update_data
(
self
,
order_id
:
int
):
def
update_data
(
self
,
order_id
:
int
):
try
:
try
:
...
@@ -27,18 +30,22 @@ class InventoryData:
...
@@ -27,18 +30,22 @@ class InventoryData:
@
staticmethod
@
staticmethod
def
find_data
(
self
,
order_id
:
int
):
def
find_data
(
self
,
order_id
:
int
):
try
:
try
:
d
=
{
"order_id"
:
order_id
}
d
=
{
"order_id"
:
order_id
}
if
2
not
in
d
.
values
():
if
2
not
in
d
.
values
():
raise
NameDoesNotExist
raise
NameDoesNotExist
except
Exception
as
e
:
except
Exception
as
e
:
print
(
e
,
"Error Detected in Finding"
)
print
(
e
,
"Error Detected in Finding"
)
@
staticmethod
def
insert_data
(
self
,
request_data
:
Inventory
):
def
insert_data
(
self
,
order_id
:
int
):
try
:
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
():
if
5
not
in
d
.
values
():
raise
NameDoesNotExist
raise
NameDoesNotExist
except
Exception
as
e
:
except
Exception
as
e
:
print
(
e
,
"Error Detected in inserting"
)
print
(
e
,
"Error Detected in inserting"
)
\ No newline at end of file
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
...
@@ -4,13 +4,13 @@ from fastapi.routing import APIRouter
from
script.constants
import
APIEndpoints
from
script.constants
import
APIEndpoints
from
script.core.handlers.inventory
import
InventoryData
from
script.core.handlers.inventory
import
InventoryData
from
script.core.schema.inventory
import
Inventory
from
script.core.schema.responses
import
DefaultResponse
from
script.core.schema.responses
import
DefaultResponse
router
=
APIRouter
(
prefix
=
APIEndpoints
.
inventory_base
)
router
=
APIRouter
(
prefix
=
APIEndpoints
.
inventory_base
)
handler
=
InventoryData
()
handler
=
InventoryData
()
@
router
.
post
(
APIEndpoints
.
delete
)
@
router
.
post
(
APIEndpoints
.
delete
)
async
def
delete_item
(
order_id
:
int
):
async
def
delete_item
(
order_id
:
int
):
"""This API deletes an item"""
"""This API deletes an item"""
...
@@ -23,39 +23,38 @@ async def delete_item(order_id: int):
...
@@ -23,39 +23,38 @@ async def delete_item(order_id: int):
logging
.
exception
(
e
)
logging
.
exception
(
e
)
return
DefaultResponse
(
message
=
"Deletion failed due to server error"
)
return
DefaultResponse
(
message
=
"Deletion failed due to server error"
)
@
router
.
post
(
APIEndpoints
.
update
)
@
router
.
post
(
APIEndpoints
.
update
)
async
def
update_item
(
order_id
:
int
):
async
def
update_item
(
order_id
:
int
):
try
:
try
:
handler
.
update_data
(
order_id
,
int
)
handler
.
update_data
(
order_id
,
int
)
return
DefaultResponse
(
message
=
"Successfully Updated"
,
status
=
"success"
)
return
DefaultResponse
(
message
=
"Successfully Updated"
,
status
=
"success"
)
except
ValueError
:
except
ValueError
:
return
DefaultResponse
(
message
=
"Due to value error"
)
return
DefaultResponse
(
message
=
"Due to value error"
)
except
Exception
as
e
:
except
Exception
as
e
:
logging
.
exception
(
e
)
logging
.
exception
(
e
)
return
DefaultResponse
(
message
=
"Updation Failed due to server error"
)
return
DefaultResponse
(
message
=
"Updation Failed due to server error"
)
@
router
.
get
(
APIEndpoints
.
find
)
@
router
.
get
(
APIEndpoints
.
find
)
async
def
find_item
(
order_id
:
int
):
async
def
find_item
(
order_id
:
int
):
try
:
try
:
handler
.
find_data
(
order_id
,
int
)
handler
.
find_data
(
order_id
,
int
)
return
DefaultResponse
(
message
=
"Successfully Found"
,
status
=
"success"
)
return
DefaultResponse
(
message
=
"Successfully Found"
,
status
=
"success"
)
except
ValueError
:
except
ValueError
:
return
DefaultResponse
(
message
=
"Due to value error"
)
return
DefaultResponse
(
message
=
"Due to value error"
)
except
Exception
as
e
:
except
Exception
as
e
:
logging
.
exception
(
e
)
logging
.
exception
(
e
)
return
DefaultResponse
(
message
=
"Finding Failed due to server error"
)
return
DefaultResponse
(
message
=
"Finding Failed due to server error"
)
@
router
.
post
(
APIEndpoints
.
insert
)
@
router
.
post
(
APIEndpoints
.
insert
)
async
def
insert_item
(
order_id
:
int
):
async
def
insert_item
(
request_data
:
Inventory
):
try
:
try
:
handler
.
insert_data
(
order_id
,
int
)
handler
.
insert_data
(
request_data
)
return
DefaultResponse
(
message
=
"Successfully inserted"
,
status
=
"success"
)
return
DefaultResponse
(
message
=
"Successfully inserted"
,
status
=
"success"
)
except
ValueError
:
except
ValueError
:
return
DefaultResponse
(
message
=
"Due to value error"
)
return
DefaultResponse
(
message
=
"Due to value error"
)
except
Exception
as
e
:
except
Exception
as
e
:
logging
.
exception
(
e
)
logging
.
exception
(
e
)
return
DefaultResponse
(
message
=
"inserted Failed due to server error"
)
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