Skip to content

Commit

Permalink
feat : Order 도메인 WebSocket 알림 컨트롤러 구현
Browse files Browse the repository at this point in the history
- 주문 생성, 주문 완료, 주문 취소, 유저에 의한 주문 취소
  • Loading branch information
mingj7235 committed May 21, 2023
1 parent c3cf523 commit 01d20d4
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,18 @@
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestHeader;
import webling.coffee.backend.domain.user.dto.request.UserRequestDto;
import webling.coffee.backend.global.responses.success.codes.AuthSuccessCode;
import webling.coffee.backend.global.responses.success.response.SuccessResponse;

import static webling.coffee.backend.global.utils.JwtUtils.ACCESS_AUTHORIZATION;

@Controller
@RequiredArgsConstructor
public class AlertController {
public class UserAlertController {

@MessageMapping("/alert.loginUser")
@MessageMapping("/alert/login")
@SendTo("/topic/public")
public ResponseEntity<SuccessResponse> loginAlert (@RequestHeader(name = ACCESS_AUTHORIZATION) String accessToken,
@Payload UserRequestDto.LoginAlert request,
public ResponseEntity<SuccessResponse> loginAlert (@Payload UserRequestDto.LoginAlert request,
SimpMessageHeaderAccessor accessor) {
accessor.setHeader(ACCESS_AUTHORIZATION, accessToken);
accessor.getSessionAttributes().put("userEmail", request.getUserEmail());
return SuccessResponse.toResponseEntity(
AuthSuccessCode.LOGIN
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package webling.coffee.backend.domain.order.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.messaging.handler.annotation.DestinationVariable;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.SimpMessageSendingOperations;
import org.springframework.stereotype.Controller;
import webling.coffee.backend.domain.order.dto.request.OrderRequestDto;
import webling.coffee.backend.domain.order.service.OrderFacade;
import webling.coffee.backend.global.responses.success.codes.OrderSuccessCode;
import webling.coffee.backend.global.responses.success.response.SuccessResponse;

@Controller
@RequiredArgsConstructor
public class OrderAlertController {

private final SimpMessageSendingOperations messagingTemplate;
private final OrderFacade orderFacade;

/**
* 주문 들어갈 때 바리스타에게 웹소켓 통해 주문 생성 알림
*/

@MessageMapping("/alert/order")
@SendTo("/topic/barista")
public ResponseEntity<SuccessResponse> orderAlert (@Payload OrderRequestDto.OrderCreateAlert request) {


return SuccessResponse.toResponseEntity(
OrderSuccessCode.CREATE
);
}

/**
* 주문 완료시 유저에게 웹소켓 통한 알림
* @param userId
*/
@MessageMapping("/alert/order/complete/{userId}")
public void orderCompleted(@DestinationVariable("userId") Long userId) {
messagingTemplate.convertAndSend("/topic/" + userId, "alarm socket connection completed.");
}

/**
* 주문 취소 (by 바리스타) 유저에게 웹소켓 통한 알림
* @param userId
*/
@MessageMapping("/alert/order/cancel/{userId}")
public void orderCancelByBarista(@DestinationVariable("userId") Long userId) {
messagingTemplate.convertAndSend("/topic/" + userId, "alarm socket connection completed.");
}

/**
* 주문 취소 (by 유저) 바리스타에게 웹소켓 통한 알림
*/
@MessageMapping("/alert/order/me/cancel")
@SendTo("/topic/barista")
public void orderCancelByUser() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,14 @@ public static class Create {
public static class Cancel {
private String cancelMessage;
}

@Getter
@Setter
@NoArgsConstructor
@Schema(name = "orderRequestCreateAlert")
public static class OrderCreateAlert {
private Long cartId;
private List<Long> orderIdList;
}

}

0 comments on commit 01d20d4

Please sign in to comment.