-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #302 from jihyun-j/main
dev브랜치 코드 main브랜치로 병합
- Loading branch information
Showing
226 changed files
with
113,638 additions
and
8,154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
name: 스토리 기능 명세 | ||
about: 요구사항 명세 | ||
title: '' | ||
labels: '' | ||
assignees: '' | ||
|
||
--- | ||
|
||
## 🤔 어떤 요구사항을 구현하나요? | ||
|
||
> 구현하고자 하는 요구사항을 적어주세요. 개발자가 아니더라도 이해할 수 있도록 직관적으로 작성해주는 것을 권장해요. | ||
## ✅ 하위 기능 명세 | ||
|
||
> 추상화된 해당 요구사항을 구현하기 위한 구체적인 Task 목록을 작성해주세요. | ||
- [ ] TODO | ||
- [ ] TODO | ||
|
||
## 📚 참고할만한 자료(선택) | ||
> 개발을 하면서 참고한 자료나 배경 지식을 공유하고 싶다면 링크나 설명을 추가해주세요. | ||
> 해당 기능과 관련된 다른 이슈 링크가 있다면 작성해주세요. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
chat/src/main/kotlin/kpring/chat/chat/api/v1/WebSocketChatController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package kpring.chat.chat.api.v1 | ||
|
||
import kpring.chat.chat.service.ChatService | ||
import kpring.chat.global.exception.ErrorCode | ||
import kpring.chat.global.exception.GlobalException | ||
import kpring.core.chat.chat.dto.request.CreateChatRequest | ||
import kpring.core.chat.chat.dto.request.DeleteChatRequest | ||
import kpring.core.chat.chat.dto.request.GetChatsRequest | ||
import kpring.core.chat.chat.dto.request.UpdateChatRequest | ||
import kpring.core.chat.model.ChatType | ||
import kpring.core.server.client.ServerClient | ||
import kpring.core.server.dto.request.GetServerCondition | ||
import lombok.RequiredArgsConstructor | ||
import org.slf4j.Logger | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.messaging.handler.annotation.MessageMapping | ||
import org.springframework.messaging.handler.annotation.Payload | ||
import org.springframework.messaging.simp.SimpMessageHeaderAccessor | ||
import org.springframework.messaging.simp.SimpMessagingTemplate | ||
import org.springframework.stereotype.Controller | ||
import org.springframework.validation.annotation.Validated | ||
import java.security.Principal | ||
|
||
@Controller | ||
@RequiredArgsConstructor | ||
class WebSocketChatController( | ||
private val chatService: ChatService, | ||
private val serverClient: ServerClient, | ||
private val simpMessagingTemplate: SimpMessagingTemplate, | ||
) { | ||
private val logger: Logger = LoggerFactory.getLogger(WebSocketChatController::class.java) | ||
|
||
@MessageMapping("/chat/create") | ||
fun createChat( | ||
@Payload @Validated request: CreateChatRequest, | ||
principal: Principal, | ||
headerAccessor: SimpMessageHeaderAccessor, | ||
) { | ||
val token = headerAccessor.getFirstNativeHeader("Authorization") ?: throw GlobalException(ErrorCode.MISSING_TOKEN) | ||
val userId = principal.name | ||
val contextId = request.contextId | ||
|
||
val result = | ||
when (request.type) { | ||
ChatType.ROOM -> chatService.createRoomChat(request, userId) | ||
ChatType.SERVER -> | ||
chatService.createServerChat( | ||
request, | ||
userId, | ||
serverClient.getServerList(token, GetServerCondition()).body!!.data!!, | ||
) | ||
} | ||
simpMessagingTemplate.convertAndSend("/topic/chatroom/$contextId", result) | ||
} | ||
|
||
@MessageMapping("/chat/update") | ||
fun updateChat( | ||
@Payload @Validated request: UpdateChatRequest, | ||
principal: Principal, | ||
) { | ||
val userId = principal.name | ||
val contextId = request.contextId | ||
|
||
val result = chatService.updateChat(request, userId) | ||
simpMessagingTemplate.convertAndSend("/topic/chatroom/$contextId", result) | ||
} | ||
|
||
@MessageMapping("/chat/delete") | ||
fun deleteChat( | ||
@Payload @Validated request: DeleteChatRequest, | ||
principal: Principal, | ||
) { | ||
val userId = principal.name | ||
val chatId = request.id | ||
val contextId = request.contextId | ||
|
||
val result = chatService.deleteChat(chatId, userId) | ||
simpMessagingTemplate.convertAndSend("/topic/chatroom/$contextId", result) | ||
} | ||
|
||
@MessageMapping("/chat") | ||
fun getChats( | ||
@Payload @Validated request: GetChatsRequest, | ||
principal: Principal, | ||
headerAccessor: SimpMessageHeaderAccessor, | ||
) { | ||
val token = headerAccessor.getFirstNativeHeader("Authorization") ?: throw GlobalException(ErrorCode.MISSING_TOKEN) | ||
val userId = principal.name | ||
val type = request.type | ||
val contextId = request.contextId | ||
val page = request.page | ||
val size = request.size | ||
|
||
val result = | ||
when (type) { | ||
ChatType.ROOM -> chatService.getRoomChats(contextId, userId, page, size) | ||
ChatType.SERVER -> | ||
chatService.getServerChats( | ||
contextId, | ||
userId, | ||
page, | ||
size, | ||
serverClient.getServerList(token, GetServerCondition()).body!!.data!!, | ||
) | ||
} | ||
logger.info("Chat result: $result") | ||
simpMessagingTemplate.convertAndSend("/topic/chatroom/$contextId", result) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
chat/src/main/kotlin/kpring/chat/chat/repository/ChatCustomRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package kpring.chat.chat.repository | ||
|
||
import kpring.chat.chat.model.Chat | ||
import kpring.core.chat.model.ChatType | ||
import org.springframework.data.domain.Page | ||
import org.springframework.data.domain.PageRequest | ||
import org.springframework.data.domain.Pageable | ||
import org.springframework.data.domain.Sort | ||
import org.springframework.data.mongodb.core.MongoTemplate | ||
import org.springframework.data.mongodb.core.query.Criteria | ||
import org.springframework.data.mongodb.core.query.Query | ||
import org.springframework.data.support.PageableExecutionUtils | ||
import org.springframework.stereotype.Repository | ||
|
||
@Repository | ||
class ChatCustomRepository( | ||
private val mongoTemplate: MongoTemplate, | ||
) { | ||
fun findListByContextIdWithPaging( | ||
contextId: String, | ||
page: Int, | ||
size: Int, | ||
type: ChatType, | ||
): List<Chat> { | ||
val sort: Sort = Sort.by(Sort.Order.desc("createdAt")) | ||
val pageable: Pageable = PageRequest.of(page, size, sort) | ||
var query: Query = | ||
Query( | ||
Criteria.where("contextId").`is`(contextId).and("chatType").`is`(type), | ||
).with(pageable) | ||
return mongoTemplate.find(query, Chat::class.java) | ||
} | ||
|
||
fun findPageByContextIdWithPaging( | ||
contextId: String, | ||
page: Int, | ||
size: Int, | ||
type: ChatType, | ||
): Page<Chat> { | ||
val sort: Sort = Sort.by(Sort.Order.desc("createdAt")) | ||
val pageable: Pageable = PageRequest.of(page, size, sort) | ||
val query: Query = | ||
Query( | ||
Criteria.where("contextId").`is`(contextId).and("chatType").`is`(type), | ||
).with(pageable) | ||
val list: List<Chat> = mongoTemplate.find(query, Chat::class.java) | ||
return PageableExecutionUtils.getPage( | ||
list, | ||
pageable, | ||
{ | ||
mongoTemplate.count(Query.of(query).limit(-1).skip(-1), Chat::class.java) | ||
}, | ||
) | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
chat/src/main/kotlin/kpring/chat/chat/repository/ChatRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package kpring.chat.chat.repository | ||
|
||
import kpring.chat.chat.model.Chat | ||
import org.springframework.data.mongodb.repository.MongoRepository | ||
import org.springframework.data.querydsl.QuerydslPredicateExecutor | ||
|
||
interface ChatRepository : MongoRepository<Chat, String>, QuerydslPredicateExecutor<Chat> |
15 changes: 0 additions & 15 deletions
15
chat/src/main/kotlin/kpring/chat/chat/repository/RoomChatRepository.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.