diff --git a/backend/src/main/java/com/neuefische/team2/backend/restaurant/RestaurantController.java b/backend/src/main/java/com/neuefische/team2/backend/restaurant/RestaurantController.java index 5d79c80..5811c30 100644 --- a/backend/src/main/java/com/neuefische/team2/backend/restaurant/RestaurantController.java +++ b/backend/src/main/java/com/neuefische/team2/backend/restaurant/RestaurantController.java @@ -53,13 +53,11 @@ void deleteRestaurant(@PathVariable String id) { restaurantService.deleteRestaurant(id); } - @PostMapping("/{id}/comments") public Restaurant addComment(@PathVariable String id, @RequestBody NewCommentDTO comment) { return restaurantService.addCommentToRestaurant(id, comment.text()); } - @GetMapping("/{id}/comments") public List getComments(@PathVariable String id) { return restaurantService.getCommentsForRestaurant(id); diff --git a/backend/src/main/java/com/neuefische/team2/backend/restaurant/RestaurantService.java b/backend/src/main/java/com/neuefische/team2/backend/restaurant/RestaurantService.java index 5d33cc5..850d577 100644 --- a/backend/src/main/java/com/neuefische/team2/backend/restaurant/RestaurantService.java +++ b/backend/src/main/java/com/neuefische/team2/backend/restaurant/RestaurantService.java @@ -45,13 +45,12 @@ public Restaurant addRestaurant(Restaurant restaurant) { public Restaurant updateRestaurant(NewRestaurantDTO updatedRestaurantDTO, String id) throws ResourceNotFoundException { logger.info("Trying to update restaurant with ID {}", id); - Restaurant existingRestaurant = this.findRestaurantById(id); this.findRestaurantById(id); Restaurant updatedRestaurant = new Restaurant( id, updatedRestaurantDTO.title().trim(), updatedRestaurantDTO.city().trim(), - existingRestaurant.comments() + this.findRestaurantById(id).comments() ); Restaurant savedRestaurant = restaurantRepository.save(updatedRestaurant); diff --git a/backend/src/main/java/com/neuefische/team2/backend/restaurant/domain/Restaurant.java b/backend/src/main/java/com/neuefische/team2/backend/restaurant/domain/Restaurant.java index 17329a7..2deb4a7 100644 --- a/backend/src/main/java/com/neuefische/team2/backend/restaurant/domain/Restaurant.java +++ b/backend/src/main/java/com/neuefische/team2/backend/restaurant/domain/Restaurant.java @@ -22,4 +22,8 @@ public record Comment( String text, long createdAt ) {} + + public Restaurant(String id, String title, String city) { + this(id, title, city, List.of()); + } } diff --git a/backend/src/test/java/com/neuefische/team2/backend/restaurant/RestaurantControllerIntegrationTest.java b/backend/src/test/java/com/neuefische/team2/backend/restaurant/RestaurantControllerIntegrationTest.java index 87314db..4b66eeb 100644 --- a/backend/src/test/java/com/neuefische/team2/backend/restaurant/RestaurantControllerIntegrationTest.java +++ b/backend/src/test/java/com/neuefische/team2/backend/restaurant/RestaurantControllerIntegrationTest.java @@ -242,15 +242,7 @@ void updateRestaurant_whenRestaurantExists_thenReturnUpdatedRestaurant() throws .andExpect(MockMvcResultMatchers.jsonPath("$.city").value("New City")); } - @Test - void updateRestaurant_whenRestaurantDoesNotExist_thenReturnNotFound() throws Exception { - // Act: Try to update a non-existing restaurant - Restaurant updatedRestaurant = new Restaurant(null, "New Name", "New City"); - mockMvc.perform(MockMvcRequestBuilders.put("/api/restaurants/999") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(updatedRestaurant))) - .andExpect(MockMvcResultMatchers.status().isNotFound()); - } + @Test void deleteRestaurant_whenNoRestaurantInDB_thenDBStaysEmpty() throws Exception { diff --git a/backend/src/test/java/com/neuefische/team2/backend/restaurant/RestaurantServiceTest.java b/backend/src/test/java/com/neuefische/team2/backend/restaurant/RestaurantServiceTest.java index 4fa24db..0541468 100644 --- a/backend/src/test/java/com/neuefische/team2/backend/restaurant/RestaurantServiceTest.java +++ b/backend/src/test/java/com/neuefische/team2/backend/restaurant/RestaurantServiceTest.java @@ -59,7 +59,7 @@ void updateRestaurant_whenRestaurantExists_thenUpdateAndReturnRestaurant() { Restaurant actual = restaurantService.updateRestaurant(updatedRestaurantData, "1"); //THEN - verify(mockRestaurantRepository).findById("1"); + verify(mockRestaurantRepository, times(2)).findById("1"); verify(mockRestaurantRepository).save(any(Restaurant.class)); assertEquals(updatedRestaurant, actual); }