Skip to content

Feat: 채팅 img 사진 #142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 11, 2025
Merged
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
Original file line number Diff line number Diff line change
@@ -12,8 +12,10 @@
public class ChatMsgResponse {
//채팅방 ID
private Long roomId;
private Long id;
//사용자(user)
private String from;
private String message;
private LocalDateTime sendAt;
private String avatarUrl; // 아바타 URL 필드 추가
}
Original file line number Diff line number Diff line change
@@ -15,4 +15,5 @@ public class ChatMsgDto {
private String nickname;
private String message;
private LocalDateTime sendAt;
private String avatarUrl; // avatarUrl 필드 추가
}
Original file line number Diff line number Diff line change
@@ -43,30 +43,29 @@ public ChatMsgResponse sendMessage(ChatMsgRequest message, Long userId, Long roo

ChatRoom chatRoom = chatRoomRepository.findChatRoomById(roomId)
.orElseThrow(() -> new CustomException(ErrorCode.NOT_FOUND_ROOM));
// 채팅 메시지 생성

ChatMsg chatMsg = ChatMsg.builder()
.message(message.getMessage())
.createdAt(LocalDateTime.now())
.user(findUser)
.chatRoom(chatRoom)
.build();

// Response message
// 응답 값으로 변환

ChatMsgResponse response = ChatMsgResponse.builder()
chatMessageRepository.save(chatMsg);

// Response message
// 응답값 변환
return ChatMsgResponse.builder()
.id(chatMsg.getId()) // chatMsgId 추가
.roomId(roomId)
.from(findUser.getNickname())
.from(findUser.getUsername())
.message(message.getMessage())
.sendAt(chatMsg.getCreatedAt())
.avatarUrl(findUser.getAvatarUrl()) // 아바타 URL 추가
.build();
chatMessageRepository.save(chatMsg);
return response;

}


@Transactional(readOnly = true)
@Override
public List<ChatMsgDto> getRoomChatMsgList(Long roomId, Long userId, Long lastId) {
@@ -83,10 +82,11 @@ public List<ChatMsgDto> getRoomChatMsgList(Long roomId, Long userId, Long lastId
for (ChatMsg chatMsg : chatMsgsList) {
ChatMsgDto build = ChatMsgDto.builder()
.chatMsgId(chatMsg.getId())
.nickname(chatMsg.getUser().getNickname())
.nickname(chatMsg.getUser().getUsername()) // nickname 대신 username 사용
.sendAt(chatMsg.getCreatedAt())
.message(chatMsg.getMessage())
.userId(chatMsg.getUser().getId())
.avatarUrl(chatMsg.getUser().getAvatarUrl()) // avatarUrl 추가
.build();
if (build.getSendAt().isAfter(joinDt)) {
chatMsgDtos.add(build);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//package cmf.commitField.domain.chat.chatRoom.controller.response;
//
//public class ChatRoomResponse {
//}
package cmf.commitField.domain.chat.chatRoom.controller.response;

public class ChatRoomResponse {
}
Original file line number Diff line number Diff line change
@@ -31,6 +31,10 @@ public class ApiV1NotiController {
private final NotiService notiService;
private final UserRepository userRepository;

// private final NotiWebSocketHandler notiWebSocketHandler;
private final ApplicationEventPublisher eventPublisher;


@GetMapping("")
public GlobalResponse<List<NotiDto>> getNoti(@AuthenticationPrincipal OAuth2User oAuth2User) {
String username = oAuth2User.getName();
Original file line number Diff line number Diff line change
@@ -10,4 +10,5 @@ public class UserChatInfoDto {
private String username;
private String nickname;
private String email;
private String avatarUrl;
}
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@ public UserChatInfoDto showUserChatInfo(String username) {
.email(user.getEmail())
.nickname(user.getNickname())
.username(user.getUsername())
.avatarUrl(user.getAvatarUrl())
.build();
}

Original file line number Diff line number Diff line change
@@ -200,8 +200,9 @@ private void handleChatMessage(WebSocketSession session, JsonNode jsonNode) {
wsMessage.put("type", "CHAT");
wsMessage.put("roomId", roomId);
wsMessage.put("userId", userId);
wsMessage.put("from", response.getFrom());
wsMessage.put("nickname", response.getFrom()); // 클라이언트 호환성을 위해 두 필드 모두 설정
wsMessage.put("from", user.getUsername()); // nickname 대신 username 사용
wsMessage.put("nickname", user.getUsername()); // nickname 대신 username 사용
wsMessage.put("avatarUrl", user.getAvatarUrl()); // 아바타 URL 추가
wsMessage.put("message", message);
wsMessage.put("sendAt", response.getSendAt().toString());

2 changes: 1 addition & 1 deletion src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ spring:
jpa:
open-in-view: false
hibernate:
ddl-auto: create
ddl-auto: update
autoconfigure: # 로컬에서 실행할 때는 Redis와 Session 설정을 제외
exclude:
- org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ spring:
jpa:
open-in-view: false
hibernate:
ddl-auto: create
ddl-auto: update
properties:
hibernate:
default_batch_fetch_size: 100