Skip to content

Commit 2ee8122

Browse files
committed
fix : 시즌 알림 추가 로직 변경 (#81)
1 parent 2d05803 commit 2ee8122

File tree

6 files changed

+43
-17
lines changed

6 files changed

+43
-17
lines changed

src/main/java/cmf/commitField/domain/noti/noti/service/NotiService.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,28 +64,23 @@ public List<Noti> getSeasonNotiCheck(User receiver, long seasonId) {
6464

6565
// 새 시즌 알림 생성
6666
@Transactional
67-
public void createNewSeason(Season season) {
67+
public void createNewSeasonNoti(Season season, User user) {
6868
System.out.println("새 시즌 알림 생성");
6969
// 메시지 생성
7070
String message = NotiService.generateMessage(NotiDetailType.SEASON_START, season.getName());
7171

72-
// 모든 사용자 조회
73-
Iterable<User> users = userRepository.findAll();
72+
Noti noti = Noti.builder()
73+
.typeCode(NotiType.SEASON)
74+
.type2Code(NotiDetailType.SEASON_START)
75+
.receiver(user)
76+
.isRead(false)
77+
.message(message)
78+
.relId(season.getId())
79+
.relTypeCode(season.getModelName())
80+
.build();
7481

75-
// 모든 유저 알림 객체 생성
76-
users.forEach(user -> {
77-
Noti noti = Noti.builder()
78-
.typeCode(NotiType.SEASON)
79-
.type2Code(NotiDetailType.SEASON_START)
80-
.receiver(user)
81-
.isRead(false)
82-
.message(message)
83-
.relId(season.getId())
84-
.relTypeCode(season.getModelName())
85-
.build();
82+
notiRepository.save(noti);
8683

87-
notiRepository.save(noti);
88-
});
8984
System.out.println("새 시즌 알림 생성 끝");
9085
}
9186

src/main/java/cmf/commitField/domain/user/service/CustomOAuth2UserService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) {
101101
if(notiService.getSeasonNotiCheck(user, season.getId()).isEmpty()){
102102
log.info("User {} does not have season noti", user.getUsername());
103103
// 가지고 있지 않다면 알림을 추가
104-
notiService.createNewSeason(season);
104+
notiService.createNewSeasonNoti(season, user);
105105
// redisTemplate.opsForValue().set(season_key, String.valueOf(count), Duration.ofHours(3)); // 3시간 캐싱
106106
}
107107

src/main/java/cmf/commitField/global/scheduler/SeasonScheduler.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// java/cmf/commitField/global/scheduler/SeasonScheduler.java
22
package cmf.commitField.global.scheduler;
33

4+
import cmf.commitField.domain.noti.noti.service.NotiService;
45
import cmf.commitField.domain.season.entity.Rank;
56
import cmf.commitField.domain.season.entity.Season;
67
import cmf.commitField.domain.season.entity.SeasonStatus;
@@ -29,6 +30,7 @@ public class SeasonScheduler {
2930
private final UserSeasonRepository userSeasonRepository;
3031
private final UserRepository userRepository;
3132
private final SeasonService seasonService;
33+
private final NotiService notiService;
3234

3335
// 매년 3, 6, 9, 12월 1일 자정마다 시즌 확인 및 생성
3436
@Scheduled(cron = "0 0 0 1 3,6,9,12 *")
@@ -53,6 +55,11 @@ public void checkAndCreateNewSeason() {
5355

5456
Season newSeason = seasonService.createNewSeason(seasonName, startDate, endDate);
5557

58+
// 모든 유저에게 새 시즌 알림 생성
59+
userRepository.findAll().forEach(user -> {
60+
notiService.createNewSeasonNoti(newSeason, user);
61+
});
62+
5663
// 모든 유저의 랭크 초기화
5764
resetUserRanks(newSeason);
5865

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package cmf.commitField.global.websocket;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
5+
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
6+
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
7+
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
8+
9+
@Configuration
10+
@EnableWebSocketMessageBroker
11+
public class NotiWebsoketConfig implements WebSocketMessageBrokerConfigurer {
12+
@Override
13+
public void registerStompEndpoints(StompEndpointRegistry registry) {
14+
registry.addEndpoint("/ws") // WebSocket 엔드포인트 설정
15+
.setAllowedOriginPatterns("*") // CORS 허용
16+
.withSockJS(); // SockJS 지원
17+
}
18+
19+
@Override
20+
public void configureMessageBroker(MessageBrokerRegistry registry) {
21+
registry.enableSimpleBroker("/topic"); // 메시지 브로커 활성화
22+
registry.setApplicationDestinationPrefixes("/app"); // 클라이언트에서 보낼 경로
23+
}
24+
}
48.3 KB
Loading
280 KB
Loading

0 commit comments

Comments
 (0)