Refactor ApiCategoryController

pull/98/head
johnniang 2019-02-21 00:30:57 +08:00
parent 0059dc7a9a
commit 3606e25184
1 changed files with 4 additions and 16 deletions

View File

@ -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());
}
} }
} }