从"Blog"仓库中分离出来
This commit is contained in:
154
src/main/java/cn/celess/blog/controller/ArticleController.java
Normal file
154
src/main/java/cn/celess/blog/controller/ArticleController.java
Normal file
@@ -0,0 +1,154 @@
|
||||
package cn.celess.blog.controller;
|
||||
|
||||
import cn.celess.blog.enmu.ResponseEnum;
|
||||
import cn.celess.blog.entity.Response;
|
||||
import cn.celess.blog.entity.model.ArticleModel;
|
||||
import cn.celess.blog.entity.request.ArticleReq;
|
||||
import cn.celess.blog.service.ArticleService;
|
||||
import cn.celess.blog.util.RedisUserUtil;
|
||||
import cn.celess.blog.util.ResponseUtil;
|
||||
import cn.celess.blog.util.SitemapGenerateUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 15:18
|
||||
*/
|
||||
@RestController
|
||||
public class ArticleController {
|
||||
@Autowired
|
||||
ArticleService articleService;
|
||||
@Autowired
|
||||
SitemapGenerateUtil sitemapGenerateUtil;
|
||||
@Autowired
|
||||
RedisUserUtil redisUserUtil;
|
||||
|
||||
/**
|
||||
* 新建一篇文章
|
||||
*
|
||||
* @param body 请求数据
|
||||
* @return Response
|
||||
*/
|
||||
@PostMapping("/admin/article/create")
|
||||
public Response create(@RequestBody ArticleReq body) {
|
||||
ArticleModel articleModel = articleService.create(body);
|
||||
sitemapGenerateUtil.createSitemap();
|
||||
return ResponseUtil.success(articleModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过文章id 删除一篇文章
|
||||
*
|
||||
* @param articleId 文章id
|
||||
* @return Response
|
||||
*/
|
||||
@DeleteMapping("/admin/article/del")
|
||||
public Response delete(@RequestParam("articleID") long articleId) {
|
||||
boolean delete = articleService.delete(articleId);
|
||||
sitemapGenerateUtil.createSitemap();
|
||||
return ResponseUtil.success(delete);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新文章
|
||||
*
|
||||
* @param body 请求数据
|
||||
* @return Response
|
||||
*/
|
||||
@PutMapping("/admin/article/update")
|
||||
public Response update(@RequestBody ArticleReq body) {
|
||||
ArticleModel update = articleService.update(body);
|
||||
sitemapGenerateUtil.createSitemap();
|
||||
return ResponseUtil.success(update);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查找一篇文章
|
||||
* 公开 =>返回数据
|
||||
* 不公开
|
||||
* *** =>作者 返回数据
|
||||
* *** =>其他 抛出错误
|
||||
*
|
||||
* @param articleId 文章id
|
||||
* @param is4update 是否是更新
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/article/articleID/{articleID}")
|
||||
public Response retrieveOneById(@PathVariable("articleID") long articleId,
|
||||
@RequestParam(value = "update", defaultValue = "false") boolean is4update,
|
||||
HttpServletRequest request) {
|
||||
ArticleModel article = articleService.retrieveOneByID(articleId, is4update);
|
||||
if (article.getOpen()) {
|
||||
return ResponseUtil.success(article);
|
||||
} else if (article.getAuthorId().equals(redisUserUtil.get(request).getId())) {
|
||||
return ResponseUtil.success(article);
|
||||
}
|
||||
return ResponseUtil.response(ResponseEnum.PERMISSION_ERROR, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取所有文章状态为开放的的文章
|
||||
*
|
||||
* @param page 页码
|
||||
* @param count 单页数据量
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/articles")
|
||||
public Response articles(@RequestParam(name = "page", defaultValue = "1") int page,
|
||||
@RequestParam(name = "count", defaultValue = "5") int count) {
|
||||
return ResponseUtil.success(articleService.retrievePageForOpen(count, page));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取所有文章
|
||||
*
|
||||
* @param page 页码
|
||||
* @param count 单页数据量
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/admin/articles")
|
||||
public Response adminArticles(@RequestParam(name = "page", defaultValue = "1") int page,
|
||||
@RequestParam(name = "count", defaultValue = "10") int count) {
|
||||
return ResponseUtil.success(articleService.adminArticles(count, page));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过分类获取文章(文章摘要)
|
||||
*
|
||||
* @param name 分类名
|
||||
* @param page 页码
|
||||
* @param count 单页数据量
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/articles/category/{name}")
|
||||
public Response findByCategory(@PathVariable("name") String name,
|
||||
@RequestParam(name = "page", defaultValue = "1") int page,
|
||||
@RequestParam(name = "count", defaultValue = "10") int count) {
|
||||
return ResponseUtil.success(articleService.findByCategory(name, page, count));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过标签名获取文章(文章摘要)
|
||||
*
|
||||
* @param name 标签名
|
||||
* @param page 页码
|
||||
* @param count 单页数据量
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/articles/tag/{name}")
|
||||
public Response findByTag(@PathVariable("name") String name,
|
||||
@RequestParam(name = "page", defaultValue = "1") int page,
|
||||
@RequestParam(name = "count", defaultValue = "10") int count) {
|
||||
return ResponseUtil.success(articleService.findByTag(name, page, count));
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/createSitemap")
|
||||
public Response createSitemap() {
|
||||
sitemapGenerateUtil.createSitemap();
|
||||
return ResponseUtil.success(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package cn.celess.blog.controller;
|
||||
|
||||
import cn.celess.blog.entity.Response;
|
||||
import cn.celess.blog.service.CategoryService;
|
||||
import cn.celess.blog.util.ResponseUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/30 20:36
|
||||
*/
|
||||
@RestController
|
||||
public class CategoryController {
|
||||
|
||||
@Autowired
|
||||
CategoryService categoryService;
|
||||
|
||||
/**
|
||||
* 新增一个分类
|
||||
*
|
||||
* @param name 分类名
|
||||
* @return Response
|
||||
*/
|
||||
@PostMapping("/admin/category/create")
|
||||
public Response addOne(@RequestParam("name") String name) {
|
||||
return ResponseUtil.success(categoryService.create(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除一个分类
|
||||
*
|
||||
* @param id 分类id
|
||||
* @return Response
|
||||
*/
|
||||
@DeleteMapping("/admin/category/del")
|
||||
public Response deleteOne(@RequestParam("id") long id) {
|
||||
return ResponseUtil.success(categoryService.delete(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新一个分类
|
||||
*
|
||||
* @param id 分类id
|
||||
* @param name 更新后的名字
|
||||
* @return Response
|
||||
*/
|
||||
@PutMapping("/admin/category/update")
|
||||
public Response updateOne(@RequestParam("id") Long id,
|
||||
@RequestParam("name") String name) {
|
||||
return ResponseUtil.success(categoryService.update(id, name));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有的分类
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/categories")
|
||||
public Response getPage() {
|
||||
return ResponseUtil.success(categoryService.retrievePage());
|
||||
}
|
||||
}
|
||||
101
src/main/java/cn/celess/blog/controller/CommentController.java
Normal file
101
src/main/java/cn/celess/blog/controller/CommentController.java
Normal file
@@ -0,0 +1,101 @@
|
||||
package cn.celess.blog.controller;
|
||||
|
||||
import cn.celess.blog.entity.Comment;
|
||||
import cn.celess.blog.entity.Response;
|
||||
import cn.celess.blog.entity.request.CommentReq;
|
||||
import cn.celess.blog.service.CommentService;
|
||||
import cn.celess.blog.util.ResponseUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/30 20:37
|
||||
*/
|
||||
@RestController
|
||||
public class CommentController {
|
||||
@Autowired
|
||||
CommentService commentService;
|
||||
|
||||
/**
|
||||
* 新增一条评论数据
|
||||
*
|
||||
* @param reqBody 请求数据
|
||||
* @return Response
|
||||
*/
|
||||
@PostMapping("/user/comment/create")
|
||||
public Response addOne(@RequestBody CommentReq reqBody) {
|
||||
return ResponseUtil.success(commentService.create(reqBody));
|
||||
}
|
||||
|
||||
@DeleteMapping("/user/comment/del")
|
||||
public Response delete(@RequestParam("id") long id) {
|
||||
return ResponseUtil.success(commentService.delete(id));
|
||||
}
|
||||
|
||||
@PutMapping("/user/comment/update")
|
||||
public Response update(@RequestBody CommentReq reqBody) {
|
||||
return ResponseUtil.success(commentService.update(reqBody));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有的一级评论
|
||||
*
|
||||
* @param articleId 文章id
|
||||
* @param count 单页数据量
|
||||
* @param page 页码
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/comments")
|
||||
public Response commentsOfArticle(@RequestParam("articleId") long articleId,
|
||||
@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
||||
return ResponseUtil.success(commentService.retrievePageByArticle(articleId, -1, page, count));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过pid获取数据
|
||||
*
|
||||
* @param pid
|
||||
* @param count
|
||||
* @param page
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/comment/pid/{pid}")
|
||||
public Response retrievePage(@PathVariable("pid") long pid,
|
||||
@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
||||
return ResponseUtil.success(commentService.retrievePageByPid(pid, page, count));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所以的一级留言
|
||||
*
|
||||
* @param count
|
||||
* @param page
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/leaveMsg")
|
||||
public Response retrievePageOfLeaveMsg(@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
||||
return ResponseUtil.success(commentService.retrievePageByTypeAndPid(false, -1, page, count));
|
||||
}
|
||||
|
||||
@GetMapping("/admin/comment/type/{type}")
|
||||
public Response retrievePageAdmin(
|
||||
@PathVariable("type") int isComment,
|
||||
@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
||||
return ResponseUtil.success(commentService.retrievePageByType(1 == isComment, page, count));
|
||||
}
|
||||
|
||||
@GetMapping("/user/comment/type/{type}")
|
||||
public Response retrievePageByAuthor(
|
||||
@PathVariable(value = "type") int isComment,
|
||||
@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
||||
return ResponseUtil.success(commentService.retrievePageByAuthor(1 == isComment, page, count));
|
||||
}
|
||||
|
||||
}
|
||||
99
src/main/java/cn/celess/blog/controller/LinksController.java
Normal file
99
src/main/java/cn/celess/blog/controller/LinksController.java
Normal file
@@ -0,0 +1,99 @@
|
||||
package cn.celess.blog.controller;
|
||||
|
||||
import cn.celess.blog.enmu.ResponseEnum;
|
||||
import cn.celess.blog.entity.PartnerSite;
|
||||
import cn.celess.blog.entity.Response;
|
||||
import cn.celess.blog.entity.request.LinkReq;
|
||||
import cn.celess.blog.exception.MyException;
|
||||
import cn.celess.blog.service.MailService;
|
||||
import cn.celess.blog.service.PartnerSiteService;
|
||||
import cn.celess.blog.util.RedisUtil;
|
||||
import cn.celess.blog.util.RegexUtil;
|
||||
import cn.celess.blog.util.ResponseUtil;
|
||||
import cn.celess.blog.util.DateFormatUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.mail.SimpleMailMessage;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/05/12 13:26
|
||||
*/
|
||||
@RestController
|
||||
public class LinksController {
|
||||
@Autowired
|
||||
PartnerSiteService partnerSiteService;
|
||||
@Autowired
|
||||
MailService mailService;
|
||||
@Autowired
|
||||
RedisUtil redisUtil;
|
||||
@Autowired
|
||||
HttpServletRequest request;
|
||||
|
||||
@PostMapping("/admin/links/create")
|
||||
public Response create(@RequestBody LinkReq reqBody) {
|
||||
return ResponseUtil.success(partnerSiteService.create(reqBody));
|
||||
}
|
||||
|
||||
@DeleteMapping("/admin/links/del/{id}")
|
||||
public Response del(@PathVariable("id") long id) {
|
||||
return ResponseUtil.success(partnerSiteService.del(id));
|
||||
}
|
||||
|
||||
@PutMapping("/admin/links/update")
|
||||
public Response update(@RequestBody LinkReq reqBody) {
|
||||
return ResponseUtil.success(partnerSiteService.update(reqBody));
|
||||
}
|
||||
|
||||
@GetMapping("/links")
|
||||
public Response allForOpen() {
|
||||
List<PartnerSite> sites = new ArrayList<>();
|
||||
for (PartnerSite p : partnerSiteService.findAll()) {
|
||||
if (p.getOpen()) {
|
||||
//隐藏open字段
|
||||
p.setOpen(null);
|
||||
sites.add(p);
|
||||
}
|
||||
}
|
||||
return ResponseUtil.success(sites);
|
||||
}
|
||||
|
||||
@GetMapping("/admin/links")
|
||||
public Response all(@RequestParam("page") int page,
|
||||
@RequestParam("count") int count) {
|
||||
return ResponseUtil.success(partnerSiteService.PartnerSitePages(page, count));
|
||||
}
|
||||
|
||||
@PostMapping("/apply")
|
||||
public Response apply(@RequestParam("name") String name,
|
||||
@RequestParam("url") String url) {
|
||||
// TODO :: 弃用发送邮件的方式。
|
||||
if (name == null || name.replaceAll(" ", "").isEmpty()) {
|
||||
return ResponseUtil.response(ResponseEnum.PARAMETERS_ERROR, null);
|
||||
}
|
||||
if (!RegexUtil.urlMatch(url)) {
|
||||
return ResponseUtil.response(ResponseEnum.PARAMETERS_URL_ERROR, null);
|
||||
}
|
||||
String applyTimeStr = redisUtil.get(request.getRemoteAddr() + "-Apply");
|
||||
int applyTime = 0;
|
||||
if (applyTimeStr != null) {
|
||||
applyTime = Integer.parseInt(applyTimeStr);
|
||||
}
|
||||
if (applyTime == 10) {
|
||||
throw new MyException(ResponseEnum.FAILURE.getCode(), "申请次数已达10次,请2小时后重试");
|
||||
}
|
||||
SimpleMailMessage message = new SimpleMailMessage();
|
||||
message.setSubject("友链申请:" + name);
|
||||
message.setTo("a@celess.cn");
|
||||
message.setText("name:" + name + "\nurl:" + url + "\n" + DateFormatUtil.getNow());
|
||||
Boolean send = mailService.send(message);
|
||||
redisUtil.setEx(request.getRemoteAddr() + "-Apply", applyTime + 1 + "", 2, TimeUnit.HOURS);
|
||||
return send ? ResponseUtil.success("") : ResponseUtil.failure("");
|
||||
|
||||
}
|
||||
}
|
||||
172
src/main/java/cn/celess/blog/controller/Other.java
Normal file
172
src/main/java/cn/celess/blog/controller/Other.java
Normal file
@@ -0,0 +1,172 @@
|
||||
package cn.celess.blog.controller;
|
||||
|
||||
import cn.celess.blog.enmu.ResponseEnum;
|
||||
import cn.celess.blog.entity.Response;
|
||||
import cn.celess.blog.entity.model.QiniuResponse;
|
||||
import cn.celess.blog.exception.MyException;
|
||||
import cn.celess.blog.service.CountService;
|
||||
import cn.celess.blog.service.QiniuService;
|
||||
import cn.celess.blog.util.RedisUtil;
|
||||
import cn.celess.blog.util.ResponseUtil;
|
||||
import cn.celess.blog.util.VeriCodeUtil;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/02 22:03
|
||||
*/
|
||||
@RestController
|
||||
public class Other {
|
||||
public static final Logger logger = LoggerFactory.getLogger(Object.class);
|
||||
|
||||
@Autowired
|
||||
CountService countService;
|
||||
@Autowired
|
||||
QiniuService qiniuService;
|
||||
@Autowired
|
||||
RedisUtil redisUtil;
|
||||
@Autowired
|
||||
HttpServletRequest request;
|
||||
|
||||
|
||||
@GetMapping("/counts")
|
||||
public Response allCount() {
|
||||
Map<String, Long> countMap = new HashMap<>();
|
||||
countMap.put("articleCount", countService.getArticleCount());
|
||||
countMap.put("commentCount", countService.getCommentCount());
|
||||
countMap.put("leaveMsgCount", countService.getLeaveMessageCount());
|
||||
countMap.put("categoryCount", countService.getCategoriesCount());
|
||||
countMap.put("tagCount", countService.getTagsCount());
|
||||
countMap.put("visitorCount", countService.getVisitorCount());
|
||||
return ResponseUtil.success(countMap);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取header的全部参数
|
||||
*
|
||||
* @param request HttpServletRequest
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/headerInfo")
|
||||
public Response headerInfo(HttpServletRequest request) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
Enumeration<String> headerNames = request.getHeaderNames();
|
||||
String str = null;
|
||||
while ((str = headerNames.nextElement()) != null) {
|
||||
map.put(str, request.getHeader(str));
|
||||
}
|
||||
map.put("sessionID", request.getSession().getId());
|
||||
map.put("request.getRemoteAddr()", request.getRemoteAddr());
|
||||
return ResponseUtil.success(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回验证码
|
||||
*
|
||||
* @param response HttpServletResponse
|
||||
* @throws IOException IOException
|
||||
*/
|
||||
@GetMapping(value = "/imgCode", produces = MediaType.IMAGE_PNG_VALUE)
|
||||
public void getImg(HttpServletResponse response) throws IOException {
|
||||
Object[] obj = VeriCodeUtil.createImage();
|
||||
request.getSession().setAttribute("code", obj[0]);
|
||||
//将图片输出给浏览器
|
||||
BufferedImage image = (BufferedImage) obj[1];
|
||||
response.setContentType("image/png");
|
||||
OutputStream os = response.getOutputStream();
|
||||
ImageIO.write(image, "png", os);
|
||||
os.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证 验证码的正确性
|
||||
*
|
||||
* @param code 传进来的验证码
|
||||
* @param request HttpServletRequest
|
||||
* @return Session中写入验证状态
|
||||
*/
|
||||
@PostMapping("/verCode")
|
||||
public Response verCode(@RequestParam("code") String code, HttpServletRequest request) {
|
||||
request.getSession().setAttribute("verImgCodeStatus", false);
|
||||
String codeStr = (String) request.getSession().getAttribute("code");
|
||||
if (code == null) {
|
||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||
}
|
||||
if (codeStr == null) {
|
||||
throw new MyException(ResponseEnum.IMG_CODE_TIMEOUT);
|
||||
}
|
||||
code = code.toLowerCase();
|
||||
codeStr = codeStr.toLowerCase();
|
||||
if (code.equals(codeStr)) {
|
||||
request.getSession().removeAttribute("code");
|
||||
request.getSession().setAttribute("verImgCodeStatus", true);
|
||||
return ResponseUtil.success("验证成功");
|
||||
} else {
|
||||
request.getSession().removeAttribute("code");
|
||||
return ResponseUtil.failure("验证失败,请重新获取验证码");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* FIXME :: 单张图片多次上传的问题
|
||||
* editor.md图片上传的接口
|
||||
* FUCK !!!
|
||||
*
|
||||
* @param file 文件
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@PostMapping("/imgUpload")
|
||||
public void upload(HttpServletRequest request, HttpServletResponse response, @RequestParam("editormd-image-file") MultipartFile file) throws IOException {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
String uploadTimesStr = redisUtil.get(request.getRemoteAddr() + "-ImgUploadTimes");
|
||||
int uploadTimes = 0;
|
||||
if (uploadTimesStr != null) {
|
||||
uploadTimes = Integer.parseInt(uploadTimesStr);
|
||||
}
|
||||
if (uploadTimes == 10) {
|
||||
throw new MyException(ResponseEnum.FAILURE.getCode(), "上传次数已达10次,请2小时后在上传");
|
||||
}
|
||||
request.setCharacterEncoding("utf-8");
|
||||
response.setContentType("text/html");
|
||||
if (file.isEmpty()) {
|
||||
jsonObject.put("success", 0);
|
||||
jsonObject.put("message", "上传失败,请选择文件");
|
||||
response.getWriter().println(jsonObject.toString());
|
||||
return;
|
||||
}
|
||||
String fileName = file.getOriginalFilename();
|
||||
String mime = fileName.substring(fileName.lastIndexOf("."));
|
||||
if (".png".equals(mime.toLowerCase()) || ".jpg".equals(mime.toLowerCase()) ||
|
||||
".jpeg".equals(mime.toLowerCase()) || ".bmp".equals(mime.toLowerCase())) {
|
||||
QiniuResponse qiniuResponse = qiniuService.uploadFile(file.getInputStream(), "img_" + System.currentTimeMillis() + mime);
|
||||
jsonObject.put("success", 0);
|
||||
jsonObject.put("message", "上传成功");
|
||||
jsonObject.put("url", "http://cdn.celess.cn/" + qiniuResponse.key);
|
||||
response.getWriter().println(jsonObject.toString());
|
||||
redisUtil.setEx(request.getRemoteAddr() + "-ImgUploadTimes", uploadTimes + 1 + "", 2, TimeUnit.HOURS);
|
||||
return;
|
||||
}
|
||||
jsonObject.put("success", 0);
|
||||
jsonObject.put("message", "上传失败,请上传图片文件");
|
||||
response.getWriter().println(jsonObject.toString());
|
||||
}
|
||||
}
|
||||
70
src/main/java/cn/celess/blog/controller/TagController.java
Normal file
70
src/main/java/cn/celess/blog/controller/TagController.java
Normal file
@@ -0,0 +1,70 @@
|
||||
package cn.celess.blog.controller;
|
||||
|
||||
import cn.celess.blog.entity.Response;
|
||||
import cn.celess.blog.entity.Tag;
|
||||
import cn.celess.blog.service.TagService;
|
||||
import cn.celess.blog.util.ResponseUtil;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/30 20:36
|
||||
*/
|
||||
@RestController
|
||||
public class TagController {
|
||||
@Autowired
|
||||
TagService tagService;
|
||||
|
||||
|
||||
@PostMapping("/admin/tag/create")
|
||||
public Response addOne(@RequestParam("name") String name) {
|
||||
return ResponseUtil.success(tagService.create(name));
|
||||
}
|
||||
|
||||
@DeleteMapping("/admin/tag/del")
|
||||
public Response delOne(@RequestParam("id") long id) {
|
||||
return ResponseUtil.success(tagService.delete(id));
|
||||
}
|
||||
|
||||
|
||||
@PutMapping("/admin/tag/update")
|
||||
public Response updateOne(@RequestParam("id") Long id, @RequestParam("name") String name) {
|
||||
return ResponseUtil.success(tagService.update(id, name));
|
||||
}
|
||||
|
||||
@GetMapping("/tag/id/{id}")
|
||||
public Response retrieveOneById(@PathVariable("id") long id) {
|
||||
return ResponseUtil.success(tagService.retrieveOneById(id));
|
||||
}
|
||||
|
||||
@GetMapping("/tag/name/{name}")
|
||||
public Response retrieveOneByName(@PathVariable("name") String name) {
|
||||
return ResponseUtil.success(tagService.retrieveOneByName(name));
|
||||
}
|
||||
|
||||
@GetMapping("/tags")
|
||||
public Response getPage(@RequestParam(required = false, defaultValue = "10", value = "count") int count,
|
||||
@RequestParam(required = false, defaultValue = "1", value = "page") int page) {
|
||||
return ResponseUtil.success(tagService.retrievePage(page, count));
|
||||
}
|
||||
|
||||
@GetMapping("/tags/nac")
|
||||
public Response getTagNameAndCount() {
|
||||
List<JSONObject> nameAndCount = new ArrayList<>();
|
||||
List<Tag> all = tagService.findAll();
|
||||
for (Tag t : all) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("name", t.getName());
|
||||
String articles = t.getArticles();
|
||||
jsonObject.put("size", articles == null ? 0 : articles.split(",").length);
|
||||
nameAndCount.add(jsonObject);
|
||||
}
|
||||
return ResponseUtil.success(nameAndCount);
|
||||
}
|
||||
|
||||
}
|
||||
122
src/main/java/cn/celess/blog/controller/UserController.java
Normal file
122
src/main/java/cn/celess/blog/controller/UserController.java
Normal file
@@ -0,0 +1,122 @@
|
||||
package cn.celess.blog.controller;
|
||||
|
||||
import cn.celess.blog.entity.Response;
|
||||
import cn.celess.blog.entity.request.LoginReq;
|
||||
import cn.celess.blog.entity.request.UserReq;
|
||||
import cn.celess.blog.service.UserService;
|
||||
import cn.celess.blog.util.ResponseUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/30 20:37
|
||||
*/
|
||||
@RestController
|
||||
public class UserController {
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
|
||||
@PostMapping("/login")
|
||||
public Response login(@RequestBody LoginReq loginReq) {
|
||||
return ResponseUtil.success(userService.login(loginReq));
|
||||
}
|
||||
|
||||
@PostMapping("/registration")
|
||||
public Response registration(@RequestParam("email") String email,
|
||||
@RequestParam("password") String password) {
|
||||
return ResponseUtil.success(userService.registration(email, password));
|
||||
}
|
||||
|
||||
@GetMapping("/logout")
|
||||
public Response logout() {
|
||||
return ResponseUtil.success(userService.logout());
|
||||
}
|
||||
|
||||
@PutMapping("/user/userInfo/update")
|
||||
public Response updateInfo(String desc, String displayName) {
|
||||
return ResponseUtil.success(userService.update(desc, displayName));
|
||||
}
|
||||
|
||||
@GetMapping("/user/userInfo")
|
||||
public Response getUserInfo() {
|
||||
return ResponseUtil.success(userService.getUserInfoBySession());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新头像
|
||||
*
|
||||
* @param file file
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@PostMapping("/user/imgUpload")
|
||||
@ResponseBody
|
||||
public Response upload(@RequestParam("file") MultipartFile file) throws IOException {
|
||||
if (file.isEmpty()) {
|
||||
return ResponseUtil.failure("上传失败,请选择文件");
|
||||
}
|
||||
String fileName = file.getOriginalFilename();
|
||||
String mime = fileName.substring(fileName.lastIndexOf("."));
|
||||
if (".png".equals(mime.toLowerCase()) || ".jpg".equals(mime.toLowerCase()) ||
|
||||
".jpeg".equals(mime.toLowerCase()) || ".bmp".equals(mime.toLowerCase())) {
|
||||
return (Response) userService.updateUserAavatarImg(file.getInputStream(), mime);
|
||||
}
|
||||
return ResponseUtil.failure("请上传图片文件");
|
||||
}
|
||||
|
||||
@PostMapping("/sendResetPwdEmail")
|
||||
public Response sendResetPwdEmail(@RequestParam("email") String email) {
|
||||
return ResponseUtil.success(userService.sendResetPwdEmail(email));
|
||||
}
|
||||
|
||||
@PostMapping("/sendVerifyEmail")
|
||||
public Response sendVerifyEmail(@RequestParam("email") String email) {
|
||||
return ResponseUtil.success(userService.sendVerifyEmail(email));
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/emailVerify")
|
||||
public Response emailVerify(@RequestParam("verifyId") String verifyId,
|
||||
@RequestParam("email") String mail) {
|
||||
return ResponseUtil.success(userService.verifyEmail(verifyId, mail));
|
||||
}
|
||||
|
||||
@PostMapping("/resetPwd")
|
||||
public Response resetPwd(@RequestParam("verifyId") String verifyId,
|
||||
@RequestParam("email") String email,
|
||||
@RequestParam("pwd") String pwd) {
|
||||
return ResponseUtil.success(userService.reSetPwd(verifyId, email, pwd));
|
||||
}
|
||||
|
||||
@DeleteMapping("/admin/user/delete")
|
||||
public Response multipleDelete(@RequestBody Integer[] ids) {
|
||||
return ResponseUtil.success(userService.deleteUser(ids));
|
||||
}
|
||||
|
||||
@DeleteMapping("/admin/user/delete/{id}")
|
||||
public Response delete(@PathVariable("id") Integer id) {
|
||||
return ResponseUtil.success(userService.deleteUser(new Integer[]{id}));
|
||||
}
|
||||
|
||||
@PutMapping("/admin/user")
|
||||
public Response updateInfoByAdmin(@RequestBody UserReq user) {
|
||||
return ResponseUtil.success(userService.adminUpdate(user));
|
||||
}
|
||||
|
||||
@GetMapping("/admin/users")
|
||||
public Response getAllUser(@RequestParam("page") int pageNum, @RequestParam("count") int count) {
|
||||
return ResponseUtil.success(userService.getUserList(pageNum, count));
|
||||
}
|
||||
|
||||
@GetMapping("/emailStatus/{email}")
|
||||
public Response getEmailStatus(@PathVariable("email") String email) {
|
||||
return ResponseUtil.success(userService.getStatusOfEmail(email));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package cn.celess.blog.controller;
|
||||
|
||||
import cn.celess.blog.entity.Response;
|
||||
import cn.celess.blog.service.CountService;
|
||||
import cn.celess.blog.service.VisitorService;
|
||||
import cn.celess.blog.util.ResponseUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/02 23:09
|
||||
*/
|
||||
@RestController
|
||||
public class VisitorController {
|
||||
@Autowired
|
||||
VisitorService visitorService;
|
||||
@Autowired
|
||||
CountService countService;
|
||||
|
||||
@GetMapping("/visitor/count")
|
||||
public Response getVisitorCount() {
|
||||
return ResponseUtil.success(countService.getVisitorCount());
|
||||
}
|
||||
|
||||
@GetMapping("/admin/visitor/page")
|
||||
public Response page(@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page,
|
||||
@RequestParam(value = "showLocation", required = false, defaultValue = "false") boolean showLocation) {
|
||||
return ResponseUtil.success(visitorService.visitorPage(page, count, showLocation));
|
||||
}
|
||||
|
||||
@PostMapping("/visit")
|
||||
public Response add(HttpServletRequest request) {
|
||||
return ResponseUtil.success(visitorService.addVisitor(request));
|
||||
}
|
||||
|
||||
@GetMapping("/dayVisitCount")
|
||||
public Response dayVisitCount() {
|
||||
return ResponseUtil.success(countService.getDayVisitCount());
|
||||
}
|
||||
|
||||
@GetMapping("/ip/{ip}")
|
||||
public Response ipLocation(@PathVariable("ip") String ip) {
|
||||
return ResponseUtil.success(visitorService.location(ip));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本地访问者的ip
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/ip")
|
||||
public Response getIp(HttpServletRequest request) {
|
||||
return ResponseUtil.success(request.getRemoteAddr());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package cn.celess.blog.controller;
|
||||
|
||||
import cn.celess.blog.entity.Response;
|
||||
import cn.celess.blog.service.WebUpdateInfoService;
|
||||
import cn.celess.blog.util.ResponseUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/05/12 13:09
|
||||
*/
|
||||
@RestController
|
||||
public class WebUpdateInfoController {
|
||||
@Autowired
|
||||
WebUpdateInfoService webUpdateInfoService;
|
||||
|
||||
@PostMapping("/admin/webUpdate/create")
|
||||
public Response create(@RequestParam("info") String info) {
|
||||
return ResponseUtil.success(webUpdateInfoService.create(info));
|
||||
}
|
||||
|
||||
@DeleteMapping("/admin/webUpdate/del/{id}")
|
||||
public Response del(@PathVariable("id") long id) {
|
||||
return ResponseUtil.success(webUpdateInfoService.del(id));
|
||||
}
|
||||
|
||||
@PutMapping("/admin/webUpdate/update")
|
||||
public Response update(@RequestParam("id") long id, @RequestParam("info") String info) {
|
||||
return ResponseUtil.success(webUpdateInfoService.update(id, info));
|
||||
}
|
||||
|
||||
@GetMapping("/webUpdate")
|
||||
public Response findAll() {
|
||||
return ResponseUtil.success(webUpdateInfoService.findAll());
|
||||
}
|
||||
|
||||
@GetMapping("/webUpdate/pages")
|
||||
public Response page(@RequestParam("page") int page, @RequestParam("count") int count) {
|
||||
return ResponseUtil.success(webUpdateInfoService.pages(count, page));
|
||||
}
|
||||
@GetMapping("/lastestUpdateTime")
|
||||
public Response lastestUpdateTime() {
|
||||
return ResponseUtil.success(webUpdateInfoService.getLastestUpdateTime());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user