Skip to content

Commit

Permalink
CD.YML update
Browse files Browse the repository at this point in the history
  • Loading branch information
LminWoo99 committed Nov 17, 2023
1 parent 9959b73 commit 43aac2d
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 32 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:

script: |
docker pull ${{ secrets.DOCKER_USERNAME }}/chat
docker stop $(docker ps -a -q)
docker rm $(docker ps --filter 'status=exited' -a -q)
docker stop $(docker ps -a -q | grep -v $(docker-compose ps -q kurento)) # Kurento 서비스를 제외한 다른 모든 컨테이너 중지
docker rm $(docker ps --filter 'status=exited' -a -q) # 종료된(exited) 상태의 모든 컨테이너 삭제
docker-compose up -d
docker image prune -a -f
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public void registerStompEndpoints(StompEndpointRegistry registry) {
.addInterceptors(new HttpSessionHandshakeInterceptor())
.withSockJS(); // SocketJS 를 연결한다는 설정
}

@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
// 메시지를 구독하는 요청 url => 즉 메시지 받을 때
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public Docket api() {
public ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("SpringBoot Rest API Documentation")
.description("화상채팅 서비스 -copyright@Lee")
.description("화상채팅서비스 -copyright@LeeMinWoo")
.version("0.1")
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public KurentoHandler kurentoHandler(){
}
@Bean
public KurentoClient kurentoClient() {
return KurentoClient.create();
String kurentoUrl = "ws://52.78.190.79:8888/kurento";
return KurentoClient.create(kurentoUrl);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
Expand All @@ -16,6 +17,7 @@

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Controller
Expand All @@ -24,43 +26,39 @@
@RequestMapping("/chat")
public class ChatRoomController {
private final ChatRoomService chatRoomService;
@GetMapping("")
@ApiOperation(value = "채팅방 리스트 조회 ", notes = "전체 채팅방 목록을 조회한다")
public String chatRoomList(Model model, @AuthenticationPrincipal SessionUser sessionUser) {
model.addAttribute("list",chatRoomService.findAllRooms());
log.info("채팅방 설정 =" + chatRoomService.findAllRooms());
// 세션에 저장된 로그인 정보를 모델에 추가
if (sessionUser != null) {
model.addAttribute("user", sessionUser.getAttributes());
}
return "roomlist";

@GetMapping("")
@ApiOperation(value = "채팅방 리스트 조회 ", notes = "전체 채팅방 목록을 조회한다")
public String chatRoomList(Model model, @AuthenticationPrincipal SessionUser sessionUser) {
model.addAttribute("list", chatRoomService.findAllRooms());
log.info("채팅방 설정 =" + chatRoomService.findAllRooms());
// 세션에 저장된 로그인 정보를 모델에 추가
if (sessionUser != null) {
model.addAttribute("user", sessionUser.getAttributes());
}
// @GetMapping("/json")
// @ApiOperation(value = "채팅방 리스트 조회 json 반환", notes = "전체 채팅방 목록을 조회한다")
// @ResponseBody
// public List<ChatRoom> chatRoomList() {
// return chatRoomService.findAllRooms();
//
// }
return "roomlist";
}

@PostMapping("/createRoom")
@ApiOperation(value = "채팅방 생성 ", notes = "채팅방을 생성한다")
public String createRoom(@RequestParam("roomName") String name, @RequestParam("roomPwd")String roomPwd, @RequestParam("secretCheck")String secretCheck,
@RequestParam(value = "maxUserCnt", defaultValue = "100")String maxUserCnt, RedirectAttributes rttr) {
@RequestParam(value = "maxUserCnt")String maxUserCnt, RedirectAttributes rttr) {
ChatRoom room = chatRoomService.createChatRoom(name, roomPwd, Boolean.parseBoolean(secretCheck), Integer.parseInt(maxUserCnt));
rttr.addFlashAttribute("roomName", room);
return "redirect:/chat";
}

@GetMapping("/room")
@ApiOperation(value = "채팅방 입장 ", notes = "파라미터로 넘어오는 ROOMID 기준으로 채팅방을 찾음 ")
public String roomDetail(Model model, String roomId){
public String roomDetail(Model model, String roomId) {
log.info("roomId {}", roomId);
ChatRoom chatRoom = chatRoomService.findRoomById(roomId);
model.addAttribute("room", chatRoom);

if (chatRoom.getChatType().equals(ChatType.MSG)) {
return "chatroom";
}else{
log.info("화상채팅 유저 확인 :"+chatRoom.getUserRtcList());
} else {
log.info("화상채팅 유저 확인 :" + chatRoom.getUserRtcList());
// model.addAttribute("uuid", UUID.randomUUID().toString());
String uuid = UUID.randomUUID().toString().split("-")[0];
model.addAttribute("uuid", uuid);
Expand All @@ -69,31 +67,56 @@ public String roomDetail(Model model, String roomId){
return "kurentoroom";
}
}

@PostMapping("/confirmPwd/{roomId}")
@ResponseBody
@ApiOperation(value = "채팅방 비밀번호 체크 ", notes = "파라미터로 넘어오는 ROOMID 기준으로 채팅방 비밀 번호 체크 ")
public boolean confirmPwd(@PathVariable String roomId, @RequestParam String roomPwd){
public boolean confirmPwd(@PathVariable String roomId, @RequestParam String roomPwd) {

// 넘어온 roomId 와 roomPwd 를 이용해서 비밀번호 찾기
// 찾아서 입력받은 roomPwd 와 room pwd 와 비교해서 맞으면 true, 아니면 false
return chatRoomService.confirmPwd(roomId, roomPwd);
}

@GetMapping("/delRoom/{roomId}")
@ApiOperation(value = "채팅방 삭제 ", notes = "파라미터로 넘어오는 ROOMID 기준으로 채팅방 삭제 ")
public String deleteChatRoom(@PathVariable String roomId){
public String deleteChatRoom(@PathVariable String roomId) {

// roomId 기준으로 chatRoomMap 에서 삭제, 해당 채팅룸 안에 있는 사진 삭제
chatRoomService.deleteChatRoom(roomId);

return "redirect:/";

return "redirect:/chat";
}

// 유저 카운트
@GetMapping("/chkUserCnt/{roomId}")
@ResponseBody
@ApiOperation(value = "채팅방 유저 카운트 ", notes = "사용자가 설정한 최대 인원 안 넘는지 체크 ")
public boolean checkUserCnt(@PathVariable String roomId){
public boolean checkUserCnt(@PathVariable String roomId) {
return chatRoomService.checkRoomUserCnt(roomId);
}

@PutMapping("/updateRoomName/{roomId}")
@ApiOperation(value = "채팅방 이름 변경", notes = "파라미터로 넘어오는 ROOMID 기준으로 채팅방 이름 변경")
public ResponseEntity<?> updateRoomName(@PathVariable String roomId, @RequestBody Map<String, String> body) {
String roomName = body.get("roomName");
chatRoomService.updateRoomName(roomId, roomName);
return ResponseEntity.ok().build(); // JSON 형태의 응답을 보내거나, 상태 코드만 보냅니다.
}

@PutMapping("/updateRoomPwd/{roomId}")
@ApiOperation(value = "채팅방 비번 변경", notes = "파라미터로 넘어오는 ROOMID 기준으로 채팅방 비번 변경")
public ResponseEntity<?> updateRoomPwd(@PathVariable String roomId, @RequestBody Map<String, String> body) {
String roomPwd = body.get("roomPwd");
chatRoomService.updateRoomPassWord(roomId, roomPwd);
return ResponseEntity.ok().build();
}
@PutMapping("/updateRoomSecret/{roomId}")
@ApiOperation(value = "채팅방 잠금 상태 변경", notes = "파라미터로 넘어오는 ROOMID 기준으로 채팅방 잠금/오픈 상태 변경")
public ResponseEntity<?> updateRoomSecretCheck(@PathVariable String roomId, @RequestBody Map<String, String> body) {
String secretCheck = body.get("secretCheck");
chatRoomService.updateRoomSecretCheck(roomId, secretCheck);
return ResponseEntity.ok().build();
}
}
2 changes: 2 additions & 0 deletions src/main/java/com/example/VideoChatting/dto/ChatDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public ChatDto(ChatMessage chatMessage) {
this.roomId = chatMessage.getChatRoom().getRoomId();
this.message = chatMessage.getMessage();
this.s3DataUrl= chatMessage.getS3DataUrl();
this.fileName= chatMessage.getFileName();
this.fileDir = chatMessage.getFileDir();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,24 @@

import com.example.VideoChatting.entity.ChatRoom;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface ChatRoomRepository extends JpaRepository<ChatRoom, Long> {
ChatRoom findByRoomId(String roomId);

boolean existsByRoomName(String roomName);

@Modifying
@Query("update ChatRoom t set t.roomName = :roomName where t.roomId = :roomId")
void updateRoomName(@Param("roomId") String roomId, @Param("roomName") String roomName);
@Modifying
@Query("update ChatRoom t set t.roomPwd = :roomPwd where t.roomId = :roomId")
void updateRoomPwd(@Param("roomId") String roomId, @Param("roomPwd") String roomPwd);
@Modifying
@Query("update ChatRoom t set t.secretCheck = :secretCheck where t.roomId = :roomId")
void updateRoomSecretCheck(@Param("roomId")String roomId, @Param("secretCheck")Boolean secretCheck);
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,21 @@ public void deleteChatRoom(String roomId) {
}


public void updateRoomName(String roomId, String roomName) {
chatRoomRepository.updateRoomName(roomId, roomName);
opsHashChatRoom.delete(CHAT_ROOMS, roomId);
opsHashChatRoom.put(CHAT_ROOMS, roomId, chatRoomRepository.findByRoomId(roomId));

}
public void updateRoomPassWord(String roomId, String roomPwd) {
chatRoomRepository.updateRoomPwd(roomId, roomPwd);
opsHashChatRoom.delete(CHAT_ROOMS, roomId);
opsHashChatRoom.put(CHAT_ROOMS, roomId, chatRoomRepository.findByRoomId(roomId));
}

public void updateRoomSecretCheck(String roomId, String secretCheck) {
chatRoomRepository.updateRoomSecretCheck(roomId, Boolean.valueOf(secretCheck));
opsHashChatRoom.delete(CHAT_ROOMS, roomId);
opsHashChatRoom.put(CHAT_ROOMS, roomId, chatRoomRepository.findByRoomId(roomId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@

import static org.hamcrest.Matchers.hasSize;
import static org.mockito.Mockito.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

Expand Down Expand Up @@ -220,4 +219,62 @@ void checkUserCnt() throws Exception{

verify(chatRoomService, times(1)).checkRoomUserCnt(roomId);
}
@Test
@DisplayName("이름 수정 컨트롤러 테스트")
void updateRoomNameTest() throws Exception{
//given
String roomName="room1";
String roomPwd = "1234";
ChatRoom createdChatRoom = new ChatRoom().create(roomName, roomPwd, Boolean.TRUE, 50);
String updateRoomName = "room2";

String roomId = createdChatRoom.getRoomId();
//when
ResultActions perform = mockMvc.perform(put("/chat/updateRoomName/" + roomId)
.contentType(MediaType.APPLICATION_JSON)
.content("{\"roomName\":\"" + updateRoomName + "\"}"));
//then
perform.andExpect(status().isOk());
verify(chatRoomService, times(1)).updateRoomName(roomId, updateRoomName);
}
@Test
@DisplayName("패스워드 수정 컨트롤러 테스트")
void updateRoomPwdTest() throws Exception{
//given
String roomName="room1";
String roomPwd = "1234";

ChatRoom createdChatRoom = new ChatRoom().create(roomName, roomPwd, Boolean.TRUE, 50);
String updateRoomPwd = "1234";
String roomId = createdChatRoom.getRoomId();

//when
mockMvc.perform(put("/chat/updateRoomPwd/" + roomId)
.contentType(MediaType.APPLICATION_JSON)
.content("{\"roomPwd\":\"" + updateRoomPwd + "\"}"))
.andExpect(status().isOk());

//then
verify(chatRoomService, times(1)).updateRoomPassWord(roomId, updateRoomPwd);
}
@Test
@DisplayName("잠금 상태 수정 컨트롤러 테스트")
void updateRoomSecretCheckTest() throws Exception{
//given
String roomName="room1";
String roomPwd = "1234";
String secretCheck = "true";

ChatRoom createdChatRoom = new ChatRoom().create(roomName, roomPwd, Boolean.valueOf(secretCheck), 50);
String updateSecretCheck = "false";
String roomId = createdChatRoom.getRoomId();

//when
mockMvc.perform(put("/chat/updateRoomSecret/" + roomId)
.contentType(MediaType.APPLICATION_JSON)
.content("{\"secretCheck\":\"" + updateSecretCheck + "\"}"))
.andExpect(status().isOk());
//then
verify(chatRoomService, times(1)).updateRoomSecretCheck(roomId, updateSecretCheck);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -340,5 +340,59 @@ void confirmPwdFailTest() throws Exception{
//then
assertThat(check).isEqualTo(Boolean.FALSE);
}
@Test
@DisplayName("채팅방 이름 수정 단위 테스트")
void updateRoomNameTest() throws Exception{
//given
String roomName = "채팅방 이름 수정";
ChatRoom createdChatRoom = chatRoomService.createChatRoom(roomName, "1234", Boolean.TRUE, 1);
String updateRoomName = "수정된 채팅방 이름";

when(chatRoomRepository.findByRoomId(createdChatRoom.getRoomId())).thenReturn(createdChatRoom);
doNothing().when(chatRoomRepository).updateRoomName(anyString(), anyString());
//when
chatRoomService.updateRoomName(createdChatRoom.getRoomId(), updateRoomName);

//then

verify(chatRoomRepository, times(1)).updateRoomName(createdChatRoom.getRoomId(), updateRoomName);

}
@Test
@DisplayName("채팅방 패스워드 수정 단위 테스트")
void updateRoomPasswordTest() throws Exception{
//given
String roomName = "채팅방 pw 수정";
ChatRoom createdChatRoom = chatRoomService.createChatRoom(roomName, "1234", Boolean.TRUE, 1);
String updateRoomPw = "수정된 채팅방 pw";

when(chatRoomRepository.findByRoomId(createdChatRoom.getRoomId())).thenReturn(createdChatRoom);
doNothing().when(chatRoomRepository).updateRoomPwd(anyString(), anyString());
//when
chatRoomService.updateRoomPassWord(createdChatRoom.getRoomId(), updateRoomPw);

//then

verify(chatRoomRepository, times(1)).updateRoomPwd(createdChatRoom.getRoomId(), updateRoomPw);

} @Test
@DisplayName("채팅방 잠금 상태 수정 단위 테스트")
void updateRoomSecretCheckTest() throws Exception{
//given
String roomName = "채팅방 상태 수정";
ChatRoom createdChatRoom = chatRoomService.createChatRoom(roomName, "1234", Boolean.TRUE, 1);
String updateSecretCheck = "true";

when(chatRoomRepository.findByRoomId(createdChatRoom.getRoomId())).thenReturn(createdChatRoom);
doNothing().when(chatRoomRepository).updateRoomSecretCheck(anyString(), anyBoolean());
//when
chatRoomService.updateRoomSecretCheck(createdChatRoom.getRoomId(), updateSecretCheck);

//then

verify(chatRoomRepository, times(1)).updateRoomSecretCheck(createdChatRoom.getRoomId(), Boolean.valueOf(updateSecretCheck));

}


}

0 comments on commit 43aac2d

Please sign in to comment.