Search in sources :

Example 6 with PostMapping

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;
}
Also used : Locale(java.util.Locale) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 7 with PostMapping

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

Example 8 with PostMapping

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

Example 9 with PostMapping

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

Example 10 with PostMapping

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";
}
Also used : Translation(com.erudika.para.core.Translation) 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