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