diff --git a/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatmember/dto/response/ChatMemberResponse.java b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatmember/dto/response/ChatMemberResponse.java new file mode 100644 index 0000000..74f0bda --- /dev/null +++ b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatmember/dto/response/ChatMemberResponse.java @@ -0,0 +1,22 @@ +package com.tadak.chatroomservice.domain.chatmember.dto.response; + +import com.tadak.chatroomservice.domain.chatmember.entity.ChatMember; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class ChatMemberResponse { + + private String username; + + public static ChatMemberResponse from(ChatMember chatMember){ + return ChatMemberResponse.builder() + .username(chatMember.getUsername()) + .build(); + } +} diff --git a/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/controller/ChatRoomController.java b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/controller/ChatRoomController.java index dc8cf82..4686038 100644 --- a/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/controller/ChatRoomController.java +++ b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/controller/ChatRoomController.java @@ -2,12 +2,9 @@ import com.tadak.chatroomservice.domain.chatmember.dto.response.EnterChatMemberResponse; import com.tadak.chatroomservice.domain.chatroom.dto.request.ChatRoomRequest; -import com.tadak.chatroomservice.domain.chatroom.dto.response.ChangeOwnerResponse; -import com.tadak.chatroomservice.domain.chatroom.dto.response.ChatRoomResponse; -import com.tadak.chatroomservice.domain.chatroom.dto.response.KickMemberResponse; +import com.tadak.chatroomservice.domain.chatroom.dto.response.*; import com.tadak.chatroomservice.domain.chatroom.service.ChatRoomService; import com.tadak.chatroomservice.domain.chatroom.dto.request.CreateChatroomRequest; -import com.tadak.chatroomservice.domain.chatroom.dto.response.CreateChatroomResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; @@ -80,4 +77,13 @@ public ResponseEntity changeOwner(@PathVariable Long roomId ChangeOwnerResponse changeOwnerResponse = chatRoomService.changeOwner(roomId, username, chatRoomRequest.getUsername()); return ResponseEntity.status(HttpStatus.OK).body(changeOwnerResponse); } + + /** + * 개별 방 조회 + */ + @GetMapping("/rooms/{roomId}") + public ResponseEntity getChatRoom(@PathVariable Long roomId){ + OneChatRoomResponse getChatRoom = chatRoomService.findChatRoom(roomId); + return ResponseEntity.status(HttpStatus.OK).body(getChatRoom); + } } diff --git a/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/dto/request/CreateChatroomRequest.java b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/dto/request/CreateChatroomRequest.java index afa1bbf..fae24d1 100644 --- a/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/dto/request/CreateChatroomRequest.java +++ b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/dto/request/CreateChatroomRequest.java @@ -14,6 +14,6 @@ public class CreateChatroomRequest { private String roomName; private String description; private String owner; - private String category; + private String hashtag; private Integer capacity; } diff --git a/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/dto/response/CreateChatroomResponse.java b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/dto/response/CreateChatroomResponse.java index 1d985e5..7bdbc53 100644 --- a/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/dto/response/CreateChatroomResponse.java +++ b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/dto/response/CreateChatroomResponse.java @@ -15,7 +15,7 @@ public class CreateChatroomResponse { private String roomName; private String description; private String owner; - private String category; + private String hashtag; private Integer participation; private Integer capacity; private EnterChatMemberResponse chatMemberResponse; @@ -27,7 +27,7 @@ public static CreateChatroomResponse of(ChatRoom chatRoom, EnterChatMemberRespon .roomName(chatRoom.getRoomName()) .description(chatRoom.getDescription()) .owner(chatRoom.getOwner()) - .category(chatRoom.getCategory()) + .hashtag(chatRoom.getHashtag()) .participation(chatRoom.getParticipation()) .capacity(chatRoom.getCapacity()) .chatMemberResponse(chatMemberResponse) diff --git a/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/dto/response/OneChatRoomResponse.java b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/dto/response/OneChatRoomResponse.java new file mode 100644 index 0000000..2d85a52 --- /dev/null +++ b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/dto/response/OneChatRoomResponse.java @@ -0,0 +1,31 @@ +package com.tadak.chatroomservice.domain.chatroom.dto.response; + +import com.tadak.chatroomservice.domain.chatmember.dto.response.ChatMemberResponse; +import com.tadak.chatroomservice.domain.chatroom.entity.ChatRoom; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class OneChatRoomResponse { + + private String roomName; + private Integer participation; + private String owner; + private List chatMemberResponses; + + public static OneChatRoomResponse of(ChatRoom chatRoom, List chatMemberResponses){ + return OneChatRoomResponse.builder() + .roomName(chatRoom.getRoomName()) + .participation(chatRoom.getParticipation()) + .owner(chatRoom.getOwner()) + .chatMemberResponses(chatMemberResponses) + .build(); + } +} diff --git a/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/entity/ChatRoom.java b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/entity/ChatRoom.java index d7cfd2f..9dd88b1 100644 --- a/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/entity/ChatRoom.java +++ b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/entity/ChatRoom.java @@ -38,7 +38,7 @@ public class ChatRoom { private String owner; @NotNull @Size(max = 10, message = "카테고리 글자는 10자를 넘길 수 없습니다.") - private String category; + private String hashtag; @NotNull private Integer participation; @NotNull @@ -58,7 +58,7 @@ public static ChatRoom toEntity(CreateChatroomRequest chatroomRequest){ .roomName(chatroomRequest.getRoomName()) .description(chatroomRequest.getDescription()) .owner(chatroomRequest.getOwner()) - .category(chatroomRequest.getCategory()) + .hashtag(chatroomRequest.getHashtag()) .participation(DEFAULT_PARTICIPATION) .capacity(chatroomRequest.getCapacity()) .build(); diff --git a/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/service/ChatRoomService.java b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/service/ChatRoomService.java index 59f7ab6..072fd98 100644 --- a/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/service/ChatRoomService.java +++ b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/service/ChatRoomService.java @@ -1,18 +1,16 @@ package com.tadak.chatroomservice.domain.chatroom.service; +import com.tadak.chatroomservice.domain.chatmember.dto.response.ChatMemberResponse; import com.tadak.chatroomservice.domain.chatmember.dto.response.EnterChatMemberResponse; import com.tadak.chatroomservice.domain.chatmember.entity.ChatMember; import com.tadak.chatroomservice.domain.chatmember.service.ChatMemberService; import com.tadak.chatroomservice.domain.chatroom.dto.request.ChatRoomRequest; -import com.tadak.chatroomservice.domain.chatroom.dto.response.ChangeOwnerResponse; -import com.tadak.chatroomservice.domain.chatroom.dto.response.ChatRoomResponse; -import com.tadak.chatroomservice.domain.chatroom.dto.response.KickMemberResponse; +import com.tadak.chatroomservice.domain.chatroom.dto.response.*; import com.tadak.chatroomservice.domain.chatroom.exception.AlreadyKickedException; import com.tadak.chatroomservice.domain.chatroom.exception.NotFoundChatRoomException; import com.tadak.chatroomservice.domain.chatroom.exception.NotRoomOwnerException; import com.tadak.chatroomservice.domain.chatroom.repository.ChatRoomRepository; import com.tadak.chatroomservice.domain.chatroom.dto.request.CreateChatroomRequest; -import com.tadak.chatroomservice.domain.chatroom.dto.response.CreateChatroomResponse; import com.tadak.chatroomservice.domain.chatroom.entity.ChatRoom; import com.tadak.chatroomservice.global.error.ErrorCode; import lombok.RequiredArgsConstructor; @@ -127,4 +125,13 @@ public ChangeOwnerResponse changeOwner(Long roomId, String username, String owne return ChangeOwnerResponse.from(chatRoom); } + + public OneChatRoomResponse findChatRoom(Long roomId) { + ChatRoom chatRoom = findByChatRoom(roomId); + + List chatMemberResponses = chatRoom.getChatMembers().stream() + .map(ChatMemberResponse::from).toList(); + + return OneChatRoomResponse.of(chatRoom, chatMemberResponses); + } } diff --git a/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/global/config/CorsConfig.java b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/global/config/CorsConfig.java new file mode 100644 index 0000000..c43bd7d --- /dev/null +++ b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/global/config/CorsConfig.java @@ -0,0 +1,25 @@ +package com.tadak.chatroomservice.global.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +@Configuration +public class CorsConfig { + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + CorsConfiguration config = new CorsConfiguration(); + config.setAllowCredentials(true); + config.addAllowedOriginPattern("*"); + config.addAllowedHeader("*"); + config.addAllowedMethod("*"); + config.addExposedHeader("Accesstoken, Refreshtoken"); + + source.registerCorsConfiguration("/**", config); + return new CorsFilter(source); + } +} +