package com.takensoft.cms.mber.web; import com.takensoft.cms.mber.service.UnifiedLoginService; import com.takensoft.cms.mber.vo.MberSocialAccountVO; import com.takensoft.common.message.MessageCode; import com.takensoft.common.service.VerificationService; import com.takensoft.common.util.ResponseUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import java.util.HashMap; import java.util.List; /** * @author takensoft * @since 2025.05.29 * @modification * since | author | description * 2025.05.29 | takensoft | 최초 등록 * * 통합 로그인 관련 컨트롤러 */ @RestController @RequiredArgsConstructor @Slf4j @RequestMapping(value = "/mbr/unified") public class UnifiedLoginController { private final UnifiedLoginService unifiedLoginService; private final VerificationService verificationService; private final ResponseUtil resUtil; /** * 연동된 계정 목록 조회 */ @PostMapping("/linkedAccounts.json") public ResponseEntity getLinkedAccounts() { try { String currentUserId = verificationService.getCurrentUserId(); List linkedAccounts = unifiedLoginService.getLinkedAccounts(currentUserId, true); return resUtil.successRes(linkedAccounts, MessageCode.COMMON_SUCCESS); } catch (Exception e) { return resUtil.errorRes(MessageCode.COMMON_UNKNOWN_ERROR); } } /** * 계정 연동 */ @PostMapping("/linkAccount.json") public ResponseEntity linkAccount(@RequestBody HashMap params) { try { String currentUserId = verificationService.getCurrentUserId(); String lgnOffrType = params.get("lgnOffrType"); String snsLgnId = params.get("snsLgnId"); String lgnId = params.get("lgnId"); String email = params.get("email"); String name = params.get("name"); boolean success = unifiedLoginService.linkAccount(currentUserId, lgnOffrType, snsLgnId, lgnId, email, name); if (success) { return resUtil.successRes("계정 연동이 완료되었습니다.", MessageCode.COMMON_SUCCESS); } else { return resUtil.errorRes(MessageCode.COMMON_UNKNOWN_ERROR); } } catch (Exception e) { return resUtil.errorRes(MessageCode.COMMON_UNKNOWN_ERROR); } } /** * 계정 연동 해지 */ @PostMapping("/unlinkAccount.json") public ResponseEntity unlinkAccount(@RequestBody HashMap params) { try { String currentUserId = verificationService.getCurrentUserId(); String lgnOffrType = params.get("lgnOffrType"); boolean success = unifiedLoginService.unlinkAccount(currentUserId, lgnOffrType); if (success) { return resUtil.successRes("계정 연동이 해지되었습니다.", MessageCode.COMMON_SUCCESS); } else { return resUtil.errorRes(MessageCode.COMMON_UNKNOWN_ERROR); } } catch (Exception e) { return resUtil.errorRes(MessageCode.COMMON_UNKNOWN_ERROR); } } /** * 계정 재연동 */ @PostMapping("/reLinkAccount.json") public ResponseEntity reLinkAccount(@RequestBody HashMap params) { try { String currentUserId = verificationService.getCurrentUserId(); String lgnOffrType = params.get("lgnOffrType"); boolean success = unifiedLoginService.reLinkAccount(currentUserId, lgnOffrType); if (success) { return resUtil.successRes("계정 연동이 활성화되었습니다.", MessageCode.COMMON_SUCCESS); } else { return resUtil.errorRes(MessageCode.COMMON_UNKNOWN_ERROR); } } catch (Exception e) { return resUtil.errorRes(MessageCode.COMMON_UNKNOWN_ERROR); } } /** * 메인 프로필 설정 */ @PostMapping("/setPrimaryProfile.json") public ResponseEntity setPrimaryProfile(@RequestBody HashMap params) { try { String currentUserId = verificationService.getCurrentUserId(); String lgnOffrType = params.get("lgnOffrType"); boolean success = unifiedLoginService.setPrimaryProfile(currentUserId, lgnOffrType); if (success) { return resUtil.successRes("메인 프로필이 설정되었습니다.", MessageCode.COMMON_SUCCESS); } else { return resUtil.errorRes(MessageCode.COMMON_UNKNOWN_ERROR); } } catch (Exception e) { return resUtil.errorRes(MessageCode.COMMON_UNKNOWN_ERROR); } } /** * 계정 통합 제안 조회 */ @PostMapping("/suggestMerge.json") public ResponseEntity suggestAccountMerge(@RequestBody HashMap params) { try { String email = params.get("email"); String newProviderType = params.get("lgnOffrType"); HashMap suggestion = unifiedLoginService.suggestAccountMerge(email, newProviderType); return resUtil.successRes(suggestion, MessageCode.COMMON_SUCCESS); } catch (Exception e) { return resUtil.errorRes(MessageCode.COMMON_UNKNOWN_ERROR); } } }