-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
58 lines (39 loc) · 1.7 KB
/
app.py
File metadata and controls
58 lines (39 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from flask import Flask, request, jsonify, make_response
from flask_sqlalchemy import SQLAlchemy
from flask_marshmallow import Marshmallow
from sqlalchemy.ext.automap import automap_base
import os
app = Flask(__name__)
app.config['SQLALCHEMY_TRACK_MODIFICATION'] = False
#init database
db = SQLAlchemy(app)
#init marshmallow
ma = Marshmallow(app)
with app.app_context():
Base = automap_base()
Base.prepare(db.engine)
Area, Property = Base.classes.Area, Base.classes.Property
class AreaSchema(ma.Schema):
class Meta:
fields = ('areaId', 'area', 'stateId')
# Init schema
area_schema = AreaSchema()
areas_schema = AreaSchema(many=True)
class PropertySchema(ma.Schema):
class Meta:
fields = ( "id", "propertyCode", "developer", "projectName","completionDate", "mapLocation", "state", "area", "propertyType", "numberOfBedrooms", "numberOfWashrooms", "description", "availableUnits", "totalUnits", "price", "propertySize" , "propertyFeatures" ,"status", "businessType", "businessName", "flyer", "video", "images")
property_schema = PropertySchema()
properties_schema = PropertySchema(many=True)
@app.route('/property', methods=['GET'])
def index():
# allProdcuts = db.session.execute(db.select(Area).filter_by(area='Lagos')).scalar_one()
# allProdcuts = db.session.execute(db.select(Area).all()
all_properties = db.session.query(Property).all()
result = properties_schema.dump(all_properties)
resp = { "data" : result , "message" : "success"}
myResponse = make_response( jsonify(resp) )
myResponse.headers['customHeader'] = 'This is a custom header'
myResponse.status_code = 201
return myResponse
if __name__ == "__main__":
app.run(port= 3030, debug=True)