Search in sources :

Example 11 with ResultBean

use of com.duan.blogos.restful.ResultBean in project BlogSystem by DuanJiaNing.

the class BloggerLinkController method delete.

/**
 * 删除链接
 */
@RequestMapping(value = "/{linkId}", method = RequestMethod.DELETE)
public ResultBean delete(HttpServletRequest request, @PathVariable Integer bloggerId, @PathVariable Integer linkId) {
    handleBloggerSignInCheck(request, bloggerId);
    RequestContext context = new RequestContext(request);
    checkLinkExist(linkId, context);
    boolean result = bloggerLinkService.deleteBloggerLink(linkId);
    if (!result)
        handlerOperateFail(request);
    return new ResultBean<>("");
}
Also used : RequestContext(org.springframework.web.servlet.support.RequestContext) ResultBean(com.duan.blogos.restful.ResultBean)

Example 12 with ResultBean

use of com.duan.blogos.restful.ResultBean in project BlogSystem by DuanJiaNing.

the class BloggerLinkController method update.

/**
 * 更新链接
 */
@RequestMapping(value = "/{linkId}", method = RequestMethod.PUT)
public ResultBean update(HttpServletRequest request, @PathVariable Integer bloggerId, @PathVariable Integer linkId, @RequestParam(value = "iconId", required = false) Integer newIconId, @RequestParam(value = "title", required = false) String newTitle, @RequestParam(value = "url", required = false) String newUrl, @RequestParam(value = "bewrite", required = false) String newBewrite) {
    RequestContext context = new RequestContext(request);
    // 都为null则无需更新
    if (newIconId == null && newTitle == null && newUrl == null && newBewrite == null) {
        throw exceptionManager.getParameterIllegalException(context);
    }
    handleBloggerSignInCheck(request, bloggerId);
    handlePictureExistCheck(request, bloggerId, newIconId);
    checkLinkExist(linkId, context);
    // 检查url规范
    if (newUrl != null && !StringUtils.isURL(newUrl)) {
        throw exceptionManager.getParameterIllegalException(context);
    }
    boolean result = bloggerLinkService.updateBloggerLink(linkId, newIconId == null ? -1 : newIconId, newTitle, newUrl, newBewrite);
    if (!result)
        handlerOperateFail(request);
    return new ResultBean<>("");
}
Also used : RequestContext(org.springframework.web.servlet.support.RequestContext) ResultBean(com.duan.blogos.restful.ResultBean)

Example 13 with ResultBean

use of com.duan.blogos.restful.ResultBean in project BlogSystem by DuanJiaNing.

the class ImageController method upload.

/**
 * 上传图片
 */
@RequestMapping(method = RequestMethod.POST)
@ResponseBody
public ResultBean upload(MultipartHttpServletRequest request, @PathVariable("bloggerId") Integer bloggerId, @RequestParam(value = "category", required = false) Integer category, @RequestParam(value = "bewrite", required = false) String bewrite, @RequestParam(value = "title", required = false) String title) {
    handleBloggerSignInCheck(request, bloggerId);
    // 与页面input的name相同
    MultipartFile file = request.getFile("image");
    int id;
    if (ImageUtils.isImageFile(file)) {
        // 默认上传到私有目录
        int cate = category == null ? BloggerPictureCategoryEnum.PRIVATE.getCode() : category;
        // 检查博主权限
        if (!validateManager.checkBloggerPictureLegal(bloggerId, cate)) {
            throw exceptionManager.getUnauthorizedException(new RequestContext(request));
        }
        id = bloggerPictureService.insertPicture(file, bloggerId, bewrite, BloggerPictureCategoryEnum.valueOf(cate), title);
        if (id <= 0)
            handlerOperateFail(request);
    } else {
        return new ResultBean(exceptionManager.getPictureFormatErrorException(new RequestContext(request)));
    }
    return new ResultBean<>(id);
}
Also used : CommonsMultipartFile(org.springframework.web.multipart.commons.CommonsMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) RequestContext(org.springframework.web.servlet.support.RequestContext) ResultBean(com.duan.blogos.restful.ResultBean)

Example 14 with ResultBean

use of com.duan.blogos.restful.ResultBean in project BlogSystem by DuanJiaNing.

the class BlogRetrievalServiceImpl method constructResult.

@Override
protected ResultBean<List<BlogListItemDTO>> constructResult(Map<Integer, Blog> blogHashMap, List<BlogStatistics> statistics, Map<Integer, int[]> blogIdMapCategoryIds, Map<Integer, String> blogImgs) {
    // 重组结果
    List<BlogListItemDTO> result = new ArrayList<>();
    String ch = dbProperties.getStringFiledSplitCharacterForNumber();
    for (BlogStatistics ss : statistics) {
        Integer blogId = ss.getBlogId();
        Blog blog = blogHashMap.get(blogId);
        // category
        int[] cids = blogIdMapCategoryIds.get(blogId);
        List<BlogCategory> categories = null;
        if (!CollectionUtils.isEmpty(cids)) {
            categories = categoryDao.listCategoryById(cids);
        }
        // label
        int[] lids = StringUtils.intStringDistinctToArray(blog.getLabelIds(), ch);
        List<BlogLabel> labels = null;
        if (!CollectionUtils.isEmpty(lids)) {
            labels = labelDao.listLabelById(lids);
        }
        String blogImg = blogImgs.get(blogId);
        BlogListItemDTO dto = dataFillingManager.blogListItemToDTO(ss, CollectionUtils.isEmpty(categories) ? null : categories.toArray(new BlogCategory[categories.size()]), CollectionUtils.isEmpty(labels) ? null : labels.toArray(new BlogLabel[labels.size()]), blog, blogImg);
        result.add(dto);
    }
    return new ResultBean<>(result);
}
Also used : BlogLabel(com.duan.blogos.entity.blog.BlogLabel) BlogCategory(com.duan.blogos.entity.blog.BlogCategory) ArrayList(java.util.ArrayList) BlogStatistics(com.duan.blogos.entity.blog.BlogStatistics) BlogListItemDTO(com.duan.blogos.dto.blog.BlogListItemDTO) Blog(com.duan.blogos.entity.blog.Blog) ResultBean(com.duan.blogos.restful.ResultBean)

Example 15 with ResultBean

use of com.duan.blogos.restful.ResultBean in project BlogSystem by DuanJiaNing.

the class BloggerBlogServiceImpl method getBlog.

@Override
public ResultBean<Blog> getBlog(int bloggerId, int blogId) {
    Blog blog = blogDao.getBlogById(blogId);
    String ch = dbProperties.getStringFiledSplitCharacterForNumber();
    String chs = dbProperties.getStringFiledSplitCharacterForString();
    String whs = websiteProperties.getUrlConditionSplitCharacter();
    if (blog != null && blog.getBloggerId().equals(bloggerId)) {
        String cids = blog.getCategoryIds();
        String lids = blog.getLabelIds();
        String keyWords = blog.getKeyWords();
        if (!StringUtils.isEmpty(cids))
            blog.setCategoryIds(cids.replace(ch, whs));
        if (!StringUtils.isEmpty(lids))
            blog.setLabelIds(lids.replace(ch, whs));
        if (!StringUtils.isEmpty_(keyWords))
            blog.setKeyWords(keyWords.replace(chs, whs));
        return new ResultBean<>(blog);
    }
    return null;
}
Also used : Blog(com.duan.blogos.entity.blog.Blog) ResultBean(com.duan.blogos.restful.ResultBean)

Aggregations

ResultBean (com.duan.blogos.restful.ResultBean)28 RequestContext (org.springframework.web.servlet.support.RequestContext)12 Blog (com.duan.blogos.entity.blog.Blog)5 BloggerAccount (com.duan.blogos.entity.blogger.BloggerAccount)5 BloggerPicture (com.duan.blogos.entity.blogger.BloggerPicture)5 HttpSession (javax.servlet.http.HttpSession)5 BlogCategory (com.duan.blogos.entity.blog.BlogCategory)4 ArrayList (java.util.ArrayList)4 BlogListItemDTO (com.duan.blogos.dto.blog.BlogListItemDTO)3 BloggerDTO (com.duan.blogos.dto.blogger.BloggerDTO)3 BloggerProfile (com.duan.blogos.entity.blogger.BloggerProfile)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 BloggerCategoryDTO (com.duan.blogos.dto.blogger.BloggerCategoryDTO)2 FavouriteBlogListItemDTO (com.duan.blogos.dto.blogger.FavouriteBlogListItemDTO)2 BlogLabel (com.duan.blogos.entity.blog.BlogLabel)2 BlogStatistics (com.duan.blogos.entity.blog.BlogStatistics)2 BlogListItemComparatorFactory (com.duan.blogos.manager.comparator.BlogListItemComparatorFactory)2 HashMap (java.util.HashMap)2 JSONObject (com.alibaba.fastjson.JSONObject)1 BlogMainContentDTO (com.duan.blogos.dto.blog.BlogMainContentDTO)1