添加请求实体,修改请求
This commit is contained in:
@@ -3,6 +3,7 @@ package cn.celess.blog.controller;
|
|||||||
import cn.celess.blog.enmu.ResponseEnum;
|
import cn.celess.blog.enmu.ResponseEnum;
|
||||||
import cn.celess.blog.entity.PartnerSite;
|
import cn.celess.blog.entity.PartnerSite;
|
||||||
import cn.celess.blog.entity.Response;
|
import cn.celess.blog.entity.Response;
|
||||||
|
import cn.celess.blog.entity.request.LinkApplyReq;
|
||||||
import cn.celess.blog.entity.request.LinkReq;
|
import cn.celess.blog.entity.request.LinkReq;
|
||||||
import cn.celess.blog.exception.MyException;
|
import cn.celess.blog.exception.MyException;
|
||||||
import cn.celess.blog.service.MailService;
|
import cn.celess.blog.service.MailService;
|
||||||
@@ -69,29 +70,7 @@ public class LinksController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/apply")
|
@PostMapping("/apply")
|
||||||
public Response apply(@RequestParam("name") String name,
|
public Response apply(@RequestBody() LinkApplyReq linkApplyReq) {
|
||||||
@RequestParam("url") String url) {
|
return Response.success(partnerSiteService.apply(linkApplyReq));
|
||||||
// TODO :: 弃用发送邮件的方式。
|
|
||||||
if (name == null || name.replaceAll(" ", "").isEmpty()) {
|
|
||||||
return Response.response(ResponseEnum.PARAMETERS_ERROR, null);
|
|
||||||
}
|
|
||||||
if (!RegexUtil.urlMatch(url)) {
|
|
||||||
return Response.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 ? Response.success("") : Response.failure("");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package cn.celess.blog.entity.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : xiaohai
|
||||||
|
* @date : 2020/07/31 20:50
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class LinkApplyReq {
|
||||||
|
private String name;
|
||||||
|
private String email;
|
||||||
|
private String url;
|
||||||
|
private String linkUrl;
|
||||||
|
private String desc;
|
||||||
|
private String iconPath;
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package cn.celess.blog.service;
|
|||||||
|
|
||||||
import cn.celess.blog.entity.PartnerSite;
|
import cn.celess.blog.entity.PartnerSite;
|
||||||
import cn.celess.blog.entity.model.PageData;
|
import cn.celess.blog.entity.model.PageData;
|
||||||
|
import cn.celess.blog.entity.request.LinkApplyReq;
|
||||||
import cn.celess.blog.entity.request.LinkReq;
|
import cn.celess.blog.entity.request.LinkReq;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -53,4 +54,10 @@ public interface PartnerSiteService {
|
|||||||
*/
|
*/
|
||||||
List<PartnerSite> findAll();
|
List<PartnerSite> findAll();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 申请友链
|
||||||
|
* @param linkApplyReq linkApplyReq
|
||||||
|
* @return linkApplyReq
|
||||||
|
*/
|
||||||
|
PartnerSite apply(LinkApplyReq linkApplyReq);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package cn.celess.blog.service.serviceimpl;
|
|||||||
import cn.celess.blog.enmu.ResponseEnum;
|
import cn.celess.blog.enmu.ResponseEnum;
|
||||||
import cn.celess.blog.entity.PartnerSite;
|
import cn.celess.blog.entity.PartnerSite;
|
||||||
import cn.celess.blog.entity.model.PageData;
|
import cn.celess.blog.entity.model.PageData;
|
||||||
|
import cn.celess.blog.entity.request.LinkApplyReq;
|
||||||
import cn.celess.blog.entity.request.LinkReq;
|
import cn.celess.blog.entity.request.LinkReq;
|
||||||
import cn.celess.blog.exception.MyException;
|
import cn.celess.blog.exception.MyException;
|
||||||
import cn.celess.blog.mapper.PartnerMapper;
|
import cn.celess.blog.mapper.PartnerMapper;
|
||||||
@@ -10,6 +11,7 @@ import cn.celess.blog.service.PartnerSiteService;
|
|||||||
import cn.celess.blog.util.RegexUtil;
|
import cn.celess.blog.util.RegexUtil;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -108,5 +110,14 @@ public class PartnerSiteServiceImpl implements PartnerSiteService {
|
|||||||
return all;
|
return all;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PartnerSite apply(LinkApplyReq linkApplyReq) {
|
||||||
|
if (StringUtils.isEmpty(linkApplyReq.getName())
|
||||||
|
|| StringUtils.isEmpty(linkApplyReq.getUrl())
|
||||||
|
|| StringUtils.isEmpty(linkApplyReq.getEmail())
|
||||||
|
|| StringUtils.isEmpty(linkApplyReq.getLinkUrl())) {
|
||||||
|
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user