Skip to content

Commit

Permalink
fix: 그룹 초대 기능
Browse files Browse the repository at this point in the history
  • Loading branch information
DongGeon0908 committed Jul 27, 2024
1 parent 8e312bd commit d1cfca1
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 10 deletions.
15 changes: 9 additions & 6 deletions sql/DDL.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,20 @@ CREATE UNIQUE INDEX uidx__username ON credential_user_info (username);
-- 그룹
CREATE TABLE `group`
(
`id` bigint NOT NULL AUTO_INCREMENT COMMENT 'group id',
`name` varchar(32) NOT NULL COMMENT '그룹명',
`description` varchar(512) DEFAULT NULL COMMENT '그룹 설명',
`owner_uid` bigint NOT NULL COMMENT 'owner uid',
`created_at` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '생성일',
`modified_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '수정일',
`id` bigint NOT NULL AUTO_INCREMENT COMMENT 'group id',
`name` varchar(32) NOT NULL COMMENT '그룹명',
`description` varchar(512) DEFAULT NULL COMMENT '그룹 설명',
`owner_uid` bigint NOT NULL COMMENT 'owner uid',
`is_hidden` tinyint NOT NULL DEFAULT 0 COMMENT '숨김 여부',
`join_code` varchar(128) not null comment '참여코드',
`created_at` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '생성일',
`modified_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '수정일',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=200000 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='그룹';

CREATE UNIQUE INDEX uidx__name ON `group` (name);
CREATE INDEX idx__owner_uid ON `group` (owner_uid);
CREATE INDEX idx__join_code ON `group` (join_code);

-- 그룹 유저
CREATE TABLE `group_user`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,19 @@ class GroupFacade(
}
}

suspend fun joinGroup(user: AuthUser, groupId: Long): JoinGroupResponse {
suspend fun joinGroup(
user: AuthUser,
groupId: Long,
joinCode: String?
): JoinGroupResponse {
return parZip(
{ groupService.findByIdOrThrow(groupId) },
{ groupUserService.findAllByUid(user.uid).associateBy { it.groupId } }
) { group, groupUsers ->
if (group.isHidden && group.joinCode != joinCode) {
throw InvalidRequestException(ErrorCode.IMPOSSIBLE_TO_JOIN_GROUP_ERROR)
}

val groupUser = groupUsers[groupId]

if (groupUser == null && groupUsers.isNotEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import kotlinx.coroutines.withContext
import org.springframework.context.ApplicationEventPublisher
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import java.util.*

@Service
class GroupService(
Expand All @@ -33,7 +34,9 @@ class GroupService(
Group(
name = request.name,
description = request.description,
ownerUid = user.uid
ownerUid = user.uid,
isHidden = request.isHidden,
joinCode = request.joinCode ?: UUID.randomUUID().toString().replace("-", "")
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ data class Group(

@Column(name = "owner_uid")
var ownerUid: Long,

@Column(name = "is_hidden")
val isHidden: Boolean,

@Column(name = "join_code")
val joinCode: String
) : BaseEntity()
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ data class CreateGroupRequest(
val name: String,
/** 그룹 설명 */
val description: String?,
/** 숨김 여부 */
val isHidden: Boolean,
/** 참여 코드, 미입력시 자동 생성 */
val joinCode: String?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ class GroupResource(
@PostMapping("/api/v1/groups/{groupId}/join")
suspend fun joinGroup(
user: AuthUser,
@PathVariable groupId: Long
) = groupFacade.joinGroup(user, groupId).wrapOk()
@PathVariable groupId: Long,
@RequestParam(required = false) joinCode: String?,
) = groupFacade.joinGroup(
user = user,
groupId = groupId,
joinCode = joinCode
).wrapOk()
}
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 @@ -34,6 +34,7 @@ enum class ErrorCode(val status: HttpStatus, val description: String) {
/** Group Error Code */
DUPLICATE_GROUP_NAME_ERROR(HttpStatus.BAD_REQUEST, "중복된 그룹명입니다."),
NOT_FOUND_GROUP_ERROR(HttpStatus.NOT_FOUND, "그룹 정보를 찾을 수 없습니다."),
IMPOSSIBLE_TO_JOIN_GROUP_ERROR(HttpStatus.BAD_REQUEST, "그룹에 들어갈 수 없습니다."),

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

0 comments on commit d1cfca1

Please sign in to comment.