Create list team api for menu/link.

pull/351/head
ruibaby 2019-10-24 10:25:14 +08:00
parent 1c38fc6471
commit eb7ff715c2
12 changed files with 76 additions and 8 deletions

View File

@ -90,7 +90,7 @@ public class WebMvcAutoConfiguration implements WebMvcConfigurer {
.addResourceLocations(workDir + "upload/");
registry.addResourceHandler("/backup/**")
.addResourceLocations(workDir + "backup/");
registry.addResourceHandler("/admin/**")
registry.addResourceHandler(haloProperties.getAdminPath() + "/**")
.addResourceLocations(workDir + HALO_ADMIN_RELATIVE_PATH)
.addResourceLocations("classpath:/admin/");

View File

@ -32,6 +32,11 @@ public class HaloProperties {
*/
private boolean authEnabled = true;
/**
* Admin path.
*/
private String adminPath = "/admin";
/**
* Work directory.
*/

View File

@ -76,4 +76,10 @@ public class LinkController {
public void deletePermanently(@PathVariable("id") Integer id) {
linkService.removeById(id);
}
@GetMapping("teams")
@ApiOperation(("List all link teams"))
public List<String> teams() {
return linkService.listAllTeams();
}
}

View File

@ -20,7 +20,8 @@ import static org.springframework.data.domain.Sort.Direction.DESC;
* Menu controller.
*
* @author johnniang
* @date 4/3/19
* @author ryanwang
* @date 2019-04-03
*/
@RestController
@RequestMapping("/api/admin/menus")
@ -88,4 +89,10 @@ public class MenuController {
}
return new MenuDTO().convertFrom(menuService.removeById(menuId));
}
@GetMapping("teams")
@ApiOperation(("List all menu teams"))
public List<String> teams() {
return menuService.listAllTeams();
}
}

View File

@ -3,7 +3,9 @@ package run.halo.app.controller.content;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import run.halo.app.config.properties.HaloProperties;
import run.halo.app.exception.ServiceException;
import run.halo.app.model.entity.User;
import run.halo.app.model.properties.BlogProperties;
@ -27,19 +29,22 @@ public class MainController {
private final OptionService optionService;
public MainController(UserService userService, OptionService optionService) {
private final HaloProperties haloProperties;
public MainController(UserService userService, OptionService optionService, HaloProperties haloProperties) {
this.userService = userService;
this.optionService = optionService;
this.haloProperties = haloProperties;
}
@GetMapping("/admin")
public String admin() {
return "redirect:/admin/index.html";
@GetMapping("/{permlink}")
public String admin(@PathVariable(name = "permlink") String permlink) {
return "redirect:/" + permlink + "/index.html";
}
@GetMapping("/install")
public String installation() {
return "redirect:/admin/index.html#install";
return "redirect:" + haloProperties.getAdminPath() + "/index.html#install";
}
@GetMapping("/version")

View File

@ -53,7 +53,7 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
String blogUrl = optionService.getBlogBaseUrl();
log.info("Halo started at {}", blogUrl);
log.info("Halo admin started at {}/admin", blogUrl);
log.info("Halo admin started at {}{}", blogUrl, haloProperties.getAdminPath());
if (!haloProperties.isDocDisabled()) {
log.debug("Halo doc was enable at {}/swagger-ui.html", blogUrl);
}

View File

@ -1,12 +1,23 @@
package run.halo.app.repository;
import org.springframework.data.jpa.repository.Query;
import run.halo.app.model.entity.Link;
import run.halo.app.repository.base.BaseRepository;
import java.util.List;
/**
* Link repository.
*
* @author johnniang
*/
public interface LinkRepository extends BaseRepository<Link, Integer> {
/**
* Find all link teams.
*
* @return a list of teams
*/
@Query(value = "select distinct a.team from Link a")
List<String> findAllTeams();
}

View File

@ -1,6 +1,7 @@
package run.halo.app.repository;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.Query;
import org.springframework.lang.NonNull;
import run.halo.app.model.entity.Menu;
import run.halo.app.repository.base.BaseRepository;
@ -23,4 +24,12 @@ public interface MenuRepository extends BaseRepository<Menu, Integer> {
List<Menu> findByParentId(@NonNull Integer id);
List<Menu> findByTeam(String team, Sort sort);
/**
* Find all menu teams.
*
* @return a list of teams
*/
@Query(value = "select distinct a.team from Menu a")
List<String> findAllTeams();
}

View File

@ -14,6 +14,7 @@ import java.util.List;
* Link service interface.
*
* @author johnniang
* @author ryanwang
* @date 2019-03-14
*/
public interface LinkService extends CrudService<Link, Integer> {
@ -52,4 +53,11 @@ public interface LinkService extends CrudService<Link, Integer> {
* @return true if exists; false otherwise
*/
boolean existByName(String name);
/**
* List all link teams.
*
* @return a list of teams.
*/
List<String> listAllTeams();
}

View File

@ -71,4 +71,11 @@ public interface MenuService extends CrudService<Menu, Integer> {
* @return a list of menu
*/
List<Menu> listByParentId(@NonNull Integer id);
/**
* List all menu teams.
*
* @return a list of teams.
*/
List<String> listAllTeams();
}

View File

@ -95,6 +95,11 @@ public class LinkServiceImpl extends AbstractCrudService<Link, Integer> implemen
return linkRepository.exists(Example.of(link));
}
@Override
public List<String> listAllTeams() {
return linkRepository.findAllTeams();
}
@NonNull
private List<LinkDTO> convertTo(@Nullable List<Link> links) {
if (CollectionUtils.isEmpty(links)) {

View File

@ -112,6 +112,11 @@ public class MenuServiceImpl extends AbstractCrudService<Menu, Integer> implemen
return menuRepository.findByParentId(id);
}
@Override
public List<String> listAllTeams() {
return menuRepository.findAllTeams();
}
@Override
public Menu create(Menu menu) {
nameMustNotExist(menu);