use of org.springframework.web.bind.annotation.PostMapping in project scoold by Erudika.
the class LanguagesController method post.
@PostMapping("/{langkey}")
public String post(@PathVariable String langkey, HttpServletRequest req, HttpServletResponse res) {
Locale locale = utils.getCurrentLocale(langkey, req);
if (locale != null) {
//1 year
int maxAge = 60 * 60 * 24 * 365;
Utils.setRawCookie(LOCALE_COOKIE, locale.getLanguage(), req, res, false, maxAge);
}
return "redirect:" + languageslink;
}
use of org.springframework.web.bind.annotation.PostMapping in project scoold by Erudika.
the class QuestionController method replyAjax.
@PostMapping({ "/{id}", "/{id}/{title}" })
public String replyAjax(@PathVariable String id, @PathVariable(required = false) String title, @RequestParam(required = false) Boolean emailme, HttpServletRequest req, HttpServletResponse res, Model model) throws IOException {
Post showPost = pc.read(id);
Profile authUser = utils.getAuthUser(req);
if (showPost != null && emailme != null) {
if (emailme) {
showPost.addFollower(authUser.getUser());
} else {
showPost.removeFollower(authUser.getUser());
}
// update without adding revisions
pc.update(showPost);
} else if (showPost != null && !showPost.isClosed() && !showPost.isReply()) {
//create new answer
Reply answer = utils.populate(req, new Reply(), "body");
Map<String, String> error = utils.validate(answer);
if (!error.containsKey("body")) {
answer.setTitle(showPost.getTitle());
answer.setCreatorid(authUser.getId());
answer.setParentid(showPost.getId());
answer.create();
showPost.setAnswercount(showPost.getAnswercount() + 1);
if (showPost.getAnswercount() >= MAX_REPLIES_PER_POST) {
showPost.setCloserid("0");
}
// update without adding revisions
pc.update(showPost);
utils.addBadgeAndUpdate(authUser, Badge.EUREKA, answer.getCreatorid().equals(showPost.getCreatorid()));
answer.setAuthor(authUser);
model.addAttribute("showPost", showPost);
model.addAttribute("answerslist", Collections.singletonList(answer));
// send email to the question author
sendReplyNotifications(showPost, answer);
return "reply";
}
}
if (utils.isAjaxRequest(req)) {
res.setStatus(200);
return "base";
} else {
return "redirect:" + questionslink + "/" + id;
}
}
use of org.springframework.web.bind.annotation.PostMapping in project scoold by Erudika.
the class QuestionController method restore.
@PostMapping("/{id}/restore/{revisionid}")
public String restore(@PathVariable String id, @PathVariable String revisionid, HttpServletRequest req) {
Post showPost = pc.read(id);
Profile authUser = utils.getAuthUser(req);
if (!utils.canEdit(showPost, authUser) || showPost == null) {
return "redirect:" + req.getRequestURI();
}
if (utils.canEdit(showPost, authUser)) {
utils.addBadgeAndUpdate(authUser, Badge.BACKINTIME, true);
showPost.restoreRevisionAndUpdate(revisionid);
}
return "redirect:" + showPost.getPostLink(false, false);
}
use of org.springframework.web.bind.annotation.PostMapping in project scoold by Erudika.
the class QuestionController method approve.
@PostMapping("/{id}/approve/{answerid}")
public String approve(@PathVariable String id, @PathVariable String answerid, HttpServletRequest req) {
Post showPost = pc.read(id);
Profile authUser = utils.getAuthUser(req);
if (!utils.canEdit(showPost, authUser) || showPost == null) {
return "redirect:" + req.getRequestURI();
}
if (utils.canEdit(showPost, authUser) && answerid != null && utils.isMine(showPost, authUser)) {
Reply answer = (Reply) pc.read(answerid);
if (answer != null && answer.isReply()) {
Profile author = pc.read(answer.getCreatorid());
if (author != null && utils.isAuthenticated(req)) {
boolean same = author.equals(authUser);
if (answerid.equals(showPost.getAnswerid())) {
// Answer approved award - UNDO
showPost.setAnswerid("");
if (!same) {
author.removeRep(ANSWER_APPROVE_REWARD_AUTHOR);
authUser.removeRep(ANSWER_APPROVE_REWARD_VOTER);
pc.updateAll(Arrays.asList(author, authUser));
}
} else {
// Answer approved award - GIVE
showPost.setAnswerid(answerid);
if (!same) {
author.addRep(ANSWER_APPROVE_REWARD_AUTHOR);
authUser.addRep(ANSWER_APPROVE_REWARD_VOTER);
utils.addBadgeOnce(authUser, Badge.NOOB, true);
pc.updateAll(Arrays.asList(author, authUser));
}
}
showPost.update();
}
}
}
return "redirect:" + showPost.getPostLink(false, false);
}
use of org.springframework.web.bind.annotation.PostMapping in project scoold by Erudika.
the class TranslateController method delete.
@PostMapping("/delete/{id}")
public String delete(@PathVariable String id, HttpServletRequest req, Model model) {
if (id != null && utils.isAuthenticated(req)) {
Translation trans = (Translation) pc.read(id);
Profile authUser = utils.getAuthUser(req);
if (authUser.getId().equals(trans.getCreatorid()) || utils.isAdmin(authUser)) {
utils.getLangutils().disapproveTranslation(trans.getLocale(), trans.getId());
pc.delete(trans);
}
if (!utils.isAjaxRequest(req)) {
return "redirect:" + req.getRequestURI();
}
}
return "base";
}
Aggregations