Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ public void updateTags(List<Tag> tags) {

if (tags != null) {
tags.forEach(tag ->
this.mentoringTags.add(new MentoringTag(this, tag))
this.mentoringTags.add(
MentoringTag.builder()
.mentoring(this)
.tag(tag)
.build()
)
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@Getter
@NoArgsConstructor
public class Tag extends BaseEntity {
@Column(length = 50, nullable = false, unique = true)
@Column(length = 50, nullable = false)
private String name;

@Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.Map;
import java.util.stream.Collectors;

@Service
Expand Down Expand Up @@ -123,33 +123,51 @@ private List<Tag> getOrCreateTags(List<String> tagNames) {
return new ArrayList<>();
}

// 기존 태그 조회
List<Tag> existingTags = tagRepository.findByNameIn(tagNames);

Set<String> existingNames = existingTags.stream()
.map(Tag::getName)
.collect(Collectors.toSet());
// 1. 동일한 사용자의 태그 중복 제거
List<String> distinctNames = tagNames.stream()
.map(String::trim)
.filter(name -> !name.isEmpty())
.distinct()
.toList();

// 신규 태그 생성
List<Tag> newTags = createNewTags(tagNames, existingNames);
// 2. 기존 태그 조회 - MySQL collation에 의해 대소문자 무시
Map<String, Tag> tagMap = tagRepository.findByNameIn(distinctNames).stream()
.collect(Collectors.toMap(
Tag::getName,
tag -> tag, (t1, t2) -> t1)
);

// 기존 태그 + 신규 태그
List<Tag> allTags = new ArrayList<>(existingTags);
allTags.addAll(newTags);
return buildTagList(distinctNames, tagMap);
}

return allTags;
/**
* 기존 태그 + 신규 태그
* - 정확히 일치하는 건 재사용 (대소문자 구분)
* - 없을 경우 신규 태그 생성
*/
private List<Tag> buildTagList(List<String> distinctNames, Map<String, Tag> tagMap) {
List<Tag> result = new ArrayList<>();
for (String name : distinctNames) {
Tag tag = tagMap.getOrDefault(name, createTagSafely(name));
if (tag != null) {
result.add(tag);
}
}
return result;
}

private List<Tag> createNewTags(List<String> tagNames, Set<String> existingNames) {
List<Tag> newTags = tagNames.stream()
.filter(name -> !existingNames.contains(name))
.map(name -> Tag.builder().name(name).build())
.toList();
private Tag createTagSafely(String name) {
// 생성 전 재조회로 중복 방지
Tag existing = tagRepository.findByNameIn(List.of(name)).stream()
.filter(tag -> tag.getName().equals(name))
.findFirst()
.orElse(null);

if (!newTags.isEmpty()) {
tagRepository.saveAll(newTags);
if (existing != null) {
return existing;
}
return newTags;

return tagRepository.save(Tag.builder().name(name).build());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,28 @@ public ReservationResponse getReservation(Member member, Long reservationId) {

@Transactional
public ReservationResponse createReservation(Mentee mentee, ReservationRequest reqDto) {
Mentoring mentoring = mentoringStorage.findMentoring(reqDto.mentoringId());
MentorSlot mentorSlot = mentoringStorage.findMentorSlot(reqDto.mentorSlotId());
try {
Mentoring mentoring = mentoringStorage.findMentoring(reqDto.mentoringId());
MentorSlot mentorSlot = mentoringStorage.findMentorSlot(reqDto.mentorSlotId());

DateTimeValidator.validateStartTimeNotInPast(mentorSlot.getStartDateTime());
validateMentorSlotStatus(mentorSlot, mentee);
validateOverlappingTimeForMentee(mentee, mentorSlot);
DateTimeValidator.validateStartTimeNotInPast(mentorSlot.getStartDateTime());
validateMentorSlotStatus(mentorSlot, mentee);
validateOverlappingTimeForMentee(mentee, mentorSlot);

Reservation reservation = Reservation.builder()
.mentoring(mentoring)
.mentee(mentee)
.mentorSlot(mentorSlot)
.preQuestion(reqDto.preQuestion())
.build();
reservationRepository.save(reservation);
Reservation reservation = Reservation.builder()
.mentoring(mentoring)
.mentee(mentee)
.mentorSlot(mentorSlot)
.preQuestion(reqDto.preQuestion())
.build();
reservationRepository.save(reservation);

mentorSlot.updateStatus(MentorSlotStatus.PENDING);
mentorSlot.updateStatus(MentorSlotStatus.PENDING);

return ReservationResponse.from(reservation);
return ReservationResponse.from(reservation);
} catch (OptimisticLockException e) {
throw new ServiceException(ReservationErrorCode.CONCURRENT_RESERVATION_CONFLICT);
}
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ public class JobRoadmapIntegrationServiceV3 {
private static final double QUALITY_NODE_COUNT_WEIGHT = 0.3; // 품질 점수: 노드 개수 가중치
private static final double QUALITY_STANDARDIZATION_WEIGHT = 0.7; // 품질 점수: 표준화율 가중치


// ========================================
// Public API
// ========================================

/**
* 직업 로드맵 통합 (DB 커넥션 점유 시간 감소를 위해 AI 호출을 트랜잭션 밖에서 수행)
*
Expand All @@ -67,7 +62,7 @@ public JobRoadmap integrateJobRoadmap(Long jobId) {
// 3. Task prefetch (트랜잭션 외부, 읽기만 수행)
Map<Long, Task> taskMap = prefetchTasks(aggregation);

// 4. 트리 구성 및 AI 호출 (트랜잭션 외부, 6-10분 소요)
// 4. 트리 구성 및 AI 호출 (트랜잭션 외부)
// 이 시간 동안 DB 커넥션은 사용하지 않음
RoadmapTreeBuilder.TreeBuildResult treeResult = roadmapTreeBuilder.build(aggregation, taskMap);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ private Map<String, RoadmapNode> buildNodesFromIntegratedTexts(
.learningAdvice(integratedTexts != null ? integratedTexts.learningAdvice() : null)
.recommendedResources(integratedTexts != null ? integratedTexts.recommendedResources() : null)
.learningGoals(integratedTexts != null ? integratedTexts.learningGoals() : null)
.difficulty(avgDifficulty != null ? avgDifficulty.intValue() : null)
.importance(avgImportance != null ? avgImportance.intValue() : null)
.difficulty(avgDifficulty != null ? (int) Math.round(avgDifficulty) : null)
.importance(avgImportance != null ? (int) Math.round(avgImportance) : null)
.estimatedHours(avgEstimatedHours)
.task(aggNode.task != null ? taskMap.get(aggNode.task.getId()) : null)
.roadmapId(0L) // 임시 값
Expand Down
Loading