Skip to content

Commit

Permalink
fix: 이미 그룹에 조인하지 않은 경우에만, 그룹 생성 가능
Browse files Browse the repository at this point in the history
  • Loading branch information
DongGeon0908 committed Jul 28, 2024
1 parent b7a023f commit c4af780
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.hero.alignlab.config.database.TransactionTemplates
import com.hero.alignlab.domain.auth.model.AuthUser
import com.hero.alignlab.domain.group.domain.Group
import com.hero.alignlab.domain.group.infrastructure.GroupRepository
import com.hero.alignlab.domain.group.infrastructure.GroupUserRepository
import com.hero.alignlab.domain.group.model.request.CreateGroupRequest
import com.hero.alignlab.domain.group.model.request.UpdateGroupRequest
import com.hero.alignlab.domain.group.model.response.CreateGroupResponse
Expand All @@ -23,6 +24,7 @@ import java.util.*
@Service
class GroupService(
private val groupRepository: GroupRepository,
private val groupUserRepository: GroupUserRepository,
private val txTemplates: TransactionTemplates,
private val publisher: ApplicationEventPublisher,
) {
Expand All @@ -31,6 +33,10 @@ class GroupService(
throw InvalidRequestException(ErrorCode.DUPLICATE_GROUP_NAME_ERROR)
}

if (withContext(Dispatchers.IO) { groupUserRepository.findAllByUid(user.uid) }.isNotEmpty()) {
throw InvalidRequestException(ErrorCode.DUPLICATE_GROUP_JOIN_ERROR)
}

val createdGroup = txTemplates.writer.executes {
val group = groupRepository.save(
Group(
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/com/hero/alignlab/exception/ErrorCode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ enum class ErrorCode(val status: HttpStatus, val description: String) {
DUPLICATE_GROUP_NAME_ERROR(HttpStatus.BAD_REQUEST, "중복된 그룹명입니다."),
NOT_FOUND_GROUP_ERROR(HttpStatus.NOT_FOUND, "그룹 정보를 찾을 수 없습니다."),
IMPOSSIBLE_TO_JOIN_GROUP_ERROR(HttpStatus.BAD_REQUEST, "그룹에 들어갈 수 없습니다."),
ALREADY_JOIN_GROUP_ERROR(HttpStatus.BAD_REQUEST, "이미 그룹에 들어가 있습니다."),

/** Group User Error Code */
DUPLICATE_GROUP_JOIN_ERROR(HttpStatus.BAD_REQUEST, "한개의 그룹만 참여 가능합니다."),
Expand Down

0 comments on commit c4af780

Please sign in to comment.