mirror of https://github.com/halo-dev/halo
Support journal type.
parent
f99bf401a5
commit
9ae1f739c7
|
@ -52,6 +52,11 @@ public class ThemeController {
|
|||
return themeService.listThemeFolderBy(themeService.getActivatedThemeId());
|
||||
}
|
||||
|
||||
@GetMapping("{themeId}/files")
|
||||
public List<ThemeFile> listFiles(@PathVariable("themeId") String themeId){
|
||||
return themeService.listThemeFolderBy(themeId);
|
||||
}
|
||||
|
||||
@GetMapping("files/content")
|
||||
public BaseResponse<String> getContentBy(@RequestParam(name = "path") String path) {
|
||||
return BaseResponse.ok(HttpStatus.OK.getReasonPhrase(), themeService.getTemplateContent(path));
|
||||
|
|
|
@ -3,6 +3,7 @@ package run.halo.app.model.entity;
|
|||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import run.halo.app.model.enums.JournalType;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
|
@ -10,6 +11,7 @@ import javax.persistence.*;
|
|||
* Journal entity
|
||||
*
|
||||
* @author johnniang
|
||||
* @author ryanwang
|
||||
* @date 3/22/19
|
||||
*/
|
||||
@Data
|
||||
|
@ -29,6 +31,9 @@ public class Journal extends BaseEntity {
|
|||
@Column(name = "likes", columnDefinition = "bigint default 0")
|
||||
private Long likes;
|
||||
|
||||
@Column(name = "type", columnDefinition = "int default 1")
|
||||
private JournalType type;
|
||||
|
||||
@Override
|
||||
public void prePersist() {
|
||||
super.prePersist();
|
||||
|
@ -38,5 +43,10 @@ public class Journal extends BaseEntity {
|
|||
if (likes == null || likes < 0) {
|
||||
likes = 0L;
|
||||
}
|
||||
|
||||
|
||||
if (type == null) {
|
||||
type = JournalType.PUBLIC;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package run.halo.app.model.enums;
|
||||
|
||||
/**
|
||||
* Journal type.
|
||||
*
|
||||
* @author ryanwnag
|
||||
*/
|
||||
public enum JournalType implements ValueEnum<Integer> {
|
||||
|
||||
/**
|
||||
* Public type.
|
||||
*/
|
||||
PUBLIC(1),
|
||||
|
||||
/**
|
||||
* Private type.
|
||||
*/
|
||||
PRIVATE(0);
|
||||
|
||||
private final int value;
|
||||
|
||||
JournalType(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package run.halo.app.model.params;
|
|||
import lombok.Data;
|
||||
import run.halo.app.model.dto.base.InputConverter;
|
||||
import run.halo.app.model.entity.Journal;
|
||||
import run.halo.app.model.enums.JournalType;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
|
@ -11,6 +12,7 @@ import javax.validation.constraints.Size;
|
|||
* Journal param.
|
||||
*
|
||||
* @author johnniang
|
||||
* @author ryanwang
|
||||
* @date 19-4-25
|
||||
*/
|
||||
@Data
|
||||
|
@ -19,4 +21,6 @@ public class JournalParam implements InputConverter<Journal> {
|
|||
@NotBlank(message = "内容不能为空")
|
||||
@Size(max = 511, message = "内容的字符长度不能超过 {max}")
|
||||
private String content;
|
||||
|
||||
private JournalType type = JournalType.PUBLIC;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package run.halo.app.model.params;
|
||||
|
||||
import lombok.Data;
|
||||
import run.halo.app.model.enums.JournalType;
|
||||
|
||||
/**
|
||||
* Journal query params.
|
||||
|
@ -15,4 +16,6 @@ public class JournalQuery {
|
|||
* Keyword.
|
||||
*/
|
||||
private String keyword;
|
||||
|
||||
private JournalType type;
|
||||
}
|
||||
|
|
|
@ -118,6 +118,10 @@ public class JournalServiceImpl extends AbstractCrudService<Journal, Integer> im
|
|||
return (Specification<Journal>) (root, query, criteriaBuilder) -> {
|
||||
List<Predicate> predicates = new LinkedList<>();
|
||||
|
||||
if (journalQuery.getType() != null) {
|
||||
predicates.add(criteriaBuilder.equal(root.get("type"), journalQuery.getType()));
|
||||
}
|
||||
|
||||
if (journalQuery.getKeyword() != null) {
|
||||
// Format like condition
|
||||
String likeCondition = String.format("%%%s%%", StringUtils.strip(journalQuery.getKeyword()));
|
||||
|
|
Loading…
Reference in New Issue