Search in sources :

Example 1 with Address

use of com.erudika.para.core.Address in project scoold by Erudika.

the class QuestionController method updateLocation.

private void updateLocation(Post showPost, Profile authUser, String location, String latlng) {
    if (!showPost.isReply() && !StringUtils.isBlank(latlng)) {
        Address addr = new Address(showPost.getId() + Config.SEPARATOR + Utils.type(Address.class));
        addr.setAddress(location);
        addr.setCountry(location);
        addr.setLatlng(latlng);
        addr.setParentid(showPost.getId());
        addr.setCreatorid(authUser.getId());
        pc.create(addr);
    }
}
Also used : Address(com.erudika.para.core.Address)

Example 2 with Address

use of com.erudika.para.core.Address 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, String space, HttpServletRequest req, HttpServletResponse res, Model model) {
    if (utils.isAuthenticated(req)) {
        Profile authUser = utils.getAuthUser(req);
        String currentSpace = utils.getValidSpaceIdExcludingAll(authUser, space, req);
        boolean needsApproval = utils.postNeedsApproval(authUser);
        Question q = utils.populate(req, needsApproval ? new UnapprovedQuestion() : new Question(), "title", "body", "tags|,", "location");
        q.setCreatorid(authUser.getId());
        q.setSpace(currentSpace);
        if (StringUtils.isBlank(q.getTagsString())) {
            q.setTags(Arrays.asList(Config.getConfigParam("default_question_tag", "question")));
        }
        Map<String, String> error = utils.validate(q);
        if (error.isEmpty()) {
            q.setLocation(location);
            q.setAuthor(authUser);
            String qid = q.create();
            utils.sendNewPostNotifications(q, req);
            if (!StringUtils.isBlank(latlng)) {
                Address addr = new Address(qid + Config.SEPARATOR + Utils.type(Address.class));
                addr.setAddress(address);
                addr.setCountry(location);
                addr.setLatlng(latlng);
                addr.setParentid(qid);
                addr.setCreatorid(authUser.getId());
                pc.create(addr);
            }
            authUser.setLastseen(System.currentTimeMillis());
            model.addAttribute("newpost", getNewQuestionPayload(q));
        } else {
            model.addAttribute("error", error);
            model.addAttribute("draftQuestion", q);
            model.addAttribute("defaultTag", "");
            model.addAttribute("path", "questions.vm");
            model.addAttribute("includeGMapsScripts", utils.isNearMeFeatureEnabled());
            model.addAttribute("askSelected", "navbtn-hover");
            return "base";
        }
        if (utils.isAjaxRequest(req)) {
            res.setStatus(200);
            res.setContentType("application/json");
            try {
                res.getWriter().println("{\"url\":\"" + q.getPostLink(false, false) + "\"}");
            } catch (IOException ex) {
            }
            return "blank";
        } else {
            return "redirect:" + q.getPostLink(false, false);
        }
    }
    if (utils.isAjaxRequest(req)) {
        res.setStatus(400);
        return "blank";
    } else {
        return "redirect:" + SIGNINLINK + "?returnto=" + QUESTIONSLINK + "/ask";
    }
}
Also used : UnapprovedQuestion(com.erudika.scoold.core.UnapprovedQuestion) Address(com.erudika.para.core.Address) Question(com.erudika.scoold.core.Question) UnapprovedQuestion(com.erudika.scoold.core.UnapprovedQuestion) IOException(java.io.IOException) Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 3 with Address

use of com.erudika.para.core.Address 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)

Aggregations

Address (com.erudika.para.core.Address)3 Profile (com.erudika.scoold.core.Profile)2 Question (com.erudika.scoold.core.Question)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 UnapprovedQuestion (com.erudika.scoold.core.UnapprovedQuestion)1 IOException (java.io.IOException)1