Package restapi.services
Class LocationService
java.lang.Object
restapi.services.LocationService
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final @NonNull DateService
private final @NonNull LocationRepository
private final Logger
private final @NonNull MatchService
private final @NonNull org.springframework.messaging.simp.SimpMessagingTemplate
private final @NonNull UserService
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
compareLocations
(@NonNull LocationDTO loc1, @NonNull LocationDTO loc2, long restriction) Returns if two users are close enough to send notificationstatic double
distance
(double lat1, double lon1, double el1, double lat2, double lon2, double el2) Calculate distance between two points in latitude and longitude taking into account height difference.@Nullable LocationDTO
getLocation
(long id) Get location saved on the database for user with id = idgetNearMe
(long userId, HashMap<Long, Long> contacts, LocationDTO locationDTO) Returns a map of contacts that are near the user and made from the map passed by parametervoid
saveLocation
(@NonNull LocationDTO locationDTO) Saves the location in the databasevoid
sendChange
(String username, MatchRequestDTO match) Send match to user via websocketvoid
sendMatch
(long userId, long contactId, ContactEntity contact) If there is a recent match between users passed by parameter, it sends it to both users via websocket
-
Field Details
-
userService
-
dateService
-
locationRepository
-
messagingTemplate
@NonNull private final @NonNull org.springframework.messaging.simp.SimpMessagingTemplate messagingTemplate -
matchService
-
logger
-
-
Constructor Details
-
LocationService
public LocationService()
-
-
Method Details
-
distance
public static double distance(double lat1, double lon1, double el1, double lat2, double lon2, double el2) Calculate distance between two points in latitude and longitude taking into account height difference. If you are not interested in height difference pass 0.0. Uses Haversine method as its base.lat1, lon1 Start point lat2, lon2 End point el1 Start altitude in meters el2 End altitude in meters
- Parameters:
lat1
- Start pointlon1
- Start pointel1
- Start altitude in meterslat2
- End pointlon2
- End pointel2
- End altitude in meters- Returns:
- Distance in Meters
-
compareLocations
protected boolean compareLocations(@NonNull @NonNull LocationDTO loc1, @NonNull @NonNull LocationDTO loc2, long restriction) Returns if two users are close enough to send notification- Parameters:
loc1
- LocationDTO of user 1loc2
- LocationDTO of user 2restriction
- maximum distance between users to consider them near each other- Returns:
- if two users are close enough to send notification
-
getNearMe
public HashMap<Long,MatchRequestDTO> getNearMe(long userId, HashMap<Long, Long> contacts, LocationDTO locationDTO) throws CustomNotFoundExceptionReturns a map of contacts that are near the user and made from the map passed by parameter- Parameters:
userId
-contacts
-locationDTO
-- Returns:
- Throws:
CustomNotFoundException
-
getLocation
Get location saved on the database for user with id = id- Parameters:
id
-- Returns:
-
saveLocation
Saves the location in the database- Parameters:
locationDTO
-- Throws:
CustomNotFoundException
-
sendMatch
public void sendMatch(long userId, long contactId, ContactEntity contact) throws CustomNotFoundException If there is a recent match between users passed by parameter, it sends it to both users via websocket- Parameters:
userId
-contactId
-contact
-- Throws:
CustomNotFoundException
-
sendChange
Send match to user via websocket- Parameters:
username
-match
-
-