Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/JavaPathENProject8.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions .idea/remote-targets.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.openclassrooms.tourguide;

import java.util.List;
import java.util.stream.Collectors;
import com.openclassrooms.tourguide.dto.NearbyAttractionDTO;
import com.openclassrooms.tourguide.dto.NearbyAttractionsResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down Expand Up @@ -42,9 +45,31 @@ public VisitedLocation getLocation(@RequestParam String userName) {
// The reward points for visiting each Attraction.
// Note: Attraction reward points can be gathered from RewardsCentral
@RequestMapping("/getNearbyAttractions")
public List<Attraction> getNearbyAttractions(@RequestParam String userName) {
VisitedLocation visitedLocation = tourGuideService.getUserLocation(getUser(userName));
return tourGuideService.getNearByAttractions(visitedLocation);
public NearbyAttractionsResponse getNearbyAttractions(@RequestParam String userName) {
User user = getUser(userName);
VisitedLocation visitedLocation = tourGuideService.getUserLocation(user);

// On récupère les 5 attractions les plus proches (classement existant)
List<Attraction> closestFive = tourGuideService.getNearByAttractions(visitedLocation);

List<NearbyAttractionDTO> dtoList = closestFive.stream()
.map(attraction -> new NearbyAttractionDTO(
attraction.attractionName,
attraction.latitude,
attraction.longitude,
visitedLocation.location.latitude,
visitedLocation.location.longitude,
tourGuideService.getDistance(attraction, visitedLocation.location),
tourGuideService.getRewardPoints(attraction, user)
))
.collect(Collectors.toList());

return new NearbyAttractionsResponse(
user.getUserName(),
visitedLocation.location.latitude,
visitedLocation.location.longitude,
dtoList
);
}

@RequestMapping("/getRewards")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.openclassrooms.tourguide.dto;

public class NearbyAttractionDTO {
private String attractionName;
private double attractionLatitude;
private double attractionLongitude;
private double userLatitude;
private double userLongitude;
private double distanceInMiles;
private int rewardPoints;

public NearbyAttractionDTO(String attractionName,
double attractionLatitude,
double attractionLongitude,
double userLatitude,
double userLongitude,
double distanceInMiles,
int rewardPoints) {
this.attractionName = attractionName;
this.attractionLatitude = attractionLatitude;
this.attractionLongitude = attractionLongitude;
this.userLatitude = userLatitude;
this.userLongitude = userLongitude;
this.distanceInMiles = distanceInMiles;
this.rewardPoints = rewardPoints;
}

public String getAttractionName() { return attractionName; }
public double getAttractionLatitude() { return attractionLatitude; }
public double getAttractionLongitude() { return attractionLongitude; }
public double getUserLatitude() { return userLatitude; }
public double getUserLongitude() { return userLongitude; }
public double getDistanceMiles() { return distanceInMiles; }
public int getRewardPoints() { return rewardPoints; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.openclassrooms.tourguide.dto;

import java.util.List;

public class NearbyAttractionsResponse {
private String userName;
private double userLatitude;
private double userLongitude;
private List<NearbyAttractionDTO> attractions;

public NearbyAttractionsResponse(String userName,
double userLatitude,
double userLongitude,
List<NearbyAttractionDTO> attractions) {
this.userName = userName;
this.userLatitude = userLatitude;
this.userLongitude = userLongitude;
this.attractions = attractions;
}

public String getUserName() { return userName; }
public double getUserLatitude() { return userLatitude; }
public double getUserLongitude() { return userLongitude; }
public List<NearbyAttractionDTO> getAttractions() { return attractions; }
}
Loading