Skip to content

Commit

Permalink
Issue jmprathab#257 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DDmit04 committed Mar 9, 2021
1 parent ff3a523 commit ca7fab6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.HashSet;
import java.util.Optional;

public interface AmenityBookingItemRepository extends JpaRepository<AmenityBookingItem, String> {
Optional<AmenityBookingItem> findByAmenityBookingItemId(String amenityBookingItemId);

HashSet<AmenityBookingItem> findAllByAmenity_AmenityId(String amenityId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.myhome.domain.Amenity;
import com.myhome.model.AmenityDto;

import java.util.List;
import java.util.Optional;
import java.util.Set;
Expand All @@ -30,9 +31,6 @@ public interface AmenityService {

boolean deleteAmenity(String amenityId);

Set<Amenity> listAllAmenities(String communityId);

boolean updateAmenity(AmenityDto updatedAmenityDto);

boolean deleteBooking(String bookingId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@
import com.myhome.domain.Amenity;
import com.myhome.domain.Community;
import com.myhome.model.AmenityDto;
import com.myhome.repositories.AmenityBookingItemRepository;
import com.myhome.repositories.AmenityRepository;
import com.myhome.repositories.CommunityRepository;
import com.myhome.services.AmenityBookingService;
import com.myhome.services.AmenityService;
import com.myhome.services.CommunityService;
import java.util.HashSet;

import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import com.myhome.services.HouseService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -38,10 +39,10 @@
public class AmenitySDJpaService implements AmenityService {

private final AmenityRepository amenityRepository;
private final CommunityRepository communityRepository;
private final CommunityService communityService;
private final AmenityApiMapper amenityApiMapper;
private final AmenityBookingItemRepository bookingRepository;
private final AmenityBookingService amenityBookingService;
private final HouseService houseService;

@Override
public Optional<List<AmenityDto>> createAmenities(Set<AmenityDto> amenities, String communityId) {
Expand Down Expand Up @@ -83,19 +84,11 @@ public boolean deleteAmenity(String amenityId) {
.orElse(false);
}

@Override
public Set<Amenity> listAllAmenities(String communityId) {
return communityRepository.findByCommunityIdWithAmenities(communityId)
.map(Community::getAmenities)
.orElse(new HashSet<>());
}

@Override
public boolean updateAmenity(AmenityDto updatedAmenity) {
String amenityId = updatedAmenity.getAmenityId();
return amenityRepository.findByAmenityId(amenityId)
.map(amenity -> communityRepository.findByCommunityId(updatedAmenity.getCommunityId())
.map(community -> {
.map(amenity -> {
Amenity updated = new Amenity();
updated.setName(updatedAmenity.getName());
updated.setPrice(updatedAmenity.getPrice());
Expand All @@ -104,17 +97,6 @@ public boolean updateAmenity(AmenityDto updatedAmenity) {
updated.setDescription(updatedAmenity.getDescription());
return updated;
})
.orElse(null))
.map(amenityRepository::save).isPresent();
}

@Override
public boolean deleteBooking(String bookingId) {
return bookingRepository.findByAmenityBookingItemId(bookingId)
.map(bookingItem -> {
bookingRepository.delete(bookingItem);
return true;
})
.orElse(false);
}
}

0 comments on commit ca7fab6

Please sign in to comment.