-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from Begin-Vegan/feature/BVVER24-146-mypage-u…
…ser-level-api Mypage 나만의 식물 일러스트 설정
- Loading branch information
Showing
23 changed files
with
367 additions
and
31 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
buildSrc/.gradle/8.4/executionHistory/executionHistory.lock
Binary file not shown.
52 changes: 52 additions & 0 deletions
52
data/src/main/java/com/example/data/di/MypageUserInfoModule.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,52 @@ | ||
package com.example.data.di | ||
|
||
import com.example.data.mapper.mypage.MypageUserInfoMapper | ||
import com.example.data.repository.local.auth.AuthTokenDataSource | ||
import com.example.data.repository.remote.mypage.MypageUserInfoRemoteDataSource | ||
import com.example.data.repository.remote.mypage.MypageUserInfoRemoteDataSourceImpl | ||
import com.example.data.repository.remote.mypage.MypageUserInfoRepositoryImpl | ||
import com.example.data.retrofit.MypageUserInfoService | ||
import com.example.domain.repository.mypage.MypageUserInfoRepository | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import retrofit2.Retrofit | ||
import javax.inject.Singleton | ||
|
||
@Module(includes = [NetworkModule::class, DataStoreModule::class]) | ||
@InstallIn(SingletonComponent::class) | ||
class MypageUserInfoModule { | ||
@Singleton | ||
@Provides | ||
fun provideMypageUserInfoService(retrofit: Retrofit): MypageUserInfoService { | ||
return retrofit.create(MypageUserInfoService::class.java) | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun provideMypageUserInfoDataSource( | ||
mypageUserInfoService: MypageUserInfoService, | ||
authTokenDataSource: AuthTokenDataSource | ||
): MypageUserInfoRemoteDataSource { | ||
return MypageUserInfoRemoteDataSourceImpl(mypageUserInfoService, authTokenDataSource) | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun provideMypageUserInfoRepository( | ||
mypageUserInfoRemoteDataSource: MypageUserInfoRemoteDataSource, | ||
mypageUserInfoMapper: MypageUserInfoMapper | ||
): MypageUserInfoRepository { | ||
return MypageUserInfoRepositoryImpl( | ||
mypageUserInfoRemoteDataSource, | ||
mypageUserInfoMapper | ||
) | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun provideMypageUserInfoMapper(): MypageUserInfoMapper { | ||
return MypageUserInfoMapper() | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
data/src/main/java/com/example/data/mapper/mypage/MypageUserInfoMapper.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.example.data.mapper.mypage | ||
|
||
import com.example.data.model.mypage.MypageUserInfoDto | ||
import com.example.domain.mapper.Mapper | ||
import com.example.domain.model.mypage.MypageUserInfo | ||
|
||
class MypageUserInfoMapper:Mapper<MypageUserInfoDto, MypageUserInfo> { | ||
override fun mapFromEntity(type: MypageUserInfoDto): MypageUserInfo { | ||
return MypageUserInfo( | ||
id = type.id, | ||
imageUrl = type.imageUrl, | ||
nickname = type.nickname, | ||
userLevel = type.userLevel, | ||
veganType = type.veganType, | ||
point = type.point | ||
) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
data/src/main/java/com/example/data/model/mypage/MypageUserInfoResponse.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.example.data.model.mypage | ||
|
||
import com.squareup.moshi.Json | ||
|
||
data class MypageUserInfoResponse( | ||
@Json(name = "check") | ||
val check: Boolean, | ||
@Json(name = "information") | ||
val information: MypageUserInfoDto | ||
) | ||
|
||
data class MypageUserInfoDto( | ||
@Json(name = "id") val id: Int, | ||
@Json(name = "imageUrl") val imageUrl:String, | ||
@Json(name = "nickname") val nickname:String, | ||
@Json(name = "userLevel") val userLevel:String, | ||
@Json(name = "veganType") val veganType:String, | ||
@Json(name = "point") val point:Int | ||
) |
8 changes: 8 additions & 0 deletions
8
...src/main/java/com/example/data/repository/remote/mypage/MypageUserInfoRemoteDataSource.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,8 @@ | ||
package com.example.data.repository.remote.mypage | ||
|
||
import com.example.data.model.mypage.MypageUserInfoResponse | ||
import com.skydoves.sandwich.ApiResponse | ||
|
||
interface MypageUserInfoRemoteDataSource { | ||
suspend fun getMypageUserInfo(): ApiResponse<MypageUserInfoResponse> | ||
} |
29 changes: 29 additions & 0 deletions
29
...main/java/com/example/data/repository/remote/mypage/MypageUserInfoRemoteDataSourceImpl.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,29 @@ | ||
package com.example.data.repository.remote.mypage | ||
|
||
import com.example.data.model.mypage.MypageUserInfoResponse | ||
import com.example.data.repository.local.auth.AuthTokenDataSource | ||
import com.example.data.retrofit.MypageUserInfoService | ||
import com.skydoves.sandwich.ApiResponse | ||
import com.skydoves.sandwich.retrofit.errorBody | ||
import com.skydoves.sandwich.suspendOnError | ||
import com.skydoves.sandwich.suspendOnSuccess | ||
import kotlinx.coroutines.flow.first | ||
import timber.log.Timber | ||
import javax.inject.Inject | ||
|
||
class MypageUserInfoRemoteDataSourceImpl @Inject constructor( | ||
private val mypageUserInfoService: MypageUserInfoService, | ||
private val authTokenDataSource: AuthTokenDataSource | ||
):MypageUserInfoRemoteDataSource { | ||
override suspend fun getMypageUserInfo(): ApiResponse<MypageUserInfoResponse> { | ||
val accessToken = authTokenDataSource.accessToken.first() | ||
val authHeader = "Bearer $accessToken" | ||
return mypageUserInfoService.getMypageUserInfo(authHeader).suspendOnSuccess { | ||
Timber.d("getMypageUserInfo successful") | ||
ApiResponse.Success(this.data) | ||
}.suspendOnError { | ||
Timber.e("getMypageUserInfo error: ${this.errorBody}") | ||
ApiResponse.Failure.Error(this.errorBody) | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
data/src/main/java/com/example/data/repository/remote/mypage/MypageUserInfoRepositoryImpl.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,39 @@ | ||
package com.example.data.repository.remote.mypage | ||
|
||
import com.example.data.mapper.mypage.MypageUserInfoMapper | ||
import com.example.domain.model.mypage.MypageUserInfo | ||
import com.example.domain.repository.mypage.MypageUserInfoRepository | ||
import com.skydoves.sandwich.ApiResponse | ||
import com.skydoves.sandwich.retrofit.errorBody | ||
import timber.log.Timber | ||
import javax.inject.Inject | ||
|
||
class MypageUserInfoRepositoryImpl @Inject constructor( | ||
private val mypageUserInfoRemoteDataSource: MypageUserInfoRemoteDataSource, | ||
private val mypageUserInfoMapper: MypageUserInfoMapper | ||
):MypageUserInfoRepository{ | ||
override suspend fun getMypageUserInfo(): Result<MypageUserInfo> { | ||
return try { | ||
val response = mypageUserInfoRemoteDataSource.getMypageUserInfo() | ||
when (response) { | ||
is ApiResponse.Success -> { | ||
val magazineList = mypageUserInfoMapper.mapFromEntity(response.data.information) | ||
Result.success(magazineList) | ||
} | ||
|
||
is ApiResponse.Failure.Error -> { | ||
Timber.e("getMypageUserInfo error: ${response.errorBody}") | ||
Result.failure(Exception("getMypageUserInfo failed")) | ||
} | ||
|
||
is ApiResponse.Failure.Exception -> { | ||
Timber.e("getMypageUserInfo exception: ${response.message}") | ||
Result.failure(response.throwable) | ||
} | ||
} | ||
} catch (e: Exception) { | ||
Timber.e(e, "getMypageUserInfo exception") | ||
Result.failure(e) | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
data/src/main/java/com/example/data/retrofit/MypageUserInfoService.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,13 @@ | ||
package com.example.data.retrofit | ||
|
||
import com.example.data.model.mypage.MypageUserInfoResponse | ||
import com.skydoves.sandwich.ApiResponse | ||
import retrofit2.http.GET | ||
import retrofit2.http.Header | ||
|
||
interface MypageUserInfoService { | ||
@GET("/api/v1/users/my-page") | ||
suspend fun getMypageUserInfo( | ||
@Header("Authorization") token: String | ||
): ApiResponse<MypageUserInfoResponse> | ||
} |
10 changes: 10 additions & 0 deletions
10
domain/src/main/java/com/example/domain/model/mypage/MypageUserInfo.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,10 @@ | ||
package com.example.domain.model.mypage | ||
|
||
data class MypageUserInfo( | ||
val id: Int, | ||
val imageUrl:String, | ||
val nickname:String, | ||
val userLevel:String, | ||
val veganType:String, | ||
val point:Int | ||
) |
7 changes: 7 additions & 0 deletions
7
domain/src/main/java/com/example/domain/repository/mypage/MypageUserInfoRepository.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,7 @@ | ||
package com.example.domain.repository.mypage | ||
|
||
import com.example.domain.model.mypage.MypageUserInfo | ||
|
||
interface MypageUserInfoRepository { | ||
suspend fun getMypageUserInfo(): Result<MypageUserInfo> | ||
} |
13 changes: 13 additions & 0 deletions
13
domain/src/main/java/com/example/domain/useCase/mypage/MypageUserInfoUseCase.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,13 @@ | ||
package com.example.domain.useCase.mypage | ||
|
||
import com.example.domain.model.mypage.MypageUserInfo | ||
import com.example.domain.repository.mypage.MypageUserInfoRepository | ||
import javax.inject.Inject | ||
|
||
class MypageUserInfoUseCase @Inject constructor( | ||
private val mypageUserInfoRepository: MypageUserInfoRepository | ||
){ | ||
suspend operator fun invoke():Result<MypageUserInfo> { | ||
return mypageUserInfoRepository.getMypageUserInfo() | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
presentation/src/main/java/com/example/presentation/util/UserLevelDrawables.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,30 @@ | ||
package com.example.presentation.util | ||
|
||
import android.content.Context | ||
import android.graphics.drawable.Drawable | ||
import androidx.core.content.ContextCompat | ||
import com.example.presentation.R | ||
|
||
data class UserLevelIllusts( | ||
val context:Context, | ||
val userLevelIllus:List<Drawable?> = listOf( | ||
ContextCompat.getDrawable(context, R.drawable.illus_user_level_1_seed), | ||
ContextCompat.getDrawable(context, R.drawable.illus_user_level_2_cotyledon), | ||
ContextCompat.getDrawable(context, R.drawable.illus_user_level_3_sprout), | ||
ContextCompat.getDrawable(context, R.drawable.illus_user_level_4_stem), | ||
ContextCompat.getDrawable(context, R.drawable.illus_user_level_5_leaf), | ||
ContextCompat.getDrawable(context, R.drawable.illus_user_level_6_tree), | ||
ContextCompat.getDrawable(context, R.drawable.illus_user_level_7_flower), | ||
ContextCompat.getDrawable(context, R.drawable.illus_user_level_8_fruit) | ||
), | ||
val userLevelIcons:List<Drawable?> = listOf( | ||
ContextCompat.getDrawable(context, R.drawable.ic_user_level_1_seed), | ||
ContextCompat.getDrawable(context, R.drawable.ic_user_level_2_cotyledon), | ||
ContextCompat.getDrawable(context, R.drawable.ic_user_level_3_sprout), | ||
ContextCompat.getDrawable(context, R.drawable.ic_user_level_4_stem), | ||
ContextCompat.getDrawable(context, R.drawable.ic_user_level_5_leaf), | ||
ContextCompat.getDrawable(context, R.drawable.ic_user_level_6_tree), | ||
ContextCompat.getDrawable(context, R.drawable.ic_user_level_7_flower), | ||
ContextCompat.getDrawable(context, R.drawable.ic_user_level_8_fruit), | ||
) | ||
) |
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
Oops, something went wrong.