Added pool_recycle to create_engine. Added logic to add shelves.
This commit is contained in:
11
index.html
11
index.html
@@ -7,6 +7,9 @@
|
||||
<button>Submit</button>
|
||||
</form>
|
||||
<form action="http://127.0.0.1:8000/checkin" method="POST">
|
||||
<label for="locationid">Location<br></label>
|
||||
<input name="locationid" id="location" value=" ">
|
||||
<br>
|
||||
<label for="isbn">Add Book<br></label>
|
||||
<input name="isbn" id="isbn" value=" ">
|
||||
<button>Submit</button>
|
||||
@@ -14,6 +17,14 @@
|
||||
<form action="http://127.0.0.1:8000/getbooks/1" method="GET">
|
||||
<button>Get Books</button>
|
||||
</form>
|
||||
|
||||
<form action="http://127.0.0.1:8000/AddLocation" method="POST">
|
||||
<label for="BookCase">Bookcase</label>
|
||||
<input name="BookCase" id="Bookcase" value=" "><br>
|
||||
<label for="Shelf">Shelf</label>
|
||||
<input name="Shelf" id="Shelf" value=" ">
|
||||
<button>Submit</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
||||
33
main.py
33
main.py
@@ -21,12 +21,22 @@ class Book(Base):
|
||||
__tablename__ = 'Book'
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
userid = Column(Integer)
|
||||
locationid = Column(Integer)
|
||||
Title = Column(TEXT)
|
||||
Author = Column(TEXT)
|
||||
|
||||
|
||||
class Location(Base):
|
||||
__tablename__ = 'Location'
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
userid = Column(Integer)
|
||||
Bookcase = Column(Integer)
|
||||
Shelf = Column(Integer)
|
||||
|
||||
|
||||
# Connect to database and establish a session
|
||||
engine = create_engine('mysql+pymysql://library:jdSCAd6KEqfbpzh9NT4x@db.dandembinski.com:3306/Library')
|
||||
engine = create_engine('mysql+pymysql://library:jdSCAd6KEqfbpzh9NT4x@db.dandembinski.com:3306/Library',
|
||||
pool_recycle=3600)
|
||||
# engine.connect()
|
||||
|
||||
Session = sessionmaker(bind=engine)
|
||||
@@ -42,10 +52,14 @@ async def root():
|
||||
|
||||
|
||||
@app.post('/checkin/')
|
||||
async def checkin(isbn: str = Form(...)):
|
||||
async def checkin(isbn: str = Form(...), locationid: int = Form(...)):
|
||||
info = await getMeta(isbn)
|
||||
session.add(Book(userid=1, Title=info['Title'], Author=info['Authors']))
|
||||
session.commit()
|
||||
session.add(Book(userid=1, Title=info['Title'], Author=info['Authors'], locationid=locationid))
|
||||
try:
|
||||
session.commit()
|
||||
except:
|
||||
session.rollback()
|
||||
raise
|
||||
return {"Checked in": info['Title']}
|
||||
|
||||
|
||||
@@ -71,6 +85,17 @@ async def lookup(isbn: str = Form(...)):
|
||||
return {"Title": info['Title']}
|
||||
|
||||
|
||||
@app.post('/AddLocation/')
|
||||
async def checkin(BookCase: str = Form(...), Shelf: str = Form(...)):
|
||||
|
||||
location = []
|
||||
session.add(Location(userid=1, Bookcase=BookCase, Shelf=Shelf))
|
||||
session.commit()
|
||||
location.append(BookCase)
|
||||
location.append(Shelf)
|
||||
return {"Location Added": location}
|
||||
|
||||
|
||||
async def getMeta(isbn):
|
||||
info = meta(isbn, service='wiki')
|
||||
return info
|
||||
|
||||
Reference in New Issue
Block a user