切换到jackson #10
@@ -9,6 +9,7 @@ import cn.celess.blog.service.ArticleService;
|
|||||||
import cn.celess.blog.util.RedisUserUtil;
|
import cn.celess.blog.util.RedisUserUtil;
|
||||||
import cn.celess.blog.util.SitemapGenerateUtil;
|
import cn.celess.blog.util.SitemapGenerateUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@@ -27,6 +28,8 @@ public class ArticleController {
|
|||||||
SitemapGenerateUtil sitemapGenerateUtil;
|
SitemapGenerateUtil sitemapGenerateUtil;
|
||||||
@Autowired
|
@Autowired
|
||||||
RedisUserUtil redisUserUtil;
|
RedisUserUtil redisUserUtil;
|
||||||
|
@Value("${spring.profiles.active}")
|
||||||
|
private String activeModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新建一篇文章
|
* 新建一篇文章
|
||||||
@@ -37,7 +40,9 @@ public class ArticleController {
|
|||||||
@PostMapping("/admin/article/create")
|
@PostMapping("/admin/article/create")
|
||||||
public Response create(@RequestBody ArticleReq body) {
|
public Response create(@RequestBody ArticleReq body) {
|
||||||
ArticleModel articleModel = articleService.create(body);
|
ArticleModel articleModel = articleService.create(body);
|
||||||
|
if ("prod".equals(activeModel)) {
|
||||||
sitemapGenerateUtil.createSitemap();
|
sitemapGenerateUtil.createSitemap();
|
||||||
|
}
|
||||||
return Response.success(articleModel);
|
return Response.success(articleModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +55,9 @@ public class ArticleController {
|
|||||||
@DeleteMapping("/admin/article/del")
|
@DeleteMapping("/admin/article/del")
|
||||||
public Response delete(@RequestParam("articleID") long articleId) {
|
public Response delete(@RequestParam("articleID") long articleId) {
|
||||||
boolean delete = articleService.delete(articleId);
|
boolean delete = articleService.delete(articleId);
|
||||||
|
if ("prod".equals(activeModel)) {
|
||||||
sitemapGenerateUtil.createSitemap();
|
sitemapGenerateUtil.createSitemap();
|
||||||
|
}
|
||||||
return Response.success(delete);
|
return Response.success(delete);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +70,9 @@ public class ArticleController {
|
|||||||
@PutMapping("/admin/article/update")
|
@PutMapping("/admin/article/update")
|
||||||
public Response update(@RequestBody ArticleReq body) {
|
public Response update(@RequestBody ArticleReq body) {
|
||||||
ArticleModel update = articleService.update(body);
|
ArticleModel update = articleService.update(body);
|
||||||
|
if ("prod".equals(activeModel)) {
|
||||||
sitemapGenerateUtil.createSitemap();
|
sitemapGenerateUtil.createSitemap();
|
||||||
|
}
|
||||||
return Response.success(update);
|
return Response.success(update);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,28 +70,15 @@ public class ArticleControllerTest extends BaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void delete() {
|
public void delete() {
|
||||||
Article article = articleMapper.getLastestArticle();
|
Article article;
|
||||||
|
do {
|
||||||
|
article = articleMapper.getLastestArticle();
|
||||||
|
create();
|
||||||
|
} while (article.isDeleted());
|
||||||
|
assertFalse(article.isDeleted());
|
||||||
|
MockHttpServletRequestBuilder delete = MockMvcRequestBuilders.delete("/admin/article/del?articleID=" + article.getId());
|
||||||
try {
|
try {
|
||||||
// 未登录删除文章
|
getMockData(delete, adminLogin()).andDo(result -> {
|
||||||
mockMvc.perform(MockMvcRequestBuilders.delete("/admin/article/del?articleID=" + article.getId())
|
|
||||||
).andDo(result -> {
|
|
||||||
assertEquals(HAVE_NOT_LOG_IN.getCode(),
|
|
||||||
JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
// user 权限删除文章
|
|
||||||
String token = userLogin();
|
|
||||||
mockMvc.perform(MockMvcRequestBuilders.delete("/admin/article/del?articleID=" + article.getId())
|
|
||||||
.header("Authorization", token))
|
|
||||||
.andDo(result -> assertEquals(PERMISSION_ERROR.getCode(),
|
|
||||||
JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code))
|
|
||||||
);
|
|
||||||
// admin 权限删除文章
|
|
||||||
token = adminLogin();
|
|
||||||
mockMvc.perform(MockMvcRequestBuilders.delete("/admin/article/del?articleID=" + article.getId())
|
|
||||||
.header("Authorization", token))
|
|
||||||
.andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
||||||
// 断言删除成功
|
// 断言删除成功
|
||||||
|
|||||||
Reference in New Issue
Block a user