mirror of https://github.com/halo-dev/halo
Add Transactional support
parent
d42e4c2599
commit
74349a11e2
|
@ -18,6 +18,7 @@ import java.util.List;
|
|||
* @author ryanwang
|
||||
* @date : 2019-03-14
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public interface CategoryService extends CrudService<Category, Integer> {
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import run.halo.app.exception.AlreadyExistsException;
|
||||
|
@ -46,6 +47,7 @@ public class CategoryServiceImpl extends AbstractCrudService<Category, Integer>
|
|||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Category create(Category category) {
|
||||
Assert.notNull(category, "Category to create must not be null");
|
||||
|
||||
|
@ -161,6 +163,7 @@ public class CategoryServiceImpl extends AbstractCrudService<Category, Integer>
|
|||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void removeCategoryAndPostCategoryBy(Integer categoryId) {
|
||||
// Remove category
|
||||
removeById(categoryId);
|
||||
|
|
|
@ -2,6 +2,7 @@ package run.halo.app.service.impl;
|
|||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import run.halo.app.exception.AlreadyExistsException;
|
||||
|
@ -35,6 +36,7 @@ public class TagServiceImpl extends AbstractCrudService<Tag, Integer> implements
|
|||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Tag create(Tag tag) {
|
||||
// Check if the tag is exist
|
||||
long count = tagRepository.countByNameOrSlugName(tag.getName(), tag.getSlugName());
|
||||
|
|
|
@ -1,24 +1,52 @@
|
|||
//package run.halo.app.service.impl;
|
||||
//
|
||||
//import org.junit.Assert;
|
||||
//import org.junit.Test;
|
||||
//import org.junit.runner.RunWith;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.boot.test.context.SpringBootTest;
|
||||
//import org.springframework.test.context.ActiveProfiles;
|
||||
//import org.springframework.test.context.junit4.SpringRunner;
|
||||
//
|
||||
//@RunWith(SpringRunner.class)
|
||||
//@SpringBootTest
|
||||
//@ActiveProfiles("dev")
|
||||
//public class PostServiceImplTest {
|
||||
//
|
||||
// @Autowired
|
||||
// private PostServiceImpl postService;
|
||||
//
|
||||
// @Test
|
||||
// public void getContent(){
|
||||
// String exportMarkdown = postService.exportMarkdown(18);
|
||||
// System.out.println(exportMarkdown);
|
||||
// }
|
||||
//}
|
||||
package run.halo.app.service.impl;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@ActiveProfiles("dev")
|
||||
public class PostServiceImplTest {
|
||||
|
||||
String standardMdContent = "---\n" +
|
||||
"title: springfox-swagger2配置成功但无法访问/swagger-ui.html\n" +
|
||||
"tags:\n" +
|
||||
" - spring boot\n" +
|
||||
" - swagger\n" +
|
||||
" - solution\n" +
|
||||
"date: 2018-11-23 16:11:28\n" +
|
||||
"---\n" +
|
||||
"\n" +
|
||||
"# Pre\n" +
|
||||
"\n" +
|
||||
"在前后端分离项目中,通常需要用到 API 文档,springfox 开发的 **[SpringFox](https://github.com/springfox/springfox)** 可以实现自动化 json API 文档。";
|
||||
|
||||
String nonStandardMdContent = "---\n" +
|
||||
"title: Basic concepts of JPA\n" +
|
||||
"date: 2018-08-03 11:57:00\n" +
|
||||
"tags: ['spring', 'jpa', 'database', 'concept']\n" +
|
||||
"---\n" +
|
||||
"\n" +
|
||||
"以下将讲解关系型数据的关系描述。仅仅是作为总结。";
|
||||
|
||||
@Autowired
|
||||
private PostServiceImpl postService;
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void getContent() {
|
||||
String exportMarkdown = postService.exportMarkdown(18);
|
||||
System.out.println(exportMarkdown);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void markdownImportTest() {
|
||||
postService.importMarkdown(standardMdContent, "standard");
|
||||
postService.importMarkdown(nonStandardMdContent, "nonStandard");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue