-
Notifications
You must be signed in to change notification settings - Fork 0
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
Setting profile #28
Setting profile #28
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.example.data.di | ||
|
||
import com.example.data.usecase.file.GetImageUseCaseImpl | ||
import com.example.data.usecase.file.GetInputStreamUseCaseImpl | ||
import com.example.data.usecase.file.UploadImageUseCaseImpl | ||
import com.example.domain.usecase.file.GetImageUseCase | ||
import com.example.domain.usecase.file.GetInputStreamUseCase | ||
import com.example.domain.usecase.file.UploadImageUseCase | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
|
||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
abstract class FileModule { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-empty-first-line-in-class-body reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶 |
||
@Binds | ||
abstract fun bindGetInputStreamUseCase(getInputStreamUseCaseImpl: GetInputStreamUseCaseImpl) : GetInputStreamUseCase | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:function-return-type-spacing reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:colon-spacing reported by reviewdog 🐶 |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶 |
||
@Binds | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:blank-line-before-declaration reported by reviewdog 🐶 |
||
abstract fun bindGetImageUseCase(getImageUseCaseImpl: GetImageUseCaseImpl) : GetImageUseCase | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:function-return-type-spacing reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:colon-spacing reported by reviewdog 🐶 |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶 |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-consecutive-blank-lines reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶 |
||
@Binds | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:blank-line-before-declaration reported by reviewdog 🐶 |
||
abstract fun bindUploadImageUseCase(uploadImageUseCaseImpl: UploadImageUseCaseImpl) : UploadImageUseCase | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:function-return-type-spacing reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:colon-spacing reported by reviewdog 🐶 |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package com.example.data.di | |
|
||
import com.example.data.BuildConfig | ||
import com.example.data.retrofit.AddInterceptor | ||
import com.example.data.retrofit.FileService | ||
import com.example.data.retrofit.UserService | ||
import com.google.gson.GsonBuilder | ||
import dagger.Module | ||
|
@@ -41,4 +42,7 @@ class RetrofitModule { | |
@Provides | ||
fun provideUserService(retrofit: Retrofit): UserService = retrofit.create(UserService::class.java) | ||
|
||
@Provides | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:blank-line-before-declaration reported by reviewdog 🐶 |
||
fun provideFileService(retrofit: Retrofit): FileService = retrofit.create(FileService::class.java) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-blank-line-before-rbrace reported by reviewdog 🐶 |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,16 @@ import com.example.data.usecase.LoginUseCaseImpl | |
import com.example.data.usecase.SetTokenUseCaseImpl | ||
import com.example.data.usecase.SignUpUseCaseImpl | ||
import com.example.data.usecase.main.setting.GetMyUserUseCaseImpl | ||
import com.example.data.usecase.main.setting.SetMyUserUseCaseImpl | ||
import com.example.data.usecase.main.setting.SetProfileImageUseCaseImpl | ||
import com.example.domain.usecase.login.ClearTokenUseCase | ||
import com.example.domain.usecase.login.GetTokenUseCase | ||
import com.example.domain.usecase.login.LoginUseCase | ||
import com.example.domain.usecase.login.SetTokenUseCase | ||
import com.example.domain.usecase.login.SignUpUseCase | ||
import com.example.domain.usecase.main.setting.GetMyUserUseCase | ||
import com.example.domain.usecase.main.setting.SetMyUserUseCase | ||
import com.example.domain.usecase.main.setting.SetProfileImageUseCase | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
|
@@ -38,4 +42,11 @@ abstract class UserModule { | |
|
||
@Binds | ||
abstract fun bindGetMyUserUseCase(getMyUserUseCaseImpl: GetMyUserUseCaseImpl) : GetMyUserUseCase | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶 |
||
@Binds | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:blank-line-before-declaration reported by reviewdog 🐶 |
||
abstract fun bindGetMyNameInfoUserUseCase(getMyNameUseCaseImpl: SetMyUserUseCaseImpl) : SetMyUserUseCase | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:function-return-type-spacing reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:colon-spacing reported by reviewdog 🐶 |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶 |
||
@Binds | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:blank-line-before-declaration reported by reviewdog 🐶 |
||
abstract fun bindSetProfileImageUseCase(setProfileImageUseCaseImpl: SetProfileImageUseCaseImpl) : SetProfileImageUseCase | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:function-return-type-spacing reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:colon-spacing reported by reviewdog 🐶 |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-blank-line-before-rbrace reported by reviewdog 🐶 |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.example.data.model | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class FileDto( | ||
@SerializedName("id") | ||
val id: Long, | ||
@SerializedName("fileName") | ||
val fileName: String, | ||
@SerializedName("createdAt") | ||
val createdAt: String, | ||
@SerializedName("filePath") | ||
val filePath:String | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:parameter-list-spacing reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:colon-spacing reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶 |
||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.example.data.model | ||
|
||
import com.google.gson.Gson | ||
import okhttp3.RequestBody | ||
import okhttp3.RequestBody.Companion.toRequestBody | ||
|
||
data class UpdateMyInfoParam( | ||
val userName: String, | ||
val extraUserInfo: String, | ||
val profileFilePath: String | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶 |
||
){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:curly-spacing reported by reviewdog 🐶 |
||
fun toRequestBody() : RequestBody { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:function-return-type-spacing reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:colon-spacing reported by reviewdog 🐶 |
||
return Gson().toJson(this).toRequestBody() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.example.data.retrofit | ||
|
||
import com.example.data.model.CommonResponse | ||
import com.example.data.model.FileDto | ||
import okhttp3.MultipartBody | ||
import retrofit2.http.Headers | ||
import retrofit2.http.Multipart | ||
import retrofit2.http.POST | ||
import retrofit2.http.Part | ||
|
||
interface FileService { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-empty-first-line-in-class-body reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶 |
||
@POST("files") | ||
@Multipart | ||
@Headers("ContentType: multipart/form-data;") | ||
suspend fun uploadFile( | ||
@Part fileName: MultipartBody.Part, | ||
@Part file: MultipartBody.Part | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶 |
||
): CommonResponse<FileDto> | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-blank-line-before-rbrace reported by reviewdog 🐶 |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.example.data.retrofit | ||
|
||
import android.net.Uri | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-unused-imports reported by reviewdog 🐶 |
||
import android.util.Log | ||
import com.example.domain.usecase.file.GetInputStreamUseCase | ||
import okhttp3.MediaType | ||
import okhttp3.RequestBody | ||
import okio.BufferedSink | ||
import okio.FileNotFoundException | ||
import okio.source | ||
|
||
class UriRequestBody( | ||
private val contentUri: String, | ||
private val getInputStreamUseCase: GetInputStreamUseCase, | ||
private val contentType: MediaType? = null, | ||
private val contentLength: Long | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶 |
||
) : RequestBody() { | ||
override fun contentType(): MediaType? { | ||
return contentType | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶 |
||
override fun contentLength(): Long { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:blank-line-before-declaration reported by reviewdog 🐶 |
||
return contentLength | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶 |
||
override fun writeTo(sink: BufferedSink) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:blank-line-before-declaration reported by reviewdog 🐶 |
||
try{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:curly-spacing reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:keyword-spacing reported by reviewdog 🐶 |
||
getInputStreamUseCase(contentUri).getOrThrow() | ||
.use { inputStream -> | ||
sink.writeAll(inputStream.source()) | ||
} | ||
}catch (e: FileNotFoundException) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:curly-spacing reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:try-catch-finally-spacing reported by reviewdog 🐶 |
||
Log.e("UriRequestBody", "${e.message}") | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,23 +5,25 @@ import com.example.data.model.UserDto | |
import okhttp3.RequestBody | ||
import retrofit2.http.Body | ||
import retrofit2.http.GET | ||
import retrofit2.http.Headers | ||
import retrofit2.http.PATCH | ||
import retrofit2.http.POST | ||
|
||
interface UserService { | ||
@POST("users/login") | ||
@Headers("Content-Type:application/json; charset=UTF-8") | ||
suspend fun login( | ||
@Body requestBody: RequestBody | ||
) : CommonResponse<String> | ||
): CommonResponse<String> | ||
|
||
@POST("users/sign-up") | ||
@Headers("Content-Type:application/json; charset=UTF-8") | ||
suspend fun signUp( | ||
@Body requestBody: RequestBody | ||
): CommonResponse<Int> | ||
|
||
@GET("users/my-page") | ||
@Headers("Content-Type:application/json; charset=UTF-8") | ||
suspend fun myPage(): CommonResponse<UserDto> | ||
suspend fun getMyPage(): CommonResponse<UserDto> | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶 |
||
@PATCH("users/my-page") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:blank-line-before-declaration reported by reviewdog 🐶 |
||
suspend fun patchMyPage( | ||
@Body request: RequestBody | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶 |
||
): CommonResponse<Long> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.example.data.usecase.file | ||
|
||
import android.content.Context | ||
import android.net.Uri | ||
import android.provider.MediaStore | ||
import android.util.Log | ||
import com.example.domain.model.Image | ||
import com.example.domain.usecase.file.GetImageUseCase | ||
import javax.inject.Inject | ||
|
||
class GetImageUseCaseImpl @Inject constructor( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:annotation reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:annotation reported by reviewdog 🐶 |
||
private val context: Context | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶 |
||
) : GetImageUseCase { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-empty-first-line-in-class-body reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶 |
||
override fun invoke(contentUri: String): Image? { | ||
val uri = Uri.parse(contentUri) | ||
val projection = arrayOf( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:multiline-expression-wrapping reported by reviewdog 🐶 |
||
MediaStore.Images.Media._ID, | ||
MediaStore.Images.Media.DISPLAY_NAME, | ||
MediaStore.Images.Media.SIZE, | ||
MediaStore.Images.Media.MIME_TYPE, | ||
) | ||
val cursor = context.contentResolver.query( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:multiline-expression-wrapping reported by reviewdog 🐶 |
||
uri, | ||
projection, | ||
null, | ||
null, | ||
null | ||
) | ||
|
||
return cursor?.use { | ||
it.moveToNext() | ||
val idIndex = it.getColumnIndexOrThrow(MediaStore.Images.Media._ID) | ||
val nameIndex = it.getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME) | ||
val sizeIndex = it.getColumnIndexOrThrow(MediaStore.Images.Media.SIZE) | ||
val mimeIndex = it.getColumnIndexOrThrow(MediaStore.Images.Media.MIME_TYPE) | ||
|
||
val name = it.getString(nameIndex) | ||
val size = it.getLong(sizeIndex) | ||
val mimeType = it.getString(mimeIndex) | ||
val image = Image( | ||
uri = contentUri, | ||
name = name, | ||
size = size, | ||
mimeType = mimeType | ||
) | ||
|
||
Log.e("GetImageUseCaseImpl curosr", "${image}") | ||
|
||
image | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.example.data.usecase.file | ||
|
||
import android.content.Context | ||
import android.net.Uri | ||
import com.example.domain.usecase.file.GetInputStreamUseCase | ||
import java.io.InputStream | ||
import javax.inject.Inject | ||
|
||
class GetInputStreamUseCaseImpl @Inject constructor( | ||
private val context: Context | ||
) : GetInputStreamUseCase{ | ||
|
||
override fun invoke(contentUri: String): Result<InputStream> = runCatching { | ||
val uri = Uri.parse(contentUri) | ||
context.contentResolver.openInputStream(uri) ?: throw IllegalStateException("inputStream Error") | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.example.data.usecase.file | ||
|
||
import com.example.data.retrofit.FileService | ||
import com.example.data.retrofit.UriRequestBody | ||
import com.example.domain.model.Image | ||
import com.example.domain.usecase.file.GetInputStreamUseCase | ||
import com.example.domain.usecase.file.UploadImageUseCase | ||
import javax.inject.Inject | ||
import okhttp3.MediaType.Companion.toMediaType | ||
import okhttp3.MultipartBody | ||
|
||
class UploadImageUseCaseImpl @Inject constructor( | ||
private val fileService: FileService, | ||
private val getInputStreamUseCase: GetInputStreamUseCase | ||
): UploadImageUseCase { | ||
override suspend fun invoke(image: Image): Result<String> = runCatching { | ||
val fileNamePart = MultipartBody.Part.createFormData( | ||
"fileName", | ||
image.name | ||
) | ||
|
||
val requestBody = UriRequestBody( | ||
image.uri, | ||
getInputStreamUseCase, | ||
image.mimeType.toMediaType(), | ||
image.size | ||
) | ||
|
||
val filePart = MultipartBody.Part.createFormData( | ||
"file", | ||
image.name, | ||
requestBody | ||
) | ||
fileService.uploadFile( | ||
fileNamePart, | ||
filePart | ||
).data.filePath | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.example.data.usecase.main.setting | ||
|
||
import com.example.data.model.UpdateMyInfoParam | ||
import com.example.data.retrofit.UserService | ||
import com.example.domain.usecase.main.setting.GetMyUserUseCase | ||
import com.example.domain.usecase.main.setting.SetMyUserUseCase | ||
import javax.inject.Inject | ||
|
||
class SetMyUserUseCaseImpl @Inject constructor( | ||
private val service: UserService, | ||
private val getMyUserUseCase: GetMyUserUseCase | ||
) : SetMyUserUseCase { | ||
override suspend fun invoke( | ||
userName: String?, | ||
profileImageUrl: String? | ||
): Result<Unit> = runCatching { | ||
val user = getMyUserUseCase().getOrThrow() | ||
val requestBody = UpdateMyInfoParam( | ||
userName = userName ?: user.username, | ||
profileFilePath = profileImageUrl ?: user.profileImageUrl.orEmpty(), | ||
extraUserInfo = "", | ||
|
||
).toRequestBody() | ||
service.patchMyPage(requestBody) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.example.data.usecase.main.setting | ||
|
||
import com.example.data.BuildConfig | ||
import com.example.domain.model.Image | ||
import com.example.domain.usecase.file.GetImageUseCase | ||
import com.example.domain.usecase.file.UploadImageUseCase | ||
import com.example.domain.usecase.main.setting.GetMyUserUseCase | ||
import com.example.domain.usecase.main.setting.SetMyUserUseCase | ||
import com.example.domain.usecase.main.setting.SetProfileImageUseCase | ||
import javax.inject.Inject | ||
|
||
class SetProfileImageUseCaseImpl @Inject constructor( | ||
private val uploadImageUseCase: UploadImageUseCase, | ||
private val getImageUseCase: GetImageUseCase, | ||
private val setMyUserUseCase: SetMyUserUseCase, | ||
private val getMyUserUseCase: GetMyUserUseCase, | ||
): SetProfileImageUseCase { | ||
override suspend fun invoke(contentUri: String) : Result<Unit> = runCatching{ | ||
//0. 현재 user 정보 가져오기 | ||
val user = getMyUserUseCase().getOrThrow() | ||
|
||
// 1. 이미지 가져오기 | ||
val image = getImageUseCase(contentUri) ?: throw NullPointerException("이미지를 찾을 수 없습니다.") | ||
|
||
//2. 이미지 서버에 업로드하기 | ||
val imagePath = uploadImageUseCase(image).getOrThrow() | ||
|
||
// 4. 내 정보 업데이트 | ||
setMyUserUseCase( | ||
userName = user.username, | ||
profileImageUrl = "${BuildConfig.api_key}/${imagePath}" | ||
).getOrThrow() | ||
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [ktlint] standard:no-consecutive-blank-lines reported by reviewdog 🐶
Needless blank line(s)