Commit 74018e38 authored by Lihinikaduwa D.N.R.  's avatar Lihinikaduwa D.N.R.

Merge branch 'it18257632' into 'master'

It18257632

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