Fix database models
This commit is contained in:
13
app/__init__.py
Normal file
13
app/__init__.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from flask import Flask
|
||||
from config import Config
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from flask_migrate import Migrate
|
||||
from flask_marshmallow import Marshmallow
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(Config)
|
||||
db = SQLAlchemy(app)
|
||||
migrate = Migrate(app, db)
|
||||
ma = Marshmallow(app)
|
||||
|
||||
from app import routes, models, schema
|
||||
363
app/models.py
Normal file
363
app/models.py
Normal file
@@ -0,0 +1,363 @@
|
||||
from app import db
|
||||
from sqlalchemy import text
|
||||
|
||||
|
||||
class Users(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||
social_id = db.Column(db.Text)
|
||||
type = db.Column(db.Integer)
|
||||
full_name = db.Column(db.String(255), index=True, unique=True)
|
||||
email = db.Column(db.String(255), index=True, unique=True)
|
||||
password = db.Column(db.String(255))
|
||||
gender = db.Column(db.Integer)
|
||||
mobile = db.Column(db.String(255))
|
||||
user_image = db.Column(db.String(255))
|
||||
city_id = db.Column(db.Integer)
|
||||
user_type = db.Column(db.Integer)
|
||||
otp = db.Column(db.String(255))
|
||||
otp_valid_time = db.Column(db.Date)
|
||||
access_key = db.Column(db.Text)
|
||||
lang_type = db.Column(db.Integer)
|
||||
badge = db.Column(db.Integer)
|
||||
status = db.Column(db.Integer)
|
||||
admin_status = db.Column(db.Integer)
|
||||
device_id = db.Column(db.Text)
|
||||
device_type = db.Column(db.Integer)
|
||||
created = db.Column(db.TIMESTAMP, nullable=False, server_default=db.func.now())
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
social_id,
|
||||
type,
|
||||
full_name,
|
||||
email,
|
||||
password,
|
||||
gender,
|
||||
mobile,
|
||||
user_image,
|
||||
city_id,
|
||||
user_type,
|
||||
otp,
|
||||
otp_valid_time,
|
||||
access_key,
|
||||
lang_type,
|
||||
badge,
|
||||
status,
|
||||
admin_status,
|
||||
device_id,
|
||||
device_type,
|
||||
):
|
||||
self.social_id = social_id
|
||||
self.type = type
|
||||
self.full_name = full_name
|
||||
self.email = email
|
||||
self.password = password
|
||||
self.gender = gender
|
||||
self.mobile = mobile
|
||||
self.user_image = user_image
|
||||
self.city_id = city_id
|
||||
self.user_type = user_type
|
||||
self.otp = otp
|
||||
self.otp_valid_time = otp_valid_time
|
||||
self.access_key = access_key
|
||||
self.lang_type = lang_type
|
||||
self.badge = badge
|
||||
self.status = status
|
||||
self.admin_status = admin_status
|
||||
self.device_id = device_id
|
||||
self.device_type = device_type
|
||||
|
||||
|
||||
class Cities(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||
name = db.Column(db.String(255))
|
||||
image = db.Column(db.String(255))
|
||||
status = db.Column(db.Enum("1", "0"))
|
||||
created = db.Column(db.DateTime, nullable=False, server_default=db.func.now())
|
||||
modified = db.Column(db.DateTime, nullable=False, onupdate=db.func.now())
|
||||
|
||||
def __init__(self, name, image, status, created, modified):
|
||||
self.name = name
|
||||
self.image = image
|
||||
self.status = status
|
||||
self.created = created
|
||||
self.modified = modified
|
||||
|
||||
|
||||
class Games(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||
name = db.Column(db.String(255))
|
||||
image = db.Column(db.String(255))
|
||||
date_time = db.Column(db.DateTime)
|
||||
price = db.Column(db.String(100))
|
||||
description = db.Column(db.Text)
|
||||
user_id = db.Column(db.Integer)
|
||||
gender = db.Column(db.Enum("1", "2", "3"))
|
||||
city_id = db.Column(db.Integer)
|
||||
venue_id = db.Column(db.Integer)
|
||||
sports_id = db.Column(db.Integer)
|
||||
no_of_player = db.Column(db.Integer)
|
||||
min_player = db.Column(db.Integer)
|
||||
already_player = db.Column(db.Integer)
|
||||
no_of_already_player = db.Column(db.Integer)
|
||||
payment_mode = db.Column(db.Integer)
|
||||
card_id = db.Column(db.Integer)
|
||||
status = db.Column(db.Integer, server_default=text("1"))
|
||||
game_status = db.Column(db.Integer, server_default=text("0"))
|
||||
cancel_status = db.Column(db.Integer)
|
||||
cancel_date = db.Column(db.DateTime)
|
||||
noti_status = db.Column(db.Integer, server_default=text("0"))
|
||||
conduct_status = db.Column(db.Integer, server_default=text("1"))
|
||||
created = db.Column(db.DateTime, nullable=False, server_default=db.func.now())
|
||||
modified = db.Column(db.DateTime, nullable=False, onupdate=db.func.now())
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
name,
|
||||
image,
|
||||
date_time,
|
||||
price,
|
||||
description,
|
||||
user_id,
|
||||
gender,
|
||||
city_id,
|
||||
venue_id,
|
||||
sports_id,
|
||||
no_of_player,
|
||||
min_player,
|
||||
already_player,
|
||||
no_of_already_player,
|
||||
payment_mode,
|
||||
card_id,
|
||||
):
|
||||
self.name = name
|
||||
self.image = image
|
||||
self.date_time = date_time
|
||||
self.price = price
|
||||
self.description = description
|
||||
self.user_id = user_id
|
||||
self.gender = gender
|
||||
self.city_id = city_id
|
||||
self.venue_id = venue_id
|
||||
self.sports_id = sports_id
|
||||
self.no_of_player = no_of_player
|
||||
self.no_of_already_player = no_of_already_player
|
||||
self.payment_mode = payment_mode
|
||||
self.card_id = card_id
|
||||
|
||||
|
||||
class Payments(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||
user_id = db.Column(db.Integer)
|
||||
game_id = db.Column(db.Integer)
|
||||
amount = db.Column(db.Integer)
|
||||
token = db.Column(db.String(100))
|
||||
charge_id = db.Column(db.String(200))
|
||||
transfer_id = db.Column(db.String(200))
|
||||
transaction_id = db.Column(db.String(200))
|
||||
account_no = db.Column(db.String(200))
|
||||
description = db.Column(db.Text)
|
||||
pay_mode = db.Column(db.Integer)
|
||||
status = db.Column(db.Integer)
|
||||
created = db.Column(db.DateTime, nullable=False, server_default=db.func.now())
|
||||
modified = db.Column(db.DateTime, nullable=False, onupdate=db.func.now())
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
user_id,
|
||||
game_id,
|
||||
amount,
|
||||
token,
|
||||
charge_id,
|
||||
transfer_id,
|
||||
transaction_id,
|
||||
account_no,
|
||||
description,
|
||||
pay_mode,
|
||||
status,
|
||||
):
|
||||
self.user_id = user_id
|
||||
self.game_id = game_id
|
||||
self.amount = amount
|
||||
self.token = token
|
||||
self.charge_id = charge_id
|
||||
self.transfer_id = transfer_id
|
||||
self.transaction_id = transaction_id
|
||||
self.account_no = account_no
|
||||
self.description = description
|
||||
self.pay_mode = pay_mode
|
||||
self.status = status
|
||||
|
||||
|
||||
class PlayerAvailabilities(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||
game_id = db.Column(db.Integer)
|
||||
player_id = db.Column(db.Integer)
|
||||
status = db.Column(db.Integer)
|
||||
created = db.Column(db.DateTime, nullable=False, server_default=db.func.now())
|
||||
modified = db.Column(db.DateTime, nullable=False, onupdate=db.func.now())
|
||||
|
||||
def __init__(
|
||||
self, game_id, player_id, status,
|
||||
):
|
||||
self.game_id = game_id
|
||||
self.player_id = player_id
|
||||
self.status = status
|
||||
|
||||
|
||||
class PlayerCancelGames(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||
player_id = db.Column(db.Integer)
|
||||
game_id = db.Column(db.Integer)
|
||||
created = db.Column(db.DateTime, nullable=False, server_default=db.func.now())
|
||||
modified = db.Column(db.DateTime, nullable=False, onupdate=db.func.now())
|
||||
|
||||
def __init__(
|
||||
self, player_id, game_id,
|
||||
):
|
||||
self.player_id = player_id
|
||||
self.game_id = game_id
|
||||
|
||||
|
||||
class PurchaseGames(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||
game_id = db.Column(db.Integer)
|
||||
user_id = db.Column(db.Integer)
|
||||
pay_mode = db.Column(db.Integer)
|
||||
created = db.Column(db.DateTime, nullable=False, server_default=db.func.now())
|
||||
modified = db.Column(db.DateTime, nullable=False, onupdate=db.func.now())
|
||||
|
||||
def __init__(
|
||||
self, game_id, user_id, pay_mode,
|
||||
):
|
||||
self.game_id = game_id
|
||||
self.user_id = user_id
|
||||
self.pay_mode = pay_mode
|
||||
|
||||
|
||||
class Sports(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||
name = db.Column(db.String(255))
|
||||
spanish_name = db.Column(db.String(100))
|
||||
status = db.Column(db.Integer)
|
||||
created = db.Column(db.DateTime, nullable=False, server_default=db.func.now())
|
||||
modified = db.Column(db.DateTime, nullable=False, onupdate=db.func.now())
|
||||
|
||||
def __init__(
|
||||
self, name, spanish_name, status,
|
||||
):
|
||||
self.name = name
|
||||
self.spanish_name = spanish_name
|
||||
self.status = status
|
||||
|
||||
|
||||
class Teams(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||
user_id = db.Column(db.Integer)
|
||||
team_id = db.Column(db.Enum("1", "2"))
|
||||
game_id = db.Column(db.Integer)
|
||||
status = db.Column(db.Integer)
|
||||
created = db.Column(db.DateTime, nullable=False, server_default=db.func.now())
|
||||
modified = db.Column(db.DateTime, nullable=False, onupdate=db.func.now())
|
||||
|
||||
def __init__(
|
||||
self, game_id, user_id, team_id, status,
|
||||
):
|
||||
self.game_id = game_id
|
||||
self.user_id = user_id
|
||||
self.team_id = team_id
|
||||
self.status = status
|
||||
|
||||
|
||||
class UserRatings(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||
game_id = db.Column(db.Integer)
|
||||
user_id = db.Column(db.Integer)
|
||||
player_id = db.Column(db.Enum("1", "2"))
|
||||
rating = db.Column(db.String(100))
|
||||
created = db.Column(db.DateTime, nullable=False, server_default=db.func.now())
|
||||
modified = db.Column(db.DateTime, nullable=False, onupdate=db.func.now())
|
||||
user_type = db.Column(db.Integer)
|
||||
|
||||
def __init__(self, game_id, user_id, player_id, rating, user_type):
|
||||
self.game_id = game_id
|
||||
self.user_id = user_id
|
||||
self.player_id = player_id
|
||||
self.rating = rating
|
||||
self.user_type = user_type
|
||||
|
||||
|
||||
class VenueImages(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||
venue_id = db.Column(db.Integer)
|
||||
user_id = db.Column(db.Integer)
|
||||
image = db.Column(db.String(255))
|
||||
created = db.Column(db.DateTime, nullable=False, server_default=db.func.now())
|
||||
updated = db.Column(db.DateTime, nullable=False, onupdate=db.func.now())
|
||||
|
||||
def __init__(
|
||||
self, venue_id, user_id, image,
|
||||
):
|
||||
self.venue_id = venue_id
|
||||
self.user_id = user_id
|
||||
self.image = image
|
||||
|
||||
|
||||
class Venues(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||
user_id = db.Column(db.Integer)
|
||||
address = db.Column(db.Text)
|
||||
latitude = db.Column(db.String(100))
|
||||
longitude = db.Column(db.String(100))
|
||||
name = db.Column(db.String(100))
|
||||
sports_id = db.Column(db.Integer)
|
||||
created = db.Column(db.DateTime, nullable=False, server_default=db.func.now())
|
||||
modified = db.Column(db.DateTime, nullable=False, onupdate=db.func.now())
|
||||
|
||||
def __init__(
|
||||
self, user_id, address, latitude, longitude, name, sports_id,
|
||||
):
|
||||
self.user_id = user_id
|
||||
self.address = address
|
||||
self.latitude = latitude
|
||||
self.longitude = longitude
|
||||
self.name = name
|
||||
self.sports_id = sports_id
|
||||
|
||||
|
||||
class ViewNews(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||
news_id = db.Column(db.Integer)
|
||||
user_id = db.Column(db.Integer)
|
||||
created = db.Column(db.DateTime, nullable=False, server_default=db.func.now())
|
||||
updated = db.Column(db.DateTime, nullable=False, onupdate=db.func.now())
|
||||
|
||||
def __init__(
|
||||
self, news_id, user_id,
|
||||
):
|
||||
self.news_id = news_id
|
||||
self.user_id = user_id
|
||||
|
||||
|
||||
class WebBookings(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||
name = db.Column(db.String(255))
|
||||
email = db.Column(db.String(255))
|
||||
contact = db.Column(db.String(100))
|
||||
message = db.Column(db.Text)
|
||||
game = db.Column(db.String(255))
|
||||
city = db.Column(db.String(100))
|
||||
created = db.Column(db.DateTime, nullable=False, server_default=db.func.now())
|
||||
updated = db.Column(db.DateTime, nullable=False, onupdate=db.func.now())
|
||||
|
||||
def __init__(
|
||||
self, user_id, address, name, email, contact, message, game, city,
|
||||
):
|
||||
self.user_id = user_id
|
||||
self.address = address
|
||||
self.name = name
|
||||
self.email = email
|
||||
self.contact = contact
|
||||
self.message = message
|
||||
self.game = game
|
||||
self.city = city
|
||||
20
app/routes.py
Normal file
20
app/routes.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from flask import request, jsonify, make_response
|
||||
from database.crud import insert_data, verify_otp
|
||||
from app.twilio import send_otp
|
||||
from app import app
|
||||
|
||||
|
||||
@app.route("/register", methods=["POST"])
|
||||
def create_user():
|
||||
data = request.get_json()
|
||||
insert_data(schema="Users", data=data)
|
||||
send_otp(receiver=data["mobile"])
|
||||
return make_response(jsonify("User created, pending OTP verification"))
|
||||
|
||||
|
||||
@app.route("/verifyotp", methods=["POST"])
|
||||
def validate_otp():
|
||||
data = request.get_json()
|
||||
if verify_otp(mobile=data["mobile"], otp=data["otp"]):
|
||||
return make_response(jsonify("The OTP has been verified successfully"))
|
||||
return make_response(jsonify("The OTP is not correct"))
|
||||
101
app/schema.py
Normal file
101
app/schema.py
Normal file
@@ -0,0 +1,101 @@
|
||||
from app import ma
|
||||
from app.models import *
|
||||
from marshmallow import fields
|
||||
from marshmallow.validate import Length, Range
|
||||
|
||||
|
||||
class UsersSchema(ma.Schema):
|
||||
full_name = fields.Str(required=True, validate=Length(max=255))
|
||||
email = fields.Email(required=True, validate=Length(max=255))
|
||||
password = fields.Str(validate=Length(max=255))
|
||||
gender = fields.Integer(required=True, validate=Range(min=1, max=2))
|
||||
mobile = fields.Str(required=True, validate=Length(max=13))
|
||||
user_image = fields.Str(validate=Length(max=255))
|
||||
user_type = fields.Integer(required=True, validate=Range(min=1, max=2))
|
||||
lang_type = fields.Integer(required=True, validate=Range(min=1, max=2))
|
||||
device_type = fields.Integer(required=True, validate=Range(min=1, max=2))
|
||||
device_id = fields.Str(required=True)
|
||||
|
||||
|
||||
class CitiesSchema(ma.SQLAlchemyAutoSchema):
|
||||
class Meta:
|
||||
model = Cities
|
||||
load_instance = True
|
||||
include_relationships = True
|
||||
|
||||
|
||||
class GamesSchema(ma.SQLAlchemyAutoSchema):
|
||||
class Meta:
|
||||
model = Games
|
||||
load_instance = True
|
||||
include_relationships = True
|
||||
|
||||
|
||||
class PlayerAvailabilitiesSchema(ma.SQLAlchemyAutoSchema):
|
||||
class Meta:
|
||||
model = PlayerAvailabilities
|
||||
load_instance = True
|
||||
include_relationships = True
|
||||
|
||||
|
||||
class PlayerCancelGamesSchema(ma.SQLAlchemyAutoSchema):
|
||||
class Meta:
|
||||
model = PlayerCancelGames
|
||||
load_instance = True
|
||||
include_relationships = True
|
||||
|
||||
|
||||
class PurchaseGamesSchema(ma.SQLAlchemyAutoSchema):
|
||||
class Meta:
|
||||
model = PurchaseGames
|
||||
load_instance = True
|
||||
include_relationships = True
|
||||
|
||||
|
||||
class SportsSchema(ma.SQLAlchemyAutoSchema):
|
||||
class Meta:
|
||||
model = Sports
|
||||
load_instance = True
|
||||
include_relationships = True
|
||||
|
||||
|
||||
class TeamsSchema(ma.SQLAlchemyAutoSchema):
|
||||
class Meta:
|
||||
model = Teams
|
||||
load_instance = True
|
||||
include_relationships = True
|
||||
|
||||
|
||||
class UserRatingsSchema(ma.SQLAlchemyAutoSchema):
|
||||
class Meta:
|
||||
model = UserRatings
|
||||
load_instance = True
|
||||
include_relationships = True
|
||||
|
||||
|
||||
class VenueImagesSchema(ma.SQLAlchemyAutoSchema):
|
||||
class Meta:
|
||||
model = VenueImages
|
||||
load_instance = True
|
||||
include_relationships = True
|
||||
|
||||
|
||||
class VenuesSchema(ma.SQLAlchemyAutoSchema):
|
||||
class Meta:
|
||||
model = Venues
|
||||
load_instance = True
|
||||
include_relationships = True
|
||||
|
||||
|
||||
class ViewNewsSchema(ma.SQLAlchemyAutoSchema):
|
||||
class Meta:
|
||||
model = ViewNews
|
||||
load_instance = True
|
||||
include_relationships = True
|
||||
|
||||
|
||||
class WebBookingsSchema(ma.SQLAlchemyAutoSchema):
|
||||
class Meta:
|
||||
model = WebBookings
|
||||
load_instance = True
|
||||
include_relationships = True
|
||||
25
app/twilio.py
Normal file
25
app/twilio.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from twilio.rest import Client
|
||||
from secrets import randbits
|
||||
from constants import account_id, token, sms_sender
|
||||
from database.crud import save_otp
|
||||
|
||||
|
||||
def connect_api():
|
||||
account_sid = account_id
|
||||
auth_token = token
|
||||
client = Client(account_sid, auth_token)
|
||||
return client
|
||||
|
||||
|
||||
def generate_code():
|
||||
bits = 16
|
||||
code = randbits(bits)
|
||||
return code
|
||||
|
||||
|
||||
def send_otp(receiver):
|
||||
client = connect_api()
|
||||
code = generate_code()
|
||||
message = "Your OTP code is {0}".format(code)
|
||||
client.messages.create(to=receiver, from_=sms_sender, body=message)
|
||||
save_otp(receiver, code)
|
||||
Reference in New Issue
Block a user