-
Notifications
You must be signed in to change notification settings - Fork 4
#30 웹소켓을 이용한 1:1 채팅 구현 #32
base: feature/29
Are you sure you want to change the base?
Changes from 1 commit
f455586
5fabb1d
bf32376
4daebd0
c19f1ba
4e73acc
cfdde06
88e212c
18c4ad4
f56371c
fc9f045
bd8c3b2
5a4efeb
c5a76b7
6e23408
f4f1fad
8d887b5
5fb8d10
7d4b6ca
825152d
e4e31df
f1d226c
05eba04
fdb1bf9
9717040
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
||
|
@@ -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) { | ||
model.addAttribute("roomDTO", roomDTO); | ||
String roomName = roomDTO.getRoomName(); | ||
|
||
RoomDTO room = null; | ||
if (roomName != null && !roomName.trim().equals("")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
int roomNumber = chattingService.getLastRoomNumber(); | ||
roomDTO = RoomDTO.builder() | ||
int roomNumber = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아래에서 아무 조건없이 바로 할당하는데 여기에 0을 할당하신 이유가 있으신가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
|
||
/** | ||
|
@@ -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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이런 값은 하드코딩보다는 config로 뺄 수 있지 않을까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이거도 코드가 이상합니다~ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 변경하겠습니다. |
||
result = chattingMapper.getLastRoomNumber(); | ||
if (result == null) | ||
result = 0; | ||
return result; | ||
} | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
____. _________.__ __ .________ | ||
| |__ __ ____ / _____/| |__ ____ ____ | | __ | ____/ | ||
| | | \/ \ \_____ \ | | \ / _ \_/ ___\| |/ / |____ \ | ||
/\__| | | / | \/ \| Y ( <_> ) \___| < / \ | ||
\________|____/|___| /_______ /|___| /\____/ \___ >__|_ \/______ / | ||
\/ \/ \/ \/ \/ \/ | ||
application.title:${application.titlke} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
model을 꼭 쓸 필요가 있을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Controller에서 생성한 데이터를 담아서 View로 전달할 때 사용하는 객체로 roomDTO에 정보가 다있어서
삭제하겠습니다.