Skip to content

Commit 05cfb15

Browse files
committed
[Feat] #29 온보딩 완료 기능 구현
1 parent d6aff49 commit 05cfb15

4 files changed

Lines changed: 40 additions & 0 deletions

File tree

src/main/java/com/leets7th/job_is_be/domain/user/controller/ProfileController.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.springframework.security.oauth2.jwt.Jwt;
1111
import org.springframework.web.bind.annotation.GetMapping;
1212
import org.springframework.web.bind.annotation.PutMapping;
13+
import org.springframework.web.bind.annotation.PostMapping;
1314
import org.springframework.web.bind.annotation.RequestBody;
1415
import org.springframework.web.bind.annotation.RequestMapping;
1516
import org.springframework.web.bind.annotation.RestController;
@@ -45,6 +46,14 @@ public ResponseEntity<ApiResponse<ProfileDraftResponse>> saveDraft(
4546
);
4647
}
4748

49+
@PostMapping("/onboarding/complete")
50+
public ResponseEntity<ApiResponse<Void>> completeOnboarding(
51+
@AuthenticationPrincipal Jwt jwt
52+
) {
53+
profileService.completeOnboarding(userId(jwt));
54+
return ApiResponse.success(SuccessStatus.PROFILE_ONBOARDING_COMPLETE_SUCCESS);
55+
}
56+
4857
private Long userId(Jwt jwt) {
4958
return Long.valueOf(jwt.getSubject());
5059
}

src/main/java/com/leets7th/job_is_be/domain/user/service/ProfileService.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
import com.leets7th.job_is_be.domain.user.repository.UserProfileRepository;
1515
import com.leets7th.job_is_be.domain.user.repository.UserRegionRepository;
1616
import com.leets7th.job_is_be.domain.user.repository.UserRepository;
17+
import com.leets7th.job_is_be.domain.user.enums.OnboardingStep;
1718
import com.leets7th.job_is_be.global.exception.GeneralException;
1819
import com.leets7th.job_is_be.global.status.ErrorStatus;
1920
import org.springframework.stereotype.Service;
2021
import org.springframework.transaction.annotation.Transactional;
2122

2223
import java.util.ArrayList;
24+
import java.time.LocalDateTime;
2325
import java.util.LinkedHashSet;
2426
import java.util.List;
2527
import java.util.Map;
@@ -105,6 +107,31 @@ public ProfileDraftResponse getDraft(Long userId) {
105107
return toDraftResponse(profile, findJobCategories(userId), findRegion(userId));
106108
}
107109

110+
@Transactional
111+
public void completeOnboarding(Long userId) {
112+
UserProfile profile = userProfileRepository.findByUserId(userId)
113+
.orElseThrow(() -> new GeneralException(ErrorStatus.PROFILE_NOT_FOUND));
114+
if (profile.isOnboardingCompleted()) {
115+
throw new GeneralException(ErrorStatus.PROFILE_ALREADY_COMPLETED);
116+
}
117+
if (profile.getOnboardingStep() != OnboardingStep.REVIEW) {
118+
throw new GeneralException(ErrorStatus.PROFILE_ONBOARDING_NOT_READY);
119+
}
120+
121+
List<UserJobCategory> jobCategories = findJobCategories(userId);
122+
long primaryCount = jobCategories.stream().filter(UserJobCategory::isPrimary).count();
123+
boolean missingRequiredValue = jobCategories.isEmpty()
124+
|| jobCategories.size() > MAX_JOB_CATEGORIES
125+
|| primaryCount != 1
126+
|| findRegion(userId) == null
127+
|| profile.getCareerLevel() == null;
128+
if (missingRequiredValue) {
129+
throw new GeneralException(ErrorStatus.PROFILE_REQUIRED_FIELDS_MISSING);
130+
}
131+
132+
profile.completeOnboarding(LocalDateTime.now());
133+
}
134+
108135
private List<JobCategory> resolveJobCategories(List<Long> requestedIds, Long primaryId) {
109136
List<Long> ids = requestedIds == null ? List.of() : requestedIds;
110137
LinkedHashSet<Long> uniqueIds = new LinkedHashSet<>(ids);

src/main/java/com/leets7th/job_is_be/global/status/ErrorStatus.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@ public enum ErrorStatus implements BaseStatus {
4949
PROFILE_JOB_CATEGORY_COUNT_INVALID(HttpStatus.BAD_REQUEST, "PROFILE_400_2", "관심 직무는 중복 없이 최대 3개까지 선택할 수 있습니다."),
5050
PROFILE_PRIMARY_JOB_CATEGORY_INVALID(HttpStatus.BAD_REQUEST, "PROFILE_400_3", "대표 관심 직무는 선택한 관심 직무에 포함되어야 합니다."),
5151
PROFILE_VALUE_TOO_LONG(HttpStatus.BAD_REQUEST, "PROFILE_400_4", "프로필 입력값이 허용 길이를 초과했습니다."),
52+
PROFILE_REQUIRED_FIELDS_MISSING(HttpStatus.BAD_REQUEST, "PROFILE_400_5", "온보딩 완료에 필요한 프로필 항목을 입력해 주세요."),
53+
PROFILE_NOT_FOUND(HttpStatus.NOT_FOUND, "PROFILE_404_1", "완료된 프로필을 찾을 수 없습니다."),
5254
PROFILE_JOB_CATEGORY_NOT_FOUND(HttpStatus.NOT_FOUND, "PROFILE_404_2", "선택한 관심 직무를 찾을 수 없습니다."),
5355
PROFILE_REGION_NOT_FOUND(HttpStatus.NOT_FOUND, "PROFILE_404_3", "선택한 희망 지역을 찾을 수 없습니다."),
5456
PROFILE_ALREADY_COMPLETED(HttpStatus.CONFLICT, "PROFILE_409_1", "이미 온보딩을 완료한 프로필입니다."),
57+
PROFILE_ONBOARDING_NOT_READY(HttpStatus.CONFLICT, "PROFILE_409_2", "온보딩 확인 단계에서 완료할 수 있습니다."),
5558

5659
/**
5760
* Deck

src/main/java/com/leets7th/job_is_be/global/status/SuccessStatus.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public enum SuccessStatus implements BaseStatus {
2727
*/
2828
PROFILE_DRAFT_GET_SUCCESS(HttpStatus.OK, "PROFILE_200_3", "온보딩 임시저장을 조회했습니다."),
2929
PROFILE_DRAFT_SAVE_SUCCESS(HttpStatus.OK, "PROFILE_200_4", "온보딩 내용을 임시저장했습니다."),
30+
PROFILE_ONBOARDING_COMPLETE_SUCCESS(HttpStatus.OK, "PROFILE_200_5", "온보딩을 완료했습니다."),
3031

3132

3233
/**

0 commit comments

Comments
 (0)