Skip to content

Commit

Permalink
Merge pull request #289 from Nexters/feature/Boolti-287
Browse files Browse the repository at this point in the history
Feature/boolti 287 프로필 조회 및 편집
  • Loading branch information
mangbaam authored Sep 9, 2024
2 parents 0b7b846 + afe1aec commit 8c403e8
Show file tree
Hide file tree
Showing 48 changed files with 2,046 additions and 66 deletions.
13 changes: 13 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,18 @@
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>

<service
android:name="com.google.android.gms.metadata.ModuleDependencies"
android:enabled="false"
android:exported="false"
tools:ignore="MissingClass">
<intent-filter>
<action android:name="com.google.android.gms.metadata.MODULE_DEPENDENCIES" />
</intent-filter>
<meta-data
android:name="photopicker_activity:0:required"
android:value="" />
</service>
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ internal class AuthDataSource @Inject constructor(
null
} else {
UserResponse(
id = it.userId ?: "",
id = it.userId,
nickname = it.nickname ?: "",
email = it.email ?: "",
imgPath = it.photo,
userCode = it.userCode,
introduction = it.profileIntroduction,
link = it.profileLink,
)
}
}
Expand Down Expand Up @@ -68,6 +70,8 @@ internal class AuthDataSource @Inject constructor(
phoneNumber = null,
photo = null,
userCode = null,
profileIntroduction = "",
profileLink = emptyList(),
accessToken = "",
refreshToken = "",
)
Expand All @@ -89,6 +93,8 @@ internal class AuthDataSource @Inject constructor(
email = user.email,
photo = user.imgPath,
userCode = user.userCode,
profileIntroduction = user.introduction,
profileLink = user.link,
)
}
Firebase.analytics.apply {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.nexters.boolti.data.datasource

import android.content.Context
import com.nexters.boolti.data.network.api.AuthFileService
import com.nexters.boolti.data.network.api.FileService
import com.nexters.boolti.data.network.response.UploadUrlsDto
import dagger.hilt.android.qualifiers.ApplicationContext
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.asRequestBody
import java.io.File
import javax.inject.Inject

internal class FileDataSource @Inject constructor(
@ApplicationContext private val context: Context,
private val authFileService: AuthFileService,
private val fileService: FileService,
) {
suspend fun requestUploadUrls(file: File): Result<UploadUrlsDto> = runCatching {
authFileService.requestUploadUrls().also {
val url = it.uploadUrl
fileService.requestUploadImage(
contentType = "image/jpeg",
url = url,
file = file.asRequestBody("image/jpeg".toMediaType()),
)
}
}.onFailure {
it.printStackTrace()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.nexters.boolti.data.datasource

import com.nexters.boolti.data.network.api.UserService
import com.nexters.boolti.data.network.response.UserResponse
import com.nexters.boolti.domain.request.EditProfileRequest
import com.nexters.boolti.domain.request.SignoutRequest
import javax.inject.Inject

Expand All @@ -14,4 +15,6 @@ internal class UserDataSource @Inject constructor(
}

suspend fun signout(request: SignoutRequest) = userService.signout(request)

suspend fun edit(request: EditProfileRequest): UserResponse = userService.editProfile(request)
}
3 changes: 3 additions & 0 deletions data/src/main/java/com/nexters/boolti/data/db/AppSettings.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.nexters.boolti.data.db

import androidx.datastore.core.Serializer
import com.nexters.boolti.domain.request.EditProfileRequest
import kotlinx.serialization.Serializable
import kotlinx.serialization.SerializationException
import kotlinx.serialization.json.Json
Expand All @@ -16,6 +17,8 @@ internal data class AppSettings(
val phoneNumber: String? = null,
val photo: String? = null,
val userCode: String? = null,
val profileIntroduction: String = "",
val profileLink: List<EditProfileRequest.LinkDto> = emptyList(),
val accessToken: String = "",
val refreshToken: String = "",
val refundPolicy: List<String> = emptyList(),
Expand Down
49 changes: 47 additions & 2 deletions data/src/main/java/com/nexters/boolti/data/di/NetworkModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ package com.nexters.boolti.data.di

import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import com.nexters.boolti.data.BuildConfig
import com.nexters.boolti.data.datasource.AuthDataSource
import com.nexters.boolti.data.datasource.TokenDataSource
import com.nexters.boolti.data.network.api.LoginService
import com.nexters.boolti.data.network.AuthAuthenticator
import com.nexters.boolti.data.datasource.AuthDataSource
import com.nexters.boolti.data.network.AuthInterceptor
import com.nexters.boolti.data.network.api.AuthFileService
import com.nexters.boolti.data.network.api.DeviceTokenService
import com.nexters.boolti.data.network.api.FileService
import com.nexters.boolti.data.network.api.GiftService
import com.nexters.boolti.data.network.api.HostService
import com.nexters.boolti.data.network.api.LoginService
import com.nexters.boolti.data.network.api.ReservationService
import com.nexters.boolti.data.network.api.ShowService
import com.nexters.boolti.data.network.api.SignUpService
Expand Down Expand Up @@ -50,6 +52,23 @@ internal object NetworkModule {
.build()
}

@Singleton
@Provides
@Named("non-auth")
fun provideNonAuthRetrofit(@Named("non-auth") okHttpClient: OkHttpClient): Retrofit {
val json = Json {
isLenient = true
prettyPrint = true
ignoreUnknownKeys = true
coerceInputValues = true
}
return Retrofit.Builder()
.baseUrl(BuildConfig.BASE_URL)
.client(okHttpClient)
.addConverterFactory(json.asConverterFactory("application/json".toMediaType()))
.build()
}

@Singleton
@Provides
fun provideRetrofit(okHttpClient: OkHttpClient): Retrofit {
Expand Down Expand Up @@ -112,6 +131,14 @@ internal object NetworkModule {
@Provides
fun provideHostService(@Named("auth") retrofit: Retrofit): HostService = retrofit.create()

@Singleton
@Provides
fun provideAuthFileService(@Named("auth") retrofit: Retrofit): AuthFileService = retrofit.create()

@Singleton
@Provides
fun provideFileService(@Named("non-auth") retrofit: Retrofit): FileService = retrofit.create()

@Singleton
@Provides
@Named("auth")
Expand Down Expand Up @@ -150,6 +177,24 @@ internal object NetworkModule {
.build()
}

@Singleton
@Provides
@Named("non-auth")
fun provideNoneAuthOkHttpClient(): OkHttpClient {
val loggingInterceptor = HttpLoggingInterceptor().apply {
level = if (BuildConfig.DEBUG) {
HttpLoggingInterceptor.Level.BODY
} else {
HttpLoggingInterceptor.Level.NONE
}
}
return OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.readTimeout(10, TimeUnit.SECONDS)
.addInterceptor(loggingInterceptor)
.build()
}

@Singleton
@Provides
fun provideAuthInterceptor(tokenDataSource: TokenDataSource): AuthInterceptor = AuthInterceptor(tokenDataSource)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package com.nexters.boolti.data.di

import com.nexters.boolti.data.repository.TicketingRepositoryImpl
import com.nexters.boolti.data.repository.AuthRepositoryImpl
import com.nexters.boolti.data.repository.ConfigRepositoryImpl
import com.nexters.boolti.data.repository.FileRepositoryImpl
import com.nexters.boolti.data.repository.GiftRepositoryImpl
import com.nexters.boolti.data.repository.ReservationRepositoryImpl
import com.nexters.boolti.data.repository.HostRepositoryImpl
import com.nexters.boolti.data.repository.ReservationRepositoryImpl
import com.nexters.boolti.data.repository.ShowRepositoryImpl
import com.nexters.boolti.data.repository.TicketRepositoryImpl
import com.nexters.boolti.data.repository.TicketingRepositoryImpl
import com.nexters.boolti.domain.repository.AuthRepository
import com.nexters.boolti.domain.repository.ConfigRepository
import com.nexters.boolti.domain.repository.FileRepository
import com.nexters.boolti.domain.repository.GiftRepository
import com.nexters.boolti.domain.repository.ReservationRepository
import com.nexters.boolti.domain.repository.HostRepository
import com.nexters.boolti.domain.repository.ReservationRepository
import com.nexters.boolti.domain.repository.ShowRepository
import com.nexters.boolti.domain.repository.TicketRepository
import com.nexters.boolti.domain.repository.TicketingRepository
Expand Down Expand Up @@ -47,4 +49,7 @@ internal abstract class RepositoryModule {

@Binds
abstract fun bindHostRepository(repository: HostRepositoryImpl): HostRepository

@Binds
abstract fun bindFileRepository(repository: FileRepositoryImpl): FileRepository
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.nexters.boolti.data.network.api

import com.nexters.boolti.data.network.response.UploadUrlsDto
import retrofit2.http.POST

interface AuthFileService {
@POST("/app/api/v1/user/profile-images/upload-urls")
suspend fun requestUploadUrls(): UploadUrlsDto
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.nexters.boolti.data.network.api

import okhttp3.RequestBody
import retrofit2.http.Body
import retrofit2.http.Header
import retrofit2.http.PUT
import retrofit2.http.Url

internal interface FileService {
@PUT
suspend fun requestUploadImage(
@Header("Content-Type") contentType: String,
@Url url: String,
@Body file: RequestBody,
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.nexters.boolti.data.network.api

import com.nexters.boolti.data.network.response.UserResponse
import com.nexters.boolti.domain.request.EditProfileRequest
import com.nexters.boolti.domain.request.SignoutRequest
import retrofit2.Response
import retrofit2.http.Body
Expand All @@ -15,4 +16,9 @@ internal interface UserService {
suspend fun signout(
@Body request: SignoutRequest,
)

@HTTP(method = "PATCH", path = "/app/api/v1/user", hasBody = true)
suspend fun editProfile(
@Body request: EditProfileRequest,
): UserResponse
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.nexters.boolti.data.network.response

import kotlinx.serialization.Serializable

@Serializable
data class UploadUrlsDto(
val uploadUrl: String,
val expectedUrl: String,
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.nexters.boolti.data.network.response

import com.nexters.boolti.domain.model.Link
import com.nexters.boolti.domain.model.User
import com.nexters.boolti.domain.request.EditProfileRequest
import kotlinx.serialization.Serializable
import java.util.UUID

@Serializable
internal data class UserResponse(
Expand All @@ -10,6 +13,8 @@ internal data class UserResponse(
val email: String? = null,
val imgPath: String? = null,
val userCode: String? = null,
val introduction: String = "",
val link: List<EditProfileRequest.LinkDto> = emptyList(),
) {
fun toDomain(): User {
return User(
Expand All @@ -18,6 +23,8 @@ internal data class UserResponse(
email = email ?: "",
photo = imgPath,
userCode = userCode ?: "",
introduction = introduction,
link = link.map { Link(id = UUID.randomUUID().toString(), it.title, it.link) },
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.nexters.boolti.data.network.response.LoginResponse
import com.nexters.boolti.domain.model.LoginUserState
import com.nexters.boolti.domain.model.User
import com.nexters.boolti.domain.repository.AuthRepository
import com.nexters.boolti.domain.request.EditProfileRequest
import com.nexters.boolti.domain.request.LoginRequest
import com.nexters.boolti.domain.request.SignUpRequest
import com.nexters.boolti.domain.request.SignoutRequest
Expand Down Expand Up @@ -64,4 +65,9 @@ internal class AuthRepositoryImpl @Inject constructor(
}

override suspend fun sendFcmToken(): Result<Unit> = deviceTokenDataSource.sendFcmToken()

override suspend fun editProfile(editProfileRequest: EditProfileRequest) =
runCatching { userDateSource.edit(editProfileRequest) }
.onSuccess { authDataSource.updateUser(it) }
.mapCatching {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.nexters.boolti.data.repository

import com.nexters.boolti.data.datasource.FileDataSource
import com.nexters.boolti.domain.repository.FileRepository
import java.io.File
import javax.inject.Inject

internal class FileRepositoryImpl @Inject constructor(
private val dataSource: FileDataSource,
) : FileRepository {
override suspend fun requestUrlForUpload(file: File): Result<String> =
dataSource.requestUploadUrls(file).map { it.expectedUrl }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package com.nexters.boolti.data.util

import com.nexters.boolti.domain.model.PaymentType
import com.nexters.boolti.domain.model.ReservationState
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.MultipartBody
import okhttp3.RequestBody.Companion.asRequestBody
import java.io.File
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
Expand Down Expand Up @@ -34,3 +38,9 @@ internal fun String?.toPaymentType(): PaymentType {
else -> PaymentType.UNDEFINED
}
}

internal fun File.toImageMultipartBody(): MultipartBody.Part = MultipartBody.Part.createFormData(
name = "image",
filename = name,
body = asRequestBody("image/*".toMediaType())
)
7 changes: 7 additions & 0 deletions domain/src/main/java/com/nexters/boolti/domain/model/Link.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.nexters.boolti.domain.model

data class Link(
val id: String,
val name: String,
val url: String,
)
2 changes: 2 additions & 0 deletions domain/src/main/java/com/nexters/boolti/domain/model/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ data class User(
val email: String = "",
val photo: String? = null,
val userCode: String = "",
val introduction: String = "",
val link: List<Link> = emptyList(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.nexters.boolti.domain.repository

import com.nexters.boolti.domain.model.LoginUserState
import com.nexters.boolti.domain.model.User
import com.nexters.boolti.domain.request.EditProfileRequest
import com.nexters.boolti.domain.request.LoginRequest
import com.nexters.boolti.domain.request.SignUpRequest
import com.nexters.boolti.domain.request.SignoutRequest
Expand All @@ -25,4 +26,6 @@ interface AuthRepository {

val loggedIn: Flow<Boolean>
val cachedUser: Flow<User?>

suspend fun editProfile(editProfileRequest: EditProfileRequest): Result<Unit>
}
Loading

0 comments on commit 8c403e8

Please sign in to comment.