Untitled

Anonymous
plain_text
09/22/2022 5:35 AM
1.5 KB
15
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...