Changeset ceaed42
- Timestamp:
- 11/11/21 12:59:26 (3 years ago)
- Branches:
- master
- Children:
- 59329aa
- Parents:
- 6c1585f
- Files:
-
- 5 added
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
trip-planner-front/src/app/_models/dto/plannerDto.ts
r6c1585f rceaed42 1 import { Location } from "../location"; 2 1 3 export class PlannerDto{ 2 4 name: string; 3 5 description: string; 4 locationList: any[]; 6 5 7 6 8 constructor(){ 7 9 this.name = ''; 8 10 this.description = ''; 9 this.locationList = [];11 10 12 } 11 13 } -
trip-planner-front/src/app/_services/location.service.ts
r6c1585f rceaed42 2 2 import { Injectable } from "@angular/core"; 3 3 import { Observable } from "rxjs"; 4 import { PlannerLocationDto } from "../_models/dto/plannerLocationDto"; 5 import { Location } from "../_models/location"; 4 6 5 7 @Injectable({ … … 9 11 constructor(private httpClient : HttpClient){} 10 12 11 getLocationsFromCity(cityId: number, companionId: number, lengthOfStay: number, categoryIds: string): Observable< Object[]>{13 getLocationsFromCity(cityId: number, companionId: number, lengthOfStay: number, categoryIds: string): Observable<Location[]>{ 12 14 let url = "http://localhost:8080/api/city/locations"; 13 15 return this.httpClient.get<Location[]>(url + '?cityId=' + cityId + '&companionId=' + companionId + '&lengthOfStay=' + lengthOfStay + '&categoryIds='+ categoryIds); … … 18 20 return this.httpClient.get<Location[]>(url + '?regionId=' + regionId + '&companionId=' + companionId + '&lengthOfStay=' + lengthOfStay + '&categoryIds='+ categoryIds); 19 21 } 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 } 20 32 } -
trip-planner-front/src/app/_services/planner.service.ts
r6c1585f rceaed42 9 9 }) 10 10 export class PlannerService{ 11 11 12 constructor(private httpClient: HttpClient){ 12 13 } 14 13 15 getAllPlanners():Observable<Planner[]>{ 14 16 let url = "http://localhost:8080/api/planners"; … … 16 18 } 17 19 18 postInitialPlanner(planner: Planner , locationList: Location[]): Observable<Object>{20 postInitialPlanner(planner: Planner): Observable<Object>{ 19 21 let url = "http://localhost:8080/api/planner/new"; 20 22 return this.httpClient.post<Planner>(url, planner); … … 30 32 return this.httpClient.get<Planner>(url); 31 33 } 34 35 32 36 } -
trip-planner-front/src/app/app.component.ts
r6c1585f rceaed42 13 13 ngOnInit(): void { 14 14 } 15 16 15 17 } -
trip-planner-front/src/app/app.module.ts
r6c1585f rceaed42 28 28 import { EditPlannerComponent } from './planner/edit-planner/edit-planner.component'; 29 29 import { DetailPlannerComponent } from './planner/detail-planner/detail-planner.component'; 30 import { AddLocationToPlannerPanelComponent } from './location/add-location-to-planner-panel/add-location-to-planner-panel.component'; 30 31 31 32 @NgModule({ … … 37 38 LocationsFormComponent, 38 39 EditPlannerComponent, 39 DetailPlannerComponent 40 DetailPlannerComponent, 41 AddLocationToPlannerPanelComponent 40 42 ], 41 43 imports: [ -
trip-planner-front/src/app/create-initial-planner/create-initial-planner.component.ts
r6c1585f rceaed42 18 18 planner: Planner; 19 19 planners: Planner[]; 20 locations : Location[];21 20 plannerDto: PlannerDto; 22 21 23 constructor(p ublicdialogRef: MatDialogRef<CreateInitialPlannerComponent>,22 constructor(private dialogRef: MatDialogRef<CreateInitialPlannerComponent>, 24 23 private plannerService : PlannerService, private router : Router) { 25 24 this.planner = new Planner; 26 25 this.planners = []; 27 this.locations = [];28 26 this.plannerDto = new PlannerDto(); 29 27 } … … 40 38 onFormSubmitPlanner(form: NgForm){ 41 39 console.log(this.planner); 42 this.plannerService.postInitialPlanner(this.planner , this.locations).subscribe(40 this.plannerService.postInitialPlanner(this.planner).subscribe( 43 41 data=>{ 44 42 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"> 2 3 3 4 <h3>Here are all locations</h3> 4 5 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'; 1 import { Route } from '@angular/compiler/src/core'; 2 import { Component, Input, OnInit, Output } from '@angular/core'; 3 import { FormBuilder, FormGroup, Validators } from '@angular/forms'; 4 import { MatDialog } from '@angular/material/dialog'; 5 import { ActivatedRoute, Router } from '@angular/router'; 6 import { Location } from '../_models/location'; 7 import { LocationService } from '../_services/location.service'; 8 import { AddLocationToPlannerPanelComponent } from './add-location-to-planner-panel/add-location-to-planner-panel.component'; 10 9 11 10 @Component({ … … 16 15 export class LocationComponent implements OnInit { 17 16 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 22 40 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 24 71 } 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 25 82 } -
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"> 2 3 3 <div class="example-form">4 4 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"> 15 6 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> 25 70 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>35 71 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>62 72 -
trip-planner-front/src/app/locations-form/locations-form.component.ts
r6c1585f rceaed42 1 import { Component, Injectable, OnInit } from '@angular/core';2 import { Form Control, NgForm} from '@angular/forms';3 import { map, startWith, switchMap} from 'rxjs/operators';4 import { forkJoin, Observable} from 'rxjs';1 import { Component, EventEmitter, OnInit, Output } from '@angular/core'; 2 import { FormBuilder, FormControl } from '@angular/forms'; 3 import { map, startWith, switchMap } from 'rxjs/operators'; 4 import { Observable } from 'rxjs'; 5 5 import { CityService } from '../_services/city.service'; 6 6 import { City } from '../_models/city'; 7 import { Country } from '../_models/country';8 import { CountryService } from '../_services/country.service';9 7 import { Companion } from '../_models/companion'; 10 8 import { CompanionService } from '../_services/companion.service'; 11 9 import { Category } from '../_models/category'; 12 10 import { CategoryService } from '../_services/cateogry.service'; 13 import {CdkDragDrop, moveItemInArray} from '@angular/cdk/drag-drop';14 11 import { MatChip } from '@angular/material/chips'; 15 12 import { LocationService } from '../_services/location.service'; 16 13 import { Region } from '../_models/region'; 17 14 import { RegionService } from '../_services/region.service'; 18 import { Router } from '@angular/router'; 15 import { ActivatedRoute, Params, Router } from '@angular/router'; 16 import { Location } from '../_models/location'; 17 18 19 19 20 20 @Component({ … … 41 41 cityOption: boolean = false; 42 42 regionOption: boolean = false; 43 value: number;43 value: number; 44 44 max: number; 45 45 toggle = true; 46 46 status = 'Enable'; 47 proba: any[]; 47 48 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) { 51 53 this.filteredOptions = new Observable<City[]>(); 52 54 this.cities = []; … … 63 65 this.value = 0; 64 66 this.max = 30; 67 this.proba = []; 65 68 } 69 70 ngOnInit(): void { 66 71 67 ngOnInit() :void {68 72 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 ); 75 79 76 80 this.cityService.getAllCities().subscribe( … … 96 100 this.companions = data; 97 101 } 98 ) 102 ); 103 99 104 } 100 105 101 106 filter(val: string): Observable<City[]> { 102 107 // call the service which makes the http-request … … 107 112 })) 108 113 ) 109 110 114 } 111 115 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 127 132 128 133 … … 135 140 result => { 136 141 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}}); 138 144 } 139 145 ); 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 } 151 155 } 152 156 … … 166 170 } 167 171 172 168 173 } -
trip-planner-front/src/app/planner/edit-planner/edit-planner.component.html
r6c1585f rceaed42 28 28 <td> <button mat-raised-button color="primary" (click)="onClickAddLocation()"> 29 29 Add locations 30 </button> 30 </button> 31 </td> 32 </tr> 33 <tr *ngFor ="let location of locations"> 34 <td> 35 {{location.name}} 31 36 </td> 32 37 </tr> -
trip-planner-front/src/app/planner/edit-planner/edit-planner.component.ts
r6c1585f rceaed42 3 3 import { ActivatedRoute, Router } from '@angular/router'; 4 4 import { PlannerDto } from 'src/app/_models/dto/plannerDto'; 5 import { Location } from 'src/app/_models/location'; 5 6 import { Planner } from 'src/app/_models/planner'; 7 import { LocationService } from 'src/app/_services/location.service'; 6 8 import { PlannerService } from 'src/app/_services/planner.service'; 7 9 … … 18 20 plannerDto: PlannerDto; 19 21 id: number; 22 locations: Location[]; 20 23 21 24 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) { 23 27 this.planner = new Planner(); 24 28 this.planners = []; 25 29 this.form = fb.group({ 26 30 title: fb.control('initial value', Validators.required) 27 });31 }); 28 32 this.plannerDto = new PlannerDto(); 29 33 this.id = 1; 34 this.locations = []; 30 35 } 31 36 … … 34 39 35 40 this.form = this.fb.group({ 36 37 38 41 name: [''], 42 description: [''], 43 locationList: [] 39 44 }); 40 45 41 46 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 44 60 } 45 61 46 47 onSubmit(){ 48 this.updatePlanner(); 49 50 } 51 52 onClickAddLocation() 53 { 62 onClickAddLocation() { 54 63 this.router.navigate(['form']); 55 64 } … … 57 66 private updatePlanner() { 58 67 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 68 79 } 69 70 } -
trip-planner-front/src/app/planner/planner.component.ts
r6c1585f rceaed42 22 22 23 23 24 constructor(private plannerService: PlannerService, p ublicdialog: MatDialog, private router: Router,24 constructor(private plannerService: PlannerService, private dialog: MatDialog, private router: Router, 25 25 private fb : FormBuilder) { 26 26 this.planners = []; … … 49 49 console.log(id); 50 50 this.plannerService.getPlannerById(id).subscribe( 51 data => { 52 53 this.router.navigate(['edit/planner/', id]) 51 data => { 52 this.router.navigate(['edit/planner/', id]); 54 53 } 55 54 ); -
trip-planner-front/tsconfig.json
r6c1585f rceaed42 20 20 "es2018", 21 21 "dom" 22 ] 22 ], 23 "noImplicitAny": false 23 24 }, 24 25 "angularCompilerOptions": { -
trip-planner/src/main/java/finki/diplomska/tripplanner/models/dto/PlannerDto.java
r6c1585f rceaed42 10 10 private String name; 11 11 private String description; 12 private List<Long> locationList;13 12 14 public PlannerDto(String name, String description , List<Long> locationList) {13 public PlannerDto(String name, String description) { 15 14 this.name = name; 16 15 this.description = description; 17 this.locationList = locationList;18 16 } 19 17 } -
trip-planner/src/main/java/finki/diplomska/tripplanner/repository/jpa/JpaLocationRepository.java
r6c1585f rceaed42 77 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 78 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); 79 85 } -
trip-planner/src/main/java/finki/diplomska/tripplanner/service/LocationService.java
r6c1585f rceaed42 3 3 4 4 import finki.diplomska.tripplanner.models.Location; 5 import finki.diplomska.tripplanner.models.Planner; 6 import finki.diplomska.tripplanner.models.dto.PlannerLocationDto; 5 7 6 8 import java.util.List; … … 17 19 List<Location> findLocationsFromCityForm(Long cityId, Long companionId, Long lengthOfStay, String categoryIds); 18 20 List<Location> findLocationsFromRegionForm(Long regionId, Long companionId, Long lengthOfStay, String categoryIds); 21 Location addLocationToPlanner(PlannerLocationDto plannerLocationDto); 22 List<Location> getAllLocationsForPlanner(Long plannerId); 23 19 24 } -
trip-planner/src/main/java/finki/diplomska/tripplanner/service/PlannerService.java
r6c1585f rceaed42 14 14 List<Planner> getAllPlaners(); 15 15 Optional<Planner> findById(Long id); 16 Planner addLocationToPlanner(Long plannerId, Long locationId);17 16 Planner editPlannerWithRequestParams(Long id, String description, String name, List<Location> locationList); 18 17 Optional<Planner> newPlanner(PlannerDto plannerDto); -
trip-planner/src/main/java/finki/diplomska/tripplanner/service/impl/LocationServiceImpl.java
r6c1585f rceaed42 2 2 3 3 import finki.diplomska.tripplanner.models.Location; 4 import finki.diplomska.tripplanner.models.Planner; 5 import finki.diplomska.tripplanner.models.dto.PlannerLocationDto; 4 6 import finki.diplomska.tripplanner.models.exceptions.LocationNotFoundException; 5 7 import finki.diplomska.tripplanner.repository.jpa.JpaLocationRepository; 8 import finki.diplomska.tripplanner.repository.jpa.JpaPlannerRepository; 6 9 import finki.diplomska.tripplanner.service.LocationService; 7 10 import org.springframework.stereotype.Service; … … 15 18 16 19 private final JpaLocationRepository locationRepository; 20 private final JpaPlannerRepository plannerRepository; 17 21 18 public LocationServiceImpl(JpaLocationRepository locationRepository ) {22 public LocationServiceImpl(JpaLocationRepository locationRepository, JpaPlannerRepository plannerRepository) { 19 23 this.locationRepository = locationRepository; 24 this.plannerRepository = plannerRepository; 20 25 } 21 26 … … 150 155 } 151 156 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 152 172 } -
trip-planner/src/main/java/finki/diplomska/tripplanner/service/impl/PlannerServiceImpl.java
r6c1585f rceaed42 22 22 private final JpaPlannerRepository plannerRepository; 23 23 private final JpaLocationRepository locationRepository; 24 private final LocationService locationService;25 24 26 public PlannerServiceImpl(JpaPlannerRepository plannerRepository, JpaLocationRepository locationRepository , LocationService locationService) {25 public PlannerServiceImpl(JpaPlannerRepository plannerRepository, JpaLocationRepository locationRepository) { 27 26 this.plannerRepository = plannerRepository; 28 27 this.locationRepository = locationRepository; 29 this.locationService = locationService;30 28 } 31 29 … … 40 38 } 41 39 42 @Override43 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 }50 40 51 41 @Override … … 84 74 planner.setName(plannerDto.getName()); 85 75 planner.setDescription(plannerDto.getDescription()); 86 76 /* 87 77 List<Location> locationList = new ArrayList<>(); 88 78 for(Long location : plannerDto.getLocationList()){ … … 92 82 } 93 83 planner.setLocationList(locationList); 84 85 */ 94 86 return Optional.of(this.plannerRepository.save(planner)); 95 87 } -
trip-planner/src/main/java/finki/diplomska/tripplanner/web/rest/LocationRestController.java
r6c1585f rceaed42 2 2 3 3 import finki.diplomska.tripplanner.models.Location; 4 import finki.diplomska.tripplanner.models.dto.PlannerLocationDto; 4 5 import finki.diplomska.tripplanner.service.LocationService; 5 6 import finki.diplomska.tripplanner.service.PlannerService; … … 50 51 return this.locationService.findLocationsFromRegionForm(regionId, companionId,lengthOfStay, categoryIds); 51 52 } 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 } 52 63 } -
trip-planner/src/main/java/finki/diplomska/tripplanner/web/rest/PlannerRestController.java
r6c1585f rceaed42 71 71 } 72 72 73 @PutMapping(value = "/add-location") 74 public Planner addLocationToPlanner(@RequestParam Long lid, @RequestParam Long pid){ 75 return this.plannerService.addLocationToPlanner(lid, pid); 76 } 73 77 74 } -
trip-planner/src/test/api.http
r6c1585f rceaed42 52 52 ### 53 53 PUT http://localhost:8080/api/add-location 54 Content-Type: application/json 55 56 {"plannerId": 1, "locationId": 2} 57 58 ### 59 GET http://localhost:8080/api/planner/locations?plannerId=1 54 60 Content-Type: application/x-www-form-urlencoded 55 61 56 lid=1&pid=1
Note:
See TracChangeset
for help on using the changeset viewer.