Skip to content

Commit

Permalink
feat: 그룹 정보 검색
Browse files Browse the repository at this point in the history
  • Loading branch information
DongGeon0908 committed Aug 21, 2024
1 parent dc55c78 commit 85d2e3d
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 9 deletions.
18 changes: 10 additions & 8 deletions sql/DDL.sql
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ CREATE INDEX idx__oauth_id__provider ON oauth_user_info (oauth_id, provider);
-- 그룹
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',
`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 '수정일',
`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 '참여코드',
`user_count` int NOT NULL DEFAULT 1 COMMENT '그룹원 수',
`user_capacity` int NOT NULL DEFAULT 0 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='그룹';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.hero.alignlab.domain.group.application
import arrow.fx.coroutines.parZip
import com.hero.alignlab.common.extension.executes
import com.hero.alignlab.common.extension.executesOrNull
import com.hero.alignlab.common.model.HeroPageRequest
import com.hero.alignlab.config.database.TransactionTemplates
import com.hero.alignlab.domain.auth.model.AuthUser
import com.hero.alignlab.domain.group.domain.Group
Expand All @@ -12,11 +13,13 @@ import com.hero.alignlab.domain.group.model.request.CreateGroupRequest
import com.hero.alignlab.domain.group.model.response.CreateGroupResponse
import com.hero.alignlab.domain.group.model.response.GetGroupResponse
import com.hero.alignlab.domain.group.model.response.JoinGroupResponse
import com.hero.alignlab.domain.group.model.response.SearchGroupResponse
import com.hero.alignlab.event.model.CreateGroupEvent
import com.hero.alignlab.exception.ErrorCode
import com.hero.alignlab.exception.InvalidRequestException
import com.hero.alignlab.exception.NotFoundException
import org.springframework.context.ApplicationEventPublisher
import org.springframework.data.domain.Page
import org.springframework.stereotype.Service

@Service
Expand Down Expand Up @@ -159,6 +162,11 @@ class GroupFacade(
}
}

suspend fun searchGroup(user: AuthUser, pageRequest: HeroPageRequest): Page<SearchGroupResponse> {
return groupService.findAll(pageRequest.toDefault())
.map { group -> SearchGroupResponse.from(group) }
}

suspend fun deleteGroupUser(user: AuthUser, groupUserId: Long) {
val groupUser = groupUserService.findByIdOrNull(groupUserId)
?: throw NotFoundException(ErrorCode.NOT_FOUND_USER_ERROR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import com.hero.alignlab.exception.ErrorCode
import com.hero.alignlab.exception.NotFoundException
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

Expand Down Expand Up @@ -67,4 +69,10 @@ class GroupService(
fun saveSync(group: Group): Group {
return groupRepository.save(group)
}

suspend fun findAll(pageable: Pageable): Page<Group> {
return withContext(Dispatchers.IO) {
groupRepository.findAll(pageable)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,11 @@ data class Group(
var isHidden: Boolean,

@Column(name = "join_code")
var joinCode: String
var joinCode: String,

@Column(name = "user_count")
var userCount: Int = 1,

@Column(name = "user_capacity")
val userCapacity: Int = 30,
) : BaseEntity()
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.hero.alignlab.domain.group.model.response

import com.hero.alignlab.domain.group.domain.Group

data class SearchGroupResponse(
/** group Id */
val id: Long,
/** 그룹원 수 */
val userCount: Int,
/** 그룹 정원 */
val userCapacity: Int,
/** 그룹명 */
val name: String,
/** 비밀 그룹 여부 */
val isHidden: Boolean,
) {
companion object {
fun from(group: Group): SearchGroupResponse {
return SearchGroupResponse(
id = group.id,
userCount = group.userCount,
userCapacity = group.userCapacity,
name = group.name,
isHidden = group.isHidden,
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ package com.hero.alignlab.domain.group.resource

import com.hero.alignlab.common.extension.wrapCreated
import com.hero.alignlab.common.extension.wrapOk
import com.hero.alignlab.common.extension.wrapPage
import com.hero.alignlab.common.extension.wrapVoid
import com.hero.alignlab.common.model.HeroPageRequest
import com.hero.alignlab.domain.auth.model.AuthUser
import com.hero.alignlab.domain.group.application.GroupFacade
import com.hero.alignlab.domain.group.application.GroupService
import com.hero.alignlab.domain.group.model.request.CreateGroupRequest
import com.hero.alignlab.domain.group.model.request.UpdateGroupRequest
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.*

Expand All @@ -31,6 +34,18 @@ class GroupResource(
@PathVariable id: Long
) = groupFacade.getGroup(user, id).wrapOk()

/**
* - 정렬 조건
* - 크루원 많은 순 : userCount,desc
* - 최신 생성 크루 순 : createdAt,desc
*/
@Operation(summary = "그룹 전체 보기")
@GetMapping("/api/v1/groups")
suspend fun searchGroups(
user: AuthUser,
@ParameterObject pageRequest: HeroPageRequest,
) = groupFacade.searchGroup(user, pageRequest).wrapPage()

@Operation(summary = "그룹 생성")
@PostMapping("/api/v1/groups")
suspend fun createGroup(
Expand Down

0 comments on commit 85d2e3d

Please sign in to comment.