Skip to content
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.

#30 웹소켓을 이용한 1:1 채팅 구현 #32

Open
wants to merge 25 commits into
base: feature/29
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f455586
#30 웹소켓을 이용한 1:1 채팅 구현
junshock5 Aug 24, 2020
5fabb1d
#30 웹소켓을 이용한 1:1 채팅 구현
junshock5 Aug 24, 2020
bf32376
#30 웹소켓을 이용한 1:1 채팅 구현
junshock5 Aug 25, 2020
4daebd0
#30 웹소켓을 이용한 1:1 채팅 구현
junshock5 Aug 25, 2020
c19f1ba
#30 웹소켓을 이용한 1:1 채팅 구현
junshock5 Aug 25, 2020
4e73acc
#30 웹소켓을 이용한 1:1 채팅 구현
junshock5 Aug 27, 2020
cfdde06
Merge branch 'develop' into feature/30
junshock5 Aug 27, 2020
88e212c
Merge branch 'feature/29' into feature/30
junshock5 Aug 27, 2020
18c4ad4
#30 웹소켓을 이용한 1:1 채팅 구현
junshock5 Aug 28, 2020
f56371c
Merge branch 'feature/30' of https://github.com/f-lab-edu/used-market…
junshock5 Aug 28, 2020
fc9f045
#30 웹소켓을 이용한 1:1 채팅 구현
junshock5 Aug 31, 2020
bd8c3b2
#30 웹소켓을 이용한 1:1 채팅 구현
junshock5 Aug 31, 2020
5a4efeb
#30 웹소켓을 이용한 1:1 채팅 구현
junshock5 Sep 1, 2020
c5a76b7
#30 웹소켓을 이용한 1:1 채팅 구현
junshock5 Sep 1, 2020
6e23408
attachFile 잘못올라간거 삭제
junshock5 Sep 1, 2020
f4f1fad
#30 웹소켓을 이용한 1:1 채팅 구현
junshock5 Sep 3, 2020
8d887b5
#30 웹소켓을 이용한 1:1 채팅 구현
junshock5 Sep 3, 2020
5fb8d10
#30 웹소켓을 이용한 1:1 채팅 구현
junshock5 Sep 3, 2020
7d4b6ca
#30 웹소켓을 이용한 1:1 채팅 구현
junshock5 Sep 6, 2020
825152d
Merge branch 'feature/29' into feature/30
junshock5 Sep 8, 2020
e4e31df
#30 웹소켓을 이용한 1:1 채팅 구현
junshock5 Sep 12, 2020
f1d226c
Merge branch 'feature/30' of https://github.com/f-lab-edu/used-market…
junshock5 Sep 12, 2020
05eba04
캐싱 만료시간 추가 , DateUtil 필요없는 로그 삭제
junshock5 Sep 12, 2020
fdb1bf9
Merge branch 'feature/29' into feature/30
junshock5 Sep 12, 2020
9717040
#30 웹소켓을 이용한 1:1 채팅 구현
junshock5 Sep 15, 2020
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
29 changes: 16 additions & 13 deletions src/main/java/com/market/server/controller/ChattingController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import com.market.server.service.ChattingService;
import io.swagger.annotations.Api;
import lombok.extern.log4j.Log4j2;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -40,19 +40,22 @@ public ModelAndView room() {
*/
@PostMapping("/rooms")
@ResponseBody
public List<RoomDTO> createRoom(@RequestParam HashMap<String, String> params) {
String roomName = (String) params.get("roomName");
RoomDTO roomDTO = null;
public List<RoomDTO> createRoom(RoomDTO roomDTO, Model model) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model을 꼭 쓸 필요가 있을까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Controller에서 생성한 데이터를 담아서 View로 전달할 때 사용하는 객체로 roomDTO에 정보가 다있어서
삭제하겠습니다.

model.addAttribute("roomDTO", roomDTO);
String roomName = roomDTO.getRoomName();

RoomDTO room = null;
if (roomName != null && !roomName.trim().equals("")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

roomName이 null이면 NPE가 날 것 같네요

int roomNumber = chattingService.getLastRoomNumber();
roomDTO = RoomDTO.builder()
int roomNumber = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아래에서 아무 조건없이 바로 할당하는데 여기에 0을 할당하신 이유가 있으신가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변경하겠습니다.

roomNumber = chattingService.getLastRoomNumber();
room = RoomDTO.builder()
.roomNumber(++roomNumber)
.roomName(roomName)
.build();
chattingService.register(roomDTO);
chattingService.register(room);
}

return chattingService.getAllRooms(roomDTO);
return chattingService.getAllRooms(room);
}

/**
Expand All @@ -73,19 +76,19 @@ public List<RoomDTO> getRoom(@RequestBody RoomDTO roomDTO) {
* @return
*/
@GetMapping("/chatting")
public ModelAndView moveRoom(@RequestParam HashMap<String, String> params) {
public ModelAndView moveRoom(RoomDTO roomDTO, Model model) {
model.addAttribute("roomDTO", roomDTO);
ModelAndView mv = new ModelAndView();
int roomNumber = Integer.parseInt((String) params.get("roomNumber"));
int roomNumber = roomDTO.getRoomNumber();

List<RoomDTO> new_list = chattingService.getAllRooms(null).stream().filter(o -> o.getRoomNumber() == roomNumber).collect(Collectors.toList());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기는 카멜케이스가 지켜지지 않았네요

if (new_list != null && new_list.size() > 0) {
mv.addObject("roomName", params.get("roomName"));
mv.addObject("roomNumber", params.get("roomNumber"));
mv.addObject("roomName", roomDTO.getRoomName());
mv.addObject("roomNumber", roomDTO.getRoomNumber());
mv.setViewName("chat");
} else {
mv.setViewName("room");
}
return mv;
}

}
2 changes: 1 addition & 1 deletion src/main/java/com/market/server/mapper/ChattingMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
public interface ChattingMapper {
public int register(RoomDTO roomDTO);
public List<RoomDTO> selectRooms(String sortStatus, int searchCount, int pagingStartOffset);
public int getLastRoomNumber();
public Integer getLastRoomNumber();
}
10 changes: 7 additions & 3 deletions src/main/java/com/market/server/service/ChattingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@ public void register(RoomDTO roomDTO) {
public List<RoomDTO> getAllRooms(RoomDTO roomDTO) {
List<RoomDTO> roomDTOList = null;
if (roomDTO == null)
roomDTOList = chattingMapper.selectRooms("NEWEST", 20, 0);
roomDTOList = chattingMapper.selectRooms("NEWEST", 30, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이런 값은 하드코딩보다는 config로 뺄 수 있지 않을까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ChattingService에 상수로 정의하겠습니다.

else
roomDTOList = chattingMapper.selectRooms(roomDTO.getSortStatus().toString(), roomDTO.getSearchCount(), roomDTO.getPagingStartOffset());
return roomDTOList;
}

public int getLastRoomNumber() {
return chattingMapper.getLastRoomNumber();
public Integer getLastRoomNumber() {
Integer result = -2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거도 코드가 이상합니다~

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변경하겠습니다.

result = chattingMapper.getLastRoomNumber();
if (result == null)
result = 0;
return result;
}

}
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/banner.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

____. _________.__ __ .________
| |__ __ ____ / _____/| |__ ____ ____ | | __ | ____/
| | | \/ \ \_____ \ | | \ / _ \_/ ___\| |/ / |____ \
/\__| | | / | \/ \| Y ( <_> ) \___| < / \
\________|____/|___| /_______ /|___| /\____/ \___ >__|_ \/______ /
\/ \/ \/ \/ \/ \/
application.title:${application.titlke}