diff --git a/src/main/kotlin/com/hero/alignlab/domain/group/application/MyGroupService.kt b/src/main/kotlin/com/hero/alignlab/domain/group/application/MyGroupService.kt new file mode 100644 index 0000000..ab5af7b --- /dev/null +++ b/src/main/kotlin/com/hero/alignlab/domain/group/application/MyGroupService.kt @@ -0,0 +1,18 @@ +package com.hero.alignlab.domain.group.application + +import com.hero.alignlab.domain.auth.model.AuthUser +import com.hero.alignlab.domain.group.model.response.MyGroupResponse +import org.springframework.stereotype.Service + +@Service +class MyGroupService( + private val groupService: GroupService, + private val groupUserService: GroupUserService, +) { + suspend fun getMyGroup(user: AuthUser): MyGroupResponse? { + val groupUser = groupUserService.findByUid(user.uid) ?: return null + val group = groupService.findByIdOrThrow(groupUser.groupId) + + return MyGroupResponse.from(group) + } +} diff --git a/src/main/kotlin/com/hero/alignlab/domain/group/model/response/MyGroupResponse.kt b/src/main/kotlin/com/hero/alignlab/domain/group/model/response/MyGroupResponse.kt new file mode 100644 index 0000000..12b06b2 --- /dev/null +++ b/src/main/kotlin/com/hero/alignlab/domain/group/model/response/MyGroupResponse.kt @@ -0,0 +1,19 @@ +package com.hero.alignlab.domain.group.model.response + +import com.hero.alignlab.domain.group.domain.Group + +data class MyGroupResponse( + val id: Long, + val name: String, + val description: String?, +) { + companion object { + fun from(group: Group): MyGroupResponse { + return MyGroupResponse( + id = group.id, + name = group.name, + description = group.description + ) + } + } +} diff --git a/src/main/kotlin/com/hero/alignlab/domain/group/resource/MyGroupResource.kt b/src/main/kotlin/com/hero/alignlab/domain/group/resource/MyGroupResource.kt new file mode 100644 index 0000000..c9d6436 --- /dev/null +++ b/src/main/kotlin/com/hero/alignlab/domain/group/resource/MyGroupResource.kt @@ -0,0 +1,25 @@ +package com.hero.alignlab.domain.group.resource + +import com.hero.alignlab.common.extension.wrapOk +import com.hero.alignlab.domain.auth.model.AuthUser +import com.hero.alignlab.domain.group.application.MyGroupService +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.GetMapping +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController + +@Tag(name = "My Group API") +@RestController +@RequestMapping(produces = [MediaType.APPLICATION_JSON_VALUE]) +class MyGroupResource( + private val myGroupService: MyGroupService, +) { + /** 그룹이 없는 경우, noContent로 반환 */ + @Operation(summary = "마이 그룹 조회") + @GetMapping("/api/v1/groups/my-group") + suspend fun getMyGroup( + user: AuthUser + ) = myGroupService.getMyGroup(user).wrapOk() +}