Skip to content

Commit

Permalink
Implement all activity state logic with client, server, and database
Browse files Browse the repository at this point in the history
  • Loading branch information
Vineet Malhotra committed Nov 24, 2021
1 parent 4076241 commit f62d4b4
Show file tree
Hide file tree
Showing 27 changed files with 339 additions and 131 deletions.
Binary file modified flask-server/__pycache__/activity.cpython-37.pyc
Binary file not shown.
Binary file modified flask-server/__pycache__/secret.cpython-37.pyc
Binary file not shown.
110 changes: 94 additions & 16 deletions flask-server/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def create_activity():
or request.args.get('actaddress') is None:
return make_response('{"Bad Request": "Check URL"}', 400)

aid = ""
ownerReceived = format(request.args.get('owner'))
nameReceived = format(request.args.get('actname'))
descReceived = format(request.args.get('actdesc'))
Expand All @@ -21,32 +22,34 @@ def create_activity():
timestampReceived = format(request.args.get('creationtime'))
addressReceived = format(request.args.get('actaddress'))

new_activity = [ownerReceived, nameReceived, descReceived, latitudeReceived, longitudeReceived, timestampReceived, addressReceived]
new_activity_json_value = ""
for value in new_activity:
if isinstance(value, str):
new_activity_json_value = new_activity_json_value + "\"" + value + "\"" + ", "
else:
new_activity_json_value = new_activity_json_value + value + ", "
new_activity_json_value = new_activity_json_value[:-2]

conn = psycopg2.connect(dbname='coredb', user='postgres', host='localhost', password=secret.getDbPass())

cursor = conn.cursor()
SQL = 'INSERT INTO "activities" (owner, act_name, act_desc, act_latitude, act_longitude, time, address) ' \
'VALUES (%s, %s, %s, %s, %s, %s, %s);'
'VALUES (%s, %s, %s, %s, %s, %s, %s) RETURNING aid;'

with conn, conn.cursor() as cursor:
cursor.execute(SQL, [ownerReceived, nameReceived, descReceived, latitudeReceived, longitudeReceived, timestampReceived, addressReceived])
aid = str(cursor.fetchone()[0])

status = cursor.statusmessage
status = cursor.statusmessage
conn.close()
print(status)
new_activity = [aid, ownerReceived, nameReceived, descReceived, latitudeReceived, longitudeReceived, timestampReceived,
addressReceived]
new_activity_json_value = ""
for value in new_activity:
if isinstance(value, str):
new_activity_json_value = new_activity_json_value + "\"" + value + "\"" + ", "
else:
new_activity_json_value = new_activity_json_value + value + ", "
new_activity_json_value = new_activity_json_value[:-2]

print(new_activity_json_value)

try:
if str(status) is not "None":
send_new_event('{"ActivityCreated": [[' + str(new_activity_json_value) + ']]}')
return make_response('{"ActivityCreated": "true"}', 200)
return make_response('{"ActivityCreated": ' + aid + '}', 200)
except Exception as e:
return make_response('{"ActivityCreated": "false"}', 404)

Expand Down Expand Up @@ -101,7 +104,45 @@ def fetch_ranged_activities():

@app.route('/activity/fetchGoing', methods=['GET', 'POST'])
def fetch_going_activities():
return fetch_activities_generic('pair')
if request.args.get("pair") is None:
return make_response('{"Bad Request": "Check URL"}', 400)

received = format(request.args.get("pair"))

conn = psycopg2.connect(dbname='coredb', user='postgres', host='localhost', password=secret.getDbPass())

cursor = conn.cursor()
SQL = 'SELECT aid, owner, act_name, act_desc, act_latitude, act_longitude, pair, address FROM "activities" WHERE ' + \
'(((length(pair) >0) AND owner=%s) OR (pair=%s));'

with conn, conn.cursor() as cursor:
cursor.execute(SQL, [received, received])

all_activities = cursor.fetchall()

print(all_activities)
all_activities_list = []
all_activities_json_value = ""
try:
if (len(str(all_activities)) == 2):
return make_response('{"ActivitiesFound": ["false"]}', 200)

elif str(all_activities) is not "None":

for inner_tuple in all_activities:
all_activities_list.append(
str(inner_tuple).replace("\'", "\"").replace("(", "[").replace(")", "]").replace("None",
"\"None\""))
# print(all_activities_list)

for activity in all_activities_list:
all_activities_json_value = all_activities_json_value + activity + ", "

all_activities_json_value = all_activities_json_value[:-2]
print(all_activities_json_value)
return make_response('{"ActivitiesFound": [' + str(all_activities_json_value) + ']}', 200)
except Exception as e:
return make_response('{"ErrorWhileFetchingSentActivities": ' + str(e) + '}', 404)

@app.route('/activity/fetchSent', methods=['GET', 'POST'])
def fetch_sent_activities():
Expand All @@ -111,7 +152,7 @@ def fetch_activities_generic(whereField):
if request.args.get(whereField) is None:
return make_response('{"Bad Request": "Check URL"}', 400)

ownerReceived = format(request.args.get(whereField))
received = format(request.args.get(whereField))

conn = psycopg2.connect(dbname='coredb', user='postgres', host='localhost', password=secret.getDbPass())

Expand All @@ -120,7 +161,7 @@ def fetch_activities_generic(whereField):
whereField + '= %s'

with conn, conn.cursor() as cursor:
cursor.execute(SQL, [ownerReceived])
cursor.execute(SQL, [received])

all_activities = cursor.fetchall()

Expand All @@ -146,14 +187,51 @@ def fetch_activities_generic(whereField):
except Exception as e:
return make_response('{"ErrorWhileFetchingSentActivities": '+str(e)+'}', 404)

@app.route('/activity/addUser', methods=['GET', 'POST'])
def add_user():
if request.args.get("pair") is None:
return make_response('{"Bad Request": "Check URL"}', 400)

receivedActivityId = format(request.args.get("aid"))
receivedPairId = format(request.args.get("pair"))

conn = psycopg2.connect(dbname='coredb', user='postgres', host='localhost', password=secret.getDbPass())

cursor = conn.cursor()
SQL = 'UPDATE "activities" SET pair=%s WHERE aid = %s RETURNING aid, owner;'

with conn, conn.cursor() as cursor:
cursor.execute(SQL, [receivedPairId, receivedActivityId])
response = cursor.fetchone()

try:
aid = str(response[0])
owner = str(response[1])
if (aid is not None and owner is not None):
json_response = '{"ActivityUpdated": [' + aid + ', ' + owner + ']}'
send_activity_pair_update(json_response)
return make_response(json_response, 200)
except Exception as e:
return make_response('{"ErrorWhileUpdatingPairId": ' + str(e) + '}', 404)

print(owner)

return owner

@socket.on('connected')
def handle_id(data):
print(data)

@socket.on('event')
def send_activity_pair_update(ownerId):
print('Sent update to: ' + ownerId)
send(ownerId, broadcast=True, namespace="")

@socket.on('message')
def send_new_event(activity):
print('Sent activity: ' + activity)
send(activity, broadcast=True, namespace="")


# @socket.on('message')
# def send_updated_activity(activity):
2 changes: 1 addition & 1 deletion flutter-ui/.flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"geocoding","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/geocoding-2.0.1/","dependencies":[]},{"name":"geolocator_apple","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/geolocator_apple-1.2.2/","dependencies":[]},{"name":"google_maps_flutter","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/google_maps_flutter-2.1.0/","dependencies":[]},{"name":"shared_preferences","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-2.0.8/","dependencies":[]}],"android":[{"name":"flutter_plugin_android_lifecycle","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_plugin_android_lifecycle-2.0.4/","dependencies":[]},{"name":"geocoding","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/geocoding-2.0.1/","dependencies":[]},{"name":"geolocator_android","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/geolocator_android-2.1.0/","dependencies":[]},{"name":"google_maps_flutter","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/google_maps_flutter-2.1.0/","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"shared_preferences","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-2.0.8/","dependencies":[]}],"macos":[{"name":"geolocator_apple","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/geolocator_apple-1.2.2/","dependencies":[]},{"name":"shared_preferences_macos","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-2.0.2/","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-2.1.0/","dependencies":[]},{"name":"shared_preferences_linux","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_linux-2.0.2/","dependencies":["path_provider_linux"]}],"windows":[{"name":"path_provider_windows","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_windows-2.0.3/","dependencies":[]},{"name":"shared_preferences_windows","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_windows-2.0.2/","dependencies":["path_provider_windows"]}],"web":[{"name":"geolocator_web","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/geolocator_web-2.0.6/","dependencies":[]},{"name":"google_maps_flutter_web","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/google_maps_flutter_web-0.3.2/","dependencies":[]},{"name":"shared_preferences_web","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-2.0.2/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"geocoding","dependencies":[]},{"name":"geolocator","dependencies":["geolocator_android","geolocator_apple","geolocator_web"]},{"name":"geolocator_android","dependencies":[]},{"name":"geolocator_apple","dependencies":[]},{"name":"geolocator_web","dependencies":[]},{"name":"google_maps_flutter","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"google_maps_flutter_web","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_linux","shared_preferences_macos","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2021-11-21 01:47:46.141214","version":"2.6.0-11.0.pre"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"geocoding","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/geocoding-2.0.1/","dependencies":[]},{"name":"geolocator_apple","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/geolocator_apple-1.2.2/","dependencies":[]},{"name":"google_maps_flutter","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/google_maps_flutter-2.1.0/","dependencies":[]},{"name":"shared_preferences","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-2.0.8/","dependencies":[]}],"android":[{"name":"flutter_plugin_android_lifecycle","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_plugin_android_lifecycle-2.0.4/","dependencies":[]},{"name":"geocoding","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/geocoding-2.0.1/","dependencies":[]},{"name":"geolocator_android","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/geolocator_android-2.1.0/","dependencies":[]},{"name":"google_maps_flutter","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/google_maps_flutter-2.1.0/","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"shared_preferences","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-2.0.8/","dependencies":[]}],"macos":[{"name":"geolocator_apple","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/geolocator_apple-1.2.2/","dependencies":[]},{"name":"shared_preferences_macos","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-2.0.2/","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-2.1.0/","dependencies":[]},{"name":"shared_preferences_linux","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_linux-2.0.2/","dependencies":["path_provider_linux"]}],"windows":[{"name":"path_provider_windows","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_windows-2.0.3/","dependencies":[]},{"name":"shared_preferences_windows","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_windows-2.0.2/","dependencies":["path_provider_windows"]}],"web":[{"name":"geolocator_web","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/geolocator_web-2.0.6/","dependencies":[]},{"name":"google_maps_flutter_web","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/google_maps_flutter_web-0.3.2/","dependencies":[]},{"name":"shared_preferences_web","path":"/Users/vinnymalhotra/Documents/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-2.0.2/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"geocoding","dependencies":[]},{"name":"geolocator","dependencies":["geolocator_android","geolocator_apple","geolocator_web"]},{"name":"geolocator_android","dependencies":[]},{"name":"geolocator_apple","dependencies":[]},{"name":"geolocator_web","dependencies":[]},{"name":"google_maps_flutter","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"google_maps_flutter_web","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_linux","shared_preferences_macos","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2021-11-24 12:08:25.398047","version":"2.6.0-11.0.pre"}
Binary file not shown.
Binary file modified flutter-ui/build/ios/Debug-iphonesimulator/App.framework/App
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</data>
<key>flutter_assets/kernel_blob.bin</key>
<data>
0BYHvFnCqausD2abF5mzZLgncF4=
pX87lc5WyVgIH9PTFx1mXJAf/OM=
</data>
<key>flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
<data>
Expand Down Expand Up @@ -117,11 +117,11 @@
<dict>
<key>hash</key>
<data>
0BYHvFnCqausD2abF5mzZLgncF4=
pX87lc5WyVgIH9PTFx1mXJAf/OM=
</data>
<key>hash2</key>
<data>
X7Nf6p+dC32IbFB0/Q9BvzZiNGb6DbB0JPfgs+F3C2g=
HY8MokF6rHdwpqxuAu6oROVmlrN677AF0TQUzC1vkZg=
</data>
</dict>
<key>flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</data>
<key>flutter_assets/kernel_blob.bin</key>
<data>
0BYHvFnCqausD2abF5mzZLgncF4=
pX87lc5WyVgIH9PTFx1mXJAf/OM=
</data>
<key>flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
<data>
Expand Down Expand Up @@ -117,11 +117,11 @@
<dict>
<key>hash</key>
<data>
0BYHvFnCqausD2abF5mzZLgncF4=
pX87lc5WyVgIH9PTFx1mXJAf/OM=
</data>
<key>hash2</key>
<data>
X7Nf6p+dC32IbFB0/Q9BvzZiNGb6DbB0JPfgs+F3C2g=
HY8MokF6rHdwpqxuAu6oROVmlrN677AF0TQUzC1vkZg=
</data>
</dict>
<key>flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
Expand Down
Binary file not shown.
Binary file modified flutter-ui/build/ios/Debug-iphonesimulator/Runner.app/Runner
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@
</data>
<key>Frameworks/App.framework/App</key>
<data>
qAng3ppmwAj1dZNxMUaiDeOregg=
YJUtCIoPR8sN8OyHmNLZZMv12/w=
</data>
<key>Frameworks/App.framework/Info.plist</key>
<data>
2WH3EkzfNpYxRzEQezsUEM18s6A=
</data>
<key>Frameworks/App.framework/_CodeSignature/CodeResources</key>
<data>
7hzSePk7mRbPPFdWIvhhyxOHSeY=
TKXRYiSBSuz96DA0LFrpLt6WicI=
</data>
<key>Frameworks/App.framework/flutter_assets/AssetManifest.json</key>
<data>
Expand Down Expand Up @@ -146,7 +146,7 @@
</data>
<key>Frameworks/App.framework/flutter_assets/kernel_blob.bin</key>
<data>
0BYHvFnCqausD2abF5mzZLgncF4=
pX87lc5WyVgIH9PTFx1mXJAf/OM=
</data>
<key>Frameworks/App.framework/flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
<data>
Expand Down Expand Up @@ -1326,7 +1326,7 @@
<dict>
<key>hash2</key>
<data>
Cksr5fmhb1hmKU9mjeL8kSxGYiLQ/jaMXHtOr87CMro=
b1nbdFY+iXDzJ6PyDy2C1z8XPNQ+kKq/svd4yPAgZao=
</data>
</dict>
<key>Frameworks/App.framework/Info.plist</key>
Expand All @@ -1340,7 +1340,7 @@
<dict>
<key>hash2</key>
<data>
Ar7d/kSjRoI+iSDMISFXKJmbBSaFPJw2EyrnEmnPkf4=
rf9mL9Z9+Rm3oFaIu0IrhzDMaqhaf/S7M8ANOIfXCZU=
</data>
</dict>
<key>Frameworks/App.framework/flutter_assets/AssetManifest.json</key>
Expand Down Expand Up @@ -1389,7 +1389,7 @@
<dict>
<key>hash2</key>
<data>
X7Nf6p+dC32IbFB0/Q9BvzZiNGb6DbB0JPfgs+F3C2g=
HY8MokF6rHdwpqxuAu6oROVmlrN677AF0TQUzC1vkZg=
</data>
</dict>
<key>Frameworks/App.framework/flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
Expand Down
Loading

0 comments on commit f62d4b4

Please sign in to comment.