示例#1
0
class Author(db.Model):
    """Represents an author."""

    author_id = db.Column(db.Integer, primary_key=True)
    first_name = db.Column(db.Text, unique=True, nullable=False)
    last_name = db.Column(db.Text, unique=True, nullable=False)

    def to_json(self):
        author = {}
        author['author_id'] = self.author_id
        author['first_name'] = self.first_name
        author['last_name'] = self.last_name

        return author
示例#2
0
class Book(db.Model):
    """Represents a book."""

    isbn = db.Column(db.Text, primary_key=True, unique=True, nullable=False)
    authors = db.relationship('Author', secondary=author_identifier)
    description = db.Column(db.Text, nullable=False)
    publisher = db.Column(db.Text, nullable=False)
    published_date = db.Column(db.Integer, nullable=False)
    title = db.Column(db.Text, nullable=False)
    thumbnail = db.Column(db.Text, nullable=False)
    small_thumbnail = db.Column(db.Text, nullable=False)
    subtitle = db.Column(db.Text)

    def to_json(self):
        book = {}
        book['isbn'] = self.isbn
        book['authors'] = [
            '{first_name} {last_name}'.format(**author.to_json())
            for author in self.authors
        ]
        book['description'] = self.description
        book['publisher'] = self.publisher
        book['publishedDate'] = self.published_date
        book['title'] = self.title
        book['thumbnail'] = self.thumbnail
        book['smallThumbnail'] = self.small_thumbnail
        book['subtitle'] = self.subtitle

        return book
示例#3
0
class Listing(db.Model):
    """Represents one of three listings -- sale, loan, or swap."""

    listing_id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.Text, db.ForeignKey('user.username'), nullable=False)
    isbn = db.Column(db.Text, db.ForeignKey('book.isbn'), nullable=False)
    condition = db.Column(db.Text, nullable=False)
    price = db.Column(db.Float)
    listing_types = db.relationship('ListingType', secondary=listing_identifier)

    def to_json(self):
        listing = {}
        listing['listingId'] = self.listing_id
        listing['username'] = self.username
        listing['isbn'] = self.isbn
        listing['condition'] = self.condition
        listing['price'] = self.price
        listing['listingTypes'] = [l.listing_type for l in self.listing_types]

        return listing
示例#4
0
class Transaction(db.Model):
    """Represents a transaction between two users."""

    transaction_id = db.Column(db.Integer, primary_key=True)
    buyer = db.Column(db.Text, db.ForeignKey('user.username'), nullable=False)
    seller = db.Column(db.Text, db.ForeignKey('user.username'), nullable=False)
    listing_id = db.Column(db.Integer,
                           db.ForeignKey('listing.listing_id'),
                           nullable=False)
    status = db.Column(db.Text, nullable=False)

    def to_json(self):
        transaction = {}
        transaction['transaction_id'] = self.transaction_id
        transaction['buyer'] = self.buyer
        transaction['seller'] = self.seller
        transaction['listing_id'] = self.listing_id
        transaction['status'] = self.status

        return transaction
示例#5
0
class User(db.Model):
    """Represents a user."""

    user_id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.Text, unique=True, nullable=False)
    password = db.Column(db.Text, nullable=False)
    first_name = db.Column(db.Text, nullable=False)
    last_name = db.Column(db.Text, nullable=False)
    owned_list = db.relationship('Book', secondary=owned_identifier)
    wanted_list = db.relationship('Book', secondary=wanted_identifier)

    def to_json(self):
        user = {}
        user['user_id'] = self.user_id
        user['username'] = self.username
        user['firstName'] = self.first_name
        user['lastName'] = self.last_name
        user['owned'] = [book.to_json() for book in self.owned_list]
        user['wanted'] = [book.to_json() for book in self.wanted_list]

        return user
示例#6
0
"""
user.py

Created by Stephen Andrews, February 17th, 2018.
"""

from book_smart.extensions import db

owned_identifier = db.Table(
    'owned_identifier',
    db.Column('user_id', db.Integer, db.ForeignKey('user.user_id')),
    db.Column('isbn', db.Text, db.ForeignKey('book.isbn')))

wanted_identifier = db.Table(
    'wanted_identifier',
    db.Column('user_id', db.Integer, db.ForeignKey('user.user_id')),
    db.Column('isbn', db.Text, db.ForeignKey('book.isbn')))


class User(db.Model):
    """Represents a user."""

    user_id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.Text, unique=True, nullable=False)
    password = db.Column(db.Text, nullable=False)
    first_name = db.Column(db.Text, nullable=False)
    last_name = db.Column(db.Text, nullable=False)
    owned_list = db.relationship('Book', secondary=owned_identifier)
    wanted_list = db.relationship('Book', secondary=wanted_identifier)

    def to_json(self):
示例#7
0
class ListingType(db.Model):

    listing_type_id = db.Column(db.Integer, primary_key=True)
    listing_type = db.Column(db.Text, nullable=False)
示例#8
0
"""
listing.py

Created by Stephen Andrews, February 19th, 2018.
"""

from book_smart.extensions import db

listing_identifier = db.Table('listing_identifier',
    db.Column('listing_id', db.Integer, db.ForeignKey('listing.listing_id')),
    db.Column('listing_type_id', db.Integer, db.ForeignKey('listing_type.listing_type_id'))
)

class ListingType(db.Model):

    listing_type_id = db.Column(db.Integer, primary_key=True)
    listing_type = db.Column(db.Text, nullable=False)


class Listing(db.Model):
    """Represents one of three listings -- sale, loan, or swap."""

    listing_id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.Text, db.ForeignKey('user.username'), nullable=False)
    isbn = db.Column(db.Text, db.ForeignKey('book.isbn'), nullable=False)
    condition = db.Column(db.Text, nullable=False)
    price = db.Column(db.Float)
    listing_types = db.relationship('ListingType', secondary=listing_identifier)

    def to_json(self):
        listing = {}
示例#9
0
"""
book.py

Created by Stephen Andrews, February 17, 2018.
"""

from book_smart.extensions import db

author_identifier = db.Table(
    'author_identifier',
    db.Column('book_isbn', db.Text, db.ForeignKey('book.isbn')),
    db.Column('author_id', db.Integer, db.ForeignKey('author.author_id')))


class Book(db.Model):
    """Represents a book."""

    isbn = db.Column(db.Text, primary_key=True, unique=True, nullable=False)
    authors = db.relationship('Author', secondary=author_identifier)
    description = db.Column(db.Text, nullable=False)
    publisher = db.Column(db.Text, nullable=False)
    published_date = db.Column(db.Integer, nullable=False)
    title = db.Column(db.Text, nullable=False)
    thumbnail = db.Column(db.Text, nullable=False)
    small_thumbnail = db.Column(db.Text, nullable=False)
    subtitle = db.Column(db.Text)

    def to_json(self):
        book = {}
        book['isbn'] = self.isbn
        book['authors'] = [