forked from baskbuddy/zhangshun
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.9 KiB
46 lines
1.9 KiB
package com.mydreamjob.bidirectionalmatch;
|
|
|
|
import com.mydreamjob.common.api.ApiResponse;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.security.core.Authentication;
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* 匹配后沟通解锁接口:基于 application 创建/获取直聊会话
|
|
*/
|
|
@Tag(name = "双向匹配沟通", description = "匹配成功后创建或获取直聊会话(幂等)")
|
|
@RestController
|
|
@RequiredArgsConstructor
|
|
public class MatchConversationController {
|
|
|
|
private final MatchConversationService matchConversationService;
|
|
|
|
@Operation(summary = "创建/获取匹配会话", description = "仅 MATCHED 双方可调用;重复调用返回同一会话")
|
|
@PostMapping("/applications/{id}/conversation")
|
|
public ResponseEntity<ApiResponse<Map<String, Object>>> createOrGetConversation(
|
|
@PathVariable Long id,
|
|
HttpServletRequest request) {
|
|
Long userId = resolveUserId(request);
|
|
Map<String, Object> conversation = matchConversationService.createOrGetMatchConversation(userId, id);
|
|
return ResponseEntity.ok(ApiResponse.ok(conversation, getRequestId(request)));
|
|
}
|
|
|
|
private Long resolveUserId(HttpServletRequest request) {
|
|
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
|
if (auth == null || !auth.isAuthenticated())
|
|
throw new com.mydreamjob.common.exception.BusinessException(
|
|
com.mydreamjob.common.exception.ErrorCode.UNAUTHORIZED);
|
|
return Long.valueOf(auth.getName());
|
|
}
|
|
|
|
private String getRequestId(HttpServletRequest request) {
|
|
return request.getHeader("X-Request-Id");
|
|
}
|
|
}
|
|
|