Skip to content

Commit

Permalink
hotfix: thread local 제대로 작동하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
ori0o0p committed Aug 26, 2024
1 parent 8dce05d commit fbb630e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected ResumeModel updateResume(ResumeModel resume, UpdateWriterInfoRequest r

final var newWriter = resume.writer().update(new ResumeElementDto.Writer.Major(major.id(), major.name()), request.email(), request.skillSet(), request.url());

eventPublisher.publishEvent(new StudentMajorUpdateEvent(major.id(), major.name()));
eventPublisher.publishEvent(new StudentMajorUpdateEvent(major.id(), major.name(), resume.writer().id()));

return resume.updateWriterInfo(newWriter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public record StudentMajorUpdateEvent(
String majorId,
String majorName
String majorName,
String studentId
) {
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.whopper.application.student.event;

import com.example.whopper.application.student.component.CurrentStudent;
import com.example.whopper.common.exception.student.StudentNotFoundException;
import com.example.whopper.domain.student.StudentRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.context.event.EventListener;
Expand All @@ -11,12 +12,12 @@
@RequiredArgsConstructor
class StudentMajorUpdateEventHandler {
private final StudentRepository studentRepository;
private final CurrentStudent currentStudent;

@Async
@EventListener(StudentMajorUpdateEvent.class)
public void handle(StudentMajorUpdateEvent event) {
var student = currentStudent.getStudent();
var student = studentRepository.findById(event.studentId())
.orElseThrow(() -> StudentNotFoundException.EXCEPTION);
var newStudent = student.updateMajor(event.majorId(), event.majorName());

studentRepository.save(newStudent);
Expand Down

0 comments on commit fbb630e

Please sign in to comment.