Skip to content

Commit 1f3f31c

Browse files
authored
Merge pull request #247 from prgrms-web-devcourse-final-project/fix/alarm-async2(WR9-143)
Fix/alarm async2(wr9 143)
2 parents 1a8ca8d + c7aa0a7 commit 1f3f31c

File tree

5 files changed

+22
-10
lines changed

5 files changed

+22
-10
lines changed

src/main/java/io/crops/warmletter/domain/share/repository/ShareProposalRepository.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ public interface ShareProposalRepository extends JpaRepository<ShareProposal,Lon
99
@Query("SELECT m.zipCode " +
1010
"FROM ShareProposal proposal " +
1111
"JOIN Member m ON proposal.requesterId = m.id " +
12-
"WHERE proposal.requesterId = :requesterId")
13-
String findZipCodeByRequesterId(Long requesterId);
12+
"WHERE proposal.id = :id " +
13+
"AND proposal.requesterId = :requesterId ")
14+
String findZipCodeByRequesterId(Long id, Long requesterId);
1415

1516
@Query("SELECT m.zipCode " +
1617
"FROM ShareProposal proposal " +
1718
"JOIN Member m ON proposal.recipientId = m.id " +
18-
"WHERE proposal.recipientId = :recipientId")
19-
String findZipCodeByRecipientId(Long recipientId);
19+
"WHERE proposal.id = :id " +
20+
"AND proposal.recipientId = :recipientId ")
21+
String findZipCodeByRecipientId(Long id, Long recipientId);
2022
}

src/main/java/io/crops/warmletter/domain/share/service/ShareProposalService.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import io.crops.warmletter.domain.share.repository.*;
1515
import io.crops.warmletter.domain.timeline.dto.request.NotificationRequest;
1616
import io.crops.warmletter.domain.timeline.enums.AlarmType;
17-
import io.crops.warmletter.domain.timeline.facade.NotificationFacade;
1817
import lombok.RequiredArgsConstructor;
1918
import org.springframework.context.ApplicationEventPublisher;
2019
import org.springframework.stereotype.Service;
@@ -79,8 +78,8 @@ public ShareProposalStatusResponse approveShareProposal(Long shareProposalId) {
7978
.build();
8079
sharePost = sharePostRepository.save(sharePost);
8180
// 알림 전송(양쪽 다)
82-
String requestZipCode = shareProposalRepository.findZipCodeByRequesterId(shareProposal.getRequesterId());
83-
String recipientZipCode = shareProposalRepository.findZipCodeByRecipientId(shareProposal.getRecipientId());
81+
String requestZipCode = shareProposalRepository.findZipCodeByRequesterId(shareProposalId, shareProposal.getRequesterId());
82+
String recipientZipCode = shareProposalRepository.findZipCodeByRecipientId(shareProposalId, shareProposal.getRecipientId());
8483
notificationPublisher.publishEvent(NotificationRequest.builder()
8584
.senderZipCode(recipientZipCode)
8685
.receiverId(shareProposal.getRequesterId())

src/main/java/io/crops/warmletter/domain/timeline/facade/NotificationFacade.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.crops.warmletter.domain.timeline.facade;
22

33
import io.crops.warmletter.domain.timeline.dto.request.NotificationRequest;
4-
import io.crops.warmletter.domain.timeline.enums.AlarmType;
54
import io.crops.warmletter.domain.timeline.service.NotificationService;
65
import lombok.RequiredArgsConstructor;
76
import org.springframework.scheduling.annotation.Async;

src/main/java/io/crops/warmletter/domain/timeline/service/NotificationService.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.crops.warmletter.domain.timeline.service;
22

3-
import io.crops.warmletter.domain.auth.exception.UnauthorizedException;
43
import io.crops.warmletter.domain.auth.facade.AuthFacade;
54
import io.crops.warmletter.domain.timeline.dto.response.NotificationResponse;
65
import io.crops.warmletter.domain.timeline.entity.Timeline;
@@ -9,6 +8,7 @@
98
import lombok.RequiredArgsConstructor;
109
import lombok.extern.slf4j.Slf4j;
1110
import org.springframework.http.MediaType;
11+
import org.springframework.scheduling.annotation.Async;
1212
import org.springframework.scheduling.annotation.Scheduled;
1313
import org.springframework.stereotype.Service;
1414
import org.springframework.transaction.annotation.Transactional;
@@ -57,7 +57,9 @@ protected void handleTimeout(Long memberId, SseEmitter emitter) {
5757
}
5858

5959
// 편지 수신, 신고 조치, 공유 요청, 공유 게시글 등록 시 호출 필요
60-
public void createNotification(String senderZipCode, Long receiverId, AlarmType alarmType, String data){
60+
@Transactional
61+
public void createNotification(String senderZipCode, Long receiverId, AlarmType alarmType, String data) {
62+
6163
Timeline.TimelineBuilder builder = Timeline.builder()
6264
.memberId(receiverId)
6365
// data = LETTER: letterId / REPORT: adminMemo, 경고횟수 / SHARE: shareProposalId / POSTED: sharePostId
@@ -111,6 +113,7 @@ protected void sendEventToClient(Long receiverId, NotificationResponse notificat
111113
}
112114

113115
// 연결을 확인하기 위한 Heartbeat를 30초마다 실행
116+
@Async
114117
@Scheduled(fixedRate = 30000)
115118
public void sendHeartbeat() {
116119
NotificationResponse notificationResponse = NotificationResponse.builder()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package io.crops.warmletter.global.config;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.scheduling.annotation.EnableAsync;
5+
6+
@Configuration
7+
@EnableAsync
8+
public class AsyncConfig {
9+
}

0 commit comments

Comments
 (0)