Restaurant Delete Service

In this lesson, we'll implement the deleteRestaurant method in our service layer to enable the deletion of restaurants from our platform.

Service Interface

The first step is to update our RestaurantService interface to include the delete operation.

public interface RestaurantService { // ... other methods ... void deleteRestaurant(String id); }

The method is designed to be simple and straightforward, taking only the restaurant's ID as a parameter.

Service Implementation

Now let's implement the delete functionality in our RestaurantServiceImpl class.

@Service @RequiredArgsConstructor public class RestaurantServiceImpl implements RestaurantService { // ... @Override public void deleteRestaurant(String id) { restaurantRepository.deleteById(id); } }

The implementation of deleteRestaurant is simply to pass through the call to the restaurantRepository.

Error Handling

When deleting a restaurant, there are two main scenarios to consider:

  • The restaurant exists and is successfully deleted
  • The restaurant doesn't exist, in which case Elasticsearch will still return successfully

This behavior means we don't need to check if the restaurant exists before attempting to delete it.

Summary

  • The deleteRestaurant method is added to RestaurantService interface
  • No need to check existence before deletion
  • The delete operation is safe to call multiple times
© 2026 Devtiro Ltd. All rights reserved