use of org.springframework.web.bind.annotation.PostMapping in project scoold by Erudika.
the class TranslateController method post.
@PostMapping("/{locale}/{index}")
public String post(@PathVariable String locale, @PathVariable String index, @RequestParam String value, HttpServletRequest req, Model model) {
Locale showLocale = utils.getLangutils().getProperLocale(locale);
if (utils.isAuthenticated(req) && showLocale != null && !"en".equals(showLocale.getLanguage())) {
Set<String> approved = utils.getLangutils().getApprovedTransKeys(showLocale.getLanguage());
Profile authUser = utils.getAuthUser(req);
String langkey = langkeys.get(getIndex(index, langkeys));
boolean isTranslated = approved.contains(langkey);
if (!StringUtils.isBlank(value) && (!isTranslated || utils.isAdmin(authUser))) {
Translation trans = new Translation(showLocale.getLanguage(), langkey, StringUtils.trim(value));
trans.setCreatorid(authUser.getId());
trans.setAuthorName(authUser.getName());
trans.setTimestamp(System.currentTimeMillis());
pc.create(trans);
model.addAttribute("newtranslation", trans);
}
if (!utils.isAjaxRequest(req)) {
return "redirect:" + translatelink + "/" + showLocale.getLanguage() + "/" + getNextIndex(getIndex(index, langkeys), approved, langkeys);
}
}
return "base";
}
use of org.springframework.web.bind.annotation.PostMapping in project scoold by Erudika.
the class TranslateController method approve.
@PostMapping("/approve/{id}")
public String approve(@PathVariable String id, HttpServletRequest req, Model model) {
Translation trans = (Translation) pc.read(id);
if (trans != null && utils.isAuthenticated(req)) {
if (trans.getApproved()) {
trans.setApproved(false);
utils.getLangutils().disapproveTranslation(trans.getLocale(), trans.getId());
} else {
trans.setApproved(true);
utils.getLangutils().approveTranslation(trans.getLocale(), trans.getThekey(), trans.getValue());
utils.addBadge((Profile) pc.read(trans.getCreatorid()), POLYGLOT, true, true);
}
pc.update(trans);
}
if (!utils.isAjaxRequest(req)) {
return "redirect:" + req.getRequestURI();
}
return "base";
}
use of org.springframework.web.bind.annotation.PostMapping in project scoold by Erudika.
the class QuestionController method delete.
@PostMapping("/{id}/delete")
public String delete(@PathVariable String id, HttpServletRequest req) {
Post showPost = pc.read(id);
Profile authUser = utils.getAuthUser(req);
if (!utils.canEdit(showPost, authUser) || showPost == null) {
return "redirect:" + req.getRequestURI();
}
if (!showPost.isReply()) {
if ((utils.isMine(showPost, authUser) || utils.isMod(authUser))) {
showPost.delete();
return "redirect:" + questionslink + "?success=true&code=16";
}
} else if (showPost.isReply()) {
if (utils.isMine(showPost, authUser) || utils.isMod(authUser)) {
Post parent = pc.read(showPost.getParentid());
parent.setAnswercount(parent.getAnswercount() - 1);
parent.update();
showPost.delete();
}
}
return "redirect:" + showPost.getPostLink(false, false);
}
use of org.springframework.web.bind.annotation.PostMapping in project scoold by Erudika.
the class QuestionsController method post.
@PostMapping("/questions/ask")
public String post(@RequestParam(required = false) String location, @RequestParam(required = false) String latlng, @RequestParam(required = false) String address, HttpServletRequest req, Model model) {
if (utils.isAuthenticated(req)) {
Profile authUser = utils.getAuthUser(req);
Question q = utils.populate(req, new Question(), "title", "body", "tags|,", "location");
q.setCreatorid(authUser.getId());
Map<String, String> error = utils.validate(q);
if (error.isEmpty()) {
q.setLocation(location);
String qid = q.create();
if (!StringUtils.isBlank(latlng)) {
Address addr = new Address();
addr.setAddress(address);
addr.setCountry(location);
addr.setLatlng(latlng);
addr.setParentid(qid);
addr.setCreatorid(authUser.getId());
pc.create(addr);
}
authUser.setLastseen(System.currentTimeMillis());
} else {
model.addAttribute("error", error);
model.addAttribute("path", "questions.vm");
model.addAttribute("includeGMapsScripts", true);
model.addAttribute("askSelected", "navbtn-hover");
return "base";
}
return "redirect:" + q.getPostLink(false, false);
}
return "redirect:" + signinlink + "?returnto=" + questionslink + "/ask";
}
use of org.springframework.web.bind.annotation.PostMapping in project scoold by Erudika.
the class ReportsController method delete.
@PostMapping("/{id}/delete")
public String delete(@PathVariable String id, HttpServletRequest req, HttpServletResponse res) {
if (utils.isAuthenticated(req)) {
Profile authUser = utils.getAuthUser(req);
Report rep = pc.read(id);
if (rep != null && utils.isAdmin(authUser)) {
rep.delete();
}
}
if (!utils.isAjaxRequest(req)) {
return "redirect:" + reportslink;
}
return "base";
}
Aggregations