Search in sources :

Example 51 with PostMapping

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";
}
Also used : Locale(java.util.Locale) Translation(com.erudika.para.core.Translation) Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 52 with PostMapping

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";
}
Also used : Translation(com.erudika.para.core.Translation) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 53 with PostMapping

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);
}
Also used : Post(com.erudika.scoold.core.Post) Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 54 with PostMapping

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";
}
Also used : Address(com.erudika.para.core.Address) Question(com.erudika.scoold.core.Question) Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 55 with PostMapping

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";
}
Also used : Report(com.erudika.scoold.core.Report) Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

PostMapping (org.springframework.web.bind.annotation.PostMapping)83 ApiOperation (io.swagger.annotations.ApiOperation)21 Profile (com.erudika.scoold.core.Profile)20 Post (com.erudika.scoold.core.Post)9 Example (tk.mybatis.mapper.entity.Example)8 HashMap (java.util.HashMap)7 Service (org.apereo.cas.authentication.principal.Service)6 ResponseEntity (org.springframework.http.ResponseEntity)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 LoginAuthDto (com.paascloud.base.dto.LoginAuthDto)5 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)5 RegisteredService (org.apereo.cas.services.RegisteredService)5 User (amu.zhcet.data.user.User)4 Report (com.erudika.scoold.core.Report)4 IOException (java.io.IOException)4 Map (java.util.Map)4 Credential (org.apereo.cas.authentication.Credential)4 Reply (com.erudika.scoold.core.Reply)3 Log (io.github.tesla.ops.common.Log)3 LinkedHashMap (java.util.LinkedHashMap)3