Refactor ApiGalleryController

pull/98/head
johnniang 2019-02-21 00:36:05 +08:00
parent 87dddd8a03
commit 2f409949d2
1 changed files with 4 additions and 14 deletions

View File

@ -52,13 +52,8 @@ public class ApiGalleryController {
* @return JsonResult * @return JsonResult
*/ */
@GetMapping @GetMapping
public JsonResult galleries() { public List<Gallery> galleries() {
final List<Gallery> galleries = galleryService.listAll(); return galleryService.listAll();
if (null != galleries && galleries.size() > 0) {
return new JsonResult(ResponseStatusEnum.SUCCESS.getCode(), ResponseStatusEnum.SUCCESS.getMsg(), galleries);
} else {
return new JsonResult(ResponseStatusEnum.EMPTY.getCode(), ResponseStatusEnum.EMPTY.getMsg());
}
} }
/** /**
@ -89,12 +84,7 @@ public class ApiGalleryController {
* @return JsonResult * @return JsonResult
*/ */
@GetMapping(value = "/{id}") @GetMapping(value = "/{id}")
public JsonResult galleries(@PathVariable("id") Long id) { public Gallery galleries(@PathVariable("id") Long id) {
final Optional<Gallery> gallery = galleryService.fetchById(id); return galleryService.getById(id);
if (gallery.isPresent()) {
return new JsonResult(ResponseStatusEnum.SUCCESS.getCode(), ResponseStatusEnum.SUCCESS.getMsg(), gallery.get());
} else {
return new JsonResult(ResponseStatusEnum.NOTFOUND.getCode(), ResponseStatusEnum.NOTFOUND.getMsg());
}
} }
} }