-
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 |
---|---|---|
@@ -1,18 +1,11 @@ | ||
package com.market.server.controller; | ||
|
||
import com.market.server.dto.RoomDTO; | ||
import com.market.server.service.ChattingService; | ||
import io.swagger.annotations.Api; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.servlet.ModelAndView; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
@@ -22,8 +15,6 @@ | |
@Log4j2 | ||
public class ChattingController { | ||
|
||
static int roomNumber = 0; | ||
private ChattingResponse chattingResponse; | ||
private final ChattingService chattingService; | ||
|
||
@Autowired | ||
|
@@ -51,10 +42,11 @@ public ModelAndView room() { | |
*/ | ||
@PostMapping("/rooms") | ||
public @ResponseBody | ||
List<RoomDTO> createRoom(@RequestParam HashMap<Object, Object> params, ChattingRequest chattingRequest) { | ||
List<RoomDTO> createRoom(@RequestParam HashMap<String, String> params) { | ||
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. 유지보수성 측면에서 Map을 쓰는게 좋을지 고민해주세요~ 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. 유지보수성 측면에서 코드 가 명시적으로 보이기 위해 |
||
String roomName = (String) params.get("roomName"); | ||
RoomDTO roomDTO = 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(); | ||
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. RoomDTO가 정상적으로 등록되지 않았다면 같은값을 반환할 수도 있습니다. |
||
roomDTO = RoomDTO.builder() | ||
.roomNumber(++roomNumber) | ||
.roomName(roomName) | ||
|
@@ -73,7 +65,7 @@ List<RoomDTO> createRoom(@RequestParam HashMap<Object, Object> params, ChattingR | |
*/ | ||
@GetMapping("/rooms") | ||
public @ResponseBody | ||
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. 변경하겠습니다. |
||
List<RoomDTO> getRoom(@RequestParam HashMap<Object, Object> params, @RequestBody RoomDTO roomDTO) { | ||
List<RoomDTO> getRoom(@RequestBody RoomDTO roomDTO) { | ||
return chattingService.getRooms(roomDTO); | ||
} | ||
|
||
|
@@ -83,37 +75,19 @@ List<RoomDTO> getRoom(@RequestParam HashMap<Object, Object> params, @RequestBody | |
* @return | ||
*/ | ||
@GetMapping("/chatting") | ||
public ModelAndView moveRoom(@RequestParam HashMap<Object, Object> params) { | ||
public ModelAndView moveRoom(@RequestParam HashMap<String, String> params) { | ||
ModelAndView mv = new ModelAndView(); | ||
int roomNumber = Integer.parseInt((String) params.get("roomNumber")); | ||
|
||
List<RoomDTO> new_list = chattingService.getRooms(null).stream().filter(o->o.getRoomNumber()==roomNumber).collect(Collectors.toList()); | ||
if(new_list != null && new_list.size() > 0) { | ||
List<RoomDTO> new_list = chattingService.getRooms(null).stream().filter(o -> o.getRoomNumber() == roomNumber).collect(Collectors.toList()); | ||
if (new_list != null && new_list.size() > 0) { | ||
mv.addObject("roomName", params.get("roomName")); | ||
mv.addObject("roomNumber", params.get("roomNumber")); | ||
mv.setViewName("chat"); | ||
}else { | ||
} else { | ||
mv.setViewName("room"); | ||
} | ||
return mv; | ||
} | ||
|
||
// -------------- response 객체 -------------- | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
private static class ChattingResponse { | ||
private List<RoomDTO> roomDTOList; | ||
} | ||
|
||
// -------------- request 객체 -------------- | ||
|
||
@Setter | ||
@Getter | ||
private static class ChattingRequest { | ||
private int roomNumber; | ||
private String roomName; | ||
private RoomDTO.Status status; | ||
private Date updatetime; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# mysql | ||
spring.datasource.url=jdbc:mysql://localhost:3307/market?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Seoul | ||
spring.datasource.username=root | ||
spring.datasource.password=wnstjr1026 | ||
|
||
# message | ||
spring.messages.basename=i18n/exception | ||
spring.messages.encoding=UTF-8 | ||
|
||
# redis | ||
spring.cache.type=redis | ||
spring.data.redis.repositories.enabled=true | ||
market.server.redis.host=localhost | ||
market.server.redis.port=6379 | ||
market.server.redis.password= | ||
|
||
# expire | ||
expire.defaultTime=36288000 | ||
|
||
#JSP, HTML ModelAndView Path Setting | ||
spring.mvc.view.prefix=/WEB-INF/jsp/ | ||
spring.mvc.view.suffix=.jsp |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# mysql | ||
spring.datasource.url=jdbc:mysql://localhost:3307/market?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Seoul | ||
spring.datasource.username=root | ||
spring.datasource.password=wnstjr1026 | ||
|
||
# message | ||
spring.messages.basename=i18n/exception | ||
spring.messages.encoding=UTF-8 | ||
|
||
# redis | ||
spring.cache.type=redis | ||
spring.data.redis.repositories.enabled=true | ||
market.server.redis.host=localhost | ||
market.server.redis.port=6379 | ||
market.server.redis.password= | ||
|
||
# expire | ||
expire.defaultTime=36288000 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,8 @@ | ||
# mysql | ||
spring.datasource.url=jdbc:mysql://localhost:3307/market?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Seoul | ||
spring.datasource.username=root | ||
spring.datasource.password=wnstjr1026 | ||
|
||
# message | ||
spring.messages.basename=i18n/exception | ||
spring.messages.encoding=UTF-8 | ||
|
||
# redis | ||
spring.cache.type=redis | ||
spring.data.redis.repositories.enabled=true | ||
market.server.redis.host=localhost | ||
market.server.redis.port=6379 | ||
market.server.redis.password= | ||
|
||
# expire | ||
expire.defaultTime=36288000 | ||
|
||
# tomcat | ||
# Server | ||
server.port=8888 | ||
|
||
#JSP, HTML ModelAndView Path Setting | ||
spring.mvc.view.prefix=/WEB-INF/jsp/ | ||
spring.mvc.view.suffix=.jsp | ||
# profile name = local, dev, prod | ||
spring.profiles.active=dev | ||
|
||
# session | ||
spring.session.store-type=redis |
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.
생성자주입시에 이 어노테이션이 필요할까요?
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.
생성자 주입시 단일 생성자(생성자가 2개 미만)인 경우에는 @Autowired 어노테이션 붙이지 않아도 주입됩니다.