Skip to content

Commit

Permalink
update version to 4.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ghkdqhrbals committed Jan 26, 2023
1 parent 6894008 commit eb2ccda
Show file tree
Hide file tree
Showing 13 changed files with 204 additions and 74 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ confluent-hub-client-latest.tar.gz
./spring-chatting-auth-server/build
./spring-chatting-auth-server/build



/.idea
/app
/backups
/kafka-connect-jdbc
.idea/
*.iml
*.iws
4 changes: 2 additions & 2 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class Chatting {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Long id;

@ManyToOne
@JoinColumn(name = "ROOM_ID")
private Room room;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ public ResponseEntity<?> findFriend(@RequestParam("userId") String userId){
public ResponseEntity<?> findChatRecords(@RequestParam("roomId") Long roomId){
Room findRoom = roomService.findByRoomId(roomId);
List<Chatting> findChattings = chatService.findAllByRoomId(findRoom.getRoomId());
return ResponseEntity.ok(findChattings);
List<ChatRecord> response = findChattings.stream().map(c -> new ChatRecord(c.getId(), c.getRoom().getRoomId(), c.getSendUser().getUserId(), c.getSendUser().getUserName(), c.getMessage(), c.getCreatedDate(), c.getCreatedTime())).collect(Collectors.toList());

return ResponseEntity.ok(response);
}

// 특정 채팅 조회
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package chatting.chat.web.kafka.dto;


import lombok.Getter;
import lombok.Setter;

import java.time.LocalDate;
import java.time.LocalTime;

@Getter
@Setter
public class ChatRecord {
private Long id;
private Long roomId;
private String sendUserId;
private String sendUserName;
private String message;
private LocalDate createdDate;
private LocalTime createdTime;

public ChatRecord(Long id, Long roomId, String sendUserId, String sendUserName, String message, LocalDate createdDate, LocalTime createdTime) {
this.id = id;
this.roomId = roomId;
this.sendUserId = sendUserId;
this.sendUserName = sendUserName;
this.message = message;
this.createdDate = createdDate;
this.createdTime = createdTime;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package chatting.chat.web.dto;


import lombok.Getter;
import lombok.Setter;

import java.time.LocalDate;
import java.time.LocalTime;

@Getter
@Setter
public class ChatRecord {
private Long id;
private Long roomId;
private String sendUserId;
private String sendUserName;
private String message;
private LocalDate createdDate;
private LocalTime createdTime;

public ChatRecord() {
}

public ChatRecord(Long id, Long roomId, String sendUserId, String sendUserName, String message, LocalDate createdDate, LocalTime createdTime) {
this.id = id;
this.roomId = roomId;
this.sendUserId = sendUserId;
this.sendUserName = sendUserName;
this.message = message;
this.createdDate = createdDate;
this.createdTime = createdTime;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,14 @@ public class RequestAddChatMessageDTO {
private String writer;
private String writerId;
private String message;

public RequestAddChatMessageDTO() {
}

public RequestAddChatMessageDTO(Long roomId, String writer, String writerId, String message) {
this.roomId = roomId;
this.writer = writer;
this.writerId = writerId;
this.message = message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,26 +230,59 @@ public String createRoomForm(@SessionAttribute(name = SessionConst.LOGIN_MEMBER,
return "redirect:/user/rooms";
}

// 패킷의 크기 또한 신경써야될듯
// 채팅방
@GetMapping("/chat")
public String chattingRoom(@RequestParam Long roomId, Model model, HttpSession session) {
User user = (User) session.getAttribute(SessionConst.LOGIN_MEMBER);
public String chattingRoom(@SessionAttribute(name = SessionConst.LOGIN_MEMBER, required = true) User user,
@RequestParam Long roomId, @RequestParam String roomName, Model model) {

try {

Flux<ChatRecord> response = webClient.mutate()
.build()
.get()
.uri("/chat/chats?roomId="+roomId)
.retrieve()
.onStatus(
HttpStatus::is4xxClientError,
r -> r.bodyToMono(ErrorResponse.class).map(CustomThrowableException::new))
.bodyToFlux(ChatRecord.class);

// Participant에서 Room참여자들 정보를 가져와 모델에 전달
Participant findParticipant = userService.findByRoomIdAndUserId(roomId,user.getUserId());
model.addAttribute("user", user);
List<ChatRecord> records = response.collect(Collectors.toList())
.share().block();

// 유저가 참여하고있는 채팅방정보를 DTO에 담아 모델에 전달
RoomInfoDTO roomInfoDTO = new RoomInfoDTO();
roomInfoDTO.setName(findParticipant.getRoomName());
roomInfoDTO.setRoomId(roomId);
model.addAttribute("room", roomInfoDTO);
model.addAttribute("roomId",roomId);
model.addAttribute("roomName",roomName);
model.addAttribute("user", user);
model.addAttribute("records",records);

// 입장한 채팅방의 채팅메세지들을 가져와 모델에 전달
List<Chatting> findChattings = chatService.findAllByRoomId(roomId);
model.addAttribute("records",findChattings);
}catch (CustomThrowableException e){
log.info(e.getErrorResponse().getCode());
log.info(e.getErrorResponse().getMessage());
return "users/chat";
}

return "/users/chat";
return "users/chat";



//
//
// // Participant에서 Room참여자들 정보를 가져와 모델에 전달
// Participant findParticipant = userService.findByRoomIdAndUserId(roomId,user.getUserId());
// model.addAttribute("user", user);
//
// // 유저가 참여하고있는 채팅방정보를 DTO에 담아 모델에 전달
// RoomInfoDTO roomInfoDTO = new RoomInfoDTO();
// roomInfoDTO.setName(findParticipant.getRoomName());
// roomInfoDTO.setRoomId(roomId);
// model.addAttribute("room", roomInfoDTO);
//
// // 입장한 채팅방의 채팅메세지들을 가져와 모델에 전달
// List<Chatting> findChattings = chatService.findAllByRoomId(roomId);
// model.addAttribute("records",findChattings);
//
// return "/users/chat";
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
package chatting.chat.web.websocket;

import chatting.chat.web.dto.ChatMessage;
import chatting.chat.web.dto.ChatRecord;
import chatting.chat.web.dto.RequestAddChatRoomDTO;
import chatting.chat.web.error.CustomThrowableException;
import chatting.chat.web.error.ErrorResponse;
import chatting.chat.web.kafka.dto.RequestAddChatMessageDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.stream.Collectors;

@Controller
@RequiredArgsConstructor
@Slf4j
public class StompChatController {

private WebClient webClient;

@Value("${backend.api.gateway}")
private String backEntry;

@PostConstruct
public void initWebClient() {
this.webClient = WebClient.create(backEntry);
}

// STOMP 템플릿
private final SimpMessagingTemplate template;

Expand All @@ -26,6 +49,25 @@ public void enter(ChatMessage message){
@MessageMapping(value = "/chat/message")
public void message(ChatMessage message){
log.info(message.getMessage());

try {
webClient.mutate()
.build()
.post()
.uri("/chat/chat")
.bodyValue(new RequestAddChatMessageDTO(message.getRoomId(), message.getWriter(), message.getWriterId(), message.getMessage()))
.retrieve()
.onStatus(
HttpStatus::is4xxClientError,
r -> r.bodyToMono(ErrorResponse.class).map(CustomThrowableException::new))
.bodyToMono(String.class).block();

}catch (CustomThrowableException e){
log.info(e.getErrorResponse().getCode());
log.info(e.getErrorResponse().getMessage());
}

template.convertAndSend("/sub/chat/room/" + message.getRoomId(), message); // Direct send topic to stomp
// kafka topic send
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


.msg-r{
background-color: #fae4a7;
background-color: #d4ffcf;
box-shadow: 0px 2px 2.2px #818181;
padding-right: 5px;
padding-left: 5px;
Expand All @@ -11,11 +11,11 @@
text-align: right;
border-radius: 5px;
margin-left: auto;
margin-right: 0;
margin-right: 10px;
}

.msg-l{
background-color: #ffffff;
background-color: #fff8d6;
box-shadow: 0px 2px 2.2px #818181;
padding-right: 5px;
padding-left: 5px;
Expand All @@ -24,7 +24,7 @@
width: fit-content;
text-align: right;
border-radius: 5px;
margin-left: 0;
margin-left: 10px;
margin-right: auto;
}

Expand All @@ -46,6 +46,11 @@
grid-auto-flow: row;
}

.m-tb-5{
margin-top: 10px;
margin-bottom: 10px;
}

.item-h-50{
max-height: 300px;
}
Expand Down
Loading

0 comments on commit eb2ccda

Please sign in to comment.