题解点赞功能

This commit is contained in:
masnn committed 2020-04-10 22:05:29 +08:00
1 parent 41261f8c4b
commit 4c2edc3948
5 files changed
+48 -21

No files matched your search

+14 -2
View File
@@ -10,7 +10,8 @@ const
{ ROUTE } = require('../service/server'),
gridfs = require('../service/gridfs'),
queue = require('../service/queue'),
{ NoProblemError, ProblemDataNotFoundError, BadRequestError } = require('../error'),
{ NoProblemError, ProblemDataNotFoundError, BadRequestError,
SolutionNotFoundError } = require('../error'),
{ constants } = require('../options'),
{
PERM_VIEW_PROBLEM,
@@ -242,13 +243,14 @@ class ProblemSolutionHandler extends ProblemDetailHandler {
}
}
let udict = await user.getList(uids);
let pssdict = solution.getListStatus(docids, this.uid);
this.ctx.body.path = [
['problem_main', '/p'],
[this.pdoc.title, `/p/${this.pdoc.pid}`, true],
['problem_solution', null]
];
this.ctx.body = Object.assign(this.ctx.body, {
psdocs, page, pcount, pscount, udict
psdocs, page, pcount, pscount, udict, pssdict
});
}
async post({ psid }) {
@@ -289,6 +291,16 @@ class ProblemSolutionHandler extends ProblemDetailHandler {
await solution.delReply(psid, psrid);
this.ctx.back();
}
async post_upvote() {
let [psdoc, pssdoc] = await solution.vote(this.psdoc._id, this.uid, 1);
this.ctx.body = { vote: psdoc.vote, user_vote: pssdoc.vote };
if (!this.ctx.preferJson) this.ctx.back();
}
async post_downvote() {
let [psdoc, pssdoc] = await solution.vote(this.psdoc._id, this.uid, -1);
this.ctx.body = { vote: psdoc.vote, user_vote: pssdoc.vote };
if (!this.ctx.preferJson) this.ctx.back();
}
}
class ProblemSolutionRawHandler extends ProblemDetailHandler {