Skip to content

Commit

Permalink
🔨 Add SellerCreateChatRoomWithSellerException
Browse files Browse the repository at this point in the history
  • Loading branch information
wonseok committed Jan 31, 2025
1 parent e8d97a8 commit f127b1f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ class ThisRoomIsNotYoursException : ChatRoomException(
httpStatusCode = HttpStatus.FORBIDDEN,
msg = "Not your room",
)

class SellerCreateChatRoomWithSellerException : ChatRoomException(
errorCode = 0,
httpStatusCode = HttpStatus.BAD_REQUEST,
msg = "Seller can't make chatRoom with himself",
)
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ class ChatRoomController(
@PostMapping("/chat/create")
fun createRoom(
@RequestBody request: CreateChatRoomRequest,
@AuthUser user: User,
): ResponseEntity<ChatRoom> {
val chatRoom = chatRoomService.createChatRoom(request.articleId, request.sellerId, request.buyerId)
val chatRoom = chatRoomService.createChatRoom(user, request.articleId, request.sellerId, request.buyerId)
return ResponseEntity.ok(chatRoom)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.toyProject7.karrot.chatRoom.service

import com.toyProject7.karrot.article.service.ArticleService
import com.toyProject7.karrot.chatRoom.ChatRoomNotFoundException
import com.toyProject7.karrot.chatRoom.SellerCreateChatRoomWithSellerException
import com.toyProject7.karrot.chatRoom.ThisRoomIsNotYoursException
import com.toyProject7.karrot.chatRoom.controller.ChatMessage
import com.toyProject7.karrot.chatRoom.controller.ChatRoom
Expand Down Expand Up @@ -81,10 +82,14 @@ class ChatRoomService(

@Transactional
fun createChatRoom(
user: User,
articleId: Long,
sellerId: String,
buyerId: String,
): ChatRoom {
if (user.id == sellerId) {
throw SellerCreateChatRoomWithSellerException()
}
val articleEntity = articleService.getArticleEntityById(articleId)
val sellerEntity = userService.getUserEntityById(sellerId)
val buyerEntity = userService.getUserEntityById(buyerId)
Expand Down

0 comments on commit f127b1f

Please sign in to comment.