Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[faet] 기존단체입장 초대코드 api 통신 #108

Merged
merged 15 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ interface PingleLocalDataSource {
var userName: String
var accessToken: String
var refreshToken: String
var groupId: Int
var groupName: String
fun clear(): Unit
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.sopt.pingle.data.datasource.remote

import org.sopt.pingle.data.model.remote.request.RequestJoinGroupCodeDto
import org.sopt.pingle.data.model.remote.response.ResponseJoinGroupCodeDto
import org.sopt.pingle.data.model.remote.response.ResponseJoinGroupInfoDto
import org.sopt.pingle.util.base.BaseResponse

interface JoinGroupRemoteDataSource {
suspend fun getJoinGroupInfo(teamId: Int): BaseResponse<ResponseJoinGroupInfoDto>
suspend fun postJoinGroupCode(
teamId: Int,
requestJoinGroupCode: RequestJoinGroupCodeDto
): BaseResponse<ResponseJoinGroupCodeDto>
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ class PingleLocalDataSourceImpl @Inject constructor(
get() = pref.getString(REFRESH_TOKEN, "") ?: ""
set(value) = pref.edit { putString(REFRESH_TOKEN, value) }

override var groupId: Int
get() = pref.getInt(GROUP_ID, -1)
set(value) = pref.edit { putInt(GROUP_ID, value) }

override var groupName: String
get() = pref.getString(GROUP_NAME, "") ?: ""
set(value) = pref.edit { putString(GROUP_NAME, value) }

override fun clear() {
pref.edit {
clear()
Expand All @@ -59,5 +67,7 @@ class PingleLocalDataSourceImpl @Inject constructor(
const val USER_NAME = "UserName"
const val ACCESS_TOKEN = "AccessToken"
const val REFRESH_TOKEN = "RefreshToken"
const val GROUP_ID = "GroupId"
const val GROUP_NAME = "GroupName"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.sopt.pingle.data.datasourceimpl.remote

import javax.inject.Inject
import org.sopt.pingle.data.datasource.remote.JoinGroupRemoteDataSource
import org.sopt.pingle.data.model.remote.request.RequestJoinGroupCodeDto
import org.sopt.pingle.data.model.remote.response.ResponseJoinGroupCodeDto
import org.sopt.pingle.data.model.remote.response.ResponseJoinGroupInfoDto
import org.sopt.pingle.data.service.JoinGroupService
import org.sopt.pingle.util.base.BaseResponse

class JoinGroupRemoteDataSourceImpl @Inject constructor(
private val joinGroupService: JoinGroupService
) : JoinGroupRemoteDataSource {
override suspend fun getJoinGroupInfo(teamId: Int): BaseResponse<ResponseJoinGroupInfoDto> =
joinGroupService.getJoinGroupInfo(teamId = teamId)

override suspend fun postJoinGroupCode(
teamId: Int,
requestJoinGroupCode: RequestJoinGroupCodeDto
): BaseResponse<ResponseJoinGroupCodeDto> =
joinGroupService.postJoinGroupCode(
teamId = teamId,
requestJoinGroupCode = requestJoinGroupCode
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.sopt.pingle.data.mapper

import org.sopt.pingle.data.model.remote.request.RequestJoinGroupCodeDto
import org.sopt.pingle.domain.model.RequestJoinGroupCodeEntity

fun RequestJoinGroupCodeEntity.toRequestJoinGroupCode() = RequestJoinGroupCodeDto(
code = code
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.sopt.pingle.data.model.remote.request

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class RequestJoinGroupCodeDto(
@SerialName("code")
val code: String
)
Original file line number Diff line number Diff line change
@@ -1,34 +1,18 @@
package org.sopt.pingle.data.model.remote.response

import kotlinx.serialization.SerialName
import org.sopt.pingle.domain.model.JoinGroupCodeEntity
import kotlinx.serialization.Serializable
import org.sopt.pingle.domain.model.ResponseJoinGroupCodeEntity

@Serializable
data class ResponseJoinGroupCodeDto(
@SerialName("code")
val code: Int,
@SerialName("message")
val message: String,
@SerialName("data")
val data: Data
@SerialName("id")
val id: Int,
@SerialName("name")
val name: String
) {
data class Data(
@SerialName("id")
val id: Int,
@SerialName("keyword")
val keyword: String,
@SerialName("name")
val name: String,
@SerialName("meetingCount")
val meetingCount: Int,
@SerialName("participantCount")
val participantCount: Int
) {
fun toJoinGroupCodeEntity() = JoinGroupCodeEntity(
id = this.id,
keyword = this.keyword,
name = this.name,
meetingCount = this.meetingCount,
participantCount = this.participantCount
)
}
fun toResponseJoinGroupCode() = ResponseJoinGroupCodeEntity(
id = id,
name = name
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.sopt.pingle.data.model.remote.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import org.sopt.pingle.domain.model.JoinGroupInfoEntity

@Serializable
data class ResponseJoinGroupInfoDto(
@SerialName("id")
val id: Int,
@SerialName("keyword")
val keyword: String,
@SerialName("name")
val name: String,
@SerialName("meetingCount")
val meetingCount: Int,
@SerialName("participantCount")
val participantCount: Int
) {
fun toJoinGroupCodeEntity() = JoinGroupInfoEntity(
id = this.id,
keyword = this.keyword,
name = this.name,
meetingCount = this.meetingCount,
participantCount = this.participantCount
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.sopt.pingle.data.repository

import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import org.sopt.pingle.data.datasource.remote.JoinGroupRemoteDataSource
import org.sopt.pingle.data.mapper.toRequestJoinGroupCode
import org.sopt.pingle.domain.model.JoinGroupInfoEntity
import org.sopt.pingle.domain.model.RequestJoinGroupCodeEntity
import org.sopt.pingle.domain.model.ResponseJoinGroupCodeEntity
import org.sopt.pingle.domain.repository.JoinGroupRepository

class JoinGroupRepositoryImpl @Inject constructor(
private val joinGroupRemoteDataSource: JoinGroupRemoteDataSource
) : JoinGroupRepository {
override fun getJoinGroupInfo(teamId: Int): Flow<JoinGroupInfoEntity> = flow {
val result = runCatching {
joinGroupRemoteDataSource.getJoinGroupInfo(teamId = teamId).data.toJoinGroupCodeEntity()
}
emit(result.getOrThrow())
}

override fun postJoinGroupCode(
teamId: Int,
requestJoinGroupCode: RequestJoinGroupCodeEntity
): Flow<ResponseJoinGroupCodeEntity> = flow {
val result = runCatching {
joinGroupRemoteDataSource.postJoinGroupCode(
teamId = teamId,
requestJoinGroupCode = requestJoinGroupCode.toRequestJoinGroupCode()
).data.toResponseJoinGroupCode()
}
emit(result.getOrThrow())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.sopt.pingle.data.service

import org.sopt.pingle.data.model.remote.request.RequestJoinGroupCodeDto
import org.sopt.pingle.data.model.remote.response.ResponseJoinGroupCodeDto
import org.sopt.pingle.data.model.remote.response.ResponseJoinGroupInfoDto
import org.sopt.pingle.util.base.BaseResponse
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Path

interface JoinGroupService {
@GET("$VERSION/$TEAMS/{$TEAM_ID}")
suspend fun getJoinGroupInfo(
@Path("$TEAM_ID") teamId: Int
): BaseResponse<ResponseJoinGroupInfoDto>

@POST("$VERSION/$TEAMS/{$TEAM_ID}/$REGISTER")
suspend fun postJoinGroupCode(
@Path("$TEAM_ID") teamId: Int,
@Body requestJoinGroupCode: RequestJoinGroupCodeDto
): BaseResponse<ResponseJoinGroupCodeDto>

companion object {
const val VERSION = "v1"
const val TEAMS = "teams"
const val TEAM_ID = "teamId"
const val REGISTER = "register"
}
}
6 changes: 6 additions & 0 deletions app/src/main/java/org/sopt/pingle/di/DataSourceModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import org.sopt.pingle.data.datasource.local.DummyLocalDataSource
import org.sopt.pingle.data.datasource.local.PingleLocalDataSource
import org.sopt.pingle.data.datasource.remote.AuthRemoteDataSource
import org.sopt.pingle.data.datasource.remote.DummyRemoteDataSource
import org.sopt.pingle.data.datasource.remote.JoinGroupRemoteDataSource
import org.sopt.pingle.data.datasource.remote.MapRemoteDataSource
import org.sopt.pingle.data.datasource.remote.PingleRemoteDataSource
import org.sopt.pingle.data.datasource.remote.PlanRemoteDataSource
import org.sopt.pingle.data.datasourceimpl.local.DummyLocalDataSourceImpl
import org.sopt.pingle.data.datasourceimpl.local.PingleLocalDataSourceImpl
import org.sopt.pingle.data.datasourceimpl.remote.AuthRemoteDataSourceImpl
import org.sopt.pingle.data.datasourceimpl.remote.DummyRemoteDataSourceImpl
import org.sopt.pingle.data.datasourceimpl.remote.JoinGroupRemoteDataSourceImpl
import org.sopt.pingle.data.datasourceimpl.remote.MapRemoteDataSourceImpl
import org.sopt.pingle.data.datasourceimpl.remote.PingleRemoteDataSourceImpl
import org.sopt.pingle.data.datasourceimpl.remote.PlanRemoteDataSourceImpl
Expand Down Expand Up @@ -50,4 +52,8 @@ abstract class DataSourceModule {
@Binds
@Singleton
abstract fun bindsPlanRemoteDataSource(planRemoteDataSourceImpl: PlanRemoteDataSourceImpl): PlanRemoteDataSource

@Binds
@Singleton
abstract fun bindsJoinGroupRemoteDataSource(joinGroupRemoteDataSourceImpl: JoinGroupRemoteDataSourceImpl): JoinGroupRemoteDataSource
}
6 changes: 6 additions & 0 deletions app/src/main/java/org/sopt/pingle/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton
import org.sopt.pingle.data.repository.AuthRepositoryImpl
import org.sopt.pingle.data.repository.DummyRepositoryImpl
import org.sopt.pingle.data.repository.JoinGroupRepositoryImpl
import org.sopt.pingle.data.repository.MapRepositoryImpl
import org.sopt.pingle.data.repository.PingleRepositoryImpl
import org.sopt.pingle.data.repository.PlanRepositoryImpl
import org.sopt.pingle.domain.repository.AuthRepository
import org.sopt.pingle.domain.repository.DummyRepository
import org.sopt.pingle.domain.repository.JoinGroupRepository
import org.sopt.pingle.domain.repository.MapRepository
import org.sopt.pingle.domain.repository.PingleRepository
import org.sopt.pingle.domain.repository.PlanRepository
Expand All @@ -38,4 +40,8 @@ abstract class RepositoryModule {
@Binds
@Singleton
abstract fun bindsPlanRepository(planRepositoryImpl: PlanRepositoryImpl): PlanRepository

@Binds
@Singleton
abstract fun bindsJoinGroupRepository(joinGroupRepositoryImpl: JoinGroupRepositoryImpl): JoinGroupRepository
}
7 changes: 6 additions & 1 deletion app/src/main/java/org/sopt/pingle/di/ServiceModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton
import org.sopt.pingle.data.service.AuthService
import org.sopt.pingle.data.service.DummyService
import org.sopt.pingle.data.service.JoinGroupService
import org.sopt.pingle.data.service.MapService
import org.sopt.pingle.data.service.PingleService
import org.sopt.pingle.data.service.PlanService
import org.sopt.pingle.di.qualifier.Pingle
import retrofit2.Retrofit
import retrofit2.create

@Module
@InstallIn(SingletonComponent::class)
Expand Down Expand Up @@ -41,4 +41,9 @@ object ServiceModule {
@Singleton
fun providesPlanService(@Pingle retrofit: Retrofit): PlanService =
retrofit.create(PlanService::class.java)

@Provides
@Singleton
fun providesJoinGroupService(@Pingle retrofit: Retrofit): JoinGroupService =
retrofit.create(JoinGroupService::class.java)
}
13 changes: 13 additions & 0 deletions app/src/main/java/org/sopt/pingle/di/UseCaseModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton
import org.sopt.pingle.domain.repository.DummyRepository
import org.sopt.pingle.domain.repository.JoinGroupRepository
import org.sopt.pingle.domain.repository.MapRepository
import org.sopt.pingle.domain.repository.PingleRepository
import org.sopt.pingle.domain.repository.PlanRepository
import org.sopt.pingle.domain.usecase.GetDummyUserListUseCase
import org.sopt.pingle.domain.usecase.GetJoinGroupInfoUseCase
import org.sopt.pingle.domain.usecase.GetPinListWithoutFilteringUseCase
import org.sopt.pingle.domain.usecase.GetPingleListUseCase
import org.sopt.pingle.domain.usecase.GetPlanLocationListUseCase
import org.sopt.pingle.domain.usecase.PostJoinGroupCodeUseCase
import org.sopt.pingle.domain.usecase.PostPingleCancelUseCase
import org.sopt.pingle.domain.usecase.PostPingleJoinUseCase
import org.sopt.pingle.domain.usecase.SetDummyDataUseCase
Expand Down Expand Up @@ -54,4 +57,14 @@ class UseCaseModule {
@Singleton
fun providesGetPlanLocationListUseCase(planRepository: PlanRepository): GetPlanLocationListUseCase =
GetPlanLocationListUseCase(planRepository = planRepository)

@Provides
@Singleton
fun providesGetJoinGroupInfoUseCase(joinGroupRepository: JoinGroupRepository): GetJoinGroupInfoUseCase =
GetJoinGroupInfoUseCase(joinGroupRepository = joinGroupRepository)

@Provides
@Singleton
fun providesPostJoinGroupCodeUseCase(joinGroupRepository: JoinGroupRepository): PostJoinGroupCodeUseCase =
PostJoinGroupCodeUseCase(joinGroupRepository = joinGroupRepository)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.sopt.pingle.domain.model

data class JoinGroupCodeEntity(
data class JoinGroupInfoEntity(
val id: Int,
val keyword: String,
val name: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.sopt.pingle.domain.model

class RequestJoinGroupCodeEntity(
val code: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.sopt.pingle.domain.model

data class ResponseJoinGroupCodeEntity(
val id: Int,
val name: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.sopt.pingle.domain.repository

import kotlinx.coroutines.flow.Flow
import org.sopt.pingle.domain.model.JoinGroupInfoEntity
import org.sopt.pingle.domain.model.RequestJoinGroupCodeEntity
import org.sopt.pingle.domain.model.ResponseJoinGroupCodeEntity

interface JoinGroupRepository {
fun getJoinGroupInfo(teamId: Int): Flow<JoinGroupInfoEntity>
fun postJoinGroupCode(
teamId: Int,
requestJoinGroupCode: RequestJoinGroupCodeEntity
): Flow<ResponseJoinGroupCodeEntity>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.sopt.pingle.domain.usecase

import kotlinx.coroutines.flow.Flow
import org.sopt.pingle.domain.model.JoinGroupInfoEntity
import org.sopt.pingle.domain.repository.JoinGroupRepository

class GetJoinGroupInfoUseCase(
private val joinGroupRepository: JoinGroupRepository
) {
operator fun invoke(teamId: Int): Flow<JoinGroupInfoEntity> =
joinGroupRepository.getJoinGroupInfo(teamId = teamId)
}
Loading
Loading