Skip to content

Commit

Permalink
Merge pull request #169 from Funssion-SWM/employer
Browse files Browse the repository at this point in the history
feat: add update status api when disconnected
  • Loading branch information
goathoon authored Nov 2, 2023
2 parents 41cb760 + e3cf2a9 commit 00130bc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/main/java/Funssion/Inforum/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Excepti
.requestMatchers("/employer/**").hasRole("EMPLOYER")
.requestMatchers(HttpMethod.POST,"/interview/questions/**").hasRole("EMPLOYER")
.requestMatchers(HttpMethod.GET,"/interview/answers/**").hasAnyRole("EMPLOYER","USER")
.requestMatchers(HttpMethod.GET,"/interview/start/**").hasRole("USER")
.requestMatchers(HttpMethod.GET,"/interview/continue/**").hasRole("USER")
.requestMatchers(HttpMethod.POST,"/interview/answers/**").hasRole("USER")
.requestMatchers(HttpMethod.GET, "/score/**").permitAll()
.requestMatchers(HttpMethod.GET,"/score/rank/**").authenticated()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ public IsSuccessResponseDto saveInterviewQuestions(@PathVariable Long employeeId
public InterviewQuestionDto getInterviewQuestion(@PathVariable Long employerId, @PathVariable Long employeeId){
return interviewService.getInterviewInfoTo(employeeId, employerId);
}
@GetMapping("/continue/{employerId}")
public InterviewStatus updateStatus(@PathVariable Long employerId){
Long userId = SecurityContextUtils.getAuthorizedUserId();

return interviewService.updateStatus(employerId,userId);
}

@ApiResponse(description="1번 문제를 봤을 때 호출됩니다. 이에 따라 status가 1번문제 보는중으로 바뀜")
@PutMapping("/start/{employerId}")
public InterviewStatus startInterviewByEmployee(@PathVariable Long employerId){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ public InterviewStatus saveAnswerOfQuestion(InterviewAnswerDto interviewAnswerDt
return interviewRepository.updateStatus(interviewAnswerDto.getEmployerId(),userId,interviewStatusAfterAnswer);

}
public InterviewStatus updateStatus(Long employerId, Long employeeId){
InterviewStatus afterStatus = switch(interviewRepository.getInterviewStatusOfUser(employerId, employeeId)){
case ING_Q1 -> InterviewStatus.ING_Q2;
case ING_Q2 -> InterviewStatus.ING_Q3;
case ING_Q3 -> InterviewStatus.DONE;
case READY -> throw new BadRequestException("READY 상태에서 update status를 호출할 수 없습니다.");
case DONE -> throw new BadRequestException("DONE 상태에서 update status를 호출할 수 없습니다.");
};
return interviewRepository.updateStatus(employerId, employeeId, afterStatus);
}

private static InterviewStatus getInterviewStatus(InterviewAnswerDto interviewAnswerDto) {
InterviewStatus interviewStatusAfterAnswer = switch (interviewAnswerDto.getQuestionNumber()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@SpringBootTest
Expand Down Expand Up @@ -169,7 +167,7 @@ void getQuestions() throws Exception {
interviewRepository.saveQuestions(saveEmployeeDto.getId(), questionsDto);

UserDetails employee = authService.loadUserByUsername(saveEmployeeDto.getEmail());
MvcResult result = mvc.perform(MockMvcRequestBuilders.get("/interview/questions/" + saveEmployerDto.getId() + "/" + saveEmployeeDto.getId())
MvcResult result = mvc.perform(get("/interview/questions/" + saveEmployerDto.getId() + "/" + saveEmployeeDto.getId())
.with(user(employee)))
.andReturn();
String responseBody = result.getResponse().getContentAsString();
Expand Down Expand Up @@ -210,6 +208,10 @@ void getQuestionsWhenDisconnectedInFirstQuestion() throws Exception {
mvc.perform(put("/interview/start/" + saveEmployerDto.getId())
.with(user(employee)));

//1번 문제 보고 종료 -> 2번 풀고있는 상태로 업데이트
mvc.perform(get("/interview/continue/" + saveEmployerDto.getId())
.with(user(employee)));

InterviewAnswerDto interviewAnswerDto = new InterviewAnswerDto(saveEmployerDto.getId(), 1,"1번문제의 답입니다.");
String firstAnswerString = objectMapper.writeValueAsString(interviewAnswerDto);
MvcResult result = mvc.perform(post("/interview/answers")
Expand Down

0 comments on commit 00130bc

Please sign in to comment.