Skip to content

Commit

Permalink
Merge pull request #346 from 6QuizOnTheBlock/and/feat#323-group-sse
Browse files Browse the repository at this point in the history
And/feat#323 group sse
  • Loading branch information
TRASALBY authored May 17, 2024
2 parents a1d509c + f7e3965 commit 768b2e4
Show file tree
Hide file tree
Showing 46 changed files with 1,035 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fun BasicAppBar(
)

val animatedHeight by animateDpAsState(
targetValue = if (expanded) 180.dp else 60.dp,
targetValue = if (expanded) 210.dp else 60.dp,
animationSpec = TweenSpec(durationMillis = 300),
label = "앱바 크기"
)
Expand Down Expand Up @@ -88,7 +88,7 @@ fun BasicAppBar(
Icon(
modifier = Modifier
.fillMaxHeight()
.padding(vertical = 16.dp)
.padding(vertical = 20.dp)
.aspectRatio(1f),
painter = painterResource(id = leftIcon),
contentDescription = "로고",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fun UlbanDefaultAppBar(
content: String,
color: Color,
expanded: Boolean = true,
onclick: () -> Unit,
onclick: () -> Unit = {},
) {
BasicAppBar(
modifier = modifier,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.sixkids.model

data class MatchingRoom(
val dataKey: String,
val minCount: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.sixkids.model

import java.time.LocalDateTime

data class RunningChallengeByStudent(
val challenge: Challenge,
val leaderStatus: Boolean? = null,
val memberNames: List<MemberSimple>,
val type: GroupType,
val createTime: LocalDateTime?,
val endStatus: Boolean?
)
16 changes: 16 additions & 0 deletions android/core/model/src/main/java/com/sixkids/model/SSeData.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.sixkids.model

import kotlinx.datetime.toKotlinLocalDateTime
import kotlinx.serialization.Serializable
import java.time.LocalDateTime
import kotlinx.datetime.LocalDateTime as KotlinLocalDateTime

@Serializable
data class SseData(
val eventType: String,
val receiverId: Long,
val url: Long?,
val data: String?,
val time: KotlinLocalDateTime = LocalDateTime.now().toKotlinLocalDateTime()

)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.sixkids.data.model.request.ChallengeCreateRequest
import com.sixkids.data.model.response.ChallengeDetailResponse
import com.sixkids.data.model.response.ChallengeHistoryResponse
import com.sixkids.data.model.response.ChallengeSimpleResponse
import com.sixkids.data.model.response.RunningChallengeByStudentResponse
import com.sixkids.data.model.response.RunningChallengeResponse
import com.sixkids.data.network.ApiResponse
import com.sixkids.data.network.ApiResult
Expand Down Expand Up @@ -51,4 +52,9 @@ interface ChallengeService {
@Path("id") reportId: Long,
@Query("reportType") acceptStatus: String,
): ApiResult<ApiResponse<Unit>>

@GET("challenges/running/member")
suspend fun getRunningChallengeByStudent(
@Query("organizationId") organizationId: Int,
): ApiResult<ApiResponse<RunningChallengeByStudentResponse>>
}
39 changes: 39 additions & 0 deletions android/data/src/main/java/com/sixkids/data/api/GroupService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.sixkids.data.api

import com.sixkids.data.model.response.GroupMatchingRoomResponse
import com.sixkids.data.network.ApiResponse
import com.sixkids.data.network.ApiResult
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Query

interface GroupService {
@POST("challenges/groups/matchingroom")
suspend fun createMatchingRoom(
@Query("challengeId") challengeId: Long,
): ApiResult<ApiResponse<GroupMatchingRoomResponse>>

@GET("challenges/groups/invite")
suspend fun inviteFriend(
@Query("key") key: String,
@Query("memberId") memberId: Long,
): ApiResult<ApiResponse<Unit>>

@DELETE("challenges/groups/matching")
suspend fun deportFriend(
@Query("key") key: String,
@Query("memberId") memberId: Long,
): ApiResult<ApiResponse<Unit>>

@POST("challenges/groups/join")
suspend fun joinGroup(
@Query("key") key: String,
@Query("joinStatus") joinStatus : Boolean,
): ApiResult<ApiResponse<Unit>>

@POST("challenges/groups")
suspend fun createGroup(
@Query("key") key: String,
): ApiResult<ApiResponse<Long>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import com.sixkids.data.repository.chatting.remote.ChattingRemoteDataSource
import com.sixkids.data.repository.chatting.remote.ChattingRemoteDataSourceImpl
import com.sixkids.data.repository.comment.remote.CommentRemoteDataSource
import com.sixkids.data.repository.comment.remote.CommentRemoteDataSourceImpl
import com.sixkids.data.repository.group.remote.GroupDataSource
import com.sixkids.data.repository.group.remote.GroupDataSourceImpl
import com.sixkids.data.repository.organization.local.OrganizationLocalDataSource
import com.sixkids.data.repository.organization.local.OrganizationLocalDataSourceImpl
import com.sixkids.data.repository.organization.remote.OrganizationRemoteDataSource
Expand Down Expand Up @@ -70,4 +72,9 @@ abstract class DataSourceModule {
abstract fun bindRelayRemoteDataSource(
relayRemoteDataSource: RelayRemoteDataSourceImpl
): RelayRemoteDataSource

@Binds
abstract fun bindGroupDataSource(
groupDataSource: GroupDataSourceImpl
): GroupDataSource
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import com.sixkids.data.repository.TokenRepositoryImpl
import com.sixkids.data.repository.challenge.ChallengeRepositoryImpl
import com.sixkids.data.repository.chatting.ChattingRepositoryImpl
import com.sixkids.data.repository.comment.CommentRepositoryImpl
import com.sixkids.data.repository.group.GroupRepositoryImpl
import com.sixkids.data.repository.organization.OrganizationRepositoryImpl
import com.sixkids.data.repository.post.PostRepositoryImpl
import com.sixkids.data.repository.relay.RelayRepositoryImpl
import com.sixkids.data.repository.user.UserRepositoryImpl
import com.sixkids.domain.repository.ChallengeRepository
import com.sixkids.domain.repository.ChattingRepository
import com.sixkids.domain.repository.CommentRepository
import com.sixkids.domain.repository.GroupRepository
import com.sixkids.domain.repository.OrganizationRepository
import com.sixkids.domain.repository.PostRepository
import com.sixkids.domain.repository.RelayRepository
Expand Down Expand Up @@ -73,4 +75,10 @@ abstract class RepositoryModule {
abstract fun bindRelayRepository(
relayRepository: RelayRepositoryImpl
): RelayRepository

@Singleton
@Binds
abstract fun bindGroupRepository(
groupRepository: GroupRepositoryImpl
): GroupRepository
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.sixkids.data.di
import com.sixkids.data.api.ChallengeService
import com.sixkids.data.api.CommentService
import com.sixkids.data.api.ChattingService
import com.sixkids.data.api.GroupService
import com.sixkids.data.api.MemberOrgService
import com.sixkids.data.api.MemberService
import com.sixkids.data.api.OrganizationService
Expand Down Expand Up @@ -101,4 +102,12 @@ object ServiceModule {
return retrofit.create(MemberOrgService::class.java)
}

@Singleton
@Provides
fun provideGroupService(
@NetworkModule.AuthRetrofit retrofit: Retrofit
): GroupService {
return retrofit.create(GroupService::class.java)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.sixkids.data.model.response

import com.sixkids.model.MatchingRoom

data class GroupMatchingRoomResponse(
val dataKey: String,
val minCount: Int
)

internal fun GroupMatchingRoomResponse.toModel(): MatchingRoom =
MatchingRoom(
dataKey = dataKey,
minCount = minCount
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sixkids.data.model.response

import com.sixkids.model.MemberSimple
import com.sixkids.model.RelayQuestion
import java.time.LocalDateTime

Expand Down Expand Up @@ -27,4 +28,10 @@ internal fun RunnerResponse.toModel() = RelayQuestion(
question = question,
turn = turn,
endStatus = endStatus,
)
)

internal fun MemberSimpleResponse.toModel() = MemberSimple(
id = id,
name = name,
photo = photo,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.sixkids.data.model.response

import com.sixkids.model.GroupType
import com.sixkids.model.RunningChallengeByStudent
import com.squareup.moshi.Json
import java.time.LocalDateTime

data class RunningChallengeByStudentResponse(
@Json(name = "challengeSimpleDTO")
val challenge: ChallengeResponse,
val leaderStatus: Boolean?,
@Json(name = "memberList")
val memberNames: List<MemberSimpleResponse>?,
val type: String,
val createTime: LocalDateTime?,
val endStatus: Boolean?
)

internal fun RunningChallengeByStudentResponse.toModel() = RunningChallengeByStudent(
challenge = challenge.toModel(),
leaderStatus = leaderStatus,
memberNames = memberNames?.map { it.toModel() }?: emptyList(),
type = GroupType.valueOf(type),
createTime = createTime,
endStatus = endStatus
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import com.sixkids.data.api.ChallengeService
import com.sixkids.data.model.response.toModel
import com.sixkids.data.repository.challenge.remote.ChallengeHistoryPagingSource
import com.sixkids.data.repository.challenge.remote.ChallengeHistoryPagingSource.Companion.DEFAULT_SIZE
import com.sixkids.data.repository.challenge.remote.ChallengeRemoteDataSourceImpl
Expand All @@ -12,6 +13,7 @@ import com.sixkids.model.AcceptStatus
import com.sixkids.model.Challenge
import com.sixkids.model.ChallengeDetail
import com.sixkids.model.GroupSimple
import com.sixkids.model.RunningChallengeByStudent
import kotlinx.coroutines.flow.Flow
import java.time.LocalDateTime
import javax.inject.Inject
Expand All @@ -38,6 +40,11 @@ class ChallengeRepositoryImpl @Inject constructor(
override suspend fun getRunningChallenge(organizationId: Int) =
challengeRemoteDataSourceImpl.getRunningChallenges(organizationId)

override suspend fun getRunningChallengesByStudent(
organizationId: Int
): RunningChallengeByStudent =
challengeRemoteDataSourceImpl.getRunningChallengesByStudent(organizationId).toModel()

override suspend fun createChallenge(
organizationId: Int,
title: String,
Expand All @@ -58,8 +65,8 @@ class ChallengeRepositoryImpl @Inject constructor(
groups
)

override suspend fun getChallengeSimple(challengeId: Int): Challenge
= challengeRemoteDataSourceImpl.getChallengeSimple(challengeId)
override suspend fun getChallengeSimple(challengeId: Int): Challenge =
challengeRemoteDataSourceImpl.getChallengeSimple(challengeId)

override suspend fun getChallengeDetail(challengeId: Long, groupId: Long?): ChallengeDetail =
challengeRemoteDataSourceImpl.getChallengeDetail(challengeId, groupId)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sixkids.data.repository.challenge.remote

import com.sixkids.data.model.response.RunningChallengeByStudentResponse
import com.sixkids.model.AcceptStatus
import com.sixkids.model.Challenge
import com.sixkids.model.ChallengeDetail
Expand All @@ -11,6 +12,8 @@ interface ChallengeRemoteDataSource {

suspend fun getRunningChallenges(organizationId: Int): RunningChallenge

suspend fun getRunningChallengesByStudent(organizationId: Int): RunningChallengeByStudentResponse

suspend fun createChallenge(
organizationId: Int,
title: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.sixkids.data.repository.challenge.remote
import com.sixkids.data.api.ChallengeService
import com.sixkids.data.model.request.ChallengeCreateRequest
import com.sixkids.data.model.request.GroupRequest
import com.sixkids.data.model.response.RunningChallengeByStudentResponse
import com.sixkids.data.model.response.toModel
import com.sixkids.model.AcceptStatus
import com.sixkids.model.Challenge
Expand All @@ -17,6 +18,12 @@ class ChallengeRemoteDataSourceImpl @Inject constructor(
override suspend fun getRunningChallenges(organizationId: Int) =
challengeService.getRunningChallenge(organizationId).getOrThrow().data.toModel()

override suspend fun getRunningChallengesByStudent(
organizationId: Int
): RunningChallengeByStudentResponse =
challengeService.getRunningChallengeByStudent(organizationId).getOrThrow().data


override suspend fun createChallenge(
organizationId: Int,
title: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.sixkids.data.repository.group

import com.sixkids.data.model.response.toModel
import com.sixkids.data.repository.group.remote.GroupDataSource
import com.sixkids.domain.repository.GroupRepository
import com.sixkids.model.MatchingRoom
import javax.inject.Inject

class GroupRepositoryImpl @Inject constructor(
private val groupDataSource: GroupDataSource
) : GroupRepository {
override suspend fun createMatchingRoom(challengeId: Long): MatchingRoom =
groupDataSource.createMatchingRoom(challengeId).toModel()

override suspend fun inviteFriend(key: String, memberId: Long) =
groupDataSource.inviteFriend(key, memberId)

override suspend fun deportFriend(key: String, memberId: Long) =
groupDataSource.deportFriend(key, memberId)

override suspend fun joinGroup(key: String, joinStatus: Boolean) =
groupDataSource.joinGroup(key, joinStatus)

override suspend fun createGroup(key: String): Long = groupDataSource.createGroup(key)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.sixkids.data.repository.group.remote

import com.sixkids.data.model.response.GroupMatchingRoomResponse

interface GroupDataSource {
suspend fun createMatchingRoom(challengeId: Long): GroupMatchingRoomResponse

suspend fun inviteFriend(key: String, memberId: Long)

suspend fun deportFriend(key: String, memberId: Long)

suspend fun joinGroup(key: String, joinStatus: Boolean)

suspend fun createGroup(key: String): Long
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.sixkids.data.repository.group.remote

import com.sixkids.data.api.GroupService
import com.sixkids.data.model.response.GroupMatchingRoomResponse
import javax.inject.Inject

class GroupDataSourceImpl @Inject constructor(
private val groupService: GroupService
) : GroupDataSource {
override suspend fun createMatchingRoom(challengeId: Long): GroupMatchingRoomResponse =
groupService.createMatchingRoom(challengeId).getOrThrow().data

override suspend fun inviteFriend(key: String, memberId: Long) =
groupService.inviteFriend(key, memberId).getOrThrow().data

override suspend fun deportFriend(key: String, memberId: Long) =
groupService.deportFriend(key, memberId).getOrThrow().data

override suspend fun joinGroup(key: String, joinStatus: Boolean) =
groupService.joinGroup(key, joinStatus).getOrThrow().data

override suspend fun createGroup(key: String): Long =
groupService.createGroup(key).getOrThrow().data
}
Loading

0 comments on commit 768b2e4

Please sign in to comment.