Complete menu updation and deletion api

pull/137/head
johnniang 2019-04-03 17:26:37 +08:00
parent 65d42a1bdb
commit 6ceb18784f
2 changed files with 21 additions and 1 deletions

View File

@ -134,7 +134,7 @@ public abstract class AbstractCrudService<DOMAIN, ID> implements CrudService<DOM
*/
@Override
public DOMAIN getById(ID id) {
return fetchById(id).orElseThrow(() -> new NotFoundException(domainName + " was not found"));
return fetchById(id).orElseThrow(() -> new NotFoundException(domainName + " was not found or has been deleted"));
}
/**

View File

@ -41,4 +41,24 @@ public class MenuController {
public MenuOutputDTO createBy(@RequestBody @Valid MenuParam menuParam) {
return new MenuOutputDTO().convertFrom(menuService.createBy(menuParam));
}
@PutMapping("{menuId:\\d+}")
@ApiOperation("Updates a menu")
public MenuOutputDTO updateBy(@PathVariable("menuId") Integer menuId,
@RequestBody @Valid MenuParam menuParam) {
// Get the menu
Menu menu = menuService.getById(menuId);
// Update changed properties of the menu
menuParam.update(menu);
// Update menu in database
return new MenuOutputDTO().convertFrom(menuService.update(menu));
}
@DeleteMapping("{menuId:\\d+}")
@ApiOperation("Deletes a menu")
public MenuOutputDTO deleteBy(@PathVariable("menuId") Integer menuId) {
return new MenuOutputDTO().convertFrom(menuService.removeById(menuId));
}
}