mirror of https://github.com/halo-dev/halo
Complete menu updation and deletion api
parent
65d42a1bdb
commit
6ceb18784f
|
@ -134,7 +134,7 @@ public abstract class AbstractCrudService<DOMAIN, ID> implements CrudService<DOM
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public DOMAIN getById(ID id) {
|
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"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -41,4 +41,24 @@ public class MenuController {
|
||||||
public MenuOutputDTO createBy(@RequestBody @Valid MenuParam menuParam) {
|
public MenuOutputDTO createBy(@RequestBody @Valid MenuParam menuParam) {
|
||||||
return new MenuOutputDTO().convertFrom(menuService.createBy(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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue