Skip to content

Commit

Permalink
#86 refactor : Merge 후 Data layer 구조 통일
Browse files Browse the repository at this point in the history
  • Loading branch information
yy0ung committed Nov 21, 2023
1 parent 9fdfe8a commit a937870
Show file tree
Hide file tree
Showing 16 changed files with 78 additions and 177 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.avengers.nibobnebob.app.di

import com.avengers.nibobnebob.data.remote.NnApi
import com.avengers.nibobnebob.data.remote.IntroAPI
import com.avengers.nibobnebob.data.remote.MyPageApi
import com.avengers.nibobnebob.data.remote.IntroApi
import com.avengers.nibobnebob.data.remote.RefreshApi
import com.avengers.nibobnebob.data.remote.ValidationApi
import dagger.Module
Expand All @@ -19,8 +19,8 @@ object ApiModule {

@Singleton
@Provides
fun provideIntroService(retrofit: Retrofit): IntroAPI {
return retrofit.create(IntroAPI::class.java)
fun provideIntroService(retrofit: Retrofit): IntroApi {
return retrofit.create(IntroApi::class.java)
}

@Singleton
Expand All @@ -36,6 +36,6 @@ object ApiModule {
}
@Singleton
@Provides
fun provideNnApi(retrofit: Retrofit) : NnApi = retrofit.create(NnApi::class.java)
fun provideMyPageService(retrofit: Retrofit) : MyPageApi = retrofit.create(MyPageApi::class.java)

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package com.avengers.nibobnebob.app.di

import android.content.Context
import com.avengers.nibobnebob.app.App.Companion.dataStore
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent


@Module
@InstallIn(SingletonComponent::class)
object DataModule {

@Provides
fun provideDataStore(@ApplicationContext context: Context) = context.dataStore
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.avengers.nibobnebob.app.di

import com.avengers.nibobnebob.data.repository.MyPageEditRepository
import com.avengers.nibobnebob.data.repository.IntroRepository
import com.avengers.nibobnebob.data.repository.IntroRepositoryImpl
import com.avengers.nibobnebob.data.repository.MyPageRepository
import com.avengers.nibobnebob.data.repository_impl.MyPageEditRepositoryImpl
import com.avengers.nibobnebob.data.repository.ValidationRepository
import com.avengers.nibobnebob.data.repository.ValidationRepositoryImpl
import com.avengers.nibobnebob.data.repository_impl.MyPageRepositoryImpl
import dagger.Binds
import dagger.Module
Expand All @@ -19,10 +21,6 @@ abstract class RepositoryModule {
@Binds
abstract fun bindMyPageRepository(myPageRepositoryImpl: MyPageRepositoryImpl): MyPageRepository

@Singleton
@Binds
abstract fun bindMyPageEditRepository(myPageRepositoryImpl: MyPageEditRepositoryImpl): MyPageEditRepository

@Singleton
@Binds
abstract fun bindIntroRepository(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.avengers.nibobnebob.data.model.request

data class MyPageEditInfoRequest(
data class EditMyInfoRequest(
val nickName: String,
val email: String,
val provider: String,
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
package com.avengers.nibobnebob.data.model.response


data class MyPageEditInfoResponse(
val data: MyPageEditInfo,
val message: String,
val statusCode: Int
)


data class MyPageEditInfo(
data class MyDefaultInfoResponse(
val userInfo: UserEditInfo
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
package com.avengers.nibobnebob.data.model.response


data class MyPageInfoResponse(
val data: MyPageInfo,
val message: String,
val statusCode: Int
)


data class MyPageInfo(
data class MyInfoResponse(
val userInfo: UserInfo
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.POST

interface IntroAPI {
interface IntroApi {

@POST("/api/user")
suspend fun signup(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.avengers.nibobnebob.data.remote

import com.avengers.nibobnebob.data.model.request.EditMyInfoRequest
import com.avengers.nibobnebob.data.model.response.MyDefaultInfoResponse
import com.avengers.nibobnebob.data.model.response.MyInfoResponse
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.PUT

interface MyPageApi {
@GET("api/user/details")
suspend fun getMyInfo(
@Header("Authorization") token : String,
) : Response<MyInfoResponse>

@GET("api/user")
suspend fun getMyDefaultInfo(
@Header("Authorization") token : String,
) : Response<MyDefaultInfoResponse>

@PUT("api/user")
suspend fun editMyInfo(
@Header("Authorization") token : String,
@Body data : EditMyInfoRequest
) : Response<Unit>

}
36 changes: 0 additions & 36 deletions Aos/app/src/main/java/com/avengers/nibobnebob/data/remote/NnApi.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import com.avengers.nibobnebob.data.model.ApiState
import com.avengers.nibobnebob.data.model.request.DetailSignupRequest
import com.avengers.nibobnebob.data.model.response.NaverLoginResponse
import com.avengers.nibobnebob.data.model.runNNApi
import com.avengers.nibobnebob.data.remote.IntroAPI
import com.avengers.nibobnebob.data.remote.IntroApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

class IntroRepositoryImpl @Inject constructor(
private val api: IntroAPI
private val api: IntroApi
) : IntroRepository {

override fun signup(body: DetailSignupRequest): Flow<ApiState<Unit>> = flow {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package com.avengers.nibobnebob.data.repository

import com.avengers.nibobnebob.data.model.ApiState
import com.avengers.nibobnebob.data.model.response.MyPageInfoResponse
import com.avengers.nibobnebob.data.model.request.EditMyInfoRequest
import com.avengers.nibobnebob.data.model.response.MyDefaultInfoResponse
import com.avengers.nibobnebob.data.model.response.MyInfoResponse
import kotlinx.coroutines.flow.Flow

interface MyPageRepository {
fun getMyPageInfo(): Flow<ApiState<MyPageInfoResponse>>
fun getMyInfo(): Flow<ApiState<MyInfoResponse>>

fun getMyDefaultInfo(): Flow<ApiState<MyDefaultInfoResponse>>

fun editMyInfo(data: EditMyInfoRequest): Flow<ApiState<Unit>>

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
package com.avengers.nibobnebob.data.repository_impl

import com.avengers.nibobnebob.data.model.ApiState
import com.avengers.nibobnebob.data.model.response.MyPageInfoResponse
import com.avengers.nibobnebob.data.remote.NnApi
import com.avengers.nibobnebob.data.model.request.EditMyInfoRequest
import com.avengers.nibobnebob.data.model.response.MyDefaultInfoResponse
import com.avengers.nibobnebob.data.model.response.MyInfoResponse
import com.avengers.nibobnebob.data.model.runNNApi
import com.avengers.nibobnebob.data.remote.MyPageApi
import com.avengers.nibobnebob.data.repository.MyPageRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

class MyPageRepositoryImpl @Inject constructor(private val nnApi: NnApi) : MyPageRepository {
class MyPageRepositoryImpl @Inject constructor(private val api: MyPageApi) : MyPageRepository {
private val token = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwiaWQiOjIsImlhdCI6MjAxNjIzOTAyMn0.VMvtPcawKVzNyOV08lrArxUvM-XxowWIknsPFkjRTws"
override fun getMyPageInfo(): Flow<ApiState<MyPageInfoResponse>> = flow {
try {
val response = nnApi.getMyPageInfo(token)
if(response.isSuccessful){
emit(ApiState.Success(response.body()!!))
}else{
emit(ApiState.Error(response.code(), response.message()))
}
}catch (e: Exception) {
emit(ApiState.Exception(e))
}
override fun getMyInfo(): Flow<ApiState<MyInfoResponse>> = flow {
val result = runNNApi { api.getMyInfo(token) }
emit(result)

}

override fun getMyDefaultInfo(): Flow<ApiState<MyDefaultInfoResponse>> = flow {
val result = runNNApi { api.getMyDefaultInfo(token) }
emit(result)
}

override fun editMyInfo(data: EditMyInfoRequest): Flow<ApiState<Unit>> = flow {
val result = runNNApi { api.editMyInfo(token, data) }
emit(result)
}

}

0 comments on commit a937870

Please sign in to comment.