Skip to content

Commit f40b2e9

Browse files
authored
Merge pull request #430 from STACKPOT/dev
[MERGE] dev->main 병합
2 parents e47b7eb + dc83ab2 commit f40b2e9

22 files changed

+286
-2760
lines changed

src/main/java/stackpot/stackpot/event/SseService.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
import stackpot.stackpot.chat.service.chatroom.ChatRoomQueryService;
1616
import stackpot.stackpot.chat.service.chatroominfo.ChatRoomInfoQueryService;
1717
import stackpot.stackpot.common.util.AuthService;
18-
import stackpot.stackpot.notification.event.FeedCommentEvent;
19-
import stackpot.stackpot.notification.event.FeedLikeEvent;
20-
import stackpot.stackpot.notification.event.PotApplicationEvent;
21-
import stackpot.stackpot.notification.event.PotCommentEvent;
18+
import stackpot.stackpot.notification.event.*;
2219
import stackpot.stackpot.pot.dto.UserMemberIdDto;
2320
import stackpot.stackpot.pot.service.potMember.PotMemberQueryService;
2421

@@ -34,6 +31,7 @@
3431
@Slf4j
3532
public class SseService {
3633

34+
// user 마다 SseEmitter 객체 저장
3735
private final Map<Long, SseEmitter> emitters = new ConcurrentHashMap<>();
3836

3937
private final ChatRoomQueryService chatRoomQueryService;
@@ -173,6 +171,28 @@ public void sendFeedLikeNotification(FeedLikeEvent event) {
173171
}
174172
}
175173

174+
/**
175+
* PotEndNotification
176+
* 팟을 끓인 후 팟 멤버들에게 실시간 알림 전송
177+
*/
178+
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
179+
public void sendPotEndNotification(PotEndEvent event) {
180+
Long potId = event.getPotId();
181+
List<Long> userIds = potMemberQueryService.selectUserIdsAboutPotMembersByPotId(potId);
182+
for (Long userId : userIds) {
183+
SseEmitter emitter = userId != null ? emitters.get(userId) : null;
184+
if (emitter != null) {
185+
try {
186+
emitter.send(SseEmitter.event()
187+
.name("Notification")
188+
.data(event.getUnReadNotificationDto(), MediaType.APPLICATION_JSON));
189+
} catch (Exception e) {
190+
emitters.remove(userId);
191+
}
192+
}
193+
}
194+
}
195+
176196
private ChatRoomResponseDto.ChatRoomListDto createChatRoomListDto(UserMemberIdDto ids) {
177197
Long potMemberId = ids.getPotMemberId();
178198
Long potId = ids.getPotId();

src/main/java/stackpot/stackpot/feed/repository/FeedRepository.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ List<Feed> findFeeds(
5454
// 커서 기반 페이징 조회
5555
List<Feed> findByUserIdAndFeedIdBefore(Long userId, Long cursorFeedId, Pageable pageable);
5656

57+
// 시리즈 필터링 추가된 페이징 조회
58+
List<Feed> findByUser_IdAndSeries_SeriesId(Long userId, Long seriesId, Pageable pageable);
59+
List<Feed> findByUser_IdAndSeries_SeriesIdAndFeedIdBefore(Long userId, Long seriesId, Long cursorFeedId, Pageable pageable);
60+
5761
@Modifying
5862
@Query("DELETE FROM Feed f WHERE f.user.id = :userId")
5963
void deleteByUserId(@Param("userId") Long userId);

src/main/java/stackpot/stackpot/feed/service/FeedCommandServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public boolean toggleLike(Long feedId) {
200200
feedLikeRepository.delete(existingLike.get());
201201
feed.setLikeCount(feed.getLikeCount() - 1);
202202
feedRepository.save(feed);
203-
203+
// todo 좋아요 알림 삭제
204204
return false; // 좋아요 취소
205205
} else {
206206
// 좋아요 추가

src/main/java/stackpot/stackpot/feed/service/FeedQueryService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
public interface FeedQueryService {
1010
FeedResponseDto.FeedPreviewList getPreViewFeeds(String category, String sort, Long cursor, int limit);
1111
FeedResponseDto.AuthorizedFeedDto getFeed(Long feedId);
12-
UserMyPageResponseDto getFeedsByUserId(Long userId, Long nextCursor, int pageSize);
12+
UserMyPageResponseDto getFeedsByUserId(Long userId, Long nextCursor, int pageSize, Long seriesId);
1313
// FeedResponseDto.FeedPreviewList searchByUserIdByKeyword(Long userId, Long nextCursor, int pageSize);
14-
UserMyPageResponseDto getFeeds(Long nextCursor, int pageSize);
14+
UserMyPageResponseDto getFeeds(Long nextCursor, int pageSize, Long seriesId);
1515
Map<Long, String> getMySeries();
1616
Long getLikeCount(Long feedId);
1717
Feed getFeedByFeedId(Long feedId);

src/main/java/stackpot/stackpot/feed/service/FeedQueryServiceImpl.java

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public FeedResponseDto.AuthorizedFeedDto getFeed(Long feedId) {
180180
}
181181

182182
@Transactional
183-
public UserMyPageResponseDto getFeedsByUserId(Long userId, Long nextCursor, int pageSize) {
183+
public UserMyPageResponseDto getFeedsByUserId(Long userId, Long nextCursor, int pageSize, Long seriesId) {
184184
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
185185
boolean isAuthenticated = authentication != null
186186
&& !(authentication instanceof AnonymousAuthenticationToken)
@@ -202,9 +202,19 @@ public UserMyPageResponseDto getFeedsByUserId(Long userId, Long nextCursor, int
202202
: List.of();
203203

204204
Pageable pageable = PageRequest.of(0, pageSize, Sort.by(Sort.Direction.DESC, "feedId"));
205-
List<Feed> feeds = (nextCursor == null)
206-
? feedRepository.findByUser_Id(userId, pageable)
207-
: feedRepository.findByUserIdAndFeedIdBefore(userId, nextCursor, pageable);
205+
// List<Feed> feeds = (nextCursor == null)
206+
// ? feedRepository.findByUser_Id(userId, pageable)
207+
// : feedRepository.findByUserIdAndFeedIdBefore(userId, nextCursor, pageable);
208+
List<Feed> feeds;
209+
if (seriesId == 0L) {
210+
feeds = (nextCursor == null)
211+
? feedRepository.findByUser_Id(userId, pageable)
212+
: feedRepository.findByUserIdAndFeedIdBefore(userId, nextCursor, pageable);
213+
} else {
214+
feeds = (nextCursor == null)
215+
? feedRepository.findByUser_IdAndSeries_SeriesId(userId, seriesId, pageable)
216+
: feedRepository.findByUser_IdAndSeries_SeriesIdAndFeedIdBefore(userId, seriesId, nextCursor, pageable);
217+
}
208218

209219
List<FeedResponseDto.FeedDto> feedDtos = feeds.stream()
210220
.map(feed -> {
@@ -233,13 +243,20 @@ public UserMyPageResponseDto getFeedsByUserId(Long userId, Long nextCursor, int
233243
}
234244

235245
@Override
236-
public UserMyPageResponseDto getFeeds(Long nextCursor, int pageSize) {
246+
public UserMyPageResponseDto getFeeds(Long nextCursor, int pageSize, Long seriesId) {
237247
User user = authService.getCurrentUser();
238248

239249
Pageable pageable = PageRequest.of(0, pageSize, Sort.by(Sort.Direction.DESC, "feedId"));
240-
List<Feed> feeds = (nextCursor == null)
241-
? feedRepository.findByUser_Id(user.getId(), pageable)
242-
: feedRepository.findByUserIdAndFeedIdBefore(user.getId(), nextCursor, pageable);
250+
List<Feed> feeds;
251+
if (seriesId == 0L) {
252+
feeds = (nextCursor == null)
253+
? feedRepository.findByUser_Id(user.getId(), pageable)
254+
: feedRepository.findByUserIdAndFeedIdBefore(user.getId(), nextCursor, pageable);
255+
} else {
256+
feeds = (nextCursor == null)
257+
? feedRepository.findByUser_IdAndSeries_SeriesId(user.getId(), seriesId, pageable)
258+
: feedRepository.findByUser_IdAndSeries_SeriesIdAndFeedIdBefore(user.getId(), seriesId, nextCursor, pageable);
259+
}
243260

244261
List<Long> likedFeedIds = feedLikeRepository.findFeedIdsByUserId(user.getId());
245262
List<Long> savedFeedIds = feedSaveRepository.findFeedIdsByUserId(user.getId());

src/main/java/stackpot/stackpot/notification/controller/NotificationController.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import java.util.List;
1616

1717
@RestController
18-
@RequestMapping("/api/notifications")
18+
@RequestMapping("/notifications")
1919
@RequiredArgsConstructor
2020
public class NotificationController {
2121

@@ -31,7 +31,10 @@ public ResponseEntity<ApiResponse<List<NotificationResponseDto.UnReadNotificatio
3131
return ResponseEntity.ok(ApiResponse.onSuccess(notificationQueryService.getAllUnReadNotifications()));
3232
}
3333

34-
@Operation(summary = "알림 읽음 처리 API")
34+
@Operation(
35+
summary = "알림 읽음 처리 API",
36+
description = "NotificationType은 알림 조회 응답의 type 필드를 그대로 보내면 됩니다"
37+
)
3538
@ApiErrorCodeExamples({
3639
ErrorStatus.NOTIFICATION_NOT_FOUND,
3740
ErrorStatus.INVALID_NOTIFICATION_TYPE

src/main/java/stackpot/stackpot/notification/converter/NotificationConverter.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import org.springframework.stereotype.Component;
44
import stackpot.stackpot.notification.dto.NotificationDto;
55
import stackpot.stackpot.notification.dto.NotificationResponseDto;
6-
import stackpot.stackpot.user.entity.enums.Role;
76

8-
import java.time.LocalDate;
97
import java.time.LocalDateTime;
108
import java.time.format.DateTimeFormatter;
119

@@ -17,19 +15,21 @@ public class NotificationConverter {
1715
public NotificationResponseDto.UnReadNotificationDto toUnReadNotificationDto(NotificationDto.UnReadNotificationDto unReadNotificationDto) {
1816
return NotificationResponseDto.UnReadNotificationDto.builder()
1917
.notificationId(unReadNotificationDto.getNotificationId())
20-
.potOrFeedId(unReadNotificationDto.getPotOrFeedId())
21-
.userName(unReadNotificationDto.getUserName() + " 새싹")
18+
.potId(unReadNotificationDto.getPotId())
19+
.feedId(unReadNotificationDto.getFeedId())
20+
.userName(unReadNotificationDto.getUserName() == null ? " " : unReadNotificationDto.getUserName() + " 새싹")
2221
.type(unReadNotificationDto.getType())
2322
.content(unReadNotificationDto.getContent())
2423
.createdAt(unReadNotificationDto.getCreatedAt().format(DATE_FORMATTER))
2524
.build();
2625
}
2726

2827
public NotificationResponseDto.UnReadNotificationDto toUnReadNotificationDto(
29-
Long notificationId, Long potOrFeedId, String userName, String type, String content, LocalDateTime createdAt) {
28+
Long notificationId, Long potId, Long feedId, String userName, String type, String content, LocalDateTime createdAt) {
3029
return NotificationResponseDto.UnReadNotificationDto.builder()
3130
.notificationId(notificationId)
32-
.potOrFeedId(potOrFeedId)
31+
.potId(potId)
32+
.feedId(feedId)
3333
.userName(userName + " 새싹")
3434
.type(type)
3535
.content(content)

src/main/java/stackpot/stackpot/notification/dto/NotificationDto.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ public class NotificationDto {
1616
@AllArgsConstructor
1717
public static class UnReadNotificationDto {
1818
private Long notificationId;
19-
private Long potOrFeedId;
19+
private Long potId;
20+
private Long feedId;
2021
private String userName;
21-
private String type;
22-
private String content;
22+
private String type; // 알림 종류
23+
private String content; // 알림 내용
2324
private LocalDateTime createdAt;
2425
}
2526
}

src/main/java/stackpot/stackpot/notification/dto/NotificationResponseDto.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ public class NotificationResponseDto {
1616
@AllArgsConstructor
1717
public static class UnReadNotificationDto {
1818
private Long notificationId;
19-
private Long potOrFeedId;
19+
private Long potId;
20+
private Long feedId;
2021
private String userName;
2122
private String type;
2223
private String content;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package stackpot.stackpot.notification.entity;
2+
3+
import jakarta.persistence.*;
4+
import lombok.*;
5+
import stackpot.stackpot.common.BaseEntity;
6+
import stackpot.stackpot.pot.entity.Pot;
7+
8+
@Entity
9+
@Getter
10+
@Builder
11+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
12+
@AllArgsConstructor
13+
public class PotEndNotification extends BaseEntity {
14+
15+
@Id
16+
@GeneratedValue(strategy = GenerationType.IDENTITY)
17+
@Column(name = "pot_end_notification_id")
18+
private Long id;
19+
20+
private Boolean isRead;
21+
22+
@OneToOne(fetch = FetchType.LAZY)
23+
@JoinColumn(name = "pot_id")
24+
private Pot pot;
25+
26+
public void updateIsRead(Boolean isRead) {
27+
this.isRead = isRead;
28+
}
29+
}

0 commit comments

Comments
 (0)