diff --git a/src/main/kotlin/com/hero/alignlab/domain/dev/model/request/DevGroupJoinRequest.kt b/src/main/kotlin/com/hero/alignlab/domain/dev/model/request/DevGroupJoinRequest.kt new file mode 100644 index 0000000..a2cf5bf --- /dev/null +++ b/src/main/kotlin/com/hero/alignlab/domain/dev/model/request/DevGroupJoinRequest.kt @@ -0,0 +1,6 @@ +package com.hero.alignlab.domain.dev.model.request + +data class DevGroupJoinRequest( + val uid: Long, + val joinCode: String? = null +) diff --git a/src/main/kotlin/com/hero/alignlab/domain/dev/resource/DevGroupResource.kt b/src/main/kotlin/com/hero/alignlab/domain/dev/resource/DevGroupResource.kt new file mode 100644 index 0000000..f9aa3ed --- /dev/null +++ b/src/main/kotlin/com/hero/alignlab/domain/dev/resource/DevGroupResource.kt @@ -0,0 +1,31 @@ +package com.hero.alignlab.domain.dev.resource + +import com.hero.alignlab.config.dev.DevResourceCheckConfig.Companion.devResource +import com.hero.alignlab.config.swagger.SwaggerTag.DEV_TAG +import com.hero.alignlab.domain.dev.model.request.DevGroupJoinRequest +import com.hero.alignlab.domain.group.application.GroupFacade +import io.swagger.v3.oas.annotations.Operation +import io.swagger.v3.oas.annotations.tags.Tag +import org.springframework.http.MediaType +import org.springframework.web.bind.annotation.* + +@Tag(name = DEV_TAG) +@RestController +@RequestMapping(produces = [MediaType.APPLICATION_JSON_VALUE]) +class DevGroupResource( + private val groupFacade: GroupFacade, +) { + @Operation(summary = "그룹 조인하기") + @PostMapping("/api/dev/v1/groups/{groupId}/join") + suspend fun joinGroup( + @RequestHeader("X-HERO-DEV-TOKEN") token: String, + @PathVariable groupId: Long, + @RequestBody request: DevGroupJoinRequest, + ) = devResource(token) { + groupFacade.joinGroup( + groupId = groupId, + uid = request.uid, + joinCode = request.joinCode + ) + } +} diff --git a/src/main/kotlin/com/hero/alignlab/domain/group/application/GroupFacade.kt b/src/main/kotlin/com/hero/alignlab/domain/group/application/GroupFacade.kt index da26a46..851ce89 100644 --- a/src/main/kotlin/com/hero/alignlab/domain/group/application/GroupFacade.kt +++ b/src/main/kotlin/com/hero/alignlab/domain/group/application/GroupFacade.kt @@ -107,10 +107,18 @@ class GroupFacade( user: AuthUser, groupId: Long, joinCode: String? + ): JoinGroupResponse { + return joinGroup(groupId, user.uid, joinCode) + } + + suspend fun joinGroup( + groupId: Long, + uid: Long, + joinCode: String? ): JoinGroupResponse { return parZip( { groupService.findByIdOrThrow(groupId) }, - { groupUserService.findAllByUid(user.uid).associateBy { it.groupId } } + { groupUserService.findAllByUid(uid).associateBy { it.groupId } } ) { group, groupUsers -> if (group.isHidden && group.joinCode != joinCode) { throw InvalidRequestException(ErrorCode.IMPOSSIBLE_TO_JOIN_GROUP_ERROR) @@ -137,7 +145,7 @@ class GroupFacade( else -> { val createdGroupUser = txTemplates.writer.executes { groupService.saveSync(group.apply { this.userCount += 1 }) - groupUserService.saveSync(groupId, user.uid) + groupUserService.saveSync(groupId, uid) } JoinGroupResponse(