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;
|
package cc.ryanc.halo.web.controller.api;
|
||||||
|
|
||||||
import cc.ryanc.halo.model.domain.Category;
|
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 cc.ryanc.halo.service.CategoryService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
@ -48,13 +46,8 @@ public class ApiCategoryController {
|
||||||
* @return JsonResult
|
* @return JsonResult
|
||||||
*/
|
*/
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public JsonResult categories() {
|
public List<Category> categories() {
|
||||||
List<Category> categories = categoryService.listAll();
|
return 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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,12 +73,7 @@ public class ApiCategoryController {
|
||||||
* @return JsonResult
|
* @return JsonResult
|
||||||
*/
|
*/
|
||||||
@GetMapping(value = "/{cateUrl}")
|
@GetMapping(value = "/{cateUrl}")
|
||||||
public JsonResult categories(@PathVariable("cateUrl") String cateUrl) {
|
public Category categories(@PathVariable("cateUrl") String cateUrl) {
|
||||||
final Category category = categoryService.findByCateUrl(cateUrl);
|
return 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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue