-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
317f795
commit 9a1bda5
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
src/main/kotlin/com/hero/alignlab/domain/group/application/MyGroupService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/kotlin/com/hero/alignlab/domain/group/model/response/MyGroupResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/kotlin/com/hero/alignlab/domain/group/resource/MyGroupResource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |