-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocationController.java
More file actions
48 lines (39 loc) · 1.73 KB
/
LocationController.java
File metadata and controls
48 lines (39 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package capstone.checkIT.controller;
import capstone.checkIT.DTO.LocationDTO.LocationRequestDTO;
import capstone.checkIT.DTO.LocationDTO.LocationResponseDTO;
import capstone.checkIT.apipayLoad.ApiResponse;
import capstone.checkIT.config.JwtManager;
import capstone.checkIT.service.deviceLocationService.DeviceLocationService;
import capstone.checkIT.service.locationService.LocationService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/location")
public class LocationController {
private final LocationService locationService;
private final DeviceLocationService deviceLocationService;
private final JwtManager jwtManager;
// 위치 데이터 저장
@PostMapping
public ApiResponse<String> saveLocation(HttpServletRequest token, @RequestBody LocationRequestDTO request) {
String accessToken = jwtManager.getToken(token);
log.info("Location save request received: {}", request);
locationService.saveLocation(accessToken, request);
log.info("Location data saved successfully.");
return ApiResponse.onSuccess("위치 저장 완료");
}
// 가장 최신 경로 반환
@GetMapping("/latest/{deviceId}")
public ApiResponse<List<LocationResponseDTO>> getLatestRoute(
HttpServletRequest token,
@PathVariable("deviceId") Long deviceId) {
String accessToken = jwtManager.getToken(token);
List<LocationResponseDTO> response = locationService.getLatestRoute(accessToken, deviceId);
return ApiResponse.onSuccess(response);
}
}