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.
89 lines
6.0 KiB
89 lines
6.0 KiB
package com.mydreamjob.talentinvitation;
|
|
|
|
import com.mydreamjob.audit.AuditContext;
|
|
import com.mydreamjob.common.api.ApiResponse;
|
|
import com.mydreamjob.common.exception.BusinessException;
|
|
import com.mydreamjob.common.exception.ErrorCode;
|
|
import com.mydreamjob.talentinvitation.dto.*;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.media.Content;
|
|
import io.swagger.v3.oas.annotations.media.Schema;
|
|
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
import jakarta.validation.Valid;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.security.core.Authentication;
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
@RestController
|
|
@RequiredArgsConstructor
|
|
@Tag(name = "企业人才邀约", description = "企业发起邀约,学生同意后建立站内会话")
|
|
public class TalentInvitationController {
|
|
private final TalentInvitationService service;
|
|
|
|
@PostMapping("/companies/me/jobs/{jobId}/talent-invitations")
|
|
@Operation(summary = "创建人才邀约", security = @SecurityRequirement(name = "bearerAuth"))
|
|
@ApiResponses(@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", content = @Content(schema = @Schema(ref = "#/components/schemas/ApiResponseCompanyTalentInvitationResponse"))))
|
|
public ApiResponse<CompanyTalentInvitationResponse> create(@PathVariable Long jobId,
|
|
@Valid @RequestBody CreateTalentInvitationRequest body,
|
|
HttpServletRequest request) {
|
|
return ApiResponse.ok(service.create(userId(), jobId, body, AuditContext.from(request)), requestId(request));
|
|
}
|
|
|
|
@GetMapping("/companies/me/talent-invitations")
|
|
@Operation(summary = "企业邀约列表", security = @SecurityRequirement(name = "bearerAuth"))
|
|
@ApiResponses(@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", content = @Content(schema = @Schema(ref = "#/components/schemas/ApiResponseCompanyTalentInvitationPageResponse"))))
|
|
public ApiResponse<TalentInvitationPageResponse<CompanyTalentInvitationResponse>> listCompany(
|
|
@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "20") int size,
|
|
HttpServletRequest request) {
|
|
return ApiResponse.ok(service.listCompany(userId(), page, size), requestId(request));
|
|
}
|
|
|
|
@GetMapping("/companies/me/talent-invitations/{invitationId}")
|
|
@Operation(summary = "企业邀约详情", security = @SecurityRequirement(name = "bearerAuth"))
|
|
@ApiResponses(@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", content = @Content(schema = @Schema(ref = "#/components/schemas/ApiResponseCompanyTalentInvitationResponse"))))
|
|
public ApiResponse<CompanyTalentInvitationResponse> getCompany(@PathVariable Long invitationId,
|
|
HttpServletRequest request) {
|
|
return ApiResponse.ok(service.getCompany(userId(), invitationId, AuditContext.from(request)), requestId(request));
|
|
}
|
|
|
|
@GetMapping("/profile/me/talent-invitations")
|
|
@Operation(summary = "学生收到的邀约列表", security = @SecurityRequirement(name = "bearerAuth"))
|
|
@ApiResponses(@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", content = @Content(schema = @Schema(ref = "#/components/schemas/ApiResponseStudentTalentInvitationPageResponse"))))
|
|
public ApiResponse<TalentInvitationPageResponse<StudentTalentInvitationResponse>> listStudent(
|
|
@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "20") int size,
|
|
HttpServletRequest request) {
|
|
return ApiResponse.ok(service.listStudent(userId(), page, size), requestId(request));
|
|
}
|
|
|
|
@GetMapping("/profile/me/talent-invitations/{invitationId}")
|
|
@Operation(summary = "学生邀约详情", security = @SecurityRequirement(name = "bearerAuth"))
|
|
@ApiResponses(@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", content = @Content(schema = @Schema(ref = "#/components/schemas/ApiResponseStudentTalentInvitationResponse"))))
|
|
public ApiResponse<StudentTalentInvitationResponse> getStudent(@PathVariable Long invitationId,
|
|
HttpServletRequest request) {
|
|
return ApiResponse.ok(service.getStudent(userId(), invitationId, AuditContext.from(request)), requestId(request));
|
|
}
|
|
|
|
@PostMapping("/profile/me/talent-invitations/{invitationId}/decision")
|
|
@Operation(summary = "处理人才邀约", description = "学生接受后才创建 TALENT_INVITATION 站内会话", security = @SecurityRequirement(name = "bearerAuth"))
|
|
@ApiResponses(@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", content = @Content(schema = @Schema(ref = "#/components/schemas/ApiResponseStudentTalentInvitationResponse"))))
|
|
public ApiResponse<StudentTalentInvitationResponse> decide(@PathVariable Long invitationId,
|
|
@Valid @RequestBody TalentInvitationDecisionRequest body,
|
|
HttpServletRequest request) {
|
|
return ApiResponse.ok(service.decide(userId(), invitationId, body, AuditContext.from(request)), requestId(request));
|
|
}
|
|
|
|
private Long userId() {
|
|
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
|
if (auth == null || !auth.isAuthenticated() || auth.getName() == null) {
|
|
throw new BusinessException(ErrorCode.UNAUTHORIZED);
|
|
}
|
|
try { return Long.valueOf(auth.getName()); }
|
|
catch (NumberFormatException e) { throw new BusinessException(ErrorCode.UNAUTHORIZED); }
|
|
}
|
|
|
|
private String requestId(HttpServletRequest request) { return request.getHeader("X-Request-Id"); }
|
|
}
|
|
|