mirror of https://github.com/halo-dev/halo
Merge remote-tracking branch 'origin/v1' into v1
commit
bade1b7358
|
@ -0,0 +1,25 @@
|
||||||
|
package cc.ryanc.halo.model.dto;
|
||||||
|
|
||||||
|
import cc.ryanc.halo.model.dto.base.OutputConverter;
|
||||||
|
import cc.ryanc.halo.model.entity.Link;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Link output dto.
|
||||||
|
*
|
||||||
|
* @author : RYAN0UP
|
||||||
|
* @date : 2019/3/21
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class LinkOutputDTO implements OutputConverter<LinkOutputDTO, Link> {
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
private String team;
|
||||||
|
}
|
|
@ -1,7 +1,12 @@
|
||||||
package cc.ryanc.halo.service;
|
package cc.ryanc.halo.service;
|
||||||
|
|
||||||
|
import cc.ryanc.halo.model.dto.LinkOutputDTO;
|
||||||
import cc.ryanc.halo.model.entity.Link;
|
import cc.ryanc.halo.model.entity.Link;
|
||||||
import cc.ryanc.halo.service.base.CrudService;
|
import cc.ryanc.halo.service.base.CrudService;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.lang.NonNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Link service.
|
* Link service.
|
||||||
|
@ -10,4 +15,11 @@ import cc.ryanc.halo.service.base.CrudService;
|
||||||
*/
|
*/
|
||||||
public interface LinkService extends CrudService<Link, Integer> {
|
public interface LinkService extends CrudService<Link, Integer> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List link dtos.
|
||||||
|
*
|
||||||
|
* @param sort sort
|
||||||
|
* @return all links
|
||||||
|
*/
|
||||||
|
List<LinkOutputDTO> listDtos(@NonNull Sort sort);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,16 @@
|
||||||
package cc.ryanc.halo.service.impl;
|
package cc.ryanc.halo.service.impl;
|
||||||
|
|
||||||
|
import cc.ryanc.halo.model.dto.LinkOutputDTO;
|
||||||
import cc.ryanc.halo.model.entity.Link;
|
import cc.ryanc.halo.model.entity.Link;
|
||||||
import cc.ryanc.halo.repository.LinkRepository;
|
import cc.ryanc.halo.repository.LinkRepository;
|
||||||
import cc.ryanc.halo.service.LinkService;
|
import cc.ryanc.halo.service.LinkService;
|
||||||
import cc.ryanc.halo.service.base.AbstractCrudService;
|
import cc.ryanc.halo.service.base.AbstractCrudService;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LinkService implementation class
|
* LinkService implementation class
|
||||||
|
@ -21,4 +27,17 @@ public class LinkServiceImpl extends AbstractCrudService<Link, Integer> implemen
|
||||||
super(linkRepository);
|
super(linkRepository);
|
||||||
this.linkRepository = linkRepository;
|
this.linkRepository = linkRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List link dtos.
|
||||||
|
*
|
||||||
|
* @param sort sort
|
||||||
|
* @return all links
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<LinkOutputDTO> listDtos(Sort sort) {
|
||||||
|
Assert.notNull(sort, "Sort info must not be null");
|
||||||
|
|
||||||
|
return listAll(sort).stream().map(link -> (LinkOutputDTO) new LinkOutputDTO().convertFrom(link)).collect(Collectors.toList());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ public class ThemeUtils {
|
||||||
themes.addAll(getThemesByPath(getInternalThemesPath(), true));
|
themes.addAll(getThemesByPath(getInternalThemesPath(), true));
|
||||||
themes.addAll(getThemesByPath(getUsersThemesPath(), false));
|
themes.addAll(getThemesByPath(getUsersThemesPath(), false));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("Themes scan failed",e);
|
throw new RuntimeException("Themes scan failed", e);
|
||||||
}
|
}
|
||||||
return themes;
|
return themes;
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ public class ThemeUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("Themes scan failed",e);
|
throw new RuntimeException("Themes scan failed", e);
|
||||||
}
|
}
|
||||||
return themes;
|
return themes;
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ public class ThemeUtils {
|
||||||
* @return File
|
* @return File
|
||||||
*/
|
*/
|
||||||
public static File getThemesPath(String themeName) throws FileNotFoundException {
|
public static File getThemesPath(String themeName) throws FileNotFoundException {
|
||||||
return isInternal(themeName)?getInternalThemesPath():getUsersThemesPath();
|
return isInternal(themeName) ? getInternalThemesPath() : getUsersThemesPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -139,7 +139,7 @@ public class ThemeUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("Failed to get theme template",e);
|
throw new RuntimeException("Failed to get theme template", e);
|
||||||
}
|
}
|
||||||
return templates;
|
return templates;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
package cc.ryanc.halo.web.controller.admin.api;
|
||||||
|
|
||||||
|
import cc.ryanc.halo.model.dto.LinkOutputDTO;
|
||||||
|
import cc.ryanc.halo.service.LinkService;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.data.web.SortDefault;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Link Controller
|
||||||
|
*
|
||||||
|
* @author : RYAN0UP
|
||||||
|
* @date : 2019/3/21
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping(value = "/admin/api/links")
|
||||||
|
public class LinkController {
|
||||||
|
|
||||||
|
private final LinkService linkService;
|
||||||
|
|
||||||
|
public LinkController(LinkService linkService) {
|
||||||
|
this.linkService = linkService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List all links
|
||||||
|
*
|
||||||
|
* @param sort sort
|
||||||
|
* @return List
|
||||||
|
*/
|
||||||
|
@GetMapping
|
||||||
|
public List<LinkOutputDTO> listLinks(@SortDefault(sort = "updateTime", direction = Sort.Direction.DESC) Sort sort) {
|
||||||
|
return linkService.listDtos(sort);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
package cc.ryanc.halo.web.controller.admin.api;
|
||||||
|
|
||||||
|
import cc.ryanc.halo.model.enums.BlogProperties;
|
||||||
|
import cc.ryanc.halo.model.support.Theme;
|
||||||
|
import cc.ryanc.halo.service.OptionService;
|
||||||
|
import cc.ryanc.halo.utils.ThemeUtils;
|
||||||
|
import cc.ryanc.halo.web.controller.content.base.BaseContentController;
|
||||||
|
import freemarker.template.Configuration;
|
||||||
|
import freemarker.template.TemplateModelException;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static cc.ryanc.halo.model.support.HaloConst.OPTIONS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : RYAN0UP
|
||||||
|
* @date : 2019/3/20
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/admin/api/themes")
|
||||||
|
public class ThemeController {
|
||||||
|
|
||||||
|
private final OptionService optionService;
|
||||||
|
|
||||||
|
private Configuration configuration;
|
||||||
|
|
||||||
|
public ThemeController(OptionService optionService,
|
||||||
|
Configuration configuration) {
|
||||||
|
this.optionService = optionService;
|
||||||
|
this.configuration = configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List all themes
|
||||||
|
*
|
||||||
|
* @return themes
|
||||||
|
*/
|
||||||
|
@GetMapping
|
||||||
|
@ApiOperation("List all themes")
|
||||||
|
public List<Theme> listAll() {
|
||||||
|
return ThemeUtils.getThemes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Active theme
|
||||||
|
*
|
||||||
|
* @param themeName theme name
|
||||||
|
* @throws TemplateModelException TemplateModelException
|
||||||
|
*/
|
||||||
|
@GetMapping(value = "active")
|
||||||
|
@ApiOperation("Active theme")
|
||||||
|
public void active(@RequestParam(name = "themeName", defaultValue = "anatole") String themeName) throws TemplateModelException {
|
||||||
|
Map<BlogProperties, String> properties = new HashMap<>(1);
|
||||||
|
properties.put(BlogProperties.THEME, themeName);
|
||||||
|
optionService.saveProperties(properties);
|
||||||
|
BaseContentController.THEME = themeName;
|
||||||
|
OPTIONS.clear();
|
||||||
|
OPTIONS = optionService.listOptions();
|
||||||
|
configuration.setSharedVariable("themeName", themeName);
|
||||||
|
configuration.setSharedVariable("options", OPTIONS);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue