Skip to content
Merged

Dev #82

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ jobs:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

# Docker Buildx μ„€μ • μΆ”κ°€
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3


# Dockerfile을 μ‚¬μš©ν•˜μ—¬ 이미지λ₯Ό λΉŒλ“œν•˜κ³  Docker Hub에 ν‘Έμ‹œν•©λ‹ˆλ‹€.
- name: Build and push Docker image
uses: docker/[email protected]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,26 @@ public SseEmitter createConnection(Long mapId, CustomUserDetails userDetails) {

connectionsByMapId.computeIfAbsent(mapId, k -> new CopyOnWriteArrayList<>()).add(connection);


// μ—°κ²° μ’…λ£Œ μ‹œ 정리 (κΈ°μ‘΄ 둜직 κ°œμ„ )
emitter.onCompletion(() -> removeConnection(mapId, connection));
emitter.onTimeout(() -> removeConnection(mapId, connection));
emitter.onCompletion(() -> {
removeConnection(mapId, connection);
broadcastUserListUpdate(mapId);
});
emitter.onTimeout(() -> {
removeConnection(mapId, connection);
broadcastUserListUpdate(mapId);
});
emitter.onError(throwable -> {
log.error("SSE μ—°κ²° 였λ₯˜ - λ§ˆμΈλ“œλ§΅ ID: {}, μ‚¬μš©μž ID: {}", mapId, userDetails.getId(), throwable);
removeConnection(mapId, connection);
broadcastUserListUpdate(mapId);
});

// μ—°κ²° ν™•μΈμš© 초기 λ©”μ‹œμ§€
sendToEmitter(emitter, "λ§ˆμΈλ“œλ§΅ " + mapId + " μ‹€μ‹œκ°„ μ—°κ²° 성곡");

log.info("SSE μ—°κ²° 생성 - λ§ˆμΈλ“œλ§΅ ID: {}, μ‚¬μš©μž ID: {}", mapId, userDetails.getId());

broadcastUserListUpdate(mapId);
return emitter;
}

Expand Down Expand Up @@ -158,9 +165,17 @@ private void removeConnection(Long mapId, SseConnection connection) {
connectionsByMapId.remove(mapId);
log.info("λ§ˆμΈλ“œλ§΅ ID {} 의 λͺ¨λ“  κ΅¬λ…μž μ—°κ²° μ’…λ£Œ", mapId);
}
broadcastUserListUpdate(mapId);
}
}

// μ‚¬μš©μž λͺ©λ‘ 변경을 λͺ¨λ“  ν΄λΌμ΄μ–ΈνŠΈμ—κ²Œ λΈŒλ‘œλ“œμΊμŠ€νŠΈ
public void broadcastUserListUpdate(Long mapId) {
// ν˜„μž¬ μ ‘μ†μž λͺ©λ‘
List<ConnectedUserDto> connectedUsers = getConnectedUsers(mapId);
// "user-list-updated" λΌλŠ” 이벀트 μ΄λ¦„μœΌλ‘œ ν˜„μž¬ μ ‘μ†μž λͺ©λ‘μ„ 전솑
sendToMapSubscribers(mapId, "user-list-updated", connectedUsers);
}

// μ ‘μ†λœ μ‚¬μš©μž 수 쑰회
public int getConnectionCount(Long mapId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ public ResponseEntity<Void> markNotificationAsRead(
return ResponseEntity.noContent().build();
}

// λͺ¨λ“  μ•Œλ¦Ό 읽음 처리
@PatchMapping("/read-all")
public ResponseEntity<Void> markAllNotificationsAsRead(
@AuthenticationPrincipal CustomUserDetails userDetails) {
notificationService.markAllAsRead(userDetails.getId());
return ResponseEntity.noContent().build();
}

// μ•Œλ¦Ό μ‚­μ œ
@DeleteMapping("/{notificationId}")
public ResponseEntity<Void> deleteNotification(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Optional;
Expand All @@ -20,4 +23,9 @@ public interface NotificationRepository extends JpaRepository<Notification, Long

// νŠΉμ • μ•Œλ¦Όμ΄ ν•΄λ‹Ή μ‚¬μš©μžμ˜ μ†Œμœ μΈμ§€ ν™•μΈν•˜λ©° 쑰회
Optional<Notification> findByIdAndUser(Long id, User user);

// νŠΉμ • μ‚¬μš©μžμ˜ λͺ¨λ“  읽지 μ•Šμ€ μ•Œλ¦Όμ„ 읽음으둜 μ²˜λ¦¬ν•˜λŠ” λ©”μ„œλ“œ
@Modifying
@Query("UPDATE Notification n SET n.read = true WHERE n.user = :user AND n.read = false")
void markAllAsReadByUser(@Param("user") User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,18 @@ public void markAsRead(Long notificationId, Long userId) {
}
}

/**
* μ‚¬μš©μžμ˜ λͺ¨λ“  μ•Œλ¦Όμ„ 읽음으둜 처리
*/
@Transactional
public void markAllAsRead(Long userId) {
User user = getUserById(userId);
notificationRepository.markAllAsReadByUser(user);

// λ³€κ²½λœ '읽지 μ•Šμ€ μ•Œλ¦Ό 개수'(0)λ₯Ό μ‹€μ‹œκ°„μœΌλ‘œ 전솑
notificationSseService.sendUnreadCount(user.getId(), 0);
}

/**
* μ•Œλ¦Ό μ‚­μ œ
*/
Expand Down