Ignore:
Timestamp:
10/19/21 16:40:43 (3 years ago)
Author:
Ema <ema_spirova@…>
Branches:
master
Children:
6a80231
Parents:
eed0bf8
Message:

location-form

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trip-planner/src/main/java/finki/diplomska/tripplanner/service/impl/LocationServiceImpl.java

    reed0bf8 r188ee53  
    5050
    5151    @Override
    52     public List<Location> findLocations(Long locationId, Long companionId, Long lengthOfStay, String categoryIds) {
     52    public List<Location> findLocationsFromCityForm(Long cityId, Long companionId, Long lengthOfStay, String categoryIds) {
    5353        List<Long> categories = null;
    5454        if(categoryIds != null && !categoryIds.isEmpty()){
     
    5656            categories = ids.stream().map(Long::valueOf).collect(Collectors.toList());
    5757        }
    58         List<Location> foundLocations = locationRepository.findLocationsFromForm(locationId, companionId, categories);
    59         return foundLocations;
     58        Long maxMinutesPerDay = lengthOfStay *6 * 60;
     59        int minutesPerDay = 0;
     60        List<Location> citylocations = this.locationRepository.findLocationsFromCityForm(cityId, companionId, categories);
     61        List<Location> newList = new ArrayList<>();
     62        int listSize = citylocations.size();
     63
     64        while(minutesPerDay < maxMinutesPerDay ){
     65            for(Location l: citylocations) {
     66                if (minutesPerDay < maxMinutesPerDay && l.getDuration() + minutesPerDay <= maxMinutesPerDay && listSize != 0) {
     67                    newList.add(l);
     68                    listSize --;
     69                }
     70                minutesPerDay += l.getDuration();
     71                if (minutesPerDay > maxMinutesPerDay) {
     72                    break;
     73                }
     74            }
     75        }
     76
     77        List<Location> foundLocations = locationRepository.findLocationsFromCityForm(cityId, companionId, categories);
     78        return newList;
    6079    }
     80
     81    @Override
     82    public List<Location> findLocationsFromRegionForm(Long regionId, Long companionId, Long lengthOfStay, String categoryIds) {
     83        List<Long> categories = null;
     84        if(categoryIds != null && !categoryIds.isEmpty()){
     85            List<String> ids = Arrays.asList(categoryIds.split(","));
     86            categories = ids.stream().map(Long::valueOf).collect(Collectors.toList());
     87        }
     88        Long maxMinutesPerDay = lengthOfStay *6 * 60;
     89        int minutesPerDay = 0;
     90        List<Location> countryLocations = this.locationRepository.findLocationsFromRegionForm(regionId, companionId, categories);
     91        List<Location> newList = new ArrayList<>();
     92        int listCountrySize = countryLocations.size();
     93
     94            while(minutesPerDay < maxMinutesPerDay){
     95                for(Location l: countryLocations) {
     96                    if (minutesPerDay < maxMinutesPerDay && l.getDuration() + minutesPerDay <= maxMinutesPerDay && listCountrySize != 0) {
     97                        newList.add(l);
     98                        listCountrySize --;
     99                    }
     100                    minutesPerDay += l.getDuration();
     101                    if (minutesPerDay > maxMinutesPerDay) {
     102                        break;
     103                    }
     104                }
     105
     106        }
     107        return newList;
     108    }
     109
    61110
    62111    @Override
Note: See TracChangeset for help on using the changeset viewer.