Search in sources :

Example 16 with BloggerPicture

use of com.duan.blogos.entity.blogger.BloggerPicture 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)

Example 17 with BloggerPicture

use of com.duan.blogos.entity.blogger.BloggerPicture in project BlogSystem by DuanJiaNing.

the class BloggerGalleryController method list.

/**
 * 获得多张图片
 */
@RequestMapping(method = RequestMethod.GET)
public ResultBean<List<BloggerPicture>> list(HttpServletRequest request, @PathVariable("bloggerId") Integer bloggerId, @RequestParam(value = "category", required = false) Integer category, @RequestParam(value = "offset", required = false) Integer offset, @RequestParam(value = "rows", required = false) Integer rows) {
    handleBloggerSignInCheck(request, bloggerId);
    RequestContext context = new RequestContext(request);
    int cate;
    if (category != null) {
        // 检查类别是否存在
        if (BloggerPictureCategoryEnum.valueOf(category) == null) {
            throw exceptionManager.getParameterIllegalException(context);
        }
        // 检查权限
        if (validateManager.checkBloggerPictureLegal(bloggerId, category))
            cate = category;
        else
            throw exceptionManager.getUnauthorizedException(context);
    } else
        cate = -1;
    int os = offset == null || offset < 0 ? 0 : offset;
    int rs = rows == null || rows < 0 ? bloggerProperties.getRequestBloggerPictureCount() : rows;
    ResultBean<List<BloggerPicture>> result = bloggerPictureService.listBloggerPicture(bloggerId, cate == -1 ? null : BloggerPictureCategoryEnum.valueOf(cate), os, rs);
    if (result == null)
        handlerEmptyResult(request);
    for (BloggerPicture picture : result.getData()) {
        String url = stringConstructorManager.constructPictureUrl(picture, DEFAULT_PICTURE);
        picture.setPath(url);
    }
    return result;
}
Also used : BloggerPicture(com.duan.blogos.entity.blogger.BloggerPicture) List(java.util.List) RequestContext(org.springframework.web.servlet.support.RequestContext)

Example 18 with BloggerPicture

use of com.duan.blogos.entity.blogger.BloggerPicture in project BlogSystem by DuanJiaNing.

the class BloggerGalleryController method delete.

/**
 * 从设备和数据库中删除图片
 */
@RequestMapping(value = "/{pictureId}", method = RequestMethod.DELETE)
@ResponseBody
public ResultBean delete(HttpServletRequest request, @PathVariable("bloggerId") Integer bloggerId, @PathVariable("pictureId") Integer pictureId) {
    handleBloggerSignInCheck(request, bloggerId);
    BloggerPicture picture = bloggerPictureService.getPicture(pictureId, bloggerId);
    if (picture == null) {
        throw exceptionManager.getUnknownPictureException(new RequestContext(request));
    }
    // 检查权限
    if (!validateManager.checkBloggerPictureLegal(bloggerId, picture.getCategory()))
        throw exceptionManager.getUnauthorizedException(new RequestContext(request));
    boolean succ = bloggerPictureService.deletePicture(bloggerId, picture.getId(), true);
    if (!succ)
        handlerOperateFail(request);
    return new ResultBean<>("");
}
Also used : BloggerPicture(com.duan.blogos.entity.blogger.BloggerPicture) RequestContext(org.springframework.web.servlet.support.RequestContext) ResultBean(com.duan.blogos.restful.ResultBean)

Aggregations

BloggerPicture (com.duan.blogos.entity.blogger.BloggerPicture)18 ResultBean (com.duan.blogos.restful.ResultBean)5 RequestContext (org.springframework.web.servlet.support.RequestContext)5 BloggerAccount (com.duan.blogos.entity.blogger.BloggerAccount)4 BloggerProfile (com.duan.blogos.entity.blogger.BloggerProfile)4 BloggerDTO (com.duan.blogos.dto.blogger.BloggerDTO)3 InternalIOException (com.duan.blogos.exception.internal.InternalIOException)3 ArrayList (java.util.ArrayList)3 BlogListItemDTO (com.duan.blogos.dto.blog.BlogListItemDTO)2 FavouriteBlogListItemDTO (com.duan.blogos.dto.blogger.FavouriteBlogListItemDTO)2 BlogListItemComparatorFactory (com.duan.blogos.manager.comparator.BlogListItemComparatorFactory)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 BloggerLinkDTO (com.duan.blogos.dto.blogger.BloggerLinkDTO)1 BloggerLink (com.duan.blogos.entity.blogger.BloggerLink)1 BloggerSetting (com.duan.blogos.entity.blogger.BloggerSetting)1 List (java.util.List)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1