-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e03f5b
commit 5620f14
Showing
1 changed file
with
74 additions
and
74 deletions.
There are no files selected for viewing
148 changes: 74 additions & 74 deletions
148
src/main/java/com/favoriteplace/app/controller/PilgrimageSocketController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,74 @@ | ||
//package com.favoriteplace.app.controller; | ||
// | ||
//import com.favoriteplace.app.domain.travel.Pilgrimage; | ||
//import com.favoriteplace.app.dto.travel.PilgrimageDto; | ||
//import com.favoriteplace.app.repository.PilgrimageRepository; | ||
//import com.favoriteplace.app.service.PilgrimageCommandService; | ||
//import com.favoriteplace.global.exception.ErrorCode; | ||
//import com.favoriteplace.global.exception.RestApiException; | ||
//import lombok.RequiredArgsConstructor; | ||
//import lombok.extern.slf4j.Slf4j; | ||
//import org.springframework.messaging.handler.annotation.DestinationVariable; | ||
//import org.springframework.messaging.handler.annotation.MessageMapping; | ||
//import org.springframework.messaging.handler.annotation.SendTo; | ||
//import org.springframework.stereotype.Controller; | ||
//import org.springframework.web.bind.annotation.RestController; | ||
// | ||
//@Controller | ||
//@Slf4j | ||
//@RequiredArgsConstructor | ||
//public class PilgrimageSocketController { | ||
// private final PilgrimageCommandService pilgrimageService; | ||
// private final PilgrimageRepository pilgrimageRepository; | ||
// | ||
// /** | ||
// * 테스트 컨트롤러 | ||
// * 요청 /app/test | ||
// * 응답 /pub/pilgrimage | ||
// * @param testMsg | ||
// * @return | ||
// */ | ||
// @MessageMapping("/test") | ||
// @SendTo("/pub/pilgrimage") | ||
// public String pilgrimageCertify(String testMsg){ | ||
// log.info("socket message: " + testMsg); | ||
// return testMsg; | ||
// } | ||
// | ||
// /** | ||
// * 위도/경도 전달 시 상태 변경 알리는 컨트롤러 | ||
// * 요청 컨트롤러 /app/location/{pilgrimageId} | ||
// * 응답 컨트롤러 /pub/statusUpdate/{pilgrimageId} | ||
// * @param pilgrimageId 성지순례 ID | ||
// * @param userLocation 위도/경도 | ||
// * @return | ||
// */ | ||
// @MessageMapping("/location/{pilgrimageId}") | ||
// @SendTo("/pub/statusUpdate/{pilgrimageId}") | ||
// public Boolean checkUserLocation(@DestinationVariable Long pilgrimageId, PilgrimageDto.PilgrimageCertifyRequestDto userLocation) { | ||
// Pilgrimage pilgrimage = pilgrimageRepository.findById(pilgrimageId) | ||
// .orElseThrow(()->new RestApiException(ErrorCode.PILGRIMAGE_NOT_FOUND)); | ||
// | ||
// boolean isUserAtPilgrimage = pilgrimageService.isUserAtPilgrimage(pilgrimage, userLocation.getLatitude(), userLocation.getLongitude()); | ||
// | ||
// if (!isUserAtPilgrimage) { | ||
// // 여기에 이벤트 동작 추가 | ||
// return false; | ||
// } | ||
// return true; | ||
// } | ||
// | ||
// /** | ||
// * 최초 접근 시 버튼 상태 전달하는 컨트롤러 | ||
// * 요청 컨트롤러 /app/connect/{pilgrimageId} | ||
// * 응답 컨트롤러 /pub/statusUpdate/{pilgrimageId} | ||
// * @param pilgrimageId 성지순례 ID | ||
// * @return | ||
// */ | ||
// @MessageMapping("/connect/{pilgrimageId}") | ||
// @SendTo("/pub/statusUpdate/{pilgrimageId}") | ||
// public Boolean sendInitialStatus(@DestinationVariable Long pilgrimageId) { | ||
// log.info("User connected to pilgrimage: " + pilgrimageId); | ||
// return true; // 초기 버튼 상태 | ||
// } | ||
//} | ||
package com.favoriteplace.app.controller; | ||
|
||
import com.favoriteplace.app.domain.travel.Pilgrimage; | ||
import com.favoriteplace.app.dto.travel.PilgrimageDto; | ||
import com.favoriteplace.app.repository.PilgrimageRepository; | ||
import com.favoriteplace.app.service.PilgrimageCommandService; | ||
import com.favoriteplace.global.exception.ErrorCode; | ||
import com.favoriteplace.global.exception.RestApiException; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.messaging.handler.annotation.DestinationVariable; | ||
import org.springframework.messaging.handler.annotation.MessageMapping; | ||
import org.springframework.messaging.handler.annotation.SendTo; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Controller | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class PilgrimageSocketController { | ||
private final PilgrimageCommandService pilgrimageService; | ||
private final PilgrimageRepository pilgrimageRepository; | ||
|
||
/** | ||
* 테스트 컨트롤러 | ||
* 요청 /app/test | ||
* 응답 /pub/pilgrimage | ||
* @param testMsg | ||
* @return | ||
*/ | ||
@MessageMapping("/test") | ||
@SendTo("/pub/pilgrimage") | ||
public String pilgrimageCertify(String testMsg){ | ||
log.info("socket message: " + testMsg); | ||
return testMsg; | ||
} | ||
|
||
/** | ||
* 위도/경도 전달 시 상태 변경 알리는 컨트롤러 | ||
* 요청 컨트롤러 /app/location/{pilgrimageId} | ||
* 응답 컨트롤러 /pub/statusUpdate/{pilgrimageId} | ||
* @param pilgrimageId 성지순례 ID | ||
* @param userLocation 위도/경도 | ||
* @return | ||
*/ | ||
@MessageMapping("/location/{pilgrimageId}") | ||
@SendTo("/pub/statusUpdate/{pilgrimageId}") | ||
public Boolean checkUserLocation(@DestinationVariable Long pilgrimageId, PilgrimageDto.PilgrimageCertifyRequestDto userLocation) { | ||
Pilgrimage pilgrimage = pilgrimageRepository.findById(pilgrimageId) | ||
.orElseThrow(()->new RestApiException(ErrorCode.PILGRIMAGE_NOT_FOUND)); | ||
|
||
boolean isUserAtPilgrimage = pilgrimageService.isUserAtPilgrimage(pilgrimage, userLocation.getLatitude(), userLocation.getLongitude()); | ||
|
||
if (!isUserAtPilgrimage) { | ||
// 여기에 이벤트 동작 추가 | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* 최초 접근 시 버튼 상태 전달하는 컨트롤러 | ||
* 요청 컨트롤러 /app/connect/{pilgrimageId} | ||
* 응답 컨트롤러 /pub/statusUpdate/{pilgrimageId} | ||
* @param pilgrimageId 성지순례 ID | ||
* @return | ||
*/ | ||
@MessageMapping("/connect/{pilgrimageId}") | ||
@SendTo("/pub/statusUpdate/{pilgrimageId}") | ||
public Boolean sendInitialStatus(@DestinationVariable Long pilgrimageId) { | ||
log.info("User connected to pilgrimage: " + pilgrimageId); | ||
return true; // 초기 버튼 상태 | ||
} | ||
} |