Skip to content

Commit

Permalink
refactor: 체중 관련 파일 코드 포맷팅
Browse files Browse the repository at this point in the history
  • Loading branch information
hxeyexn committed Dec 18, 2023
1 parent e3fb548 commit 0454076
Show file tree
Hide file tree
Showing 10 changed files with 261 additions and 243 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ import java.lang.reflect.Type
object WeightClient {
private const val BASE_URL = "https://dev.meongcare.com/"

private val logging = HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
}
private val logging
= HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
}

// cURL을 확인 하기 위해 사용
private val okHttpClient = OkHttpClient.Builder()
.addInterceptor(logging)
.build()
private val okHttpClient
= OkHttpClient.Builder()
.addInterceptor(logging)
.build()

private fun getRetrofit(): Retrofit {
return Retrofit.Builder()
Expand All @@ -30,13 +32,19 @@ object WeightClient {
}

// 비어있는 응답을 null로 처리
private val nullOnEmptyConverterFactory = object : Converter.Factory() {
fun converterFactory() = this
override fun responseBodyConverter(type: Type, annotations: Array<out Annotation>, retrofit: Retrofit) = object : Converter<ResponseBody, Any?> {
val nextResponseBodyConverter = retrofit.nextResponseBodyConverter<Any?>(converterFactory(), type, annotations)
override fun convert(value: ResponseBody) = if (value.contentLength() != 0L) nextResponseBodyConverter.convert(value) else null
private val nullOnEmptyConverterFactory
= object : Converter.Factory() {
fun converterFactory() = this
override fun responseBodyConverter(
type: Type,
annotations: Array<out Annotation>,
retrofit: Retrofit,
) = object : Converter<ResponseBody, Any?> {
val nextResponseBodyConverter = retrofit.nextResponseBodyConverter<Any?>(converterFactory(), type, annotations)

override fun convert(value: ResponseBody) = if (value.contentLength() != 0L) nextResponseBodyConverter.convert(value) else null
}
}
}

val weightService: WeightService = getRetrofit().create(WeightService::class.java)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,143 +6,148 @@ import com.project.meongcare.weight.model.entities.WeightGetRequest
import com.project.meongcare.weight.model.entities.WeightMonthResponse
import com.project.meongcare.weight.model.entities.WeightPatchRequest
import com.project.meongcare.weight.model.entities.WeightPostRequest
import com.project.meongcare.weight.model.entities.WeightWeekResponse
import com.project.meongcare.weight.model.entities.WeightWeeksResponse
import org.json.JSONObject
import javax.inject.Inject

class WeightRemoteDataSource @Inject constructor() {
private val accessToken =
"Bearer eyJhbGciOiJIUzI1NiJ9.eyJpZCI6NiwiZXhwIjoxNzAyMzY3NDAzfQ.5GM7dR3jwmUE1MDAOt9m-h4E0n9l5_g7ONvtGFlgNV4"
private val weightApiService = WeightClient.weightService
class WeightRemoteDataSource
@Inject
constructor() {
private val accessToken =
"Bearer eyJhbGciOiJIUzI1NiJ9.eyJpZCI6NiwiZXhwIjoxNzAyMzY3NDAzfQ.5GM7dR3jwmUE1MDAOt9m-h4E0n9l5_g7ONvtGFlgNV4"
private val weightApiService = WeightClient.weightService

suspend fun postWeight(
weightPostRequest: WeightPostRequest,
): Int? {
try {
val postResponse = weightApiService.postWeight(
accessToken,
weightPostRequest,
)
suspend fun postWeight(
weightPostRequest: WeightPostRequest,
): Int? {
try {
val postResponse
= weightApiService.postWeight(
accessToken,
weightPostRequest,
)

return if (postResponse.code() == SUCCESS) {
Log.d("WeightSuccess", postResponse.code().toString())
postResponse.body()
} else {
Log.d("WeightFailure", postResponse.code().toString())
val stringToJson = JSONObject(postResponse.errorBody()?.string()!!)
Log.d("WeightFailure", "$stringToJson")
null
return if (postResponse.code() == SUCCESS) {
Log.d("WeightSuccess", postResponse.code().toString())
postResponse.body()
} else {
Log.d("WeightFailure", postResponse.code().toString())
val stringToJson = JSONObject(postResponse.errorBody()?.string()!!)
Log.d("WeightFailure", "$stringToJson")
null
}
} catch (e: Exception) {
Log.e("WeightException", e.toString())
return null
}
} catch (e: Exception) {
Log.e("WeightException", e.toString())
return null
}
}

suspend fun patchWeight(
weightPatchRequest: WeightPatchRequest
): Int? {
try {
val patchResponse = weightApiService.patchWeight(
accessToken,
weightPatchRequest.dogId,
weightPatchRequest.kg,
weightPatchRequest.date,
)
suspend fun patchWeight(
weightPatchRequest: WeightPatchRequest,
): Int? {
try {
val patchResponse
= weightApiService.patchWeight(
accessToken,
weightPatchRequest.dogId,
weightPatchRequest.kg,
weightPatchRequest.date,
)

return if (patchResponse.code() == SUCCESS) {
Log.d("WeightPatchSuccess", patchResponse.code().toString())
patchResponse.body()
} else {
val stringToJson = JSONObject(patchResponse.errorBody()?.string()!!)
Log.d("WeightPatchFailure", patchResponse.code().toString())
Log.d("WeightPatchFailure", "$stringToJson")
null
return if (patchResponse.code() == SUCCESS) {
Log.d("WeightPatchSuccess", patchResponse.code().toString())
patchResponse.body()
} else {
val stringToJson = JSONObject(patchResponse.errorBody()?.string()!!)
Log.d("WeightPatchFailure", patchResponse.code().toString())
Log.d("WeightPatchFailure", "$stringToJson")
null
}
} catch (e: Exception) {
Log.e("WeightPatchException", e.toString())
return null
}
} catch (e: Exception) {
Log.e("WeightPatchException", e.toString())
return null
}
}

suspend fun getWeeklyWeight(
weightGetRequest: WeightGetRequest
): WeightWeeksResponse? {
try {
val getWeeklyResponse = weightApiService.getWeeklyWeight(
accessToken,
weightGetRequest.dogId,
weightGetRequest.date,
)
suspend fun getWeeklyWeight(
weightGetRequest: WeightGetRequest,
): WeightWeeksResponse? {
try {
val getWeeklyResponse
= weightApiService.getWeeklyWeight(
accessToken,
weightGetRequest.dogId,
weightGetRequest.date,
)

return if (getWeeklyResponse.code() == SUCCESS) {
Log.d("WeeklyWeightGetSuccess", getWeeklyResponse.code().toString())
getWeeklyResponse.body()
} else {
val stringToJson = JSONObject(getWeeklyResponse.errorBody()?.string()!!)
Log.d("WeeklyWeightGetFailure", getWeeklyResponse.code().toString())
Log.d("WeeklyWeightGetFailure", "$stringToJson")
null
return if (getWeeklyResponse.code() == SUCCESS) {
Log.d("WeeklyWeightGetSuccess", getWeeklyResponse.code().toString())
getWeeklyResponse.body()
} else {
val stringToJson = JSONObject(getWeeklyResponse.errorBody()?.string()!!)
Log.d("WeeklyWeightGetFailure", getWeeklyResponse.code().toString())
Log.d("WeeklyWeightGetFailure", "$stringToJson")
null
}
} catch (e: Exception) {
Log.e("WeeklyWeightGetException", e.toString())
return null
}
} catch (e: Exception) {
Log.e("WeeklyWeightGetException", e.toString())
return null
}
}

suspend fun getMonthlyWeight(
weightGetRequest: WeightGetRequest
): WeightMonthResponse? {
try {
val getMonthlyResponse = weightApiService.getMonthlyWeight(
accessToken,
weightGetRequest.dogId,
weightGetRequest.date,
)
suspend fun getMonthlyWeight(
weightGetRequest: WeightGetRequest,
): WeightMonthResponse? {
try {
val getMonthlyResponse
= weightApiService.getMonthlyWeight(
accessToken,
weightGetRequest.dogId,
weightGetRequest.date,
)

return if (getMonthlyResponse.code() == SUCCESS) {
Log.d("MonthlyWeightGetSuccess", getMonthlyResponse.code().toString())
getMonthlyResponse.body()
} else {
val stringToJson = JSONObject(getMonthlyResponse.errorBody()?.string()!!)
Log.d("MonthlyWeightGetFailure", getMonthlyResponse.code().toString())
Log.d("MonthlyWeightGetFailure", "$stringToJson")
null
return if (getMonthlyResponse.code() == SUCCESS) {
Log.d("MonthlyWeightGetSuccess", getMonthlyResponse.code().toString())
getMonthlyResponse.body()
} else {
val stringToJson = JSONObject(getMonthlyResponse.errorBody()?.string()!!)
Log.d("MonthlyWeightGetFailure", getMonthlyResponse.code().toString())
Log.d("MonthlyWeightGetFailure", "$stringToJson")
null
}
} catch (e: Exception) {
Log.e("MonthlyWeightGetException", e.toString())
return null
}
} catch (e: Exception) {
Log.e("MonthlyWeightGetException", e.toString())
return null
}
}

suspend fun getDayWeight(
weightGetRequest: WeightGetRequest
): WeightDayResponse? {
try {
val getDayResponse = weightApiService.getDayWeight(
accessToken,
weightGetRequest.dogId,
weightGetRequest.date,
)
suspend fun getDayWeight(
weightGetRequest: WeightGetRequest,
): WeightDayResponse? {
try {
val getDayResponse
= weightApiService.getDayWeight(
accessToken,
weightGetRequest.dogId,
weightGetRequest.date,
)

return if (getDayResponse.code() == SUCCESS) {
Log.d("DailyWeightGetSuccess", getDayResponse.code().toString())
getDayResponse.body()
} else {
val stringToJson = JSONObject(getDayResponse.errorBody()?.string()!!)
Log.d("DailyWeightGetFailure", getDayResponse.code().toString())
Log.d("DailyWeightGetFailure", "$stringToJson")
null
return if (getDayResponse.code() == SUCCESS) {
Log.d("DailyWeightGetSuccess", getDayResponse.code().toString())
getDayResponse.body()
} else {
val stringToJson = JSONObject(getDayResponse.errorBody()?.string()!!)
Log.d("DailyWeightGetFailure", getDayResponse.code().toString())
Log.d("DailyWeightGetFailure", "$stringToJson")
null
}
} catch (e: Exception) {
Log.e("DailyWeightGetException", e.toString())
return null
}
} catch (e: Exception) {
Log.e("DailyWeightGetException", e.toString())
return null
}
}

companion object {
const val SUCCESS = 200
companion object {
const val SUCCESS = 200
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.project.meongcare.weight.model.data.remote
import com.project.meongcare.weight.model.entities.WeightDayResponse
import com.project.meongcare.weight.model.entities.WeightMonthResponse
import com.project.meongcare.weight.model.entities.WeightPostRequest
import com.project.meongcare.weight.model.entities.WeightWeekResponse
import com.project.meongcare.weight.model.entities.WeightWeeksResponse
import retrofit2.Response
import retrofit2.http.Body
Expand Down Expand Up @@ -49,5 +48,4 @@ interface WeightService {
@Path("dogId") dogId: Long,
@Query("date") date: String,
): Response<WeightDayResponse>

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object WeightModule {
@Singleton
fun provideWeightRepository(
weightRepositoryImpl: WeightRepositoryImpl,
): WeightRepository{
): WeightRepository {
return weightRepositoryImpl
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@ import com.project.meongcare.weight.model.entities.WeightPatchRequest
import com.project.meongcare.weight.model.entities.WeightPostRequest
import javax.inject.Inject

class WeightRepositoryImpl @Inject constructor(
private val weightDataSource: WeightRemoteDataSource
) : WeightRepository {
override suspend fun postWeight(weightPostRequest: WeightPostRequest) =
weightDataSource.postWeight(weightPostRequest)
class WeightRepositoryImpl
@Inject
constructor(
private val weightDataSource: WeightRemoteDataSource,
) : WeightRepository {
override suspend fun postWeight(weightPostRequest: WeightPostRequest)
= weightDataSource.postWeight(weightPostRequest)

override suspend fun patchWeight(weightPatchRequest: WeightPatchRequest) =
weightDataSource.patchWeight(weightPatchRequest)
override suspend fun patchWeight(weightPatchRequest: WeightPatchRequest)
= weightDataSource.patchWeight(weightPatchRequest)

override suspend fun getWeeklyWeight(weightGetRequest: WeightGetRequest) =
weightDataSource.getWeeklyWeight(weightGetRequest)
override suspend fun getWeeklyWeight(weightGetRequest: WeightGetRequest)
= weightDataSource.getWeeklyWeight(weightGetRequest)

override suspend fun getMonthlyWeight(weightGetRequest: WeightGetRequest) =
weightDataSource.getMonthlyWeight(weightGetRequest)
override suspend fun getMonthlyWeight(weightGetRequest: WeightGetRequest)
= weightDataSource.getMonthlyWeight(weightGetRequest)

override suspend fun getDayWeight(weightGetRequest: WeightGetRequest) =
weightDataSource.getDayWeight(weightGetRequest)
}
override suspend fun getDayWeight(weightGetRequest: WeightGetRequest)
= weightDataSource.getDayWeight(weightGetRequest)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.project.meongcare.weight.model.entities

data class WeightDayResponse (
data class WeightDayResponse(
val weight: Double,
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.project.meongcare.weight.model.entities

data class WeightMonthResponse (
data class WeightMonthResponse(
val lastMonthWeight: Double,
val thisMonthWeight: Double,
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.project.meongcare.weight.model.entities

data class WeightWeeksResponse(
val weeks: List<WeightWeekResponse>
val weeks: List<WeightWeekResponse>,
)
Loading

0 comments on commit 0454076

Please sign in to comment.