package com.ruoyi.web.controller.app;
import com.ruoyi.system.domain.UserLocation;
import com.ruoyi.framework.websocket.LocationService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/location")
@RequiredArgsConstructor
// 备选通信方式(当webScoker连接不可用时,只需要一次性查询时等等情况才使用这个接口,平常位置信息通过websocket传递)
public class LocationController {

    private final LocationService locationService;

    @PostMapping("/update")
    public void updateLocation(@RequestBody UserLocation location) {
        locationService.updateLocation(location);
    }

    @GetMapping("/nearby/{userId}")
    public List<UserLocation> getNearbyUsers(@PathVariable String userId,
                                             @RequestParam(defaultValue = "5.0") double radius) {
        return locationService.getNearbyUsers(userId, radius);
    }
}
