mirror of https://github.com/halo-dev/halo
Refactor ApiCategoryController
parent
0059dc7a9a
commit
3606e25184
|
@ -1,8 +1,6 @@
|
|||
package cc.ryanc.halo.web.controller.api;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Category;
|
||||
import cc.ryanc.halo.model.dto.JsonResult;
|
||||
import cc.ryanc.halo.model.enums.ResponseStatusEnum;
|
||||
import cc.ryanc.halo.service.CategoryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
@ -48,13 +46,8 @@ public class ApiCategoryController {
|
|||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping
|
||||
public JsonResult categories() {
|
||||
List<Category> categories = categoryService.listAll();
|
||||
if (null != categories && categories.size() > 0) {
|
||||
return new JsonResult(ResponseStatusEnum.SUCCESS.getCode(), ResponseStatusEnum.SUCCESS.getMsg(), categories);
|
||||
} else {
|
||||
return new JsonResult(ResponseStatusEnum.EMPTY.getCode(), ResponseStatusEnum.EMPTY.getMsg());
|
||||
}
|
||||
public List<Category> categories() {
|
||||
return categoryService.listAll();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -80,12 +73,7 @@ public class ApiCategoryController {
|
|||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "/{cateUrl}")
|
||||
public JsonResult categories(@PathVariable("cateUrl") String cateUrl) {
|
||||
final Category category = categoryService.findByCateUrl(cateUrl);
|
||||
if (null != category) {
|
||||
return new JsonResult(ResponseStatusEnum.SUCCESS.getCode(), ResponseStatusEnum.SUCCESS.getMsg(), category);
|
||||
} else {
|
||||
return new JsonResult(ResponseStatusEnum.EMPTY.getCode(), ResponseStatusEnum.EMPTY.getMsg());
|
||||
}
|
||||
public Category categories(@PathVariable("cateUrl") String cateUrl) {
|
||||
return categoryService.findByCateUrl(cateUrl);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue