Search in sources :

Example 36 with PostMapping

use of org.springframework.web.bind.annotation.PostMapping in project scoold by Erudika.

the class CommentController method deleteAjax.

@PostMapping("/{id}/delete")
public void deleteAjax(@PathVariable String id, HttpServletRequest req, HttpServletResponse res) {
    if (utils.isAuthenticated(req)) {
        Comment comment = pc.read(id);
        Profile authUser = utils.getAuthUser(req);
        boolean isMod = utils.isMod(authUser);
        if (comment != null && (comment.getCreatorid().equals(authUser.getId()) || isMod)) {
            // check parent and correct (for multi-parent-object pages)
            comment.delete();
            if (!isMod) {
                utils.addBadgeAndUpdate(authUser, DISCIPLINED, true);
            }
        }
    }
    res.setStatus(200);
}
Also used : Comment(com.erudika.scoold.core.Comment) Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 37 with PostMapping

use of org.springframework.web.bind.annotation.PostMapping in project scoold by Erudika.

the class FeedbackController method replyAjax.

@PostMapping({ "/{id}", "/{id}/{title}" })
public String replyAjax(@PathVariable String id, @PathVariable(required = false) String title, HttpServletRequest req, HttpServletResponse res, Model model) throws IOException {
    Post showPost = pc.read(id);
    Profile authUser = utils.getAuthUser(req);
    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, Profile.Badge.EUREKA, answer.getCreatorid().equals(showPost.getCreatorid()));
            answer.setAuthor(authUser);
            model.addAttribute("showPost", showPost);
            model.addAttribute("answerslist", Collections.singletonList(answer));
            return "reply";
        }
    }
    if (utils.isAjaxRequest(req)) {
        res.setStatus(200);
        return "base";
    } else {
        return "redirect:" + feedbacklink + "/" + id;
    }
}
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 38 with PostMapping

use of org.springframework.web.bind.annotation.PostMapping in project scoold by Erudika.

the class ProfileController method edit.

@PostMapping("/{id}")
public String edit(@PathVariable(required = false) String id, @RequestParam(required = false) String name, @RequestParam(required = false) String location, @RequestParam(required = false) String website, @RequestParam(required = false) String aboutme, @RequestParam(required = false) String picture, HttpServletRequest req) {
    Profile authUser = utils.getAuthUser(req);
    String showId = StringUtils.isBlank(id) ? authUser.getId() : id;
    if (canEditProfile(authUser, showId)) {
        Profile showUser = utils.getParaClient().read(Profile.id(id));
        boolean update = false;
        if (!StringUtils.isBlank(name)) {
            showUser.setName(name);
            update = true;
        }
        if (!StringUtils.isBlank(location)) {
            showUser.setLocation(location);
            update = true;
        }
        if (!StringUtils.isBlank(website)) {
            showUser.setWebsite(website);
            update = true;
        }
        if (!StringUtils.isBlank(aboutme)) {
            showUser.setAboutme(aboutme);
            update = true;
        }
        if (!StringUtils.isBlank(picture)) {
            showUser.setPicture(picture);
            update = true;
        }
        boolean isComplete = showUser.isComplete() && isMyid(authUser, showUser.getId());
        if (update || utils.addBadgeOnce(authUser, Badge.NICEPROFILE, isComplete)) {
            showUser.update();
        }
    }
    return "redirect:" + profilelink;
}
Also used : Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 39 with PostMapping

use of org.springframework.web.bind.annotation.PostMapping in project scoold by Erudika.

the class ProfileController method mods.

@PostMapping(path = "/{id}", params = { "makemod" })
public String mods(@PathVariable String id, @RequestParam Boolean makemod, HttpServletRequest req) {
    Profile authUser = utils.getAuthUser(req);
    if (!isMyid(authUser, Profile.id(id))) {
        Profile showUser = utils.getParaClient().read(Profile.id(id));
        if (showUser != null) {
            boolean isShowUserAdmin = User.Groups.ADMINS.toString().equals(showUser.getGroups());
            boolean isShowUserMod = User.Groups.MODS.toString().equals(showUser.getGroups());
            if (makemod && utils.isAdmin(authUser) && !isShowUserAdmin) {
                showUser.setGroups(isShowUserMod ? USERS.toString() : MODS.toString());
                showUser.update();
            }
        }
    }
    return "redirect:" + profilelink + "/" + id;
}
Also used : Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 40 with PostMapping

use of org.springframework.web.bind.annotation.PostMapping in project scoold by Erudika.

the class QuestionController method close.

@PostMapping("/{id}/close")
public String close(@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 (utils.isMod(authUser)) {
        if (showPost.isClosed()) {
            showPost.setCloserid(null);
        } else {
            showPost.setCloserid(authUser.getId());
        }
        showPost.update();
    }
    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)

Aggregations

PostMapping (org.springframework.web.bind.annotation.PostMapping)40 Profile (com.erudika.scoold.core.Profile)20 Post (com.erudika.scoold.core.Post)9 HashMap (java.util.HashMap)6 Report (com.erudika.scoold.core.Report)4 Map (java.util.Map)4 RegisteredService (org.apereo.cas.services.RegisteredService)4 ResponseEntity (org.springframework.http.ResponseEntity)4 Translation (com.erudika.para.core.Translation)3 Reply (com.erudika.scoold.core.Reply)3 RegexRegisteredService (org.apereo.cas.services.RegexRegisteredService)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 Comment (com.erudika.scoold.core.Comment)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 Locale (java.util.Locale)2 AuthenticationException (org.apereo.cas.authentication.AuthenticationException)2