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

changed the models #4

Open
wants to merge 1 commit into
base: main
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
43 changes: 43 additions & 0 deletions migrations/versions/973c23c9a386_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""empty message

Revision ID: 973c23c9a386
Revises: ba9c3c892444
Create Date: 2021-06-21 13:20:41.830001

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '973c23c9a386'
down_revision = 'ba9c3c892444'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('log_lag',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('logitude', sa.Float(), nullable=True),
sa.Column('latitude', sa.Float(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('user',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('token', sa.String(length=50), nullable=True),
sa.Column('name', sa.String(length=50), nullable=True),
sa.Column('password', sa.String(length=128), nullable=True),
sa.Column('admin', sa.Boolean(), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('token')
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('user')
op.drop_table('log_lag')
# ### end Alembic commands ###
43 changes: 43 additions & 0 deletions migrations/versions/ba9c3c892444_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""empty message

Revision ID: ba9c3c892444
Revises: c7cb3ebf9fc1
Create Date: 2021-06-21 13:07:26.638233

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'ba9c3c892444'
down_revision = 'c7cb3ebf9fc1'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('log_lag',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('logitude', sa.Float(precision=128), nullable=True),
sa.Column('latitude', sa.Float(precision=128), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('user',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('token', sa.String(length=50), nullable=True),
sa.Column('name', sa.String(length=50), nullable=True),
sa.Column('password', sa.String(length=128), nullable=True),
sa.Column('admin', sa.Boolean(), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('token')
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('user')
op.drop_table('log_lag')
# ### end Alembic commands ###
36 changes: 25 additions & 11 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,36 @@
db = SQLAlchemy(app)
migrate = Migrate(app, db)


# user table
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
company_Name = db.Column(db.String(50), nullable=False)
email = db.Column(db.String(20), nullable=False)
password = db.Column(db.String(20), nullable=False)
files = db.relationship('File', backref='author', lazy=True)

def __repr__(self):
return f"User('{self.company_Name}', '{self.email}' )"

class User(db.Model):

#File Table
class File(db.Model):
id = db.Column(db.Integer, primary_key=True)
token = db.Column(db.String(50), unique=True)
name = db.Column(db.String(50))
password = db.Column(db.String(128))
admin = db.Column(db.Boolean)
file = db.Column(db.LargeBinary, nullable=False)
user = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
file_Metadatas = db.relationship('File_metadata', backref='uploadedFile', lazy=True)

def __repr__(self):
return f"File('{self.id}', )"

class LogLag(db.Model):
# Metadata table
class File_metadata(db.Model):
id = db.Column(db.Integer, primary_key=True)
logitude = db.Column(db.Float(128))
latitude = db.Column(db.Float(128))
file_Name = db.Column(db.String(20), nullable=False)
file_Type = db.Column(db.String(10), nullable=False)
file = db.Column(db.Integer, db.ForeignKey('file.id'), nullable=False)

def __init__(self, logitude, latitude):
self.logitude = logitude
self.latitude = latitude
def __repr__(self):
return f"File_metadata({self.file_Name}, {self.file_Type})"

45 changes: 23 additions & 22 deletions views.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
from flask import jsonify, json, request

from core import app
from models import db, LogLag
# from models import db
# , LogLag


@app.route('/submit', methods=['POST'])
def submit():
data = json.loads(request.data, strict=False)
new_loglat = LogLag(logitude=data['logitude'], latitude=data['latitude'])
db.session.add(new_loglat)
db.session.commit()
return jsonify({"message": "Logititude and Latitude submitted successfully"})
# @app.route('/submit', methods=['POST'])
# def submit():
# data = json.loads(request.data, strict=False)
# new_loglat = LogLag(logitude=data['logitude'], latitude=data['latitude'])
# db.session.add(new_loglat)
# db.session.commit()
# return jsonify({"message": "Logititude and Latitude submitted successfully"})

@app.route('/retrieve', methods=['GET'])
def getLogLat():
location = []
data = json.loads(request.data, strict=False)
resultt = LogLag.query.filter_by(logitude=data['logitude'], latitude=data['latitude'])
for log in resultt:
logi = log.logitude
lati = log.latitude
result = {
"Requested logitude" : logi,
"Requested latitude ": lati
}
location.append(result)
return jsonify( location)
# @app.route('/retrieve', methods=['GET'])
# def getLogLat():
# location = []
# data = json.loads(request.data, strict=False)
# resultt = LogLag.query.filter_by(logitude=data['logitude'], latitude=data['latitude'])
# for log in resultt:
# logi = log.logitude
# lati = log.latitude
# result = {
# "Requested logitude" : logi,
# "Requested latitude ": lati
# }
# location.append(result)
# return jsonify(location)