Skip to content

Commit

Permalink
feat-be: 지원자 기본 정보 조회 (#63)
Browse files Browse the repository at this point in the history
* Create draft PR for #62

* feat: 지원자 기본 정보 조회

* chore(slack-alert): PR review 개별 comment 알림 기능 수정

* test: 테스트 문구 및 처리 방법 변경

* chore(slack-alert): PR review 완료, approve Slack 알림 기능 수정

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: HyungHoKim00 <hkim1109@naver.com>
Co-authored-by: Do Yeop Kim <113661364+Dobby-Kim@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 18, 2024
1 parent 31e11cc commit fe6657b
Show file tree
Hide file tree
Showing 8 changed files with 202 additions and 5 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/be-pr-event-alert.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
echo "REVIEWER_SLACK_ID=${{ env[github.event.requested_reviewer.login] }}" >> $GITHUB_ENV
echo "SENDER_SLACK_ID=${{ env[github.event.sender.login] }}" >> $GITHUB_ENV
- name: pr reviewer 되면 slack 알림 보냄
- name: pr reviewe 요청 시 slack 알림 보내기
uses: slackapi/slack-github-action@v1.24.0
with:
channel-id: ${{ secrets.REVIEW_MENTION_CHANNEL_ID }}
Expand All @@ -64,7 +64,7 @@ jobs:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}

review-submitted_alert:
if: github.event.action == 'submitted' && github.event.review.state != 'APPROVED'
if: github.event.action == 'submitted' && github.event.review.state != 'APPROVED'
runs-on: ubuntu-latest
steps:
- name: Set reviewer and reviewee variables
Expand All @@ -73,7 +73,8 @@ jobs:
echo "REVIEWER_SLACK_ID=${{ env[github.event.sender.login] }}" >> $GITHUB_ENV
echo "ASSIGNEE_SLACK_ID=${{ env[github.event.pull_request.login] }}" >> $GITHUB_ENV
- name: pr 리뷰 요청시 reviewer에게 slack 알림 발송
- name: pr 리뷰 완료 후 submit되면 reviewee에게 slack 알림 발송
if: env.ASSIGNEE_SLACK_ID != ''
uses: slackapi/slack-github-action@v1.24.0
with:
channel-id: ${{ secrets.REVIEW_MENTION_CHANNEL_ID }}
Expand Down Expand Up @@ -102,7 +103,7 @@ jobs:
run: |
echo "ASSIGNEE_SLACK_ID=${{ env[github.event.pull_request.assignee.login] }}" >> $GITHUB_ENV
- name: pr reviewer 되면 slack 알림 보냄
- name: pr reviewer가 Approve 하면 slack 알림 보냄
uses: slackapi/slack-github-action@v1.24.0
with:
channel-id: ${{ secrets.TASK_COMPLETE_SLACK_CHANNEL_ID }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.cruru.applicant.controller;

import com.cruru.applicant.controller.dto.ApplicantMoveRequest;
import com.cruru.applicant.controller.dto.ApplicantResponse;
import com.cruru.applicant.service.ApplicantService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -25,4 +27,10 @@ public ResponseEntity<Void> updateApplicantProcess(
applicantService.updateApplicantProcess(processId, moveRequest);
return ResponseEntity.ok().build();
}

@GetMapping("/{applicant_id}")
public ResponseEntity<ApplicantResponse> read(@PathVariable("applicant_id") Long id) {
ApplicantResponse applicantResponse = applicantService.findById(id);
return ResponseEntity.ok().body(applicantResponse);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.cruru.applicant.controller.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.time.LocalDateTime;

public record ApplicantResponse(
@JsonProperty(value = "applicant_id")
Long id,

String name,

String email,

String phone,

@JsonProperty("created_at")
LocalDateTime createdAt
) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.cruru.applicant.exception;

import com.cruru.advice.NotFoundException;

public class ApplicantNotFoundException extends NotFoundException {

private static final String MESSAGE = "존재하지 않는 지원자입니다.";

public ApplicantNotFoundException() {
super(MESSAGE);
}
}
18 changes: 18 additions & 0 deletions src/main/java/com/cruru/applicant/service/ApplicantService.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.cruru.applicant.service;

import com.cruru.applicant.controller.dto.ApplicantMoveRequest;
import com.cruru.applicant.controller.dto.ApplicantResponse;
import com.cruru.applicant.domain.Applicant;
import com.cruru.applicant.domain.repository.ApplicantRepository;
import com.cruru.applicant.exception.ApplicantNotFoundException;
import com.cruru.process.domain.Process;
import com.cruru.process.domain.repository.ProcessRepository;
import com.cruru.process.exception.ProcessNotFoundException;
Expand All @@ -27,4 +29,20 @@ public void updateApplicantProcess(long processId, ApplicantMoveRequest moveRequ
List<Applicant> applicants = applicantRepository.findAllById(moveRequest.applicantIds());
applicants.forEach(applicant -> applicant.updateProcess(process));
}

public ApplicantResponse findById(Long id) {
Applicant applicant = applicantRepository.findById(id)
.orElseThrow(ApplicantNotFoundException::new);
return toApplicantResponse(applicant);
}

private ApplicantResponse toApplicantResponse(Applicant applicant) {
return new ApplicantResponse(
applicant.getId(),
applicant.getName(),
applicant.getEmail(),
applicant.getPhone(),
applicant.getCreatedDate()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.cruru.applicant.controller;

import com.cruru.applicant.controller.dto.ApplicantMoveRequest;
import com.cruru.applicant.domain.Applicant;
import com.cruru.applicant.domain.repository.ApplicantRepository;
import com.cruru.process.domain.Process;
import com.cruru.process.domain.repository.ProcessRepository;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;

@DisplayName("지원자 컨트롤러 테스트")
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class ApplicantControllerTest {

@LocalServerPort
private int port;

@Autowired
private ProcessRepository processRepository;

@Autowired
private ApplicantRepository applicantRepository;

@BeforeEach
void setUp() {
RestAssured.port = port;
applicantRepository.deleteAll();
processRepository.deleteAll();
}

@DisplayName("지원자들의 프로세스를 일괄적으로 옮기는 데 성공하면 200을 응답한다.")
@Test
void updateApplicantProcess() {
Process now = new Process(1L, 0, "서류", "서류 전형", null);
now = processRepository.save(now);
Process next = new Process(2L, 1, "최종 합격", "최종 합격", null);
next = processRepository.save(next);
Applicant applicant = new Applicant(1L, "name", "email", "phone", now);
applicantRepository.save(applicant);

RestAssured.given().log().all()
.contentType(ContentType.JSON)
.body(new ApplicantMoveRequest(List.of(applicant.getId())))
.when().put("/api/v1/applicants/move-process/" + next.getId())
.then().log().all().statusCode(200);
}

@DisplayName("지원자의 기본 정보를 읽어오는 데 성공하면 200을 응답한다.")
@Test
void read() {
Applicant applicant = applicantRepository.save(new Applicant("name", "email", "phone", null));

RestAssured.given().log().all()
.when().get("/api/v1/applicants/" + applicant.getId())
.then().log().all().statusCode(200);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.cruru.applicant.domain.repository;

import static org.assertj.core.api.Assertions.assertThat;

import com.cruru.applicant.domain.Applicant;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;

@DisplayName("지원자 레포지토리 테스트")
@DataJpaTest
class ApplicantRepositoryTest {

@Autowired
private ApplicantRepository applicantRepository;

@DisplayName("이미 DB에 저장되어 있는 ID를 가진 프로세스를 저장하면, 해당 ID의 프로세스는 후에 작성된 정보로 업데이트한다.")
@Test
void sameIdUpdate() {
//given
Applicant applicant = new Applicant("이름", "이메일", "전화번호", null);
Applicant saved = applicantRepository.save(applicant);

//when
Applicant updatedApplicant = new Applicant(saved.getId(), "다른이름", "다른이메일", "다른번호", null);
applicantRepository.save(updatedApplicant);

//then
Applicant foundApplicant = applicantRepository.findById(saved.getId()).get();
assertThat(foundApplicant.getName()).isEqualTo("다른이름");
assertThat(foundApplicant.getEmail()).isEqualTo("다른이메일");
assertThat(foundApplicant.getPhone()).isEqualTo("다른번호");
}

@DisplayName("ID가 없는 프로세스를 저장하면, 순차적으로 ID가 부여하여 저장된다.")
@Test
void saveNoId() {
//given
Applicant applicant1 = new Applicant("이름", "이메일", "전화번호", null);
Applicant applicant2 = new Applicant("다른이름", "다른이메일", "다른번호", null);

//when
Applicant savedApplicant1 = applicantRepository.save(applicant1);
Applicant savedApplicant2 = applicantRepository.save(applicant2);

//then
assertThat(savedApplicant1.getId() + 1).isEqualTo(savedApplicant2.getId());
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.cruru.applicant.service;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import com.cruru.applicant.controller.dto.ApplicantMoveRequest;
import com.cruru.applicant.controller.dto.ApplicantResponse;
import com.cruru.applicant.domain.Applicant;
import com.cruru.applicant.domain.repository.ApplicantRepository;
import com.cruru.applicant.exception.ApplicantNotFoundException;
import com.cruru.dashboard.domain.Dashboard;
import com.cruru.dashboard.domain.repository.DashboardRepository;
import com.cruru.process.domain.Process;
Expand Down Expand Up @@ -56,5 +59,26 @@ void updateApplicantProcess() {
.allMatch(process -> process.equals(afterProcess));
assertThat(processAllMoved).isTrue();
}
}

@DisplayName("id로 지원자를 찾는다.")
@Test
void findById() {
// given
Applicant applicant = new Applicant(1L, "명오", "myun@mail.com", "01012341234", null);
applicant = applicantRepository.save(applicant);

// when
ApplicantResponse found = applicantService.findById(applicant.getId());

// then
assertThat(applicant.getId()).isEqualTo(found.id());
}

@DisplayName("id에 해당하는 지원자가 존재하지 않으면 Not Found 예외가 발생한다.")
@Test
void invalidFindByIdThrowsException() {
// given&when&then
assertThatThrownBy(() -> applicantService.findById(-1L))
.isInstanceOf(ApplicantNotFoundException.class);
}
}

0 comments on commit fe6657b

Please sign in to comment.