Skip to content

Commit

Permalink
Merge pull request #174 from 1e5i-Shark/dev
Browse files Browse the repository at this point in the history
dev -> main
  • Loading branch information
GiHoo authored May 12, 2024
2 parents d738c06 + 35d1e0d commit b58e937
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ public void endCodingTest(
);
}

@MessageMapping("/chat/volume")
public void volume(
MessageRequest messageRequestDto,
@Header("Authorization") String authorization
) {
chatService.volume(
messageRequestDto.getRoomShortUuid(),
tempParseMemberIdFromHeader(authorization),
messageRequestDto.getMessage()
);
}

@MessageExceptionHandler
public String exception() {
return "Error has occurred.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,12 @@ public static MessageResponse endCoding(Long memberId) {
null
);
}

public static MessageResponse volume(Long memberId, String message) {
return new MessageResponse(
memberId,
MessageType.VOLUME,
message
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public enum MessageType {
UNREADY_ROOM("unready"),
CHANGE_HOST("change-host"),
START_CODING("start-coding"),
END_CODING("end-coding");
END_CODING("end-coding"),
VOLUME("volume");

@JsonValue
private final String value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ public interface ChatService {
void startCodingTest(String roomShortUuid, Long memberId);

void endCodingTest(String roomShortUuid, Long memberId);

void volume(String roomShortUuid, Long memberId, String message);
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ public void endCodingTest(String roomShortUuid, Long memberId) {
messageService.sendMessage(roomShortUuid, MessageResponse.endCoding(memberId));
}

@Override
public void volume(String roomShortUuid, Long memberId, String message) {
messageService.sendMessage(roomShortUuid, MessageResponse.volume(memberId, message));
}

private void checkMemberIsHost(String roomShortUuid, Long memberId) {
roomMemberService.validateHost(roomShortUuid, memberId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public Message<?> preSend(Message<?> message, MessageChannel channel) {
accessor.getCommand() == StompCommand.SEND) {
try {
String token = extractToken(accessor);
if (token == null || !jwtProvider.validateToken(token)) {
log.warn("토큰 null or 유효하지 않은 토큰");
if (!jwtProvider.validateToken(token)) {
log.warn("jwtProvider에서 validate 하지 못한 값");
throw new IllegalArgumentException("Invalid token");
}
} catch (Exception e) {
Expand All @@ -42,8 +42,12 @@ public Message<?> preSend(Message<?> message, MessageChannel channel) {

private String extractToken(StompHeaderAccessor accessor) {
String authorization = accessor.getFirstNativeHeader(AUTHORIZATION_HEADER);
if (authorization == null || !authorization.startsWith(BEARER_PREFIX)) {
throw new IllegalArgumentException("Invalid token");
if (authorization == null) {
log.warn("토큰이 null 입니다.");
throw new IllegalArgumentException("token is null");
} else if (!authorization.startsWith(BEARER_PREFIX)) {
log.warn("Bearer 로 시작하지 않는 토큰입니다.");
throw new IllegalArgumentException("invalid token");
}
return authorization.substring(BEARER_PREFIX.length());
}
Expand Down

0 comments on commit b58e937

Please sign in to comment.