Changeset ceaed42


Ignore:
Timestamp:
11/11/21 12:59:26 (3 years ago)
Author:
Ema <ema_spirova@…>
Branches:
master
Children:
59329aa
Parents:
6c1585f
Message:

add location to planner

Files:
5 added
23 edited

Legend:

Unmodified
Added
Removed
  • trip-planner-front/src/app/_models/dto/plannerDto.ts

    r6c1585f rceaed42  
     1import { Location } from "../location";
     2
    13export class PlannerDto{
    24    name: string;
    35    description: string;
    4     locationList: any[];
     6
    57
    68    constructor(){
    79        this.name = '';
    810        this.description = '';
    9         this.locationList = [];
     11     
    1012    }
    1113}
  • trip-planner-front/src/app/_services/location.service.ts

    r6c1585f rceaed42  
    22import { Injectable } from "@angular/core";
    33import { Observable } from "rxjs";
     4import { PlannerLocationDto } from "../_models/dto/plannerLocationDto";
     5import { Location } from "../_models/location";
    46
    57@Injectable({
     
    911    constructor(private httpClient : HttpClient){}
    1012
    11     getLocationsFromCity(cityId: number, companionId: number, lengthOfStay: number, categoryIds: string): Observable<Object[]>{
     13    getLocationsFromCity(cityId: number, companionId: number, lengthOfStay: number, categoryIds: string): Observable<Location[]>{
    1214        let url = "http://localhost:8080/api/city/locations";
    1315        return this.httpClient.get<Location[]>(url + '?cityId=' + cityId + '&companionId=' + companionId + '&lengthOfStay=' + lengthOfStay + '&categoryIds='+ categoryIds);
     
    1820        return this.httpClient.get<Location[]>(url + '?regionId=' + regionId + '&companionId=' + companionId + '&lengthOfStay=' + lengthOfStay + '&categoryIds='+ categoryIds);
    1921    }
     22
     23    postLocationToPlanner(plannerLocationDto : PlannerLocationDto) : Observable<Location>{
     24        let url = "http://localhost:8080/api/add-location";
     25        return this.httpClient.put<Location>(url, plannerLocationDto);
     26    }
     27
     28    getLocationsFroPlanner(plannerId : number) : Observable<Location[]>{
     29        let url = "http://localhost:8080/api/planner/locations";
     30        return this.httpClient.get<Location[]>(url + '?plannerId=' + plannerId);
     31    }
    2032}
  • trip-planner-front/src/app/_services/planner.service.ts

    r6c1585f rceaed42  
    99})
    1010export class PlannerService{
     11   
    1112    constructor(private httpClient: HttpClient){
    1213    }
     14
    1315    getAllPlanners():Observable<Planner[]>{
    1416        let url = "http://localhost:8080/api/planners";
     
    1618    }
    1719
    18     postInitialPlanner(planner: Planner, locationList: Location[]): Observable<Object>{     
     20    postInitialPlanner(planner: Planner): Observable<Object>{     
    1921        let url = "http://localhost:8080/api/planner/new";
    2022        return this.httpClient.post<Planner>(url, planner);
     
    3032        return this.httpClient.get<Planner>(url);
    3133    }
     34
     35
    3236}
  • trip-planner-front/src/app/app.component.ts

    r6c1585f rceaed42  
    1313  ngOnInit(): void {
    1414  }
     15
     16 
    1517}
  • trip-planner-front/src/app/app.module.ts

    r6c1585f rceaed42  
    2828import { EditPlannerComponent } from './planner/edit-planner/edit-planner.component';
    2929import { DetailPlannerComponent } from './planner/detail-planner/detail-planner.component';
     30import { AddLocationToPlannerPanelComponent } from './location/add-location-to-planner-panel/add-location-to-planner-panel.component';
    3031
    3132@NgModule({
     
    3738    LocationsFormComponent,
    3839    EditPlannerComponent,
    39     DetailPlannerComponent
     40    DetailPlannerComponent,
     41    AddLocationToPlannerPanelComponent
    4042    ],
    4143  imports: [
  • trip-planner-front/src/app/create-initial-planner/create-initial-planner.component.ts

    r6c1585f rceaed42  
    1818  planner: Planner;
    1919  planners: Planner[];
    20   locations : Location[];
    2120  plannerDto: PlannerDto;
    2221
    23   constructor(public dialogRef: MatDialogRef<CreateInitialPlannerComponent>,
     22  constructor(private dialogRef: MatDialogRef<CreateInitialPlannerComponent>,
    2423              private plannerService : PlannerService, private router : Router) {
    2524                this.planner = new Planner;
    2625                this.planners = [];
    27                 this.locations = [];
    2826                this.plannerDto = new PlannerDto();
    2927              }
     
    4038  onFormSubmitPlanner(form: NgForm){
    4139   console.log(this.planner);
    42       this.plannerService.postInitialPlanner(this.planner, this.locations).subscribe(
     40      this.plannerService.postInitialPlanner(this.planner).subscribe(
    4341        data=>{
    4442          console.log(data);
  • trip-planner-front/src/app/location/location.component.html

    r6c1585f rceaed42  
    1 <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
     1<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet"
     2  integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
    23
    34<h3>Here are all locations</h3>
    45
    5 <div class="container">
    6   <table mat-table  class="mat-elevation-z8">
    7 
    8     <!--- Note that these columns can be defined in any order.
    9           The actual rendered columns are set as a property on the row definition" -->
    10  
    11     <!-- Position Column -->
    12     <ng-container matColumnDef="position">
    13       <th mat-header-cell *matHeaderCellDef> Location name </th>
    14       <td mat-cell *matCellDef="let element">  </td>
    15     </ng-container>
    16  
    17  
    18     <!-- Symbol Column -->
    19     <ng-container matColumnDef="symbol">
    20       <th mat-header-cell *matHeaderCellDef> Symbol </th>
    21       <td mat-cell *matCellDef="let element">  </td>
    22     </ng-container>
    23  
    24     <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
    25     <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
    26   </table>
    27 </div>
     6<table class="table" >
     7  <thead>
     8    <tr>
     9      <th scope="col">#</th>
     10      <th scope="col">Location name</th>
     11      <th scope="col"> Add to my planner</th>
     12      <th scope="col">See details </th>
     13    </tr>
     14  </thead>
     15  <tbody>
     16    <tr *ngFor="let location of listLocations">
     17      <td>{{location.id}}</td>
     18      <td>{{location.name}}</td>
     19      <td><button mat-raised-button color="primary" (click)="openDialogSave(location.id)">Add to my planner</button></td>
     20      <td><button mat-raised-button color="primary">See details</button></td>
     21    </tr> 
     22  </tbody>
     23</table>
  • trip-planner-front/src/app/location/location.component.ts

    r6c1585f rceaed42  
    1 import { Component, OnInit } from '@angular/core';
    2 import { Category } from '../_models/category';
    3 import { City } from '../_models/city';
    4 import { Companion } from '../_models/companion';
    5 import { Country } from '../_models/country';
    6 import { CategoryService } from '../_services/cateogry.service';
    7 import { CityService } from '../_services/city.service';
    8 import { CompanionService } from '../_services/companion.service';
    9 import { CountryService } from '../_services/country.service';
     1import { Route } from '@angular/compiler/src/core';
     2import { Component, Input, OnInit, Output } from '@angular/core';
     3import { FormBuilder, FormGroup, Validators } from '@angular/forms';
     4import { MatDialog } from '@angular/material/dialog';
     5import { ActivatedRoute, Router } from '@angular/router';
     6import { Location } from '../_models/location';
     7import { LocationService } from '../_services/location.service';
     8import { AddLocationToPlannerPanelComponent } from './add-location-to-planner-panel/add-location-to-planner-panel.component';
    109
    1110@Component({
     
    1615export class LocationComponent implements OnInit {
    1716
    18   constructor() {
    19    
    20    }
    21    
     17  form: FormGroup;
     18  categoryIds: string;
     19  cityId: number;
     20  companionId: number;
     21  lengthOfStay: number;
     22  listLocations: any[];
     23  cityOption: boolean = false;
     24  regionOption: boolean = false;
     25  regionId: number;
     26
     27  constructor(private fb: FormBuilder, private route: ActivatedRoute, private locationService: LocationService,
     28    private router: Router, private dialog: MatDialog) {
     29    this.form = fb.group({
     30      title: fb.control('initial value', Validators.required)
     31    });
     32    this.cityId = 1;
     33    this.companionId = 1;
     34    this.lengthOfStay = 1;
     35    this.categoryIds = '';
     36    this.listLocations = [];
     37    this.regionId = 1;
     38  }
     39
    2240  ngOnInit(): void {
    23    
     41
     42    this.route.queryParams
     43      .subscribe(params => {
     44        console.log(params);
     45        this.cityId = params.cityId;
     46        this.regionId = params.regionId;
     47        this.companionId = params.companionId;
     48        this.lengthOfStay = params.lengthOfStay;
     49        this.categoryIds = params.categoryIds;
     50      }
     51      );
     52
     53    if (this.route.snapshot.queryParams['cityId']) {
     54      this.locationService.getLocationsFromCity(this.cityId, this.companionId, this.lengthOfStay, this.categoryIds).subscribe(
     55        result => {
     56          console.log(result);
     57          this.listLocations = result;
     58        }
     59      );
     60    } else
     61      if (this.route.snapshot.queryParams['regionId']) {
     62        console.log("I am in region console");
     63        this.locationService.getLocationsFromRegion(this.regionId, this.companionId, this.lengthOfStay, this.categoryIds).subscribe(
     64          result => {
     65            console.log(result);
     66            this.listLocations = result;
     67          }
     68        );
     69      }
     70
    2471  }
     72
     73  openDialogSave(locationId: number){
     74    console.log(locationId);
     75      const dialogRef = this.dialog.open(AddLocationToPlannerPanelComponent, {
     76        width: '250px',
     77        data: {}
     78      });
     79      this.router.navigate(['locations'], {queryParams: {locationId: locationId}});
     80  }
     81
    2582}
  • trip-planner-front/src/app/locations-form/locations-form.component.html

    r6c1585f rceaed42  
    1 <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
     1<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet"
     2  integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
    23
    3 <div class="example-form">
    44
    5   <div class="form-group">
    6     <button class="btn" (click)="chooseCityOption()" >
    7       City
    8     </button>
    9     <button class="btn" (click)="chooseRegionOption()">
    10       Region
    11     </button>
    12   </div>
    13   <br>
    14   <br>
     5    <div class="example-form">
    156
    16   <div *ngIf="cityOption">
    17     <label><h5>Please select a city</h5></label>
    18     <mat-form-field appearance="fill" class="example-full-width">
    19       <mat-label>Please select a city</mat-label>
    20       <mat-select [(ngModel)]="cityId" placeholder="Select city">
    21         <mat-option [value]="city.id" *ngFor="let city of cities" [value]="city.id"> {{city.name}}</mat-option>
    22       </mat-select>
    23     </mat-form-field>
    24   </div>
     7      <div class="form-group">
     8        <button class="btn" (click)="chooseCityOption()">
     9          City
     10        </button>
     11        <button class="btn" (click)="chooseRegionOption()">
     12          Region
     13        </button>
     14      </div>
     15      <br>
     16      <br>
     17 
     18      <div *ngIf="cityOption">
     19        <label>
     20          <h5>Please select a city</h5>
     21        </label>
     22        <mat-form-field appearance="fill" class="example-full-width">
     23          <mat-label>Please select a city</mat-label>
     24          <mat-select [(ngModel)]="cityId" placeholder="Select city" name="city">
     25            <mat-option [value]="city.id" *ngFor="let city of cities" > {{city.name}}</mat-option>
     26          </mat-select>
     27        </mat-form-field>
     28      </div>
     29 
     30      <div *ngIf="regionOption">
     31        <label>
     32          <h5>Please select a region</h5>
     33        </label>
     34        <mat-form-field appearance="fill" class="example-full-width">
     35          <mat-label>Please select a region</mat-label>
     36          <mat-select [(ngModel)]="regionId" placeholder="Select region" name="region">
     37            <mat-option [value]="region.id" *ngFor="let region of regions" [value]="region.id"> {{region.name}}
     38            </mat-option>
     39          </mat-select>
     40        </mat-form-field>
     41      </div>
     42 
     43      <h5>Who are you travelling with? </h5>
     44      <mat-form-field appearance="fill" class="example-full-width">
     45        <mat-label>Please select a companion</mat-label>
     46        <mat-select [(ngModel)]="companionId" placeholder="Please select a companion" name="company">
     47          <mat-option [value]="companion.id" *ngFor="let companion of companions">{{companion.type}}</mat-option>
     48        </mat-select>
     49      </mat-form-field>
     50 
     51      <h5>How many days are you willing to stay ?</h5>
     52      <mat-form-field class="example-full-width" appearance="fill">
     53        <mat-label>Please select a number of days</mat-label>
     54        <input matInput placeholder="No. Days" type="number" min="1" value="0" max="30" [constraintMaxNumberDays()]
     55          [(ngModel)]="lengthOfStay" name="nomdays" [value] = "lengthOfStay">
     56      </mat-form-field>
     57 
     58      <h5>What are your priorities to visit?</h5>
     59      <mat-chip-list selectable multiple>
     60        <mat-chip #c="matChip" selected *ngFor="let category of categories" (click)="toggleSelection(c, category)"
     61          [ngClass]="{'yellow' : toggle}" name="chips">
     62          <mat-icon *ngIf="!c.selected">check</mat-icon>
     63          {{category.name}}
     64        </mat-chip>
     65      </mat-chip-list>
     66      <br>
     67      <button mat-raised-button color="primary" (click)="createMyPlanner()">Create my planner</button>
     68 
     69    </div>
    2570
    26   <div *ngIf="regionOption">
    27     <label><h5>Please select a region</h5></label>
    28     <mat-form-field appearance="fill" class="example-full-width">
    29       <mat-label>Please select a region</mat-label>
    30       <mat-select [(ngModel)]="regionId" placeholder="Select region">
    31         <mat-option [value]="region.id" *ngFor="let region of regions" [value]="region.id"> {{region.name}}</mat-option>
    32       </mat-select>
    33     </mat-form-field>
    34   </div>
    3571
    36   <h5>Who are you travelling with?  </h5>
    37   <mat-form-field appearance="fill" class="example-full-width">
    38     <mat-label>Please select a companion</mat-label>
    39     <mat-select [(ngModel)]="companionId" placeholder="Please select a companion">
    40       <mat-option [value]="companion.id" *ngFor="let companion of companions">{{companion.type}}</mat-option>
    41     </mat-select>
    42   </mat-form-field>
    43 
    44   <h5>How many days are you willing to stay ?</h5>
    45   <mat-form-field class="example-full-width" appearance="fill">
    46     <mat-label>Please select a number of days</mat-label>
    47     <input matInput placeholder="No. Days"  type="number" min="1" value="0" max="30" [constraintMaxNumberDays()] [(ngModel)]="lengthOfStay">
    48   </mat-form-field>
    49 
    50    <h5>What are your priorities to visit?</h5>
    51   <mat-chip-list  selectable multiple >
    52     <mat-chip #c="matChip" selected *ngFor="let category of categories"
    53     (click)="toggleSelection(c, category)" [ngClass]="{'yellow' : toggle}">
    54   <mat-icon *ngIf="!c.selected" >check</mat-icon>
    55   {{category.name}}
    56   </mat-chip>
    57   </mat-chip-list>
    58   <br>
    59   <button mat-raised-button color="primary" (click)="createMyPlanner()">Create my planner</button>
    60 
    61 </div>
    6272 
  • trip-planner-front/src/app/locations-form/locations-form.component.ts

    r6c1585f rceaed42  
    1 import { Component, Injectable, OnInit } from '@angular/core';
    2 import { FormControl, NgForm } from '@angular/forms';
    3 import {map, startWith, switchMap} from 'rxjs/operators';
    4 import {forkJoin, Observable} from 'rxjs';
     1import { Component, EventEmitter, OnInit, Output } from '@angular/core';
     2import { FormBuilder, FormControl } from '@angular/forms';
     3import { map, startWith, switchMap } from 'rxjs/operators';
     4import { Observable } from 'rxjs';
    55import { CityService } from '../_services/city.service';
    66import { City } from '../_models/city';
    7 import { Country } from '../_models/country';
    8 import { CountryService } from '../_services/country.service';
    97import { Companion } from '../_models/companion';
    108import { CompanionService } from '../_services/companion.service';
    119import { Category } from '../_models/category';
    1210import { CategoryService } from '../_services/cateogry.service';
    13 import {CdkDragDrop, moveItemInArray} from '@angular/cdk/drag-drop';
    1411import { MatChip } from '@angular/material/chips';
    1512import { LocationService } from '../_services/location.service';
    1613import { Region } from '../_models/region';
    1714import { RegionService } from '../_services/region.service';
    18 import { Router } from '@angular/router';
     15import { ActivatedRoute, Params, Router } from '@angular/router';
     16import { Location } from '../_models/location';
     17
     18
    1919
    2020@Component({
     
    4141  cityOption: boolean = false;
    4242  regionOption: boolean = false;
    43   value:number;
     43  value: number;
    4444  max: number;
    4545  toggle = true;
    4646  status = 'Enable';
     47  proba: any[];
    4748
    48   constructor(private cityService : CityService, private regionService: RegionService,
    49               private companionService : CompanionService, private categoryService : CategoryService,
    50               private locationService: LocationService, private router : Router){
     49
     50  constructor(private cityService: CityService, private regionService: RegionService,
     51    private companionService: CompanionService, private categoryService: CategoryService,
     52    private locationService: LocationService, private router: Router, private fb: FormBuilder, private route: ActivatedRoute) {
    5153    this.filteredOptions = new Observable<City[]>();
    5254    this.cities = [];
     
    6365    this.value = 0;
    6466    this.max = 30;
     67    this.proba = [];
    6568  }
     69
     70  ngOnInit(): void {
    6671 
    67   ngOnInit() :void {
    6872    this.filteredOptions = this.myControl.valueChanges
    69     .pipe(
    70       startWith(''),
    71       switchMap(val => {
    72         return this.filter(val || '')
    73       })       
    74     );
     73      .pipe(
     74        startWith(''),
     75        switchMap(val => {
     76          return this.filter(val || '')
     77        })
     78      );
    7579
    7680    this.cityService.getAllCities().subscribe(
     
    96100        this.companions = data;
    97101      }
    98     )
     102    );
     103
    99104  }
    100  
     105
    101106  filter(val: string): Observable<City[]> {
    102107    // call the service which makes the http-request
     
    107112        }))
    108113      )
    109 
    110114  }
    111115
    112  toggleSelection(chip: MatChip, category: Category){
    113   chip.toggleSelected();
    114  
    115    if (this.chipsSeletion.length > 0) {
    116      if (this.chipsSeletion.indexOf(category.id) <= -1) {
    117        this.chipsSeletion.push(category.id);
    118      } else {
    119        const index = this.chipsSeletion.indexOf(category.id);
    120        this.chipsSeletion.splice(index, 1);
    121      }
    122    } else {
    123      this.chipsSeletion.push(category.id);
    124    }
    125    console.log(this.chipsSeletion);
    126  }
     116  toggleSelection(chip: MatChip, category: Category) {
     117    chip.toggleSelected();
     118
     119    if (this.chipsSeletion.length > 0) {
     120      if (this.chipsSeletion.indexOf(category.id) <= -1) {
     121        this.chipsSeletion.push(category.id);
     122      } else {
     123        const index = this.chipsSeletion.indexOf(category.id);
     124        this.chipsSeletion.splice(index, 1);
     125      }
     126    } else {
     127      this.chipsSeletion.push(category.id);
     128    }
     129    console.log(this.chipsSeletion);
     130  }
     131
    127132
    128133
     
    135140        result => {
    136141          console.log(result);
    137           this.router.navigate(['locations']);
     142          this.proba = result;
     143          this.router.navigate(['locations'], {queryParams: {cityId: this.cityId, companionId: this.companionId, lengthOfStay: this.lengthOfStay, categoryIds: this.categoryIds}});
    138144        }
    139145      );
    140     } else if (this.regionOption) {
    141       this.locationService.getLocationsFromRegion(this.regionId, this.companionId, this.lengthOfStay, this.categoryIds).subscribe(
    142         result => {
    143           console.log(result);
    144           this.router.navigate(['locations']);
    145         }
    146       );
    147     }
    148 
    149 
    150 
     146    } else
     147      if (this.regionOption) {
     148        this.locationService.getLocationsFromRegion(this.regionId, this.companionId, this.lengthOfStay, this.categoryIds).subscribe(
     149          result => {
     150            console.log(result);
     151            this.router.navigate(['locations'], {queryParams: {regionId: this.regionId, companionId: this.companionId, lengthOfStay: this.lengthOfStay, categoryIds: this.categoryIds}});
     152          }
     153        );
     154      }
    151155  }
    152156
     
    166170  }
    167171
     172
    168173}
  • trip-planner-front/src/app/planner/edit-planner/edit-planner.component.html

    r6c1585f rceaed42  
    2828                            <td> <button mat-raised-button color="primary" (click)="onClickAddLocation()">
    2929                                 Add locations
    30                               </button>
     30                                 </button>
     31                            </td>
     32                        </tr>
     33                        <tr *ngFor ="let location of locations">
     34                            <td>
     35                                {{location.name}}
    3136                            </td>
    3237                        </tr>
  • trip-planner-front/src/app/planner/edit-planner/edit-planner.component.ts

    r6c1585f rceaed42  
    33import { ActivatedRoute, Router } from '@angular/router';
    44import { PlannerDto } from 'src/app/_models/dto/plannerDto';
     5import { Location } from 'src/app/_models/location';
    56import { Planner } from 'src/app/_models/planner';
     7import { LocationService } from 'src/app/_services/location.service';
    68import { PlannerService } from 'src/app/_services/planner.service';
    79
     
    1820  plannerDto: PlannerDto;
    1921  id: number;
     22  locations: Location[];
    2023
    2124
    22   constructor(private router: Router, private route: ActivatedRoute ,private fb: FormBuilder, private plannerService: PlannerService) {
     25  constructor(private router: Router, private route: ActivatedRoute, private fb: FormBuilder, private plannerService: PlannerService,
     26    private locationService : LocationService) {
    2327    this.planner = new Planner();
    2428    this.planners = [];
    2529    this.form = fb.group({
    2630      title: fb.control('initial value', Validators.required)
    27   });
     31    });
    2832    this.plannerDto = new PlannerDto();
    2933    this.id = 1;
     34    this.locations = [];
    3035  }
    3136
     
    3439
    3540    this.form = this.fb.group({
    36         name: [''],
    37         description: [''],
    38         locationList: []
     41      name: [''],
     42      description: [''],
     43      locationList: []
    3944    });
    4045
    4146    this.plannerService.getPlannerById(this.id)
    42     .pipe()
    43     .subscribe(x => this.form.patchValue(x));
     47      .pipe()
     48      .subscribe(x => this.form.patchValue(x));
     49
     50    this.locationService.getLocationsFroPlanner(this.id).subscribe(
     51      data => {
     52          this.locations = data;
     53      }
     54    );
     55    }
     56 
     57  onSubmit() {
     58    this.updatePlanner();
     59
    4460  }
    4561
    46 
    47   onSubmit(){
    48     this.updatePlanner();
    49      
    50   }
    51 
    52   onClickAddLocation()
    53   {
     62  onClickAddLocation() {
    5463    this.router.navigate(['form']);
    5564  }
     
    5766  private updatePlanner() {
    5867    this.plannerService.updatePlanner(this.id, this.form.value)
    59         .pipe()
    60         .subscribe({
    61             next: () => {
    62               this.router.navigate(['planners']);
    63             },
    64             error: error => {
    65                 console.log("error");
    66             }
    67         });
     68      .pipe()
     69      .subscribe({
     70        next: () => {
     71          this.router.navigate(['planners']);
     72        },
     73        error: error => {
     74          console.log("error");
     75        }
     76      });
     77  }
     78
    6879}
    69  
    70 }
  • trip-planner-front/src/app/planner/planner.component.ts

    r6c1585f rceaed42  
    2222
    2323
    24   constructor(private plannerService: PlannerService, public dialog: MatDialog, private router: Router,
     24  constructor(private plannerService: PlannerService, private dialog: MatDialog, private router: Router,
    2525    private fb : FormBuilder) {
    2626    this.planners = [];
     
    4949    console.log(id);
    5050        this.plannerService.getPlannerById(id).subscribe(
    51             data => {
    52              
    53               this.router.navigate(['edit/planner/', id])
     51            data => {         
     52              this.router.navigate(['edit/planner/', id]);
    5453            }
    5554     );
  • trip-planner-front/tsconfig.json

    r6c1585f rceaed42  
    2020      "es2018",
    2121      "dom"
    22     ]
     22    ],
     23    "noImplicitAny": false
    2324  },
    2425  "angularCompilerOptions": {
  • trip-planner/src/main/java/finki/diplomska/tripplanner/models/dto/PlannerDto.java

    r6c1585f rceaed42  
    1010    private String name;
    1111    private String description;
    12     private List<Long> locationList;
    1312
    14     public PlannerDto(String name, String description, List<Long> locationList) {
     13    public PlannerDto(String name, String description) {
    1514        this.name = name;
    1615        this.description = description;
    17         this.locationList = locationList;
    1816    }
    1917}
  • trip-planner/src/main/java/finki/diplomska/tripplanner/repository/jpa/JpaLocationRepository.java

    r6c1585f rceaed42  
    7777            "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)
    7878    List<Location> findLocationsFromRegionForm(@Param("regionId") Long regionId, @Param("companionId") Long companionId, @Param("categoryIds") List<Long> categoryIds);
     79
     80    @Query(value = "SELECT * " +
     81            "FROM locations AS l " +
     82            "WHERE l.id_location IN " +
     83            "(SELECT pl.id_location FROM planners_contain AS pl WHERE pl.id_planner = :plannerId)", nativeQuery = true)
     84    List<Location> getAllLocationsForPlanner(@Param("plannerId") Long plannerId);
    7985}
  • trip-planner/src/main/java/finki/diplomska/tripplanner/service/LocationService.java

    r6c1585f rceaed42  
    33
    44import finki.diplomska.tripplanner.models.Location;
     5import finki.diplomska.tripplanner.models.Planner;
     6import finki.diplomska.tripplanner.models.dto.PlannerLocationDto;
    57
    68import java.util.List;
     
    1719    List<Location> findLocationsFromCityForm(Long cityId, Long companionId, Long lengthOfStay, String categoryIds);
    1820    List<Location> findLocationsFromRegionForm(Long regionId, Long companionId, Long lengthOfStay, String categoryIds);
     21    Location addLocationToPlanner(PlannerLocationDto plannerLocationDto);
     22    List<Location> getAllLocationsForPlanner(Long plannerId);
     23
    1924}
  • trip-planner/src/main/java/finki/diplomska/tripplanner/service/PlannerService.java

    r6c1585f rceaed42  
    1414        List<Planner> getAllPlaners();
    1515        Optional<Planner> findById(Long id);
    16         Planner addLocationToPlanner(Long plannerId, Long locationId);
    1716        Planner editPlannerWithRequestParams(Long id, String description, String name, List<Location> locationList);
    1817        Optional<Planner> newPlanner(PlannerDto plannerDto);
  • trip-planner/src/main/java/finki/diplomska/tripplanner/service/impl/LocationServiceImpl.java

    r6c1585f rceaed42  
    22
    33import finki.diplomska.tripplanner.models.Location;
     4import finki.diplomska.tripplanner.models.Planner;
     5import finki.diplomska.tripplanner.models.dto.PlannerLocationDto;
    46import finki.diplomska.tripplanner.models.exceptions.LocationNotFoundException;
    57import finki.diplomska.tripplanner.repository.jpa.JpaLocationRepository;
     8import finki.diplomska.tripplanner.repository.jpa.JpaPlannerRepository;
    69import finki.diplomska.tripplanner.service.LocationService;
    710import org.springframework.stereotype.Service;
     
    1518
    1619    private final JpaLocationRepository locationRepository;
     20    private final JpaPlannerRepository plannerRepository;
    1721
    18     public LocationServiceImpl(JpaLocationRepository locationRepository) {
     22    public LocationServiceImpl(JpaLocationRepository locationRepository, JpaPlannerRepository plannerRepository) {
    1923        this.locationRepository = locationRepository;
     24        this.plannerRepository = plannerRepository;
    2025    }
    2126
     
    150155    }
    151156
     157    @Override
     158    public Location addLocationToPlanner(PlannerLocationDto plannerLocationDto) {
     159        Location location = this.locationRepository.findById(plannerLocationDto.getLocationId())
     160                .orElseThrow(() -> new LocationNotFoundException(plannerLocationDto.getLocationId()));
     161        Planner planner = this.plannerRepository.getById(plannerLocationDto.getPlannerId());
     162        planner.getLocationList().add(location);
     163        return this.locationRepository.save(location);
     164    }
     165
     166    @Override
     167    public List<Location> getAllLocationsForPlanner(Long plannerId) {
     168        return this.locationRepository.getAllLocationsForPlanner(plannerId);
     169    }
     170
     171
    152172}
  • trip-planner/src/main/java/finki/diplomska/tripplanner/service/impl/PlannerServiceImpl.java

    r6c1585f rceaed42  
    2222    private final JpaPlannerRepository plannerRepository;
    2323    private final JpaLocationRepository locationRepository;
    24     private final LocationService locationService;
    2524
    26     public PlannerServiceImpl(JpaPlannerRepository plannerRepository, JpaLocationRepository locationRepository, LocationService locationService) {
     25    public PlannerServiceImpl(JpaPlannerRepository plannerRepository, JpaLocationRepository locationRepository) {
    2726        this.plannerRepository = plannerRepository;
    2827        this.locationRepository = locationRepository;
    29         this.locationService = locationService;
    3028    }
    3129
     
    4038    }
    4139
    42     @Override
    43     public Planner addLocationToPlanner(Long plannerId, Long locationId) {
    44         Location location = this.locationService.findById(locationId)
    45                 .orElseThrow(() -> new LocationNotFoundException(locationId));
    46         Planner planner = this.plannerRepository.getById(plannerId);
    47         planner.getLocationList().add(location);
    48         return this.plannerRepository.save(planner);
    49     }
    5040
    5141    @Override
     
    8474        planner.setName(plannerDto.getName());
    8575        planner.setDescription(plannerDto.getDescription());
    86 
     76/*
    8777        List<Location> locationList  = new ArrayList<>();
    8878        for(Long location : plannerDto.getLocationList()){
     
    9282        }
    9383        planner.setLocationList(locationList);
     84
     85 */
    9486        return Optional.of(this.plannerRepository.save(planner));
    9587    }
  • trip-planner/src/main/java/finki/diplomska/tripplanner/web/rest/LocationRestController.java

    r6c1585f rceaed42  
    22
    33import finki.diplomska.tripplanner.models.Location;
     4import finki.diplomska.tripplanner.models.dto.PlannerLocationDto;
    45import finki.diplomska.tripplanner.service.LocationService;
    56import finki.diplomska.tripplanner.service.PlannerService;
     
    5051        return this.locationService.findLocationsFromRegionForm(regionId, companionId,lengthOfStay, categoryIds);
    5152    }
     53
     54    @PutMapping(value = "/add-location")
     55    public Location addLocationToPlanner(@RequestBody PlannerLocationDto plannerLocationDto){
     56        return this.locationService.addLocationToPlanner(plannerLocationDto);
     57    }
     58
     59    @GetMapping(value = "/planner/locations")
     60    public List<Location> getAllLocationsForPlanner (@RequestParam Long plannerId){
     61        return this.locationService.getAllLocationsForPlanner(plannerId);
     62    }
    5263}
  • trip-planner/src/main/java/finki/diplomska/tripplanner/web/rest/PlannerRestController.java

    r6c1585f rceaed42  
    7171    }
    7272
    73     @PutMapping(value = "/add-location")
    74     public Planner addLocationToPlanner(@RequestParam Long lid, @RequestParam Long pid){
    75         return this.plannerService.addLocationToPlanner(lid, pid);
    76     }
     73
    7774}
  • trip-planner/src/test/api.http

    r6c1585f rceaed42  
    5252###
    5353PUT http://localhost:8080/api/add-location
     54Content-Type: application/json
     55
     56{"plannerId": 1, "locationId": 2}
     57
     58###
     59GET http://localhost:8080/api/planner/locations?plannerId=1
    5460Content-Type: application/x-www-form-urlencoded
    5561
    56 lid=1&pid=1
Note: See TracChangeset for help on using the changeset viewer.