Skip to content
This repository has been archived by the owner on May 16, 2019. It is now read-only.

Commit

Permalink
Adding the ability to get sales by their status to the REST API.
Browse files Browse the repository at this point in the history
This includes a db.sales.get_by_status() function.
  • Loading branch information
TimPollard committed Jul 6, 2016
1 parent 5ba23b6 commit d5fb5e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion api/restapi.py
Expand Up @@ -1110,7 +1110,10 @@ def mark_chat_message_as_read(self, request):
@GET('^/api/v1/get_sales')
@authenticated
def get_sales(self, request):
sales = self.db.sales.get_all()
if "status" in request.args:
sales = self.db.sales.get_by_status(request.args["status"][0])
else:
sales = self.db.sales.get_all()
sales_list = []
for sale in sales:
sale_json = {
Expand Down
10 changes: 10 additions & 0 deletions db/datastore.py
Expand Up @@ -1084,6 +1084,16 @@ def get_all(self):
conn.close()
return ret

def get_by_status(self, status):
conn = Database.connect_database(self.PATH)
cursor = conn.cursor()
cursor.execute('''SELECT id, title, description, timestamp, btc, status,
thumbnail, buyer, contractType, unread, statusChanged FROM sales WHERE
status=?''', (status,))
ret = cursor.fetchall()
conn.close()
return ret

def get_unfunded(self):
conn = Database.connect_database(self.PATH)
cursor = conn.cursor()
Expand Down

0 comments on commit d5fb5e8

Please sign in to comment.