Skip to content

Commit

Permalink
feat : AttendeeCacheEvent를 이용해 Attendee를 비동기적으로 캐싱하는 AttendanceServic…
Browse files Browse the repository at this point in the history
…e 구현 (#62)
  • Loading branch information
binary-ho committed Aug 22, 2023
1 parent 5700866 commit 71b9fad
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/gdsc/binaryho/imhere/ImhereApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;

@EnableAsync
@SpringBootApplication
public class ImhereApplication {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package gdsc.binaryho.imhere.core.lecture.application;

import gdsc.binaryho.imhere.core.lecture.model.StudentIds;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public class AttendeeCacheEvent {

private final Long lectureId;
private final StudentIds studentIds;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package gdsc.binaryho.imhere.core.lecture.application;

import gdsc.binaryho.imhere.core.lecture.application.port.AttendeeCacheRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

@Service
@RequiredArgsConstructor
public class AttendeeCacheService {

private final AttendeeCacheRepository attendeeCacheRepository;

@Async
@Transactional(propagation = Propagation.REQUIRES_NEW)
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
public void cache(AttendeeCacheEvent event) {
attendeeCacheRepository.cache(event.getLectureId(), event.getStudentIds());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package gdsc.binaryho.imhere.core.lecture.model;

import java.util.List;
import lombok.Getter;

@Getter
public class StudentIds {

private final List<Long> studentIds;

public StudentIds(List<Long> studentIds) {
this.studentIds = studentIds;
}

public StudentIds(Long studentId) {
this.studentIds = List.of(studentId);
}
}

0 comments on commit 71b9fad

Please # to comment.