Untitled
unknown
plain_text
3 years ago
1.2 kB
5
Indexable
//CategoryRest
@PostMapping(path = "/delete/{id}")
ResponseEntity<String> deleteCategory(@PathVariable Integer id);
//categoryRestImpl
@Override
public ResponseEntity<String> deleteCategory(Integer id) {
try {
return categoryService.deleteCategory(id);
}catch(Exception ex){
ex.printStackTrace();
}
return FoodUtils.getResponseEntity(FoodConstants.SOMETHING_WENT_WRONG,HttpStatus.INTERNAL_SERVER_ERROR);
}
//categoryService
ResponseEntity<String> deleteCategory(Integer id);
//categoryServiceImpl
@Override
public ResponseEntity<String> deleteCategory(Integer id) {
try {
if (jwtFilter.isAdmin()) {
Optional optional = categoryDao.findById(id);
if (!optional.isEmpty()) {
categoryDao.deleteById(id);
return FoodUtils.getResponseEntity("Category Deleted Successfully", HttpStatus.OK);
}
return FoodUtils.getResponseEntity("Category id does not exist", HttpStatus.OK);
} else {
return FoodUtils.getResponseEntity(FoodConstants.UNAUTHORIZED_ACCESS, HttpStatus.UNAUTHORIZED);
}
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
Editor is loading...