diff --git a/service-api/src/main/java/greencity/dto/place/UpdatePlaceStatusWithUserEmailDto.java b/service-api/src/main/java/greencity/dto/place/UpdatePlaceStatusWithUserEmailDto.java index c99910ee1..c9b10c037 100644 --- a/service-api/src/main/java/greencity/dto/place/UpdatePlaceStatusWithUserEmailDto.java +++ b/service-api/src/main/java/greencity/dto/place/UpdatePlaceStatusWithUserEmailDto.java @@ -4,7 +4,9 @@ import jakarta.validation.constraints.Email; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; @NoArgsConstructor @AllArgsConstructor diff --git a/service-api/src/main/java/greencity/service/PlaceService.java b/service-api/src/main/java/greencity/service/PlaceService.java index 769fe8e25..7bd31635e 100644 --- a/service-api/src/main/java/greencity/service/PlaceService.java +++ b/service-api/src/main/java/greencity/service/PlaceService.java @@ -2,10 +2,23 @@ import greencity.dto.PageableDto; import greencity.dto.filter.FilterPlaceDto; -import greencity.dto.place.*; +import greencity.dto.place.AddPlaceDto; +import greencity.dto.place.AdminPlaceDto; +import greencity.dto.place.BulkUpdatePlaceStatusDto; +import greencity.dto.place.FilterAdminPlaceDto; +import greencity.dto.place.FilterPlaceCategory; +import greencity.dto.place.PlaceAddDto; +import greencity.dto.place.PlaceByBoundsDto; +import greencity.dto.place.PlaceInfoDto; +import greencity.dto.place.PlaceResponse; +import greencity.dto.place.PlaceUpdateDto; +import greencity.dto.place.PlaceVO; +import greencity.dto.place.UpdatePlaceStatusDto; +import greencity.dto.place.UpdatePlaceStatusWithUserEmailDto; import greencity.dto.search.SearchPlacesDto; import greencity.dto.user.UserVO; import greencity.enums.PlaceStatus; +import greencity.exception.exceptions.NotFoundException; import java.security.Principal; import java.util.List; import java.util.Optional; @@ -241,5 +254,13 @@ public interface PlaceService { */ PageableDto search(Pageable pageable, String searchQuery, Boolean isFavorite, Long userId); + /** + * Updates the status of a place and ensures the user with the given email + * exists. + * + * @param dto Contains the place name, user email, and the new status. + * @return The same UpdatePlaceStatusWithUserEmailDto. + * @throws NotFoundException If the place or user is not found. + */ UpdatePlaceStatusWithUserEmailDto updatePlaceStatus(UpdatePlaceStatusWithUserEmailDto dto); } \ No newline at end of file diff --git a/service-api/src/test/java/greencity/client/RestClientTest.java b/service-api/src/test/java/greencity/client/RestClientTest.java index a83c8fa1b..af76d43b0 100644 --- a/service-api/src/test/java/greencity/client/RestClientTest.java +++ b/service-api/src/test/java/greencity/client/RestClientTest.java @@ -692,7 +692,6 @@ void sendEmailNotificationChangesPlaceStatusTest() { message.setEmail("test@example.com"); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); - HttpEntity entity = new HttpEntity<>(message, headers); String expectedUrl = GREEN_CITY_USER_ADDRESS + RestTemplateLinks.SEND_NOTIFICATION_STATUS_PLACE; when(restTemplate.exchange(eq(expectedUrl), eq(HttpMethod.POST), any(HttpEntity.class), eq(Object.class))) .thenReturn(ResponseEntity.ok().build()); diff --git a/service/src/main/java/greencity/service/PlaceServiceImpl.java b/service/src/main/java/greencity/service/PlaceServiceImpl.java index c5486a3af..9261c426f 100644 --- a/service/src/main/java/greencity/service/PlaceServiceImpl.java +++ b/service/src/main/java/greencity/service/PlaceServiceImpl.java @@ -641,8 +641,11 @@ private PageableDto getSearchPlacesDtoPageableDto(Page p public UpdatePlaceStatusWithUserEmailDto updatePlaceStatus(UpdatePlaceStatusWithUserEmailDto dto) { Place place = placeRepo.findByNameIgnoreCase(dto.getPlaceName()) .orElseThrow(() -> new NotFoundException(ErrorMessage.PLACE_NOT_FOUND_BY_NAME + dto.getPlaceName())); - User user = userRepo.findByEmail(dto.getEmail()) - .orElseThrow(() -> new NotFoundException(ErrorMessage.USER_NOT_FOUND_BY_EMAIL + dto.getEmail())); + + if (userRepo.findByEmail(dto.getEmail()).isEmpty()) { + throw new NotFoundException(ErrorMessage.USER_NOT_FOUND_BY_EMAIL + dto.getEmail()); + } + place.setStatus(dto.getNewStatus()); placeRepo.save(place); return dto; diff --git a/service/src/test/java/greencity/service/PlaceServiceImplTest.java b/service/src/test/java/greencity/service/PlaceServiceImplTest.java index aa11b74bb..9c9eec70b 100644 --- a/service/src/test/java/greencity/service/PlaceServiceImplTest.java +++ b/service/src/test/java/greencity/service/PlaceServiceImplTest.java @@ -879,9 +879,6 @@ void updatePlaceStatusWithUserEmailTest() { place.setId(1L); place.setName("test1"); place.setStatus(PlaceStatus.PROPOSED); - User user = new User(); - user.setEmail("user@example.com"); - user.setName("testUser"); when(placeRepo.findByNameIgnoreCase(dto.getPlaceName())).thenReturn(Optional.of(place)); when(userRepo.findByEmail(dto.getEmail())).thenReturn(Optional.of(user)); when(placeRepo.save(any(Place.class))).thenReturn(place);