Changeset 188ee53


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

location-form

Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • trip-planner-front/src/app/_services/location.service.ts

    reed0bf8 r188ee53  
    99    constructor(private httpClient : HttpClient){}
    1010
    11     getAllPlaces(locationId: number, companionId: number, lengthOfStay: number, categoryIds: string): Observable<Object[]>{
    12         let url = "http://localhost:8080/api/trip/locations";
    13         return this.httpClient.get<Location[]>(url + '?locationId=' + locationId + '&companionId=' + companionId + '&lengthOfStay=' + lengthOfStay + '&categoryIds='+ categoryIds);
     11    getLocationsFromCity(cityId: number, companionId: number, lengthOfStay: number, categoryIds: string): Observable<Object[]>{
     12        let url = "http://localhost:8080/api/city/locations";
     13        return this.httpClient.get<Location[]>(url + '?cityId=' + cityId + '&companionId=' + companionId + '&lengthOfStay=' + lengthOfStay + '&categoryIds='+ categoryIds);
     14    }
     15
     16    getLocationsFromRegion(regionId: number, companionId: number, lengthOfStay: number, categoryIds: string):Observable<Object[]>{
     17        let url = "http://localhost:8080/api/region/locations";
     18        return this.httpClient.get<Location[]>(url + '?regionId=' + regionId + '&companionId=' + companionId + '&lengthOfStay=' + lengthOfStay + '&categoryIds='+ categoryIds);
    1419    }
    1520}
  • trip-planner-front/src/app/locations-form/locations-form.component.css

    reed0bf8 r188ee53  
    1818  float: right;
    1919}
     20
     21.colorClass{
     22  color:yellow;
     23}
  • trip-planner-front/src/app/locations-form/locations-form.component.html

    reed0bf8 r188ee53  
    33<div class="example-form">
    44
    5   <div class="d-block">
     5  <div class="form-group">
    66    <button class="btn" (click)="chooseCityOption()" >
    77      City
     
    3535    <mat-form-field appearance="fill" class="example-full-width">
    3636      <mat-label>Please select a city</mat-label>
    37       <mat-select [(ngModel)]="locationId" placeholder="Select city">
     37      <mat-select [(ngModel)]="cityId" placeholder="Select city">
    3838        <mat-option [value]="city.id" *ngFor="let city of cities" [value]="city.id"> {{city.name}}</mat-option>
    3939      </mat-select>
    4040    </mat-form-field>
    4141  </div>
     42
    4243
    4344  <div *ngIf="regionOption">
     
    6263  <mat-form-field class="example-full-width" appearance="fill">
    6364    <mat-label>Please select a number of days</mat-label>
    64     <input matInput placeholder="No. Days"  type="number" [(ngModel)]="lengthOfStay">
     65    <input matInput placeholder="No. Days"  type="number" min="1" value="0" max="30" [constraintMaxNumberDays()] [(ngModel)]="lengthOfStay">
    6566  </mat-form-field>
    6667
     
    6869  <mat-chip-list  selectable multiple>
    6970    <mat-chip #c="matChip" selected *ngFor="let category of categories"
    70     (click)="toggleSelection(c, category)" >
     71    (click)="toggleSelection(c, category)">
    7172  <mat-icon *ngIf="!c.selected" >check</mat-icon>
    7273  {{category.name}}
    7374  </mat-chip>
    7475  </mat-chip-list>
     76  <br>
    7577  <button mat-raised-button color="primary" (click)="createMyPlanner()">Create my planner</button>
    76 
    7778
    7879</div>
  • trip-planner-front/src/app/locations-form/locations-form.component.ts

    reed0bf8 r188ee53  
    3535  locationId: number;
    3636  regionId: number;
     37  cityId: number;
    3738  companionId: number;
    3839  lengthOfStay: number;
    3940  cityOption: boolean = false;
    4041  regionOption: boolean = false;
     42  value:number;
     43  max: number;
    4144
    4245  constructor(private cityService : CityService, private regionService: RegionService,
     
    5457    this.categoryIds = '';
    5558    this.regionId = 0;
     59    this.cityId = 0;
     60    this.value = 0;
     61    this.max = 30;
    5662  }
    5763 
     
    119125 createMyPlanner(){
    120126   this.categoryIds = this.chipsSeletion.join(',');
    121    console.log(this.companionId);
    122    this.locationService.getAllPlaces(this.locationId, this.companionId, this.lengthOfStay, this.categoryIds).subscribe(
    123      result => {
    124        console.log(result);
    125      }
    126    );
     127   console.log(this.categoryIds);
     128   
     129   if(this.cityOption){
     130    this.locationService.getLocationsFromCity(this.cityId, this.companionId, this.lengthOfStay, this.categoryIds).subscribe(
     131      result => {
     132        console.log(result);
     133      }
     134    );
     135   }else if(this.regionOption){
     136 
     137    this.locationService.getLocationsFromRegion(this.regionId, this.companionId, this.lengthOfStay, this.categoryIds).subscribe(
     138      result => {
     139        console.log(result);
     140      }
     141    );
     142   }
     143   
     144 
    127145 }
    128146 chooseCityOption(){
     
    134152    this.cityOption = false;
    135153  }
     154
     155  constraintMaxNumberDays(){
     156     if(this.value > this.max){
     157       this.value = this.max;
     158     }
     159  }
    136160}
  • trip-planner/src/main/java/finki/diplomska/tripplanner/repository/jpa/JpaLocationRepository.java

    reed0bf8 r188ee53  
    4646
    4747    @Query(value = "SELECT  * FROM locations AS l  " +
    48             "LEFT JOIN recommended_companion AS rc ON l.id_location = rc.id_location " +
    49             "LEFT JOIN companions AS com ON rc.id_companion = com.id_companion " +
    50             "LEFT JOIN locations_belong lb ON l.id_location = lb.id_location " +
    51             "LEFT JOIN categories AS cate ON lb.id_category = cate.id_category " +
    52             "LEFT JOIN regions AS r" +
    53             " ON l.id_region = r.id_region" +
    54             " LEFT JOIN cities AS cit" +
    55             " ON r.id_region = cit.id_region AND cit.id_city = l.id_city " +
    56             "WHERE cit.id_city = :locationId and com.id_companion = :companionId and cate.id_category in (:categories) " +
    57             "GROUP BY l.id_location " +
    58             "ORDER BY CASE l.priority WHEN 'high' THEN 1 WHEN 'medium' THEN 2 WHEN 'low' THEN 3 END", nativeQuery = true)
    59     List<Location> findLocationsFromForm(@Param("locationId") Long locationId, @Param("companionId") Long companionId, @Param("categories") List<Long> categories);
     48            "LEFT JOIN recommended_companion AS rc " +
     49            "ON l.id_location = rc.id_location " +
     50            "LEFT JOIN companions AS companion " +
     51            "ON rc.id_companion = companion.id_companion " +
     52            "LEFT JOIN locations_belong lb " +
     53            "ON l.id_location = lb.id_location " +
     54            "LEFT JOIN categories AS category " +
     55            "ON lb.id_category = category.id_category " +
     56            "LEFT JOIN cities AS city " +
     57            "ON city.id_city = l.id_city " +
     58            "WHERE city.id_city = :cityId and companion.id_companion = :companionId and category.id_category IN (:categoryIds) " +
     59            "GROUP BY l.id_location ORDER BY CASE l.priority WHEN 'high' THEN 1 WHEN 'medium' THEN 2 WHEN 'low' THEN 3 END", nativeQuery = true)
     60    List<Location> findLocationsFromCityForm(@Param("cityId") Long cityId, @Param("companionId") Long companionId, @Param("categoryIds") List<Long> categoryIds);
     61
     62    @Query(value="SELECT * FROM locations AS location " +
     63            "LEFT JOIN recommended_companion AS rc " +
     64            "ON location.id_location = rc.id_location " +
     65            "LEFT JOIN companions AS companion " +
     66            "ON rc.id_companion = companion.id_companion " +
     67            "LEFT JOIN locations_belong lb " +
     68            "ON location.id_location = lb.id_location " +
     69            "LEFT JOIN categories AS category " +
     70            "ON lb.id_category = category.id_category " +
     71            "LEFT JOIN regions AS region " +
     72            "ON location.id_region = region.id_region " +
     73            "LEFT JOIN cities AS city " +
     74            "ON region.id_region  = city.id_region " +
     75            "AND city.id_city = location.id_city " +
     76            "WHERE region.id_region = :regionId AND companion.id_companion  = :companionId AND category.id_category  IN (:categoryIds) " +
     77            "GROUP BY location.id_location ORDER BY CASE location.priority WHEN 'high' THEN 1 WHEN 'medium' THEN 2 WHEN 'low' THEN 3 END", nativeQuery = true)
     78    List<Location> findLocationsFromRegionForm(@Param("regionId") Long regionId, @Param("companionId") Long companionId, @Param("categoryIds") List<Long> categoryIds);
    6079}
  • trip-planner/src/main/java/finki/diplomska/tripplanner/service/LocationService.java

    reed0bf8 r188ee53  
    1010public interface LocationService {
    1111    List<Location> findLocationsFromCity(String locName, String companion, List<String> categories);
     12    List<Location> findLocationsFromCountry (String locName, String companion,String region, List<String> categories );
    1213    List<Location> findAll();
    1314    Location getById(Long id);
    14     List<Location> findLocationsFromCountry (String locName, String companion,String region, List<String> categories );
    1515    List<Location> scheduleLocations(String locName, String companion,String region, List<String> categories, int numberOfDays);
    1616    Optional<Location> findById(Long id);
    17 
    18     List<Location> findLocations(Long locationId, Long companionId, Long lengthOfStay, String categoryIds);
     17    List<Location> findLocationsFromCityForm(Long cityId, Long companionId, Long lengthOfStay, String categoryIds);
     18    List<Location> findLocationsFromRegionForm(Long regionId, Long companionId, Long lengthOfStay, String categoryIds);
    1919}
  • 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
  • trip-planner/src/main/java/finki/diplomska/tripplanner/web/rest/LocationRestController.java

    reed0bf8 r188ee53  
    3434    }
    3535
    36     @GetMapping(value = "/trip/locations")
    37     public List<Location> allLocationsAfterSubmittedForm(@RequestParam(required = false) Long locationId,
     36    @GetMapping(value = "/city/locations")
     37    public List<Location> getAllLocationsFromCity(@RequestParam(required = false) Long cityId,
    3838                                                         @RequestParam(required = false)  Long companionId,
    3939                                                         @RequestParam(required = false) Long lengthOfStay,
    4040                                                         @RequestParam(required = false) String categoryIds)  {
    41         return this.locationService.findLocations(locationId, companionId, lengthOfStay, categoryIds);
    42         /* List<Location> generatedLocations = this.locationService.scheduleLocations(locName, companion, region, categories, numberOfDays);
    43         if(locName.equals("Macedonia")){
    44             return generatedLocations;
    45         }else{
    46             return generatedLocations;
    47         }*/
     41        return this.locationService.findLocationsFromCityForm(cityId, companionId, lengthOfStay, categoryIds);
     42
     43    }
     44
     45    @GetMapping(value = "/region/locations")
     46    public List<Location> getAllLocationsFromRegion(@RequestParam(required = false) Long regionId,
     47                                                    @RequestParam(required = false)  Long companionId,
     48                                                    @RequestParam(required = false) Long lengthOfStay,
     49                                                    @RequestParam(required = false) String categoryIds){
     50        return this.locationService.findLocationsFromRegionForm(regionId, companionId,lengthOfStay, categoryIds);
    4851    }
    4952}
  • trip-planner/src/test/api.http

    reed0bf8 r188ee53  
    3030
    3131###
    32 GET http://localhost:8080/api/trip/locations
    33 Content-Type: application/x-www-form-urlencoded
     32GET http://localhost:8080/api/city/locations?cityId=1&companionId=1&lengthOfStay=1&categoryIds=1,2
    3433
    35 locName=Macedonia&companion=Wandering Solo&region=Skopje Region&categories=sightseeing&numberOfDays=1
     34###
     35GET http://localhost:8080/api/region/locations?regionId=1&companionId=1&lengthOfStay=1&categoryIds=1,2
    3636
    3737###
Note: See TracChangeset for help on using the changeset viewer.