Skip to content

Commit

Permalink
Feature(#1) : 알림 전송, 알림 답장 MessageMapping으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Ban-gilhyeon committed Feb 5, 2025
1 parent d02d7ad commit 1c5e1e7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.messaging.handler.annotation.DestinationVariable;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import urdego.io.urdego_notification_service.common.exception.notification.NotFoundNotification;
Expand All @@ -34,17 +36,17 @@ public class NotificationController {
private final NotificationService notificationService;
//TODO : Response에 Entity를 리턴하는 행위는 좋지 않음 차후 NotificationResponse로 수정해야 함

@PostMapping("/send")
@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = WebSocketMessage.class)))
@MessageMapping("/send")
@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = WebSocketMessageResponse.class)))
@Operation(summary = "게임초대 알림 전송",description = "userId로 게임초대 알림 전송")
public ResponseEntity<WebSocketMessage<Notification>> sendNotification(@RequestBody NotificationRequest request) {
WebSocketMessage<Notification> response = notificationService.publishNotification(request);
return ResponseEntity.ok().body(response);
}

@GetMapping("/{userId}/reply")
@MessageMapping("/{userId}/reply")
@Operation(summary = "알림 답장", description = "notificationId로 게임초대 알림에 대한 답변 받기")
public ResponseEntity<Object> replyNotification(@PathVariable("userId") Long userId,
public ResponseEntity<Object> replyNotification(@DestinationVariable("userId") Long userId,
@RequestBody ReplyRequest request) {
Notification updatedNotification = notificationService.updateReadStatus(request, userId);
return ResponseEntity.ok().body(updatedNotification);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@
import urdego.io.urdego_notification_service.controller.client.GameServiceClient;
import urdego.io.urdego_notification_service.controller.dto.request.NotificationRequest;
import urdego.io.urdego_notification_service.controller.dto.request.ReplyRequest;
import urdego.io.urdego_notification_service.controller.dto.response.NotificationResponse;
import urdego.io.urdego_notification_service.controller.dto.response.WebSocketMessageResponse;
import urdego.io.urdego_notification_service.common.enums.MessageType;
import urdego.io.urdego_notification_service.controller.dto.request.notification.NotificationRequest;
import urdego.io.urdego_notification_service.controller.dto.WebSocketMessage;
import urdego.io.urdego_notification_service.domain.entity.Notification;

import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
Expand Down Expand Up @@ -60,10 +58,11 @@ public Notification updateReadStatus(ReplyRequest request, Long userId) {

Notification updatedNotification = notifications.get(index);
updatedNotification.updateReply(request.isAccepted());
simpMessagingTemplate.convertAndSend("/urdego/sub/notifications/" + updatedNotification.getTargetId(), updatedNotification);

//redis에 수정사항 저장
//TODO 수정 후 redis에 저장이 안됨..;;
redisTemplate.opsForList().set(key,index, updatedNotification);
redisTemplate.opsForList().set(key,index, notifications);
return updatedNotification;
}

Expand Down

0 comments on commit 1c5e1e7

Please sign in to comment.