Skip to content
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

Book search api #24

Merged
merged 9 commits into from
Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified HeliumDB.db
Binary file not shown.
2 changes: 2 additions & 0 deletions consts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DB_FILE = 'HeliumDB.db'
SEARCH_PAGE_SIZE = 20
35 changes: 16 additions & 19 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from flask import Flask, request, jsonify
from flask import Flask, request
from flask_restful import Resource, Api
import sqlite3 as sql
import traceback, sys

from consts import DB_FILE
from search import Search

app = Flask(__name__, static_url_path='/')
api = Api(app)
Expand All @@ -11,20 +13,8 @@ def index():

app.add_url_rule('/', 'index', index)

with sql.connect('HeliumDB.db') as conn:
file = open('./resources/schema.sql', mode = 'r', encoding='utf-8')
c = conn.cursor()
c.executescript(file.read())

class Quote(Resource):
def get(self):
args = request.args
with sql.connect('HeliumDB.db') as conn:
conn.row_factory = sql.Row
c = conn.cursor()
#return jsonify({"message": 200, "success":True, "data": [dict(x) for x in (c.execute('SELECT * FROM quote').fetchall())]})
return [dict(x) for x in (c.execute('SELECT * FROM quote').fetchall())]

#TODO: refactor as a Borrower Resource with a .put method
def create_borrower():
args = request.args

Expand All @@ -35,7 +25,7 @@ def create_borrower():

stuff = "SSN: " + ssn + "\tBNAME: " + bname + "\tADDRESS: " + address + "\tPHONE: " + phone
return stuff,203
with sql.connect('HeliumDB.db') as conn:
with sql.connect(DB_FILE) as conn:
conn.row_factory = sql.Row
c = conn.cursor()
# @TODO: Check for existing SSN and return useful error if it already exists
Expand All @@ -48,10 +38,17 @@ def create_borrower():
# return [dict(x) for x in (c.execute('SELECT * FROM quote').fetchall())]
return app.make_response(200)

app.add_url_rule('/borrower/create', 'create_borrower', create_borrower, methods=["POST"])

api.add_resource(Quote, '/quote', endpoint='quote')

app.add_url_rule('/borrower/create', 'create_borrower', create_borrower, methods=["POST"])
api.add_resource(Search, '/book/search', endpoint='search')


if __name__ == '__main__':
app.run(debug=True)

with sql.connect(DB_FILE) as conn:
file = open('./resources/schema.sql', mode = 'r', encoding='utf-8')
c = conn.cursor()
c.executescript(file.read())

app.run(debug=True)
Loading