✨ feat: 添加面试邀约删除接口及相关服务实现
This commit is contained in:
@@ -119,4 +119,17 @@ public class AppInterviewController extends BaseController {
|
||||
}
|
||||
return success(interviewInvitationService.updateReadAll(SiteSecurityUtils.getUserId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除我的面试邀约,路径中的逗号分隔 ID 可用于批量删除。
|
||||
*/
|
||||
@ApiOperation("删除我的面试邀约(支持批量)")
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids) {
|
||||
if (!SiteSecurityUtils.isLogin()) {
|
||||
return error("未登录");
|
||||
}
|
||||
return toAjax(interviewInvitationService.deleteInterviewInvitationIdsByUserId(
|
||||
ids, SiteSecurityUtils.getUserId()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,15 @@ public interface InterviewInvitationService {
|
||||
|
||||
int deleteInterviewInvitationIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除指定求职者自己的面试邀约(支持批量)。
|
||||
*
|
||||
* @param ids 面试邀约 ID 集合
|
||||
* @param userId 当前登录求职者 ID
|
||||
* @return 删除记录数
|
||||
*/
|
||||
int deleteInterviewInvitationIdsByUserId(Long[] ids, Long userId);
|
||||
|
||||
InterviewInvitation getInterviewInvitationById(Long id);
|
||||
|
||||
InterviewInvitationVO getInterviewInvitationVOById(Long id);
|
||||
|
||||
@@ -203,6 +203,16 @@ public class InterviewInvitationServiceImpl implements InterviewInvitationServic
|
||||
return interviewInvitationMapper.deleteBatchIds(Arrays.asList(ids));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteInterviewInvitationIdsByUserId(Long[] ids, Long userId) {
|
||||
if (ids == null || ids.length == 0 || userId == null) {
|
||||
return 0;
|
||||
}
|
||||
return interviewInvitationMapper.delete(Wrappers.<InterviewInvitation>lambdaQuery()
|
||||
.in(InterviewInvitation::getId, Arrays.asList(ids))
|
||||
.eq(InterviewInvitation::getUserId, userId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public InterviewInvitation getInterviewInvitationById(Long id) {
|
||||
return interviewInvitationMapper.selectById(id);
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.ruoyi.cms.controller.app;
|
||||
|
||||
import com.ruoyi.cms.service.InterviewInvitationService;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.domain.entity.AppUser;
|
||||
import com.ruoyi.common.core.domain.model.LoginSiteUser;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class AppInterviewControllerTest {
|
||||
|
||||
@AfterEach
|
||||
void clearSecurityContext() {
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
void loggedInUserCanDeleteOneOrMoreOwnInvitations() throws Exception {
|
||||
InterviewInvitationService service = mock(InterviewInvitationService.class);
|
||||
when(service.deleteInterviewInvitationIdsByUserId(any(Long[].class), eq(12L))).thenReturn(2);
|
||||
authenticateSiteUser(12L);
|
||||
|
||||
AppInterviewController controller = controllerWith(service);
|
||||
AjaxResult result = controller.remove(new Long[]{10L, 11L});
|
||||
|
||||
ArgumentCaptor<Long[]> idsCaptor = ArgumentCaptor.forClass(Long[].class);
|
||||
verify(service).deleteInterviewInvitationIdsByUserId(idsCaptor.capture(), eq(12L));
|
||||
assertArrayEquals(new Long[]{10L, 11L}, idsCaptor.getValue());
|
||||
assertEquals(200, result.get(AjaxResult.CODE_TAG));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anonymousUserCannotDeleteInvitations() throws Exception {
|
||||
InterviewInvitationService service = mock(InterviewInvitationService.class);
|
||||
AppInterviewController controller = controllerWith(service);
|
||||
|
||||
AjaxResult result = controller.remove(new Long[]{10L});
|
||||
|
||||
assertEquals(500, result.get(AjaxResult.CODE_TAG));
|
||||
assertEquals("未登录", result.get(AjaxResult.MSG_TAG));
|
||||
verify(service, never()).deleteInterviewInvitationIdsByUserId(new Long[]{10L}, 12L);
|
||||
}
|
||||
|
||||
private AppInterviewController controllerWith(InterviewInvitationService service) throws Exception {
|
||||
AppInterviewController controller = new AppInterviewController();
|
||||
Field field = AppInterviewController.class.getDeclaredField("interviewInvitationService");
|
||||
field.setAccessible(true);
|
||||
field.set(controller, service);
|
||||
return controller;
|
||||
}
|
||||
|
||||
private void authenticateSiteUser(Long userId) {
|
||||
LoginSiteUser loginUser = new LoginSiteUser(userId, new AppUser());
|
||||
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(
|
||||
loginUser, null, Collections.emptyList());
|
||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user