Skip to content

Commit

Permalink
feat: 그룹 조인하기 개발용 api
Browse files Browse the repository at this point in the history
  • Loading branch information
DongGeon0908 committed Aug 27, 2024
1 parent 4ea0f4f commit 3a65890
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.hero.alignlab.domain.dev.model.request

data class DevGroupJoinRequest(
val uid: Long,
val joinCode: String? = null
)
Original file line number Diff line number Diff line change
@@ -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
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand Down

0 comments on commit 3a65890

Please sign in to comment.