Added isbn and chekedin to Book table. Moved checkin to add and began reworking how chckedin works. Also added new 'Add' barcode.
This commit is contained in:
40
main.py
40
main.py
@@ -24,8 +24,10 @@ class Book(Base):
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
userid = Column(Integer)
|
||||
locationid = Column(Integer)
|
||||
isbn = Column(String)
|
||||
Title = Column(TEXT)
|
||||
Author = Column(TEXT)
|
||||
CheckedIn = Column(Integer)
|
||||
|
||||
|
||||
class Location(Base):
|
||||
@@ -54,16 +56,40 @@ async def root():
|
||||
return {"message": "Hello World"}
|
||||
|
||||
|
||||
@app.post('/checkin/')
|
||||
async def checkin(isbn: str = Form(...), locationid: int = Form(...), userid: int = Form(...)):
|
||||
@app.post('/add/')
|
||||
async def add(isbn: str = Form(...), locationid: int = Form(...), userid: int = Form(...)):
|
||||
info = await getMeta(isbn)
|
||||
session.add(Book(userid=userid, Title=info['Title'], Author=info['Authors'], locationid=locationid))
|
||||
session.add(Book(userid=userid, Title=info['Title'], Author=info['Authors'], locationid=locationid,
|
||||
isbn=isbn, CheckedIn=1))
|
||||
try:
|
||||
session.commit()
|
||||
except:
|
||||
session.rollback()
|
||||
raise
|
||||
return {"Checked in": info['Title']}
|
||||
return {"Added": info['Title']}
|
||||
|
||||
|
||||
@app.post('/checkin/')
|
||||
async def checkin(isbn: str = Form(...), locationid: int = Form(...)):
|
||||
# for info in session.query(Book).filter(Book.isbn == isbn).first():
|
||||
# print(info.Title)
|
||||
# title = info.Title
|
||||
try:
|
||||
info = session.query(Book).filter(Book.isbn == isbn).first()
|
||||
|
||||
session.query(Book).filter(Book.isbn == isbn, Book.CheckedIn == 0).update({Book.locationid: locationid})
|
||||
session.query(Book).filter(Book.isbn == isbn, Book.CheckedIn == 0).update({Book.CheckedIn: 1})
|
||||
|
||||
try:
|
||||
session.commit()
|
||||
except:
|
||||
session.rollback()
|
||||
raise
|
||||
return {"Checked In": info.Title}
|
||||
|
||||
except:
|
||||
print('none')
|
||||
return {"Checked In": "Failed"}
|
||||
|
||||
|
||||
@app.get('/checkout/{isbn}')
|
||||
@@ -100,11 +126,7 @@ async def checkin(BookCase: str = Form(...), Shelf: str = Form(...)):
|
||||
|
||||
@app.post('/barcodes')
|
||||
async def barcodes(userid: int = Form(...)):
|
||||
barcode = {'Check In': 'CI', 'Check Out': 'CO', 'Lookup': 'LU', 'Update': 'UPDATE', 'Check In1': 'CI',
|
||||
'Check Out1': 'CO', 'Lookup1': 'LU', 'Update1': 'UPDATE','Check In2': 'CI', 'Check Out2': 'CO',
|
||||
'Lookup2': 'LU', 'Update2': 'UPDATE','Check In3': 'CI', 'Check Out3': 'CO', 'Lookup3': 'LU', 'Update3': 'UPDATE', 'Check In4': 'CI',
|
||||
'Check Out4': 'CO', 'Lookup4': 'LU', 'Update4': 'UPDATE','Check In5': 'CI', 'Check Out5': 'CO',
|
||||
'Lookup5': 'LU', 'Update5': 'UPDATE'}
|
||||
barcode = {'Check In': 'CI', 'Check Out': 'CO', 'Lookup': 'LU', 'Update': 'UPDATE', 'Add': 'AD'}
|
||||
pdf = FPDF()
|
||||
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user