Skip to content

Commit

Permalink
feat: 그룹원 내보내기
Browse files Browse the repository at this point in the history
  • Loading branch information
DongGeon0908 committed Aug 2, 2024
1 parent f374d7c commit 1bb6c5c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import com.hero.alignlab.exception.InvalidRequestException
import com.hero.alignlab.exception.NotFoundException
import org.springframework.context.ApplicationEventPublisher
import org.springframework.stereotype.Service
import java.util.*

@Service
class GroupFacade(
Expand Down Expand Up @@ -155,4 +154,14 @@ class GroupFacade(
}
}
}

suspend fun deleteGroupUser(user: AuthUser, groupUserId: Long) {
val groupUser = groupUserService.findByIdOrNull(groupUserId)
?: throw NotFoundException(ErrorCode.NOT_FOUND_USER_ERROR)

groupService.findByIdAndOwnerUid(groupUser.groupId, user.uid)
?: throw NotFoundException(ErrorCode.NOT_FOUND_USER_ERROR)

groupUserService.deleteSync(groupUserId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

Expand Down Expand Up @@ -75,4 +76,14 @@ class GroupUserService(
groupUserRepository.findAllByGroupId(groupId, pageable)
}
}

suspend fun findByIdOrNull(groupUserId: Long): GroupUser? {
return withContext(Dispatchers.IO) {
groupUserRepository.findByIdOrNull(groupUserId)
}
}

fun deleteSync(groupUserId: Long) {
groupUserRepository.deleteById(groupUserId)
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package com.hero.alignlab.domain.group.resource

import com.hero.alignlab.common.extension.wrapPage
import com.hero.alignlab.common.extension.wrapVoid
import com.hero.alignlab.common.model.AlignlabPageRequest
import com.hero.alignlab.domain.auth.model.AuthUser
import com.hero.alignlab.domain.group.application.GroupFacade
import com.hero.alignlab.domain.group.application.GroupUserService
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import org.springdoc.core.annotations.ParameterObject
import org.springframework.http.MediaType
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.bind.annotation.*

@Tag(name = "Group User API")
@RestController
@RequestMapping(produces = [MediaType.APPLICATION_JSON_VALUE])
class GroupUserResource(
private val groupUserService: GroupUserService,
private val groupFacade: GroupFacade,
) {
@Operation(summary = "그룹원 조회")
@GetMapping("/api/v1/group-users")
Expand All @@ -30,4 +30,11 @@ class GroupUserResource(
groupId = groupId,
pageable = pageRequest.toDefault()
).wrapPage()

@Operation(summary = "그룹원 내보내기")
@DeleteMapping("/api/v1/group-users/{groupUserId}")
suspend fun deleteGroupUser(
user: AuthUser,
@PathVariable groupUserId: Long,
) = groupFacade.deleteGroupUser(user, groupUserId).wrapVoid()
}

0 comments on commit 1bb6c5c

Please sign in to comment.