Skip to content

Commit

Permalink
feat: 내 그룹 조회
Browse files Browse the repository at this point in the history
  • Loading branch information
DongGeon0908 committed Sep 1, 2024
1 parent 317f795 commit 9a1bda5
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -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
)
}
}
}
Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit 9a1bda5

Please sign in to comment.