Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
JungYoonShin committed Aug 26, 2024
1 parent 0e03f5b commit 5620f14
Showing 1 changed file with 74 additions and 74 deletions.
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; // 초기 버튼 상태
}
}

0 comments on commit 5620f14

Please sign in to comment.