Support journal search.

pull/146/head
ruibaby 2019-04-26 22:58:27 +08:00
parent c438d99d47
commit 6f35efe90f
78 changed files with 151 additions and 80 deletions

View File

@ -13,7 +13,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
* Halo run!
* </pre>
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2017/11/14
*/
@SpringBootApplication

View File

@ -18,7 +18,7 @@ import javax.annotation.PostConstruct;
/**
* FreeMarker configuration.
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2018/4/26
*/
@Slf4j

View File

@ -30,7 +30,7 @@ import java.util.List;
/**
* Mvc configuration.
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2018/1/2
*/
@Slf4j

View File

@ -12,6 +12,7 @@ import run.halo.app.model.dto.JournalDTO;
import run.halo.app.model.dto.JournalWithCmtCountDTO;
import run.halo.app.model.entity.Journal;
import run.halo.app.model.params.JournalParam;
import run.halo.app.model.params.JournalQuery;
import run.halo.app.model.vo.BaseCommentVO;
import run.halo.app.model.vo.BaseCommentWithParentVO;
import run.halo.app.service.JournalCommentService;
@ -27,6 +28,7 @@ import static org.springframework.data.domain.Sort.Direction.DESC;
* Journal controller.
*
* @author johnniang
* @author ryanwang
* @date 19-4-25
*/
@RestController
@ -49,8 +51,9 @@ public class JournalController {
@GetMapping
@ApiOperation("Gets latest journals")
public Page<JournalWithCmtCountDTO> pageBy(@PageableDefault(sort = "updateTime", direction = DESC) Pageable pageable) {
Page<Journal> journalPage = journalService.listAll(pageable);
public Page<JournalWithCmtCountDTO> pageBy(@PageableDefault(sort = "updateTime", direction = DESC) Pageable pageable,
JournalQuery journalQuery) {
Page<Journal> journalPage = journalService.pageBy(journalQuery,pageable);
return journalService.convertToCmtCountDto(journalPage);
}

View File

@ -15,7 +15,7 @@ import java.util.List;
/**
* Link Controller
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019/3/21
*/
@RestController

View File

@ -6,7 +6,7 @@ import org.springframework.web.bind.annotation.GetMapping;
/**
* Admin page.
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019-04-23
*/
@Controller

View File

@ -21,7 +21,7 @@ import static org.springframework.data.domain.Sort.Direction.DESC;
/**
* Photo controller
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019/3/21
*/
@RestController

View File

@ -18,7 +18,7 @@ import java.util.Set;
/**
* Theme controller.
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019/3/20
*/
@RestController

View File

@ -28,7 +28,7 @@ import static org.springframework.data.domain.Sort.Direction.DESC;
/**
* Blog archive page controller
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019-03-17
*/
@Slf4j

View File

@ -21,7 +21,7 @@ import run.halo.app.service.ThemeService;
import static org.springframework.data.domain.Sort.Direction.DESC;
/**
* @author : RYAN0UP
* @author ryanwang
* @date : 2019/3/20
*/
@Controller

View File

@ -24,7 +24,7 @@ import java.util.List;
import static org.springframework.data.domain.Sort.Direction.DESC;
/**
* @author : RYAN0UP
* @author ryanwang
* @date : 2019-03-21
*/
@Controller

View File

@ -24,7 +24,7 @@ import static org.springframework.data.domain.Sort.Direction.DESC;
/**
* Blog index page controller
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019-03-17
*/
@Slf4j

View File

@ -24,7 +24,7 @@ import static org.springframework.data.domain.Sort.Direction.DESC;
/**
* Search Controller
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019-04-21
*/
@Controller

View File

@ -12,7 +12,7 @@ import run.halo.app.service.SheetService;
import run.halo.app.service.ThemeService;
/**
* @author : RYAN0UP
* @author ryanwang
* @date : 2019-03-21
*/
@Controller

View File

@ -23,7 +23,7 @@ import static org.springframework.data.domain.Sort.Direction.DESC;
/**
* Tag Controller
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019-03-21
*/
@Controller

View File

@ -18,7 +18,7 @@ import java.io.FileNotFoundException;
/**
* Error page Controller
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2017/12/26
*/
@Slf4j

View File

@ -29,7 +29,7 @@ import static run.halo.app.model.support.HaloConst.DEFAULT_THEME_ID;
/**
* Installation controller.
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019-03-17
*/
@Slf4j

View File

@ -5,7 +5,7 @@ import org.springframework.core.convert.converter.ConverterFactory;
import org.springframework.stereotype.Component;
/**
* @author : RYAN0UP
* @author ryanwang
* @date : 2019/3/14
*/
@Component

View File

@ -7,7 +7,7 @@ import java.util.Objects;
/**
* Theme property.
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019-03-22
*/
@Data

View File

@ -23,7 +23,7 @@ import java.util.List;
/**
* The method executed after the application is started.
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2018/12/5
*/
@Slf4j

View File

@ -7,7 +7,7 @@ import lombok.Data;
/**
* Link output dto.
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019/3/21
*/
@Data

View File

@ -7,7 +7,7 @@ import lombok.Data;
import java.util.Date;
/**
* @author : RYAN0UP
* @author ryanwang
* @date : 2019/3/21
*/
@Data

View File

@ -12,7 +12,7 @@ import javax.persistence.*;
/**
* Attachment entity
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019-03-12
*/
@Data

View File

@ -11,7 +11,7 @@ import javax.persistence.*;
/**
* Link entity
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019-03-12
*/
@Data

View File

@ -11,7 +11,7 @@ import javax.persistence.*;
/**
* Menu entity
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019-03-12
*/
@Data

View File

@ -12,7 +12,7 @@ import java.util.Date;
/**
* Photo entity
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019-03-12
*/
@Data

View File

@ -11,7 +11,7 @@ import java.util.Objects;
/**
* Post tag entity.
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019-03-12
*/
@Data

View File

@ -11,7 +11,7 @@ import javax.persistence.*;
/**
* Tag entity
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019-03-12
*/
@Data

View File

@ -14,7 +14,7 @@ import java.util.Date;
/**
* User entity
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019-03-12
*/
@Data

View File

@ -3,7 +3,7 @@ package run.halo.app.model.enums;
/**
* Attach origin.
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019-03-12
*/
public enum AttachmentType implements ValueEnum<Integer> {

View File

@ -9,7 +9,7 @@ import org.springframework.stereotype.Component;
import java.util.List;
/**
* @author : RYAN0UP
* @author ryanwang
* @date : 2018/12/21
*/
@Component

View File

@ -7,7 +7,7 @@ import org.springframework.stereotype.Component;
import java.util.List;
/**
* @author : RYAN0UP
* @author ryanwang
* @date : 2018/12/31
*/
@Component

View File

@ -7,7 +7,7 @@ import org.springframework.stereotype.Component;
import java.util.List;
/**
* @author : RYAN0UP
* @author ryanwang
* @date : 2018/12/31
*/
@Component

View File

@ -12,7 +12,7 @@ import java.util.Map;
/**
* Freemarker custom tag of category.
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019/3/22
*/
@Component

View File

@ -12,7 +12,7 @@ import java.util.Map;
/**
* Freemarker custom tag of comment.
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019/3/22
*/
@Component

View File

@ -15,7 +15,7 @@ import static org.springframework.data.domain.Sort.Direction.DESC;
/**
* Freemarker custom tag of link.
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019/3/22
*/
@Component

View File

@ -12,7 +12,7 @@ import java.util.Map;
/**
* Freemarker custom tag of menu.
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019/3/22
*/
@Component

View File

@ -15,7 +15,7 @@ import static org.springframework.data.domain.Sort.Direction.DESC;
/**
* Freemarker custom tag of photo.
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019/4/21
*/
@Component

View File

@ -12,7 +12,7 @@ import java.util.Map;
/**
* Freemarker custom tag of post.
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2018/4/26
*/
@Component

View File

@ -12,7 +12,7 @@ import java.util.Map;
/**
* Freemarker custom tag of tag.
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019/3/22
*/
@Component

View File

@ -10,7 +10,7 @@ import javax.validation.constraints.Size;
/**
* Attachment params.
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019/04/20
*/
@Data

View File

@ -6,7 +6,7 @@ import run.halo.app.model.enums.AttachmentType;
/**
* Attachment query params.
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019/04/18
*/
@Data

View File

@ -6,7 +6,7 @@ import run.halo.app.model.enums.CommentStatus;
/**
* Comment query params.
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019/04/18
*/
@Data

View File

@ -0,0 +1,18 @@
package run.halo.app.model.params;
import lombok.Data;
/**
* Journal query params.
*
* @author ryanwang
* @date : 2019/04/26
*/
@Data
public class JournalQuery {
/**
* Keyword.
*/
private String keyword;
}

View File

@ -10,7 +10,7 @@ import java.util.Date;
/**
* Post param.
*
* @author RYAN0UP
* @author ryanwang
* @date 2019/04/25
*/
@Data

View File

@ -5,7 +5,7 @@ import lombok.Data;
/**
* Photo query params.
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019/04/25
*/
@Data

View File

@ -1,7 +1,7 @@
package run.halo.app.model.properties;
/**
* @author : RYAN0UP
* @author ryanwang
* @date : 2019-03-17
*/
public enum BlogProperties implements PropertyEnum {

View File

@ -9,7 +9,7 @@ import java.util.Date;
*
* </pre>
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2018/6/4
*/
@Data

View File

@ -5,7 +5,7 @@ package run.halo.app.model.support;
*
* </pre>
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2017/12/29
*/
public class HaloConst {

View File

@ -5,7 +5,7 @@ package run.halo.app.model.support;
*
* </pre>
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2018/1/19
*/
public interface LogsRecord {

View File

@ -9,7 +9,7 @@ import java.util.List;
/**
* Theme file.
*
* @author RYAN0UP
* @author ryanwang
* @date 2019/04/02
*/
@Data

View File

@ -9,7 +9,7 @@ import java.util.List;
/**
* Link team vo.
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019/3/22
*/
@Data

View File

@ -6,7 +6,7 @@ import run.halo.app.model.dto.MenuDTO;
import java.util.List;
/**
* @author : RYAN0UP
* @author ryanwang
* @date : 2019-04-07
*/
@Data

View File

@ -9,7 +9,7 @@ import java.util.List;
/**
* Link team vo.
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019/3/22
*/
@Data

View File

@ -1,5 +1,6 @@
package run.halo.app.repository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import run.halo.app.model.entity.Journal;
import run.halo.app.repository.base.BaseRepository;
@ -9,6 +10,6 @@ import run.halo.app.repository.base.BaseRepository;
* @author johnniang
* @date 3/22/19
*/
public interface JournalRepository extends BaseRepository<Journal, Integer> {
public interface JournalRepository extends BaseRepository<Journal, Integer>, JpaSpecificationExecutor<Journal> {
}

View File

@ -10,7 +10,7 @@ import run.halo.app.repository.base.BasePostRepository;
* Post repository.
*
* @author johnniang
* @author RYAN0UP
* @author ryanwang
*/
public interface PostRepository extends BasePostRepository<Post>, JpaSpecificationExecutor<Post> {

View File

@ -8,6 +8,7 @@ import run.halo.app.model.dto.JournalDTO;
import run.halo.app.model.dto.JournalWithCmtCountDTO;
import run.halo.app.model.entity.Journal;
import run.halo.app.model.params.JournalParam;
import run.halo.app.model.params.JournalQuery;
import run.halo.app.service.base.CrudService;
import java.util.List;
@ -16,6 +17,7 @@ import java.util.List;
* Journal service interface.
*
* @author johnniang
* @author ryanwang
* @date 19-4-24
*/
public interface JournalService extends CrudService<Journal, Integer> {
@ -37,6 +39,16 @@ public interface JournalService extends CrudService<Journal, Integer> {
*/
Page<Journal> pageLatest(int top);
/**
* Pages journals.
*
* @param journalQuery journal query must not be null
* @param pageable page info must not be null
* @return a page of post
*/
@NonNull
Page<Journal> pageBy(@NonNull JournalQuery journalQuery, @NonNull Pageable pageable);
/**
* Converts to journal dto.
*

View File

@ -5,7 +5,7 @@ import java.util.Map;
/**
* Mail server
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019-03-17
*/
public interface MailService {

View File

@ -14,7 +14,7 @@ import java.util.List;
* Menu service.
*
* @author johnniang
* @author RYAN0UP
* @author ryanwang
*/
public interface MenuService extends CrudService<Menu, Integer> {

View File

@ -20,7 +20,7 @@ import java.util.Set;
* Post service.
*
* @author johnniang
* @author RYAN0UP
* @author ryanwang
*/
public interface PostService extends BasePostService<Post> {

View File

@ -14,7 +14,7 @@ import java.util.Optional;
import java.util.Set;
/**
* @author : RYAN0UP
* @author ryanwang
* @date : 2019/3/26
*/
public interface ThemeService {

View File

@ -30,7 +30,7 @@ import java.util.Objects;
/**
* AttachmentService implementation
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019-03-14
*/
@Slf4j

View File

@ -24,7 +24,7 @@ import java.util.stream.Collectors;
/**
* CategoryService implementation class
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019-03-14
*/
@Slf4j

View File

@ -1,7 +1,11 @@
package run.halo.app.service.impl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
@ -9,22 +13,22 @@ import run.halo.app.model.dto.JournalDTO;
import run.halo.app.model.dto.JournalWithCmtCountDTO;
import run.halo.app.model.entity.Journal;
import run.halo.app.model.params.JournalParam;
import run.halo.app.model.params.JournalQuery;
import run.halo.app.repository.JournalRepository;
import run.halo.app.service.JournalCommentService;
import run.halo.app.service.JournalService;
import run.halo.app.service.base.AbstractCrudService;
import run.halo.app.utils.ServiceUtils;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.persistence.criteria.Predicate;
import java.util.*;
import java.util.stream.Collectors;
/**
* Journal service implementation.
*
* @author johnniang
* @author ryanwang
* @date 19-4-24
*/
@Service
@ -53,6 +57,13 @@ public class JournalServiceImpl extends AbstractCrudService<Journal, Integer> im
return listAll(ServiceUtils.buildLatestPageable(top));
}
@Override
public Page<Journal> pageBy(JournalQuery journalQuery, Pageable pageable) {
Assert.notNull(journalQuery, "Journal query must not be null");
Assert.notNull(pageable, "Page info must not be null");
return journalRepository.findAll(buildSpecByQuery(journalQuery), pageable);
}
@Override
public JournalDTO convertTo(Journal journal) {
Assert.notNull(journal, "Journal must not be null");
@ -94,4 +105,30 @@ public class JournalServiceImpl extends AbstractCrudService<Journal, Integer> im
}
/**
* Build specification by journal query.
*
* @param journalQuery query query must not be null
* @return a query specification
*/
@NonNull
private Specification<Journal> buildSpecByQuery(@NonNull JournalQuery journalQuery) {
Assert.notNull(journalQuery, "Journal query must not be null");
return (Specification<Journal>) (root, query, criteriaBuilder) -> {
List<Predicate> predicates = new LinkedList<>();
if (journalQuery.getKeyword() != null) {
// Format like condition
String likeCondition = String.format("%%%s%%", StringUtils.strip(journalQuery.getKeyword()));
// Build like predicate
Predicate contentLike = criteriaBuilder.like(root.get("content"), likeCondition);
predicates.add(criteriaBuilder.or(contentLike));
}
return query.where(predicates.toArray(new Predicate[0])).getRestriction();
};
}
}

View File

@ -23,7 +23,7 @@ import java.util.stream.Collectors;
/**
* LinkService implementation class
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019-03-14
*/
@Service

View File

@ -14,7 +14,7 @@ import org.springframework.util.Assert;
/**
* LogService implementation class
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019-03-14
*/
@Service

View File

@ -19,7 +19,7 @@ import java.util.Properties;
/**
* Mail service implementation.
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019-03-17
*/
@Slf4j

View File

@ -22,7 +22,7 @@ import java.util.stream.Collectors;
/**
* MenuService implementation class
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019-03-14
*/
@Service

View File

@ -28,7 +28,7 @@ import java.util.stream.Collectors;
/**
* OptionService implementation class
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019-03-14
*/
@Slf4j

View File

@ -28,7 +28,7 @@ import java.util.stream.Collectors;
/**
* PhotoService implementation class
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019-03-14
*/
@Service

View File

@ -27,7 +27,7 @@ import java.util.stream.Collectors;
/**
* PostCommentService implementation class
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019-03-14
*/
@Slf4j

View File

@ -41,7 +41,7 @@ import static org.springframework.data.domain.Sort.Direction.DESC;
* Post service implementation.
*
* @author johnniang
* @author RYAN0UP
* @author ryanwang
*/
@Slf4j
@Service

View File

@ -19,7 +19,7 @@ import java.util.stream.Collectors;
/**
* TagService implementation class
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019-03-14
*/
@Slf4j

View File

@ -51,7 +51,7 @@ import java.util.zip.ZipInputStream;
import static run.halo.app.model.support.HaloConst.DEFAULT_THEME_ID;
/**
* @author : RYAN0UP
* @author ryanwang
* @date : 2019/3/26
*/
@Slf4j

View File

@ -32,7 +32,7 @@ import java.util.concurrent.TimeUnit;
/**
* UserService implementation class
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2019-03-14
*/
@Service

View File

@ -25,7 +25,7 @@ import java.util.UUID;
*
* </pre>
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2017/12/22
*/
@Slf4j

View File

@ -17,7 +17,7 @@ import java.util.Set;
/**
* Markdown utils
*
* @author : RYAN0UP
* @author ryanwang
* @date : 2018/11/14
*/
public class MarkdownUtils {

View File

@ -3,7 +3,7 @@ package run.halo.app.utils;
import org.junit.Test;
/**
* @author : RYAN0UP
* @author ryanwang
* @date : 2017/12/26
* @version : 1.0
* description: