-
Notifications
You must be signed in to change notification settings - Fork 0
[Refactor] 기수 관리 추가 및 기존 기능과 연동 #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c6ef036
feat: 기수관리를 위한 엔티티, 서비스, 레포지토리 생성 및 대응하는 에러코드 추가 (DASOMBE-16)
junjinyun f5f2e82
test: GenerationService의 테스트 코드 작성 (DASOMBE-16)
junjinyun 232da0a
refactor: 모집일정에 기수를 의미하는 GENERATION 키 생성 (DASOMBE-16)
junjinyun 2378c41
refactor: 모집일정의 조회, 수정 부분에 기수 반영 및 테스트코드에 반영하고 기수 조회, 수정 코드 하단에 추가 (D…
junjinyun e9f82d9
refactor: 멤버 엔티티에 기수 추가 및 회원가입 시 GenerationService의 값을 읽어 자동으로 기수 기입하…
junjinyun 45abfc2
feat: 기수 관리(조회,수정) 을 담당하는 AdminGenerationController 추가 (DASOMBE-16)
junjinyun b3c9981
fix: ErrorCode 에 리베이스 중 누락된 EXECUTIVE_NOT_FOUND 추가
junjinyun 7d5e1b5
refactor: 기수 시스템을 모집일정에 통합시키기 위해 Generation 관련 기능 삭제(DASOMBE-16)
junjinyun 744a6e9
refactor: 기수 시스템을 모집일정에 통합 && 코드 정리 및 통합
junjinyun f297a80
refactor: 기수 시스템을 모집일정에 통합함에 따라 멤버의 기수 코드 수정 후 코드 정리 && 회원가입 시 선택적으로 …
junjinyun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| import dmu.dasom.api.domain.recruit.enums.ConfigKey; | ||
| import dmu.dasom.api.domain.recruit.enums.ResultCheckType; | ||
| import dmu.dasom.api.domain.recruit.repository.RecruitRepository; | ||
| import dmu.dasom.api.global.generation.service.GenerationService; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
@@ -24,14 +25,26 @@ | |
| public class RecruitServiceImpl implements RecruitService { | ||
|
|
||
| private final RecruitRepository recruitRepository; | ||
| private final GenerationService generationService; | ||
|
|
||
| // 모집 일정 설정 조회 | ||
| @Override | ||
| public List<RecruitConfigResponseDto> getRecruitSchedule() { | ||
| return findAll().stream() | ||
| .map(config -> config.getKey() == ConfigKey.INTERVIEW_TIME_START || config.getKey() == ConfigKey.INTERVIEW_TIME_END | ||
| ? config.toTimeResponse() : config.toResponse()) | ||
| .toList(); | ||
| .map(config -> { | ||
| if(config.getKey() == ConfigKey.GENERATION) { //기수 조회 추가 | ||
| String currentGeneration = generationService.getCurrentGeneration(); | ||
| return RecruitConfigResponseDto.builder() | ||
| .key(ConfigKey.GENERATION) | ||
| .value(currentGeneration) | ||
| .build(); | ||
| } else if(config.getKey() == ConfigKey.INTERVIEW_TIME_START || config.getKey() == ConfigKey.INTERVIEW_TIME_END) { | ||
| return config.toTimeResponse(); | ||
| } else { | ||
| return config.toResponse(); | ||
| } | ||
| }) | ||
|
||
| .toList(); | ||
| } | ||
|
|
||
| // 모집 일정 설정 수정 | ||
|
|
@@ -45,9 +58,13 @@ public void modifyRecruitSchedule(final RecruitScheduleModifyRequestDto request) | |
| config.updateTime(time); | ||
| return; | ||
| } | ||
|
|
||
| final LocalDateTime dateTime = parseDateTimeFormat(request.getValue()); | ||
| config.updateDateTime(dateTime); | ||
| else { | ||
| final LocalDateTime dateTime = parseDateTimeFormat(request.getValue()); | ||
| config.updateDateTime(dateTime); | ||
| } | ||
| final Recruit generationConfig = findByKey(ConfigKey.GENERATION); | ||
| String currentGeneration = generationService.getCurrentGeneration(); | ||
| generationConfig.updateGeneration(currentGeneration); | ||
| } | ||
|
|
||
| // 모집 기간 여부 확인 | ||
|
|
||
34 changes: 34 additions & 0 deletions
34
src/main/java/dmu/dasom/api/global/admin/controller/AdminGenerationController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package dmu.dasom.api.global.admin.controller; | ||
|
|
||
| import dmu.dasom.api.global.generation.service.GenerationService; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.Parameter; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/api/admin") | ||
| @RequiredArgsConstructor | ||
| public class AdminGenerationController { | ||
|
|
||
| private final GenerationService generationService; | ||
|
|
||
| // 기수 조회 | ||
| @Operation(summary = "현재 저장된 기수 조회") | ||
| @GetMapping("/generation") | ||
| public ResponseEntity<String> getCurrentGeneration() { | ||
| String currentGeneration = generationService.getCurrentGeneration(); | ||
| return ResponseEntity.ok(currentGeneration); | ||
| } | ||
|
|
||
| // 기수 수정 | ||
| @Operation(summary = "기수 수정") | ||
| @PatchMapping("/generation") | ||
| public ResponseEntity<Void> updateGeneration( | ||
| @RequestParam @Parameter(description = "새로운 기수 (예: '1기')") String generationValue | ||
| ) { | ||
| generationService.saveOrUpdateGeneration(generationValue); | ||
| return ResponseEntity.ok().build(); | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
src/main/java/dmu/dasom/api/global/generation/entity/Generation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package dmu.dasom.api.global.generation.entity; | ||
|
|
||
| import jakarta.persistence.*; | ||
| import lombok.*; | ||
| import org.hibernate.annotations.DynamicUpdate; | ||
|
|
||
| @AllArgsConstructor | ||
| @Builder | ||
| @DynamicUpdate | ||
| @Entity | ||
| @Getter | ||
| @NoArgsConstructor | ||
| public class Generation { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; // 기본키 | ||
|
|
||
| @Column(nullable = false, unique = true, length = 10) | ||
| private String generation; // 기수 (예: "1기", "2기") | ||
|
|
||
|
|
||
| public void updateGeneration(String generation) { | ||
| this.generation = generation; | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
src/main/java/dmu/dasom/api/global/generation/repository/GenerationRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package dmu.dasom.api.global.generation.repository; | ||
|
|
||
| import dmu.dasom.api.global.generation.entity.Generation; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| public interface GenerationRepository extends JpaRepository<Generation, Long> { | ||
|
|
||
| // 가장 최근 기수 1개 조회 | ||
| Optional<Generation> findFirstByOrderByIdDesc(); | ||
| } |
61 changes: 61 additions & 0 deletions
61
src/main/java/dmu/dasom/api/global/generation/service/GenerationService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package dmu.dasom.api.global.generation.service; | ||
|
|
||
| import dmu.dasom.api.domain.common.exception.CustomException; | ||
| import dmu.dasom.api.domain.common.exception.ErrorCode; | ||
| import dmu.dasom.api.global.generation.entity.Generation; | ||
| import dmu.dasom.api.global.generation.repository.GenerationRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.util.regex.Pattern; | ||
|
|
||
| @Slf4j | ||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional(readOnly = true) | ||
| public class GenerationService { | ||
|
|
||
| private final GenerationRepository generationRepository; | ||
|
|
||
| // 기본값 해당 변수로 관리 | ||
| private static final String DEFAULT_GENERATION = "34기"; | ||
|
|
||
| // 정규식: 숫자 + "기" 형식 (예: "1기", "12기") | ||
| private static final Pattern GENERATION_PATTERN = Pattern.compile("^[0-9]+기$"); | ||
|
|
||
| //현재 저장된 기수 조회 | ||
| public String getCurrentGeneration() { | ||
| try { | ||
| return generationRepository.findFirstByOrderByIdDesc() | ||
| .map(Generation::getGeneration) | ||
| .orElseGet(() -> { | ||
| log.warn("저장된 기수 없음, 기본값 사용: {}", DEFAULT_GENERATION); | ||
| return DEFAULT_GENERATION; | ||
| }); | ||
| } catch (Exception e) { | ||
| throw new CustomException(ErrorCode.INTERNAL_SERVER_ERROR); | ||
| } | ||
| } | ||
|
|
||
| //새로운 기수 저장 또는 기존 기수 수정 (유효성 검사 포함) | ||
| @Transactional | ||
| public void saveOrUpdateGeneration(String generationValue) { | ||
| if (!GENERATION_PATTERN.matcher(generationValue).matches()) { | ||
| throw new CustomException(ErrorCode.INVALID_GENERATION_FORMAT); | ||
| } | ||
|
|
||
| try { | ||
| Generation generation = generationRepository.findFirstByOrderByIdDesc() | ||
| .orElseGet(() -> Generation.builder().build()); | ||
|
|
||
| generation.updateGeneration(generationValue); | ||
| generationRepository.save(generation); | ||
|
|
||
| } catch (Exception e) { | ||
| throw new CustomException(ErrorCode.WRITE_FAIL); | ||
| } | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| import dmu.dasom.api.domain.member.entity.Member; | ||
| import dmu.dasom.api.domain.member.repository.MemberRepository; | ||
| import dmu.dasom.api.domain.member.service.MemberServiceImpl; | ||
| import dmu.dasom.api.global.generation.service.GenerationService; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
|
|
@@ -28,6 +29,9 @@ class MemberServiceTest { | |
| @Mock | ||
| MemberRepository memberRepository; | ||
|
|
||
| @Mock | ||
| private GenerationService generationService; | ||
|
|
||
| @InjectMocks | ||
| private MemberServiceImpl memberService; | ||
|
|
||
|
|
@@ -101,12 +105,13 @@ void signUp_success() { | |
| when(request.getPassword()).thenReturn("password"); | ||
| when(encoder.encode("password")).thenReturn("encodedPassword"); | ||
| when(memberRepository.existsByEmail("[email protected]")).thenReturn(false); | ||
|
|
||
| when(generationService.getCurrentGeneration()).thenReturn("34기"); | ||
| // when | ||
| memberService.signUp(request); | ||
|
|
||
| // then | ||
| verify(memberRepository, times(1)).save(any()); | ||
| verify(generationService, times(1)).getCurrentGeneration(); | ||
| } | ||
|
|
||
| @Test | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
기수 번호는 2자리수인데 속성 길이가 16이나 필요할까요?