Skip to content

Commit

Permalink
Accept and Decline restaurant
Browse files Browse the repository at this point in the history
  • Loading branch information
0akkung committed Nov 4, 2023
1 parent e8bffa4 commit 1e36477
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ public ResponseEntity<Restaurant> update(@PathVariable Long id, @Valid @RequestB
return new ResponseEntity<>(updatedRestaurant, HttpStatus.OK);
}

@PutMapping("/{id}/accept")
public ResponseEntity<Restaurant> accept(@PathVariable Long id) {
Restaurant acceptedRestaurant = service.acceptRestaurant(id);
publisher.publishJson("events.restaurant", "restaurant.updated", acceptedRestaurant);
return new ResponseEntity<>(acceptedRestaurant, HttpStatus.OK);
}

@PutMapping("/{id}/accept")
public ResponseEntity<Restaurant> decline(@PathVariable Long id) {
Restaurant declinedRestaurant = service.declineRestaurant(id);
publisher.publishJson("events.restaurant", "restaurant.updated", declinedRestaurant);
return new ResponseEntity<>(declinedRestaurant, HttpStatus.OK);
}

@DeleteMapping("/{id}")
public ResponseEntity<Restaurant> delete(@PathVariable Long id,
@AuthenticationPrincipal Jwt jwt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ public Restaurant updateRestaurant(Long id, RestaurantRequest requestBody) {
return restaurantRepository.save(record);
}

public Restaurant acceptRestaurant(Long id) {
Restaurant record = getRestaurantById(id);
record.setStatus(RestaurantStatus.ACCEPTED);
return restaurantRepository.save(record);
}

public Restaurant declineRestaurant(Long id) {
Restaurant record = getRestaurantById(id);
record.setStatus(RestaurantStatus.DECLINED);
return restaurantRepository.save(record);
}

public Restaurant deleteRestaurant(Long id, Long userId) {

// Get the restaurant by its ID
Expand Down

0 comments on commit 1e36477

Please sign in to comment.