diff --git a/app.py b/app.py index 1782212..1328c91 100644 --- a/app.py +++ b/app.py @@ -158,7 +158,7 @@ def user_checkin(gid): if location is None: abort(404) g.user.last_checkin = datetime.datetime.utcnow - g.user.checkin_location = location + location.checkedInUsers.append(g.user) DB.session.commit() return jsonify( result=True diff --git a/location_db.py b/location_db.py index e1485a0..80d824b 100644 --- a/location_db.py +++ b/location_db.py @@ -10,7 +10,7 @@ class Location_DB(DB.Model): __tablename__ = 'locations' id = DB.Column(DB.Integer, primary_key=True) - gid = DB.Column(DB.String(255)) # google id, api returns location with id + gid = DB.Column(DB.String(255), unique=True) # google id, api returns location with id name = DB.Column(DB.String(127)) address = DB.Column(DB.String(127)) phoneNumber = DB.Column(DB.String(50)) diff --git a/migrations/versions/69ed2d1c50d5_.py b/migrations/versions/9c5d06b1cc7c_.py similarity index 79% rename from migrations/versions/69ed2d1c50d5_.py rename to migrations/versions/9c5d06b1cc7c_.py index 7e8e3d4..513cd75 100644 --- a/migrations/versions/69ed2d1c50d5_.py +++ b/migrations/versions/9c5d06b1cc7c_.py @@ -1,8 +1,8 @@ """empty message -Revision ID: 69ed2d1c50d5 +Revision ID: 9c5d06b1cc7c Revises: -Create Date: 2018-03-26 16:53:27.142562 +Create Date: 2018-03-26 23:31:47.287481 """ from alembic import op @@ -10,7 +10,7 @@ # revision identifiers, used by Alembic. -revision = '69ed2d1c50d5' +revision = '9c5d06b1cc7c' down_revision = None branch_labels = None depends_on = None @@ -27,7 +27,8 @@ def upgrade(): sa.Column('priceLevel', sa.Integer(), nullable=True), sa.Column('rating', sa.Float(), nullable=True), sa.Column('currentUserCount', sa.Integer(), nullable=True), - sa.PrimaryKeyConstraint('id') + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('gid') ) op.create_table('users', sa.Column('id', sa.Integer(), nullable=False), @@ -36,6 +37,9 @@ def upgrade(): sa.Column('name', sa.String(length=32), nullable=True), sa.Column('surname', sa.String(length=32), nullable=True), sa.Column('date_created', sa.DateTime(), nullable=True), + sa.Column('lastCheckIn', sa.DateTime(), nullable=True), + sa.Column('checkInLocation', sa.String(length=255), nullable=True), + sa.ForeignKeyConstraint(['checkInLocation'], ['locations.gid'], ), sa.PrimaryKeyConstraint('id') ) # ### end Alembic commands ### diff --git a/user_db.py b/user_db.py index e2e4bb9..5e74565 100644 --- a/user_db.py +++ b/user_db.py @@ -17,9 +17,9 @@ class User_DB(DB.Model): surname = DB.Column(DB.String(32)) date_created = DB.Column(DB.DateTime, default=datetime.datetime.utcnow) # defaults to creation time but should be changed each time user checks in - last_checkin = DB.Column(DB.DateTime) + lastCheckIn = DB.Column(DB.DateTime) # Foreign Key creates a pointer to the locations table - google location id column - checkInlocation = DB.Column(DB.String(255), ForeignKey('locations.gid')) + checkInLocation = DB.Column(DB.String(255), ForeignKey('locations.gid')) # Foreign Key creates a pointer to the matched user #current_match_id = DB.Column(DB.Integer, ForeignKey('users.id'))