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

Information of the book #50

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

*.ids
*.xml
*.xml
*.ids
*.xml
*.xml
*.pyc
*.xml
1,179 changes: 675 additions & 504 deletions .idea/dataSources.ids

Large diffs are not rendered by default.

11 changes: 4 additions & 7 deletions .idea/dataSources.local.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

405 changes: 270 additions & 135 deletions .idea/workspace.xml

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions apps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from werkzeug.security import generate_password_hash, check_password_hash
from functools import wraps
from flask_cors import CORS
from base64 import b64encode


app = Flask(__name__)
Expand All @@ -24,15 +25,15 @@
import apps.api


def createDB():
engine = sqlalchemy.create_engine('postgresql://postgres:mvjunetwo@localhost') #connects to server
conn = engine.connect()
conn.execute("commit")
conn.execute("create database bookshelf")
conn.close()

def createTables():
db.create_all()
# def createDB():
# engine = sqlalchemy.create_engine('postgresql://postgres:mvjunetwo@localhost') #connects to server
# conn = engine.connect()
# conn.execute("commit")
# conn.execute("create database bookshelf")
# conn.close()
#
# def createTables():
db.create_all()

#createDB()
createTables()
# createTables()
Binary file modified apps/__init__.pyc
Binary file not shown.
34 changes: 34 additions & 0 deletions apps/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,40 @@ def viewbooks(current_user):

return jsonify({'book': output})

@app.route('/book/info/<int:book_id>', methods=['GET'])
def bookDetail(book_id):

books = Books.query.filter(Books.book_id==book_id).first()

if books is None:
return jsonify({'message': 'No book found!'})

user_data = {}
user_data['title'] = books.title
user_data['description'] = books.description
user_data['edition'] = books.edition
user_data['year'] = books.year_published
user_data['isbn'] = books.isbn
user_data['types'] = books.types
book_author = WrittenByAssociation.query.filter(WrittenByAssociation.book_id==books.book_id).first()
author = Author.query.filter(Author.author_id==book_author.author_id).first()
publisher = Publisher.query.filter(Publisher.publisher_id==books.publisher_id).first()
user_data['publishers'] = publisher.publisher_name
user_data['author_name'] = author.author_name

comments = BookCommentAssociation.query.filter(BookCommentAssociation.book_id==book_id).all()
output = []
for comment in comments:
comment_data = {}
user = User.query.filter(User.id==comment.user_id).first()
comment_data['first_name'] = user.first_name
comment_data['last_name'] = user.last_name
comment_data['comment'] = comment.comment
comment_data['date'] = comment.date
output.append(comment_data)

return jsonify({'book': user_data, 'comments': output})

@app.route('/category/<string:category>/', methods=['GET'])
def category(category):

Expand Down
Binary file modified apps/api.pyc
Binary file not shown.
15 changes: 7 additions & 8 deletions apps/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ class User(UserMixin, db.Model):
contact_number = db.Column(db.String(11))
birth_date = db.Column(db.DATE, nullable=False)
gender = db.Column(db.String(6), nullable=False)
longitude = db.Column(db.FLOAT)
latitude = db.Column(db.FLOAT)
address = db.Column(db.String(100))
profpic = db.Column(db.TEXT)
bookshelf_user = db.relationship('Bookshelf', uselist=False, backref='user_bookshelf')
borrow_bookshelfs = db.relationship('BorrowsAssociation', backref='user_borrow')
Expand Down Expand Up @@ -106,13 +105,11 @@ class Category(db.Model):
class Author(db.Model):
__tablename__ = 'author'
author_id = db.Column(db.Integer, db.ForeignKey('author.author_id'), primary_key=True)
author_first_name = db.Column(db.String(50))
author_last_name = db.Column(db.String(50))
author_name = db.Column(db.String(50))
authorBooks = db.relationship('WrittenByAssociation', backref="author_books")

def __init__(self, author_first_name='', author_last_name=''):
self.author_first_name = author_first_name
self.author_last_name = author_last_name
def __init__(self, author_name=''):
self.author_first_name = author_name


class WrittenByAssociation(db.Model):
Expand Down Expand Up @@ -220,8 +217,9 @@ def __init__(self, user_id='', bookid=''):
# Rates (book)
class BookRateAssociation(db.Model):
__tablename__ = 'bookRate'
comment_id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
book_id = db.Column(db.Integer, db.ForeignKey('books.book_id'), primary_key=True)
book_id = db.Column(db.Integer, db.ForeignKey('books.book_id'))
rating = db.Column(db.Integer)
comment = db.Column(db.TEXT)
user = db.relationship('User', backref='user_booksRate')
Expand Down Expand Up @@ -282,6 +280,7 @@ class BookCommentAssociation(db.Model):
user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
book_id = db.Column(db.Integer, db.ForeignKey('books.book_id'), primary_key=True)
comment = db.Column(db.TEXT)
date = db.Column(db.DATE)
user = db.relationship('User', backref='user_booksComment')
books = db.relationship('Books', backref='bookComment')

Expand Down
Binary file modified apps/models.pyc
Binary file not shown.
4 changes: 2 additions & 2 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

if __name__ == '__main__':
app.run(debug=True)
# port = int(os.environ.get("PORT", 5000))
# app.run(host="0.0.0.0", port=port)
# port = int(os.environ.get("PORT", 5000))
# app.run(host="0.0.0.0", port=port)