Skip to content
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

Merged
merged 3 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions data/src/main/java/com/example/data/di/FileModule.kt
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


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)

@Module
@InstallIn(SingletonComponent::class)
abstract class FileModule {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:no-empty-first-line-in-class-body reported by reviewdog 🐶
Class body should not start with blank line

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶
Trailing space(s)

@Binds
abstract fun bindGetInputStreamUseCase(getInputStreamUseCaseImpl: GetInputStreamUseCaseImpl) : GetInputStreamUseCase

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:function-return-type-spacing reported by reviewdog 🐶
Unexpected whitespace

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:colon-spacing reported by reviewdog 🐶
Unexpected spacing before ":"


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶
Trailing space(s)

@Binds

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:blank-line-before-declaration reported by reviewdog 🐶
Expected a blank line for this declaration

abstract fun bindGetImageUseCase(getImageUseCaseImpl: GetImageUseCaseImpl) : GetImageUseCase

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:function-return-type-spacing reported by reviewdog 🐶
Unexpected whitespace

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:colon-spacing reported by reviewdog 🐶
Unexpected spacing before ":"


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶
Trailing space(s)


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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶
Trailing space(s)

@Binds

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:blank-line-before-declaration reported by reviewdog 🐶
Expected a blank line for this declaration

abstract fun bindUploadImageUseCase(uploadImageUseCaseImpl: UploadImageUseCaseImpl) : UploadImageUseCase

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:function-return-type-spacing reported by reviewdog 🐶
Unexpected whitespace

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:colon-spacing reported by reviewdog 🐶
Unexpected spacing before ":"

}
4 changes: 4 additions & 0 deletions data/src/main/java/com/example/data/di/RetrofitModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -41,4 +42,7 @@ class RetrofitModule {
@Provides
fun provideUserService(retrofit: Retrofit): UserService = retrofit.create(UserService::class.java)

@Provides

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:blank-line-before-declaration reported by reviewdog 🐶
Expected a blank line for this declaration

fun provideFileService(retrofit: Retrofit): FileService = retrofit.create(FileService::class.java)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶
Trailing space(s)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:no-blank-line-before-rbrace reported by reviewdog 🐶
Unexpected blank line(s) before "}"

}
11 changes: 11 additions & 0 deletions data/src/main/java/com/example/data/di/UserModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -38,4 +42,11 @@ abstract class UserModule {

@Binds
abstract fun bindGetMyUserUseCase(getMyUserUseCaseImpl: GetMyUserUseCaseImpl) : GetMyUserUseCase

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶
Trailing space(s)

@Binds

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:blank-line-before-declaration reported by reviewdog 🐶
Expected a blank line for this declaration

abstract fun bindGetMyNameInfoUserUseCase(getMyNameUseCaseImpl: SetMyUserUseCaseImpl) : SetMyUserUseCase

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:function-return-type-spacing reported by reviewdog 🐶
Unexpected whitespace

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:colon-spacing reported by reviewdog 🐶
Unexpected spacing before ":"


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶
Trailing space(s)

@Binds

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:blank-line-before-declaration reported by reviewdog 🐶
Expected a blank line for this declaration

abstract fun bindSetProfileImageUseCase(setProfileImageUseCaseImpl: SetProfileImageUseCaseImpl) : SetProfileImageUseCase

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:function-return-type-spacing reported by reviewdog 🐶
Unexpected whitespace

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:colon-spacing reported by reviewdog 🐶
Unexpected spacing before ":"


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶
Trailing space(s)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:no-blank-line-before-rbrace reported by reviewdog 🐶
Unexpected blank line(s) before "}"

}
14 changes: 14 additions & 0 deletions data/src/main/java/com/example/data/model/FileDto.kt
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:parameter-list-spacing reported by reviewdog 🐶
Whitespace after ':' is missing

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:colon-spacing reported by reviewdog 🐶
Missing spacing after ":"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶
Missing trailing comma before ")"

)
15 changes: 15 additions & 0 deletions data/src/main/java/com/example/data/model/UpdateMyInfoParam.kt
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶
Missing trailing comma before ")"

){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:curly-spacing reported by reviewdog 🐶
Missing spacing before "{"

fun toRequestBody() : RequestBody {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:function-return-type-spacing reported by reviewdog 🐶
Unexpected whitespace

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:colon-spacing reported by reviewdog 🐶
Unexpected spacing before ":"

return Gson().toJson(this).toRequestBody()
}
}
21 changes: 21 additions & 0 deletions data/src/main/java/com/example/data/retrofit/FileService.kt
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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:no-empty-first-line-in-class-body reported by reviewdog 🐶
Class body should not start with blank line

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶
Trailing space(s)

@POST("files")
@Multipart
@Headers("ContentType: multipart/form-data;")
suspend fun uploadFile(
@Part fileName: MultipartBody.Part,
@Part file: MultipartBody.Part

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶
Missing trailing comma before ")"

): CommonResponse<FileDto>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶
Trailing space(s)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:no-blank-line-before-rbrace reported by reviewdog 🐶
Unexpected blank line(s) before "}"

}
36 changes: 36 additions & 0 deletions data/src/main/java/com/example/data/retrofit/UriRequestBody.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.example.data.retrofit

import android.net.Uri

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:no-unused-imports reported by reviewdog 🐶
Unused import

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶
Missing trailing comma before ")"

) : RequestBody() {
override fun contentType(): MediaType? {
return contentType
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶
Trailing space(s)

override fun contentLength(): Long {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:blank-line-before-declaration reported by reviewdog 🐶
Expected a blank line for this declaration

return contentLength
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶
Trailing space(s)

override fun writeTo(sink: BufferedSink) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:blank-line-before-declaration reported by reviewdog 🐶
Expected a blank line for this declaration

try{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:curly-spacing reported by reviewdog 🐶
Missing spacing before "{"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:keyword-spacing reported by reviewdog 🐶
Missing spacing after "try"

getInputStreamUseCase(contentUri).getOrThrow()
.use { inputStream ->
sink.writeAll(inputStream.source())
}
}catch (e: FileNotFoundException) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:curly-spacing reported by reviewdog 🐶
Missing spacing after "}"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:try-catch-finally-spacing reported by reviewdog 🐶
A single space is required before 'catch'

Log.e("UriRequestBody", "${e.message}")
}
}
}
14 changes: 8 additions & 6 deletions data/src/main/java/com/example/data/retrofit/UserService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶
Trailing space(s)

@PATCH("users/my-page")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:blank-line-before-declaration reported by reviewdog 🐶
Expected a blank line for this declaration

suspend fun patchMyPage(
@Body request: RequestBody

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶
Missing trailing comma before ")"

): 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(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:annotation reported by reviewdog 🐶
Expected newline before annotation

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:annotation reported by reviewdog 🐶
Expected newline after last annotation

private val context: Context

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶
Missing trailing comma before ")"

) : GetImageUseCase {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:no-empty-first-line-in-class-body reported by reviewdog 🐶
Class body should not start with blank line

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶
Trailing space(s)

override fun invoke(contentUri: String): Image? {
val uri = Uri.parse(contentUri)
val projection = arrayOf(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:multiline-expression-wrapping reported by reviewdog 🐶
A multiline expression should start on a new line

MediaStore.Images.Media._ID,
MediaStore.Images.Media.DISPLAY_NAME,
MediaStore.Images.Media.SIZE,
MediaStore.Images.Media.MIME_TYPE,
)
val cursor = context.contentResolver.query(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:multiline-expression-wrapping reported by reviewdog 🐶
A multiline expression should start on a new line

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
Expand Up @@ -10,7 +10,7 @@ class GetMyUserUseCaseImpl @Inject constructor(
private val userService: UserService
) : GetMyUserUseCase {
override suspend fun invoke(): Result<User> = runCatching {
val userDto = userService.myPage().data
val userDto = userService.getMyPage().data
Log.e("GetMyUserUseCaseImpl", "userDto: $userDto")
userDto.toUser()
}
Expand Down
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()

}
}
2 changes: 2 additions & 0 deletions domain/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import java.util.Properties
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
alias(libs.plugins.kotlin.serialization)
}

val properties = Properties()
Expand Down Expand Up @@ -53,5 +54,6 @@ dependencies {
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
implementation(libs.converter.gson)

}
Loading
Loading