-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Storeitem #2
base: master
Are you sure you want to change the base?
Storeitem #2
Changes from 6 commits
4aa1ea3
46d7a5e
2e868aa
766f812
f535a9e
10cc2a8
11bcf92
c3cc83a
980f9c6
aa74658
dda9135
48aa807
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from utils import database | ||
def dltItem(ItemID): | ||
db=database.Db | ||
query=("DELETE FROM ItemRateChart WHERE ItemID=%s") | ||
params=(ItemID) | ||
return db.delete(query,params) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from utils import database | ||
|
||
def findItem(ItemID): | ||
db= database.Db() | ||
query=("SELECT * FROM ItemRateChart WHERE ItemName=%s") | ||
params=(ItemID,) | ||
return db.select(query,params) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from utils import database | ||
|
||
def addItem(ItemID,ItemName,ItemUnit,CurrentRate): | ||
db=database.Db | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
query=("INSERT INTO ItemRateChart (ItemID,ItemName,ItemUnit,CurrentRate) VALUES(%s,%s,%s,%s)") | ||
params=(ItemID,ItemName,ItemUnit,CurrentRate) | ||
return db.insert(query, params) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from utils import database | ||
|
||
def updateInfo(ItemID,ItemName,ItemUnit,CurrentRate): | ||
db= database.Db | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
query=("UPDATE ItemRateChart SET ItemName=%s,ItemUnit=%s,CurrentRate=%s WHERE ItemID=%s") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if i want to update a single column? |
||
params=(ItemName,ItemUnit,CurrentRate) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why params only have 3 value? How to pass the item_id in the where clause? |
||
return db.update(query,params) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from flask_restful import Resource | ||
from utils import response | ||
from store import get_item,post_item,put_item,delete_item | ||
from flask import request | ||
class Item(Resource): | ||
def get(self,ItemID): | ||
key, data = get_item.findItem(ItemID) | ||
if len(data) == 0: | ||
return response.styler(404) | ||
itemdetails = dict(zip(key,data[0])) | ||
return response.styler(200, itemdetails) | ||
|
||
def post(self,ItemID): | ||
ItemName= request.form["ItemName"] | ||
ItemUnit= request.form["ItemUnit"] | ||
CurrentRate= request.form["CurrentRate"] | ||
err=post_item.addItem(ItemID,ItemName,ItemUnit,CurrentRate) | ||
if err != True: | ||
return response.styler(204) | ||
return response.styler(400) | ||
|
||
def put(self,ItemID): | ||
ItemName=request.form["ItemName"] | ||
ItemUnit=request.form["ItemUnit"] | ||
CurrentRate=request.form["CurrentRate"] | ||
err=put_item.updateInfo(ItemID,ItemName,ItemUnit,CurrentRate) | ||
if err!=True: | ||
return response.styler(204) | ||
return response.styler(400) | ||
|
||
def delete(self,ItemID): | ||
err=delete_item.dltItem(ItemID) | ||
if err!= True: | ||
return response.styler(204) | ||
return response.styler(404) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
from flask import Flask | ||
from flask_restful import Resource, Api | ||
from user import user_routes | ||
from store import store_routes | ||
|
||
app = Flask(__name__) | ||
api = Api(app) | ||
|
||
api.add_resource(user_routes.User, '/user/<string:mobile_num>') | ||
|
||
api.add_resource(store_routes.Item,'/store/<string:ItemID>') |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,4 +29,25 @@ def insert(self,query,params): | |
return True | ||
self.mariadb_connection.commit() | ||
return self.cursor.lastrowid | ||
|
||
def update(self,query,params): | ||
try: | ||
self.cursor.execute(query,params) | ||
print(self.cursor.rowcount, "record updated") | ||
except mariadb.Error as error: | ||
print("Error: {}".format(error)) | ||
return True | ||
self.mariadb_connection.commit() | ||
return self.cursor.lastrowid | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why retrun last row id for update? |
||
|
||
def delete(self,query,params): | ||
try: | ||
self.cursor.execute(query,params) | ||
print(self.cursor.rowcount, "row deleted") | ||
except mariadb.Error as error: | ||
print("Error: {}".format(error)) | ||
return True | ||
self.mariadb_connection.commit() | ||
return self.cursor.lastrowid | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why return last row ID for delete? |
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Db is a class, so needs to have ( ), chek user module.