Commit 474784d5 authored by Lihinikaduwa D.N.R.  's avatar Lihinikaduwa D.N.R.

Read session and save save_activity_details done

parent c460d9e0
...@@ -3,7 +3,7 @@ from flask import Flask, redirect, url_for, render_template, request, jsonify, m ...@@ -3,7 +3,7 @@ from flask import Flask, redirect, url_for, render_template, request, jsonify, m
import random import random
import os import os
from API.model.colorModel import get_color_activities1, get_color_activities2, get_color_activity_result from API.model.colorModel import get_color_activities1, get_color_activities2, get_color_activity_result
from API.model.readModel import get_reading_activities, save_activity_details from API.model.readModel import get_reading_activities, save_activity_details, save_session_details
from API.model.userModel import getUser, saveUserSession from API.model.userModel import getUser, saveUserSession
from API.model.colorModel import get_color_activities1, get_color_activities2, get_color_activity_result, storeResult from API.model.colorModel import get_color_activities1, get_color_activities2, get_color_activity_result, storeResult
from API.model.readModel import get_reading_activities from API.model.readModel import get_reading_activities
...@@ -106,9 +106,9 @@ def predict(): ...@@ -106,9 +106,9 @@ def predict():
# return jsonify("print") # return jsonify("print")
# return "Print" # return "Print"
@app.route("/store", methods=["POST"]) @app.route("/store", methods=["POST"])
def store(): def store():
req = request.get_json() req = request.get_json()
value = req['value'] value = req['value']
date = req['date'] date = req['date']
...@@ -123,6 +123,7 @@ def store(): ...@@ -123,6 +123,7 @@ def store():
print(e) print(e)
return e return e
# Read Function Route (IT) # Read Function Route (IT)
...@@ -170,6 +171,20 @@ def login(): ...@@ -170,6 +171,20 @@ def login():
return make_response(body) return make_response(body)
@app.route("/readingSession", methods=['POST'])
def reading_session():
req = request.get_json()
userId = req['userId']
token = save_session_details(userId, 1)
data = {
"token": token,
"message": "Success",
"status": 200
}
body = jsonify(data)
return make_response(body)
@app.route("/reading", methods=['POST']) @app.route("/reading", methods=['POST'])
def reading(): def reading():
req = request.get_json() req = request.get_json()
...@@ -179,7 +194,6 @@ def reading(): ...@@ -179,7 +194,6 @@ def reading():
level = req['level'] level = req['level']
triedCount = req['triedCount'] triedCount = req['triedCount']
result = save_activity_details(userId, word, token, level, triedCount) result = save_activity_details(userId, word, token, level, triedCount)
print(result)
body = jsonify(word) body = jsonify(word)
return make_response(body) return make_response(body)
......
...@@ -32,7 +32,6 @@ def get_all_data(query): ...@@ -32,7 +32,6 @@ def get_all_data(query):
return result return result
def insert_data_pandas_df(pd_df, table_name): def insert_data_pandas_df(pd_df, table_name):
db = create_con_pandas() db = create_con_pandas()
pd_df.to_sql(name=table_name, con=db, if_exists='append', index=False) pd_df.to_sql(name=table_name, con=db, if_exists='append', index=False)
......
from API.db.dbConnection import get_all_data, insert from API.db.dbConnection import get_all_data, insert
from flask import jsonify from flask import jsonify
from API.util.util import getUUID
def get_reading_activities(): def get_reading_activities():
data_dic = [] data_dic = []
...@@ -24,3 +24,11 @@ def save_activity_details(userId, word, token, level, triedCount): ...@@ -24,3 +24,11 @@ def save_activity_details(userId, word, token, level, triedCount):
args = (userId, word, token, level, triedCount) args = (userId, word, token, level, triedCount)
result = insert(qry, args) result = insert(qry, args)
return result return result
def save_session_details(userId, status):
token = getUUID()
qry = 'INSERT INTO readingSession (id,userId,token,status) VALUES (NULL, %s, %s, %s)'
args = (userId, token, status)
insert(qry, args)
return token
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment