Skip to content

Commit

Permalink
sonarCloud fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
VasylyshynDmytro committed Dec 16, 2024
1 parent 30bd6d2 commit 025b3c3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 22 additions & 1 deletion service-api/src/main/java/greencity/service/PlaceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -241,5 +254,13 @@ public interface PlaceService {
*/
PageableDto<SearchPlacesDto> 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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,6 @@ void sendEmailNotificationChangesPlaceStatusTest() {
message.setEmail("[email protected]");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<UpdatePlaceStatusWithUserEmailDto> 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());
Expand Down
7 changes: 5 additions & 2 deletions service/src/main/java/greencity/service/PlaceServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,11 @@ private PageableDto<SearchPlacesDto> getSearchPlacesDtoPageableDto(Page<Place> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -879,9 +879,6 @@ void updatePlaceStatusWithUserEmailTest() {
place.setId(1L);
place.setName("test1");
place.setStatus(PlaceStatus.PROPOSED);
User user = new User();
user.setEmail("[email protected]");
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);
Expand Down

0 comments on commit 025b3c3

Please sign in to comment.