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);
}
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;
}
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<>("");
}
Aggregations