Skip to content

Commit cd27d4f

Browse files
committed
[Fix] #29 온보딩 부분 임시저장 데이터 유지
1 parent 7f6dfda commit cd27d4f

2 files changed

Lines changed: 69 additions & 11 deletions

File tree

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

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,41 @@ public ProfileDraftResponse saveDraft(Long userId, ProfileDraftRequest request)
8080
throw new GeneralException(ErrorStatus.PROFILE_ALREADY_COMPLETED);
8181
}
8282

83-
List<JobCategory> jobCategories = resolveJobCategories(
84-
request.jobCategoryIds(),
85-
request.primaryJobCategoryId()
86-
);
87-
Region region = resolveRegion(request.regionId());
83+
List<UserJobCategory> currentSelections = findJobCategories(userId);
8884
profile.updateDraft(
89-
request.careerLevel(),
85+
request.careerLevel() != null ? request.careerLevel() : profile.getCareerLevel(),
9086
request.onboardingStep(),
91-
valueCodec.encode(request.preferenceNotes()),
92-
valueCodec.encode(request.excludeKeywords()),
93-
valueCodec.encode(request.techStacks())
87+
request.preferenceNotes() != null
88+
? valueCodec.encode(request.preferenceNotes())
89+
: profile.getPreferenceNote(),
90+
request.excludeKeywords() != null
91+
? valueCodec.encode(request.excludeKeywords())
92+
: profile.getExcludeKeywords(),
93+
request.techStacks() != null
94+
? valueCodec.encode(request.techStacks())
95+
: profile.getTechStack()
9496
);
9597
userProfileRepository.save(profile);
96-
replaceJobCategories(user, jobCategories, request.primaryJobCategoryId());
97-
replaceRegion(user, region);
98+
99+
if (request.jobCategoryIds() != null || request.primaryJobCategoryId() != null) {
100+
List<Long> categoryIds = request.jobCategoryIds() != null
101+
? request.jobCategoryIds()
102+
: currentSelections.stream()
103+
.map(selection -> selection.getJobCategory().getId())
104+
.toList();
105+
Long primaryId = request.primaryJobCategoryId() != null
106+
? request.primaryJobCategoryId()
107+
: currentSelections.stream()
108+
.filter(UserJobCategory::isPrimary)
109+
.map(selection -> selection.getJobCategory().getId())
110+
.findFirst()
111+
.orElse(null);
112+
replaceJobCategories(user, resolveJobCategories(categoryIds, primaryId), primaryId);
113+
}
114+
115+
if (request.regionId() != null) {
116+
replaceRegion(user, resolveRegion(request.regionId()));
117+
}
98118

99119
return toDraftResponse(profile, findJobCategories(userId), findRegion(userId));
100120
}

src/test/java/com/leets7th/job_is_be/domain/user/controller/ProfileControllerIntegrationTest.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,44 @@ void rejectsMoreThanThreeJobCategories() throws Exception {
194194
.andExpect(jsonPath("$.code").value("PROFILE_400_2"));
195195
}
196196

197+
@Test
198+
void preservesExistingDraftValuesWhenLaterStepOmitsThem() throws Exception {
199+
mockMvc.perform(put("/api/profile/draft")
200+
.with(userJwt())
201+
.contentType(MediaType.APPLICATION_JSON)
202+
.content("""
203+
{
204+
"onboardingStep": "PROFILE",
205+
"jobCategoryIds": [%d],
206+
"primaryJobCategoryId": %d,
207+
"regionId": %d,
208+
"careerLevel": "ENTRY",
209+
"preferenceNotes": ["remote"],
210+
"excludeKeywords": ["night shift"],
211+
"techStacks": ["Java"]
212+
}
213+
""".formatted(jobCategoryIds.get(0), jobCategoryIds.get(0), regionId)))
214+
.andExpect(status().isOk());
215+
216+
mockMvc.perform(put("/api/profile/draft")
217+
.with(userJwt())
218+
.contentType(MediaType.APPLICATION_JSON)
219+
.content("""
220+
{
221+
"onboardingStep": "QUIZ"
222+
}
223+
"""))
224+
.andExpect(status().isOk())
225+
.andExpect(jsonPath("$.data.onboardingStep").value("QUIZ"))
226+
.andExpect(jsonPath("$.data.jobCategories.length()").value(1))
227+
.andExpect(jsonPath("$.data.jobCategories[0].id").value(jobCategoryIds.get(0)))
228+
.andExpect(jsonPath("$.data.region.id").value(regionId))
229+
.andExpect(jsonPath("$.data.careerLevel").value("ENTRY"))
230+
.andExpect(jsonPath("$.data.preferenceNotes[0]").value("remote"))
231+
.andExpect(jsonPath("$.data.excludeKeywords[0]").value("night shift"))
232+
.andExpect(jsonPath("$.data.techStacks[0]").value("Java"));
233+
}
234+
197235
@Test
198236
void profileEndpointRejectsIncompleteDraft() throws Exception {
199237
mockMvc.perform(put("/api/profile/draft")

0 commit comments

Comments
 (0)