Complete category updating api

pull/146/head
johnniang 2019-04-26 09:57:23 +08:00
parent 1c7e6eaeb7
commit ad751f1797
1 changed files with 21 additions and 11 deletions

View File

@ -37,6 +37,19 @@ public class CategoryController {
this.postCategoryService = postCategoryService; this.postCategoryService = postCategoryService;
} }
/**
* Get Category by id
*
* @param id id
* @return CategoryDTO
*/
@GetMapping("{id:\\d+}")
@ApiOperation("Get category detail by id")
public CategoryDTO getBy(@PathVariable("id") Integer id) {
return new CategoryDTO().convertFrom(categoryService.getById(id));
}
@GetMapping @GetMapping
@ApiOperation("List all categories") @ApiOperation("List all categories")
public List<? extends CategoryDTO> listAll( public List<? extends CategoryDTO> listAll(
@ -64,16 +77,13 @@ public class CategoryController {
return new CategoryDTO().convertFrom(categoryService.create(category)); return new CategoryDTO().convertFrom(categoryService.create(category));
} }
/** @PutMapping("{id:\\d+}")
* Get Category by id @ApiOperation("Update category")
* public CategoryDTO updateBy(@PathVariable("id") Integer id,
* @param id id @RequestBody @Valid CategoryParam categoryParam) {
* @return CategoryDTO Category categoryToUpdate = categoryService.getById(id);
*/ categoryParam.update(categoryToUpdate);
@GetMapping("{id:\\d+}") return new CategoryDTO().convertFrom(categoryService.update(categoryToUpdate));
@ApiOperation("Get category detail by id")
public CategoryDTO getBy(@PathVariable("id") Integer id) {
return new CategoryDTO().convertFrom(categoryService.getById(id));
} }
/** /**
@ -82,7 +92,7 @@ public class CategoryController {
* @param id id * @param id id
*/ */
@DeleteMapping("{id:\\d+}") @DeleteMapping("{id:\\d+}")
@ApiOperation("Delete category by id") @ApiOperation("Delete category")
public void deletePermanently(@PathVariable("id") Integer id) { public void deletePermanently(@PathVariable("id") Integer id) {
categoryService.removeCategoryAndPostCategoryBy(id); categoryService.removeCategoryAndPostCategoryBy(id);
} }