-
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
497802d
commit b7087bb
Showing
58 changed files
with
1,790 additions
and
20 deletions.
There are no files selected for viewing
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
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
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
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
12 changes: 12 additions & 0 deletions
12
core/data/src/main/kotlin/com/withpeace/withpeace/core/data/mapper/ChangedProfileMapper.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,12 @@ | ||
package com.withpeace.withpeace.core.data.mapper | ||
|
||
import com.withpeace.withpeace.core.domain.model.profile.ChangedProfile | ||
import com.withpeace.withpeace.core.domain.model.profile.Nickname | ||
import com.withpeace.withpeace.core.network.di.response.ChangedProfileResponse | ||
|
||
fun ChangedProfileResponse.toDomain(): ChangedProfile { | ||
return ChangedProfile( | ||
nickname = Nickname(this.nickname), | ||
profileImageUrl = profileImageUrl, | ||
) | ||
} |
13 changes: 13 additions & 0 deletions
13
core/data/src/main/kotlin/com/withpeace/withpeace/core/data/mapper/ProfileInfoMapper.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.withpeace.withpeace.core.data.mapper | ||
|
||
import com.withpeace.withpeace.core.domain.model.profile.Nickname | ||
import com.withpeace.withpeace.core.domain.model.profile.ProfileInfo | ||
import com.withpeace.withpeace.core.network.di.response.ProfileResponse | ||
|
||
fun ProfileResponse.toDomain(): ProfileInfo { | ||
return ProfileInfo( | ||
nickname = Nickname(nickname), | ||
profileImageUrl = profileImageUrl, | ||
email = email, | ||
) | ||
} |
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
162 changes: 162 additions & 0 deletions
162
...ata/src/main/kotlin/com/withpeace/withpeace/core/data/repository/DefaultUserRepository.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,162 @@ | ||
package com.withpeace.withpeace.core.data.repository | ||
|
||
import android.content.Context | ||
import android.net.Uri | ||
import com.skydoves.sandwich.messageOrNull | ||
import com.skydoves.sandwich.suspendMapSuccess | ||
import com.skydoves.sandwich.suspendOnError | ||
import com.skydoves.sandwich.suspendOnException | ||
import com.withpeace.withpeace.core.data.mapper.toDomain | ||
import com.withpeace.withpeace.core.data.util.convertToFile | ||
import com.withpeace.withpeace.core.datastore.dataStore.TokenPreferenceDataSource | ||
import com.withpeace.withpeace.core.domain.model.WithPeaceError | ||
import com.withpeace.withpeace.core.domain.model.profile.ChangedProfile | ||
import com.withpeace.withpeace.core.domain.model.profile.Nickname | ||
import com.withpeace.withpeace.core.domain.model.profile.ProfileInfo | ||
import com.withpeace.withpeace.core.domain.repository.UserRepository | ||
import com.withpeace.withpeace.core.network.di.common.getErrorBody | ||
import com.withpeace.withpeace.core.network.di.request.NicknameRequest | ||
import com.withpeace.withpeace.core.network.di.service.UserService | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flow | ||
import okhttp3.MediaType.Companion.toMediaTypeOrNull | ||
import okhttp3.MultipartBody | ||
import okhttp3.RequestBody.Companion.asRequestBody | ||
import okhttp3.RequestBody.Companion.toRequestBody | ||
import java.io.File | ||
import javax.inject.Inject | ||
|
||
class DefaultUserRepository @Inject constructor( | ||
@ApplicationContext private val context: Context, | ||
private val userService: UserService, | ||
private val tokenPreferenceDataSource: TokenPreferenceDataSource, | ||
) : UserRepository { | ||
override fun getProfile( | ||
onError: suspend (WithPeaceError) -> Unit, | ||
): Flow<ProfileInfo> = flow { | ||
userService.getProfile().suspendMapSuccess { | ||
emit(this.data.toDomain()) | ||
}.suspendOnError { | ||
if (statusCode.code == 401) { | ||
onError(WithPeaceError.UnAuthorized()) | ||
} else { | ||
val errorBody = errorBody?.getErrorBody() | ||
onError(WithPeaceError.GeneralError(errorBody?.code, errorBody?.message)) | ||
} | ||
}.suspendOnException { | ||
onError(WithPeaceError.GeneralError(message = messageOrNull)) | ||
} | ||
} | ||
|
||
override fun registerProfile( | ||
nickname: String, | ||
profileImage: String, | ||
onError: (WithPeaceError) -> Unit, | ||
): Flow<Unit> { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun updateProfile( | ||
nickname: String, | ||
profileImage: String, | ||
onError: suspend (WithPeaceError) -> Unit, | ||
): Flow<ChangedProfile> = flow { | ||
val imagePart = getImagePart(profileImage) | ||
userService.updateProfile( | ||
nickname.toRequestBody("text/plain".toMediaTypeOrNull()), imagePart, | ||
).suspendMapSuccess { | ||
emit(this.data.toDomain()) | ||
}.suspendOnError { | ||
if (statusCode.code == 401) { | ||
onError(WithPeaceError.UnAuthorized()) | ||
} else { | ||
val errorBody = errorBody?.getErrorBody() | ||
onError(WithPeaceError.GeneralError(errorBody?.code, errorBody?.message)) | ||
} | ||
}.suspendOnException { | ||
onError(WithPeaceError.GeneralError(message = messageOrNull)) | ||
} | ||
} | ||
|
||
override fun updateNickname( | ||
nickname: String, | ||
onError: suspend (WithPeaceError) -> Unit, | ||
): Flow<ChangedProfile> = | ||
flow { | ||
userService.updateNickname(NicknameRequest(nickname)).suspendMapSuccess { | ||
emit(ChangedProfile(nickname = Nickname(this.data))) | ||
}.suspendOnError { | ||
if (statusCode.code == 401) { | ||
onError(WithPeaceError.UnAuthorized()) | ||
} else { | ||
val errorBody = errorBody?.getErrorBody() | ||
onError(WithPeaceError.GeneralError(errorBody?.code, errorBody?.message)) | ||
} | ||
}.suspendOnException { | ||
onError(WithPeaceError.GeneralError(message = messageOrNull)) | ||
} | ||
} | ||
|
||
override fun updateProfileImage( | ||
profileImage: String, | ||
onError: suspend (WithPeaceError) -> Unit, | ||
): Flow<ChangedProfile> = flow { | ||
val imagePart = getImagePart(profileImage) | ||
userService.updateImage(imagePart).suspendMapSuccess { | ||
emit(ChangedProfile(profileImageUrl = this.data)) | ||
}.suspendOnError { | ||
if (statusCode.code == 401) { | ||
onError(WithPeaceError.UnAuthorized()) | ||
} else { | ||
val errorBody = errorBody?.getErrorBody() | ||
onError(WithPeaceError.GeneralError(errorBody?.code, errorBody?.message)) | ||
} | ||
}.suspendOnException { | ||
onError(WithPeaceError.GeneralError(message = messageOrNull)) | ||
} | ||
} | ||
|
||
override fun verifyNicknameDuplicated( | ||
nickname: Nickname, | ||
onError: suspend (WithPeaceError) -> Unit, | ||
): Flow<Unit> = flow { | ||
userService.isNicknameDuplicate(nickname.value).suspendMapSuccess { | ||
if (this.data) { | ||
onError(WithPeaceError.GeneralError(code = 2)) | ||
} else { | ||
emit(Unit) | ||
} | ||
}.suspendOnError { | ||
onError(WithPeaceError.GeneralError(statusCode.code, messageOrNull)) | ||
}.suspendOnException { | ||
onError(WithPeaceError.GeneralError(message = messageOrNull)) | ||
} | ||
} | ||
|
||
override fun logout(onError: suspend (WithPeaceError) -> Unit): Flow<Unit> = flow { | ||
userService.logout().suspendMapSuccess { | ||
tokenPreferenceDataSource.removeAll() | ||
emit(Unit) | ||
}.suspendOnError { | ||
if (statusCode.code == 401) { | ||
onError(WithPeaceError.UnAuthorized()) | ||
} else { | ||
val errorBody = errorBody?.getErrorBody() | ||
onError(WithPeaceError.GeneralError(errorBody?.code, errorBody?.message)) | ||
} | ||
}.suspendOnException { | ||
onError(WithPeaceError.GeneralError(message = messageOrNull)) | ||
} | ||
} | ||
|
||
private fun getImagePart(profileImage: String): MultipartBody.Part { | ||
val requestFile: File = Uri.parse(profileImage).convertToFile(context) | ||
val imageRequestBody = requestFile.asRequestBody("image/*".toMediaTypeOrNull()) | ||
return MultipartBody.Part.createFormData( | ||
"imageFile", | ||
requestFile.name, | ||
imageRequestBody, | ||
) | ||
} | ||
} |
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
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
29 changes: 29 additions & 0 deletions
29
core/designsystem/src/main/java/com/withpeace/withpeace/core/designsystem/ui/TitleBar.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.withpeace.withpeace.core.designsystem.ui | ||
|
||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import com.withpeace.withpeace.core.designsystem.theme.WithpeaceTheme | ||
|
||
@Composable | ||
fun TitleBar(title: String, modifier: Modifier = Modifier) { | ||
Row( | ||
verticalAlignment = Alignment.CenterVertically, | ||
modifier = modifier | ||
.fillMaxWidth() | ||
.height(56.dp) | ||
.padding(start = 24.dp), | ||
) { | ||
Text( | ||
text = title, | ||
style = WithpeaceTheme.typography.title1, | ||
color = WithpeaceTheme.colors.SystemBlack, | ||
) | ||
} | ||
} |
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.