Commit 935e189f authored by Lihinikaduwa D.N.R.  's avatar Lihinikaduwa D.N.R.

Get Level by userId Done

parent 93e39e4e
......@@ -191,9 +191,10 @@ def logout():
return make_response(body)
@app.route("/readingSession", methods=['POST'])
def reading_session():
token = save_session_details(1)
@app.route("/readingSession/<userId>", methods=['POST'])
def reading_session(userId):
assert userId == request.view_args['userId']
token = save_session_details(userId, 1)
response = {
"token": token,
"message": "Success",
......@@ -203,11 +204,11 @@ def reading_session():
return make_response(body)
@app.route("/readingSession/<readingToken>", methods=['PUT'])
@app.route("/readingSession/<userId>", methods=['PUT'])
def reading_session_status_update(readingToken):
assert readingToken == request.view_args['readingToken']
token = readingToken
token = update_session_status(token)
update_session_status(token)
response = {
"message": "Success",
"status": 200
......@@ -219,14 +220,29 @@ def reading_session_status_update(readingToken):
@app.route("/reading/<readingToken>", methods=['POST'])
def save_reading(readingToken):
assert readingToken == request.view_args['readingToken']
token = readingToken
req = request.get_json()
word = req['word']
userId = req['userId']
level = req['level']
triedCount = req['triedCount']
result = save_activity_details(userId, word, token, level, triedCount)
result = save_activity_details(userId, word, readingToken, level, triedCount)
response = {
"message": "Success",
"status": 200
}
body = jsonify(response)
return make_response(body)
@app.route("/level/<userId>", methods=['GET'])
def get_completed_levels(userId):
assert userId == request.view_args['userId']
level = get_completed_levels_by_user(userId)
x = level[0]
y = level[1]
response = {
"level1": x[0],
"level2": y[0],
"message": "Success",
"status": 200
}
......
......@@ -27,10 +27,10 @@ def save_activity_details(userId, word, token, level, triedCount):
return result
def save_session_details(status):
def save_session_details(userId, status):
token = getUUID()
qry = 'INSERT INTO readingSession (id,token,status) VALUES (NULL, %s, %s)'
args = ( token, status)
qry = 'INSERT INTO readingSession (id,userId,token,status) VALUES (NULL, %s, %s, %s)'
args = (userId, token, status)
insert(qry, args)
return token
......@@ -38,3 +38,8 @@ def save_session_details(status):
def update_session_status(token):
qry = 'UPDATE readingSession SET status = 0 WHERE token = "{}"'.format(token)
return update_data(qry)
def get_completed_levels_by_user(userId):
qry = 'SELECT level FROM readingSession WHERE userId = "{}"'.format(userId)
return get_data(qry)
......@@ -13,7 +13,7 @@ import Client from '../../screen/client/Client';
import AsyncStorage from '@react-native-async-storage/async-storage';
const ReadCategory = props => {
const {title, image, id, color, path} = props;
const {title, image, isDisable, path} = props;
const navigation = useNavigation();
......@@ -21,10 +21,8 @@ const ReadCategory = props => {
AsyncStorage.getItem('readingSession')
.then(value => {
if (value == null) {
console.log('bfxcvbfvfdxv', value);
getReadingSession(value);
createReadingSession(value);
} else {
console.log('bfxcvbfvfdxv');
navigation.navigate(path);
}
})
......@@ -33,34 +31,42 @@ const ReadCategory = props => {
});
};
const getReadingSession = () => {
Client.post('readingSession', {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
})
.then(res => {
console.log(res.data);
if (res.status == 200) {
console.log(res.data);
const token = res.data.token;
try {
AsyncStorage.setItem('readingSession', token);
} catch (error) {
const createReadingSession = () => {
AsyncStorage.getItem('userId')
.then(userId => {
Client.post('readingSession/' + userId, {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
})
.then(res => {
console.log(res.data);
if (res.status == 200) {
const token = res.data.token;
try {
AsyncStorage.setItem('readingSession', token);
} catch (error) {
console.log(error);
}
navigation.navigate(path);
}
})
.catch(error => {
console.log(error);
}
navigation.navigate(path);
}
});
})
.catch(error => {
console.log(error);
});
};
return (
<View style={styles.gameItem}>
<TouchableOpacity
disabled={false}
onPress={() => {
checkReadingSession();
}}>
......
......@@ -21,9 +21,12 @@ import ImageButton from '../component/ImageButton';
import ButtonView from '../component/buttonView';
import ReadCategory from '../component/reading/ReadCategory';
import {ImagePaths} from '../assets/read/data/ReadData';
import AsyncStorage from '@react-native-async-storage/async-storage';
import Client from './client/Client';
export default function Read() {
const [activity, setActivity] = useState([]);
const [level1, setLevel1] = useState([]);
const [level2, setLevel2] = useState([]);
const navigation = useNavigation();
......@@ -39,6 +42,35 @@ export default function Read() {
return unsubscribe;
}, [navigation]);
useEffect(() => {
getCompletedLevel();
}, [navigation]);
const getCompletedLevel = () => {
AsyncStorage.getItem('userId')
.then(value => {
Client.get('level/' + value, {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
})
.then(res => {
console.log(res.data);
setLevel1(res.data.level1);
setLevel2(res.data.level2);
})
.catch(error => {
console.log(error);
});
})
.catch(error => {
console.log(error);
});
console.log('getCompletedLevel', level1, level2);
};
return (
<SafeAreaView>
<ScrollView>
......@@ -51,6 +83,7 @@ export default function Read() {
</View> */}
<TouchableOpacity style={styles.screen}>
<ReadCategory
isDisable={''}
title={'Basic'}
image={ImagePaths.roundOne}
path={'ReadActivityNo'}
......
......@@ -84,14 +84,6 @@ export default function ReadActivityGo() {
}
};
const stopRecording = async () => {
try {
await Voice.stop();
} catch (error) {
console.log(error);
}
};
return (
<SafeAreaView>
<View style={{flexDirection: 'column'}}>
......@@ -108,14 +100,6 @@ export default function ReadActivityGo() {
<Text style={styles.text}>Pronounce this Word!</Text>
</View>
</View>
{/* <View style={styles.textBody}>
<Text style={styles.text}>Pronounce this Word!</Text>
</View>
<View style={styles.robo}>
<Image
source={require('../../assets/read/activity-2-rob.png')}></Image>
</View> */}
<View>
<Image style={styles.blackboard} source={ImagePaths.go}></Image>
</View>
......
......@@ -40,15 +40,7 @@ export default function ReadActivityNo() {
};
}, []);
const getToken = data => {
AsyncStorage.getItem('readingSession')
.then(readingSession => {
sendRedingData(data, readingSession);
})
.catch(error => {
console.log(error);
});
};
const sendRedingData = (data, readingSession) => {
Client.post('reading/' + readingSession, JSON.stringify(data), {
......@@ -104,6 +96,17 @@ export default function ReadActivityNo() {
console.log('count', count);
};
const getToken = data => {
AsyncStorage.getItem('readingSession')
.then(readingSession => {
console.log('correct', readingSession);
sendRedingData(data, readingSession);
})
.catch(error => {
console.log(error);
});
};
const startRecording = async () => {
try {
await Voice.start('en-US');
......
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