Search in sources :

Example 21 with ResultBean

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

the class BloggerStatisticsServiceImpl method getBloggerStatistics.

@Override
public ResultBean<BloggerStatisticsDTO> getBloggerStatistics(int bloggerId) {
    int blogCount = blogDao.countBlogByBloggerId(bloggerId, BlogStatusEnum.PUBLIC.getCode());
    List<Blog> blogs = blogDao.listAllWordCountByBloggerId(bloggerId, BlogStatusEnum.PUBLIC.getCode());
    int wordCountSum = blogs.stream().mapToInt(Blog::getWordCount).sum();
    int likeCount = blogs.stream().mapToInt(Blog::getId).map(statisticsDao::getLikeCount).sum();
    int likeGiveCount = likeDao.countLikeByLikerId(bloggerId);
    int categoryCount = categoryDao.countByBloggerId(bloggerId);
    int labelCount = labelDao.countByBloggerId(bloggerId);
    int collectCount = collectDao.countByCollectorId(bloggerId);
    int collectedCount = blogs.stream().mapToInt(Blog::getId).map(statisticsDao::getCollectCount).sum();
    int linkCount = linkDao.countLinkByBloggerId(bloggerId);
    BloggerStatisticsDTO dto = dataFillingManager.bloggerStatisticToDTO(blogCount, wordCountSum, likeCount, likeGiveCount, categoryCount, labelCount, collectCount, collectedCount, linkCount);
    return new ResultBean<>(dto);
}
Also used : BloggerStatisticsDTO(com.duan.blogos.dto.blogger.BloggerStatisticsDTO) Blog(com.duan.blogos.entity.blog.Blog) ResultBean(com.duan.blogos.restful.ResultBean)

Example 22 with ResultBean

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

the class BlogStatisticsServiceImpl method getBlogStatisticsCount.

@Override
public ResultBean<BlogStatisticsCountDTO> getBlogStatisticsCount(int blogId) {
    BlogStatistics statistics = statisticsDao.getStatistics(blogId);
    if (statistics == null)
        return null;
    BlogStatisticsCountDTO dto = dataFillingManager.blogStatisticsCountToDTO(statistics);
    return new ResultBean<>(dto);
}
Also used : BlogStatisticsCountDTO(com.duan.blogos.dto.blog.BlogStatisticsCountDTO) ResultBean(com.duan.blogos.restful.ResultBean)

Example 23 with ResultBean

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

the class BloggerAccountController method modifyUsername.

/**
 * 修改用户名
 */
@RequestMapping(value = "/{bloggerId}/item=name", method = RequestMethod.PUT)
public ResultBean modifyUsername(HttpServletRequest request, @PathVariable Integer bloggerId, @RequestParam(value = "username") String newUserName) {
    handleBloggerSignInCheck(request, bloggerId);
    handleNameCheck(request, newUserName);
    boolean result = accountService.updateAccountUserName(bloggerId, newUserName);
    if (!result)
        handlerOperateFail(request);
    // 更新session信息
    HttpSession session = request.getSession();
    session.setAttribute(bloggerProperties.getSessionNameOfBloggerName(), newUserName);
    return new ResultBean<>("");
}
Also used : HttpSession(javax.servlet.http.HttpSession) ResultBean(com.duan.blogos.restful.ResultBean)

Example 24 with ResultBean

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

the class BloggerBlogController method update.

/**
 * 更新博文
 */
@RequestMapping(value = "/{blogId}", method = RequestMethod.PUT)
public ResultBean update(HttpServletRequest request, @PathVariable Integer bloggerId, @PathVariable Integer blogId, @RequestParam(value = "title", required = false) String newTitle, @RequestParam(value = "content", required = false) String newContent, @RequestParam(value = "contentMd", required = false) String newContentMd, @RequestParam(value = "summary", required = false) String newSummary, @RequestParam(value = "cids", required = false) String newCategoryIds, @RequestParam(value = "lids", required = false) String newLabelIds, @RequestParam(value = "kword", required = false) String newKeyWord, @RequestParam(value = "status", required = false) Integer newStatus) {
    // 所有参数都为null,则不更新。
    if (Stream.of(newTitle, newContent, newSummary, newCategoryIds, newLabelIds, newKeyWord, newStatus).filter(Objects::nonNull).count() <= 0)
        throw exceptionManager.getParameterIllegalException(new RequestContext(request));
    // 检查修改到的博文状态是否允许
    if (newStatus != null && !blogValidateManager.isBlogStatusAllow(newStatus))
        throw exceptionManager.getParameterIllegalException(new RequestContext(request));
    handleBloggerSignInCheck(request, bloggerId);
    handleBlogExistAndCreatorCheck(request, bloggerId, blogId);
    // 将 Unicode 解码
    newContent = StringUtils.unicodeToString(newContent);
    newContentMd = StringUtils.unicodeToString(newContentMd);
    handleBlogContentCheck(request, newTitle, newContent, newContentMd, newSummary, newKeyWord);
    String sp = websiteProperties.getUrlConditionSplitCharacter();
    int[] cids = newCategoryIds == null ? null : StringUtils.intStringDistinctToArray(newCategoryIds, sp);
    int[] lids = newLabelIds == null ? null : StringUtils.intStringDistinctToArray(newLabelIds, sp);
    // 检查博文类别和标签
    handleCategoryAndLabelCheck(request, bloggerId, cids, lids);
    String[] kw = newKeyWord == null ? null : StringUtils.stringArrayToArray(newKeyWord, sp);
    BlogStatusEnum stat = newStatus == null ? null : BlogStatusEnum.valueOf(newStatus);
    // 执行更新
    if (!bloggerBlogService.updateBlog(bloggerId, blogId, cids, lids, stat, newTitle, newContent, newContentMd, newSummary, kw))
        handlerOperateFail(request);
    return new ResultBean<>("");
}
Also used : BlogStatusEnum(com.duan.blogos.enums.BlogStatusEnum) Objects(java.util.Objects) RequestContext(org.springframework.web.servlet.support.RequestContext) ResultBean(com.duan.blogos.restful.ResultBean)

Example 25 with ResultBean

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

the class BloggerGalleryController method get.

/**
 * 根据id获取图片
 */
@RequestMapping(value = "/{pictureId}", method = RequestMethod.GET)
public ResultBean<BloggerPicture> get(HttpServletRequest request, @PathVariable("bloggerId") Integer bloggerId, @PathVariable("pictureId") Integer pictureId) {
    handleBloggerSignInCheck(request, bloggerId);
    RequestContext context = new RequestContext(request);
    if (pictureId <= 0)
        throw exceptionManager.getParameterIllegalException(context);
    BloggerPicture picture = bloggerPictureService.getPicture(pictureId, bloggerId);
    if (picture == null)
        handlerEmptyResult(request);
    String url = stringConstructorManager.constructPictureUrl(picture, DEFAULT_PICTURE);
    picture.setPath(url);
    return new ResultBean<>(picture);
}
Also used : BloggerPicture(com.duan.blogos.entity.blogger.BloggerPicture) RequestContext(org.springframework.web.servlet.support.RequestContext) 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