Skip to content

Commit c010716

Browse files
committed
Start integration of Solve Count
1 parent 2cd5f93 commit c010716

File tree

6 files changed

+136
-67
lines changed

6 files changed

+136
-67
lines changed

client/src/api/user.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import request from '@/utils/request'
2+
3+
export function getUser(username) {
4+
return request({
5+
url: `/api/v1/user/${username}`,
6+
method: 'get'
7+
})
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { default as UserProfile } from './userProfile.vue'
2+
export { default as SolveCount } from './solveCount.vue'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<template lang="pug">
2+
div
3+
h1.text-center Solve Count
4+
el-table(:data="getSolveCount")
5+
el-table-column(prop="index" label="#")
6+
el-table-column(prop="oj" label="OJ")
7+
</template>
8+
9+
<script>
10+
import { mapGetters } from 'vuex'
11+
import { GetOjInfo } from '@/store/actions'
12+
13+
export default {
14+
props: ['username'],
15+
computed: {
16+
...mapGetters([
17+
'ojInfo'
18+
]),
19+
getSolveCount() {
20+
return Object.keys(this.ojInfo).map((oj, ind) => {
21+
return {
22+
index: ind,
23+
oj
24+
}
25+
})
26+
}
27+
},
28+
async created() {
29+
if (Object.keys(this.ojInfo).length === 0) {
30+
await this.$store.dispatch(GetOjInfo)
31+
}
32+
console.log(this.ojInfo)
33+
}
34+
}
35+
</script>
36+
37+
<style rel="stylesheet/scss" lang="scss" scoped>
38+
39+
</style>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<template lang="pug">
2+
div
3+
h1.text-center User Profile
4+
el-table(:data="getUserFields" align="center")
5+
el-table-column
6+
template(slot-scope="scope")
7+
fa-icon.vertical-middle(:name="scope.row.icon")
8+
span.ml-2 {{scope.row.feature}}
9+
el-table-column(align="center")
10+
template(slot-scope="scope")
11+
template(v-if="scope.row.feature=='Password'")
12+
el-button(size="mini" type="primary" round) Update Password
13+
template(v-else)
14+
span {{scope.row.value}}
15+
</template>
16+
17+
<script>
18+
import { mapGetters } from 'vuex'
19+
20+
export default {
21+
props: ['username'],
22+
computed: {
23+
...mapGetters([
24+
'user'
25+
]),
26+
getUserFields() {
27+
return [{
28+
feature: 'Email',
29+
icon: 'envelope',
30+
value: this.user.email
31+
}, {
32+
feature: 'Username',
33+
icon: 'user',
34+
value: this.user.username
35+
}, {
36+
feature: 'Roles',
37+
icon: 'users',
38+
value: this.user.roles.join(', ')
39+
}, {
40+
feature: 'Password',
41+
icon: 'key'
42+
}]
43+
}
44+
}
45+
}
46+
</script>
47+
48+
<style rel="stylesheet/scss" lang="scss" scoped>
49+
50+
</style>

client/src/views/users/index.vue

+8-39
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,19 @@
22
.app-container
33
el-row(type="flex" justify="center")
44
el-col
5-
h1.text-center User Profile
6-
el-table(:data="getUserFields" align="center")
7-
el-table-column
8-
template(slot-scope="scope")
9-
fa-icon.vertical-middle(:name="scope.row.icon")
10-
span.ml-2 {{scope.row.feature}}
11-
el-table-column(align="center")
12-
template(slot-scope="scope")
13-
template(v-if="scope.row.feature=='Password'")
14-
el-button(size="mini" type="primary" round) Update Password
15-
template(v-else)
16-
span {{scope.row.value}}
5+
UserProfile
6+
el-col
7+
h1.text-center Classroom
8+
el-row
9+
el-col
10+
SolveCount
1711
</template>
1812

1913
<script>
20-
import { mapGetters } from 'vuex'
14+
import { UserProfile, SolveCount } from './components'
2115
2216
export default {
23-
name: 'profile',
24-
props: ['username'],
25-
computed: {
26-
...mapGetters([
27-
'token',
28-
'user'
29-
]),
30-
getUserFields() {
31-
return [{
32-
feature: 'Email',
33-
icon: 'envelope',
34-
value: this.user.email
35-
}, {
36-
feature: 'Username',
37-
icon: 'user',
38-
value: this.user.username
39-
}, {
40-
feature: 'Roles',
41-
icon: 'users',
42-
value: this.user.roles.join(', ')
43-
}, {
44-
feature: 'Password',
45-
icon: 'key'
46-
}]
47-
}
48-
}
17+
components: { UserProfile, SolveCount }
4918
}
5019
</script>
5120

server/api/v1/users.js

+29-28
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ const User = require('mongoose').model('User');
55
// const Gate = require('mongoose').model('Gate');
66
// const ojnames = require(path.join(rootPath, 'models/ojnames'));
77
// const ojnamesOnly = ojnames.data.map((x)=>x.name);
8-
const logger = require('logger');
8+
// const logger = require('logger');
99
// const queue = require('queue');
1010

1111
// router.get('/users/username-userId/:username', getUserIdFromUsername );
1212
// router.get('/users/stats/whoSolvedIt', whoSolvedIt );
1313

1414
router.get('/users/info', getInfo);
1515
router.post('/users/logout', logout);
16-
// router.get('/users/:username', getUser );
16+
router.get('/user/:username', getUser );
1717
// router.get('/users/:username/root-stats', rootStats);
1818
// router.put('/users/:username/sync-solve-count', syncSolveCount);
1919
//
@@ -74,32 +74,33 @@ function logout(req, res, next) {
7474
// }
7575
// }
7676
//
77-
// async function getUser(req, res, next) {
78-
// try {
79-
// const {username} = req.params;
80-
// const {select} = req.query;
81-
//
82-
// const user = await User.findOne({username}).select(select).exec();
83-
//
84-
// if (!user) {
85-
// const err = new Error('No such user');
86-
// err.status = 400;
87-
// throw err;
88-
// }
89-
//
90-
// // Remove sensitive information
91-
// user.email = undefined;
92-
// user.password = undefined;
93-
//
94-
// return res.status(200).json({
95-
// status: 200,
96-
// data: user,
97-
// });
98-
// } catch (err) {
99-
// return next(err);
100-
// }
101-
// }
102-
//
77+
async function getUser(req, res, next) {
78+
try {
79+
const {username} = req.params;
80+
const {select} = req.query;
81+
82+
const user = await User.findOne({_id: username}).select(select).exec();
83+
84+
if (!user) {
85+
return next({
86+
status: 400,
87+
message: `BADPARAM: No such user with username: ${username}.`,
88+
});
89+
}
90+
91+
// Remove sensitive information
92+
user.email = undefined;
93+
user.password = undefined;
94+
95+
return res.status(200).json({
96+
status: 200,
97+
data: user,
98+
});
99+
} catch (err) {
100+
return next(err);
101+
}
102+
}
103+
103104
// async function whoSolvedIt(req, res, next) {
104105
// try {
105106
// const {problemList, classId} = req.query;

0 commit comments

Comments
 (0)