Skip to content

Commit

Permalink
Merge pull request #113 from meongCare/feature/feed
Browse files Browse the repository at this point in the history
refactor: 사료 유효성 검사 로직 추가 및 임시 값 data store 값으로 교체
  • Loading branch information
hxeyexn authored Jan 18, 2024
2 parents f20dab8 + dee9622 commit 8e85b8d
Show file tree
Hide file tree
Showing 30 changed files with 1,115 additions and 255 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import javax.inject.Inject
class FeedRemoteDataSource
@Inject
constructor() {
private val accessToken =
"Bearer eyJhbGciOiJIUzI1NiJ9.eyJpZCI6NiwiZXhwIjoxNzAzMzY1MjQ2fQ.qbSYeabyBpAni3yISWDUGYgFkQdKYfdFqPlMlz7DKCs"
private val feedApiService = FeedClient.feedService

suspend fun postFeed(feedUploadRequest: FeedUploadRequest): Int? {
suspend fun postFeed(
accessToken: String,
feedUploadRequest: FeedUploadRequest,
): Int? {
try {
val postFeedResponse =
feedApiService.postFeed(
Expand All @@ -43,12 +44,15 @@ class FeedRemoteDataSource
}
}

suspend fun getFeed(): FeedGetResponse? {
suspend fun getFeed(
accessToken: String,
dogId: Long,
): FeedGetResponse? {
try {
val getFeedResponse =
feedApiService.getFeed(
accessToken,
2L,
dogId,
)
return if (getFeedResponse.code() == SUCCESS) {
Log.d("FeedGetSuccess", getFeedResponse.code().toString())
Expand All @@ -65,12 +69,16 @@ class FeedRemoteDataSource
}
}

suspend fun getFeedPart(feedRecordId: Long): FeedPartRecords? {
suspend fun getFeedPart(
accessToken: String,
dogId: Long,
feedRecordId: Long,
): FeedPartRecords? {
try {
val getFeedPartResponse =
feedApiService.getFeedPart(
accessToken,
2L,
dogId,
feedRecordId,
)
return if (getFeedPartResponse.code() == SUCCESS) {
Expand All @@ -88,12 +96,15 @@ class FeedRemoteDataSource
}
}

suspend fun getFeeds(): Feeds? {
suspend fun getFeeds(
accessToken: String,
dogId: Long,
): Feeds? {
try {
val getFeedsResponse =
feedApiService.getFeeds(
accessToken,
2L,
dogId,
)
return if (getFeedsResponse.code() == SUCCESS) {
Log.d("FeedsGetSuccess", getFeedsResponse.code().toString())
Expand All @@ -110,12 +121,16 @@ class FeedRemoteDataSource
}
}

suspend fun getPreviousFeed(feedRecordId: Long): FeedRecords? {
suspend fun getPreviousFeed(
accessToken: String,
dogId: Long,
feedRecordId: Long,
): FeedRecords? {
try {
val getPreviousFeedResponse =
feedApiService.getPreviousFeed(
accessToken,
2L,
dogId,
feedRecordId,
)

Expand All @@ -135,6 +150,7 @@ class FeedRemoteDataSource
}

suspend fun getFeedDetail(
accessToken: String,
feedId: Long,
feedRecordId: Long,
): FeedDetailGetResponse? {
Expand All @@ -161,7 +177,10 @@ class FeedRemoteDataSource
}
}

suspend fun patchFeed(feedPatchRequest: FeedPatchRequest): Int? {
suspend fun patchFeed(
accessToken: String,
feedPatchRequest: FeedPatchRequest,
): Int? {
try {
val patchFeedResponse =
feedApiService.patchFeed(
Expand All @@ -184,7 +203,10 @@ class FeedRemoteDataSource
}
}

suspend fun putFeed(feedUploadRequest: FeedUploadRequest): Int? {
suspend fun putFeed(
accessToken: String,
feedUploadRequest: FeedUploadRequest,
): Int? {
try {
val putFeedResponse =
feedApiService.putFeed(
Expand All @@ -208,7 +230,10 @@ class FeedRemoteDataSource
}
}

suspend fun deleteFeed(feedId: Long): Int? {
suspend fun deleteFeed(
accessToken: String,
feedId: Long,
): Int? {
try {
val deleteFeedResponse =
feedApiService.deleteFeed(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,51 @@ import com.project.meongcare.feed.model.entities.FeedUploadRequest
import com.project.meongcare.feed.model.entities.Feeds

interface FeedRepository {
suspend fun getFeed(): FeedGetResponse?

suspend fun postFeed(feedUploadRequest: FeedUploadRequest): Int?

suspend fun getFeedPart(feedRecordId: Long): FeedPartRecords?
suspend fun getFeed(
accessToken: String,
dogId: Long,
): FeedGetResponse?

suspend fun postFeed(
accessToken: String,
feedUploadRequest: FeedUploadRequest,
): Int?

suspend fun getFeedPart(
accessToken: String,
dogId: Long,
feedRecordId: Long,
): FeedPartRecords?

suspend fun getFeeds(): Feeds?
suspend fun getFeeds(
accessToken: String,
dogId: Long,
): Feeds?

suspend fun getPreviousFeed(feedRecordId: Long): FeedRecords?
suspend fun getPreviousFeed(
accessToken: String,
dogId: Long,
feedRecordId: Long,
): FeedRecords?

suspend fun getDetailFeed(
accessToken: String,
feedId: Long,
feedRecordId: Long,
): FeedDetailGetResponse?

suspend fun patchFeed(feedPatchRequest: FeedPatchRequest): Int?
suspend fun patchFeed(
accessToken: String,
feedPatchRequest: FeedPatchRequest,
): Int?

suspend fun putFeed(feedUploadRequest: FeedUploadRequest): Int?
suspend fun putFeed(
accessToken: String,
feedUploadRequest: FeedUploadRequest,
): Int?

suspend fun deleteFeed(feedId: Long): Int?
suspend fun deleteFeed(
accessToken: String,
feedId: Long,
): Int?
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,51 @@ class FeedRepositoryImpl
constructor(
private val feedRemoteDataSource: FeedRemoteDataSource,
) : FeedRepository {
override suspend fun getFeed() = feedRemoteDataSource.getFeed()

override suspend fun postFeed(feedUploadRequest: FeedUploadRequest) = feedRemoteDataSource.postFeed(feedUploadRequest)

override suspend fun getFeedPart(feedRecordId: Long) = feedRemoteDataSource.getFeedPart(feedRecordId)
override suspend fun getFeed(
accessToken: String,
dogId: Long,
) = feedRemoteDataSource.getFeed(accessToken, dogId)

override suspend fun postFeed(
accessToken: String,
feedUploadRequest: FeedUploadRequest,
) = feedRemoteDataSource.postFeed(accessToken, feedUploadRequest)

override suspend fun getFeedPart(
accessToken: String,
dogId: Long,
feedRecordId: Long,
) = feedRemoteDataSource.getFeedPart(accessToken, dogId, feedRecordId)

override suspend fun getFeeds() = feedRemoteDataSource.getFeeds()
override suspend fun getFeeds(
accessToken: String,
dogId: Long,
) = feedRemoteDataSource.getFeeds(accessToken, dogId)

override suspend fun getPreviousFeed(feedRecordId: Long) = feedRemoteDataSource.getPreviousFeed(feedRecordId)
override suspend fun getPreviousFeed(
accessToken: String,
dogId: Long,
feedRecordId: Long,
) = feedRemoteDataSource.getPreviousFeed(accessToken, dogId, feedRecordId)

override suspend fun getDetailFeed(
accessToken: String,
feedId: Long,
feedRecordId: Long,
) = feedRemoteDataSource.getFeedDetail(feedId, feedRecordId)
) = feedRemoteDataSource.getFeedDetail(accessToken, feedId, feedRecordId)

override suspend fun patchFeed(feedPatchRequest: FeedPatchRequest) = feedRemoteDataSource.patchFeed(feedPatchRequest)
override suspend fun patchFeed(
accessToken: String,
feedPatchRequest: FeedPatchRequest,
) = feedRemoteDataSource.patchFeed(accessToken, feedPatchRequest)

override suspend fun putFeed(feedUploadRequest: FeedUploadRequest) = feedRemoteDataSource.putFeed(feedUploadRequest)
override suspend fun putFeed(
accessToken: String,
feedUploadRequest: FeedUploadRequest,
) = feedRemoteDataSource.putFeed(accessToken, feedUploadRequest)

override suspend fun deleteFeed(feedId: Long) = feedRemoteDataSource.deleteFeed(feedId)
override suspend fun deleteFeed(
accessToken: String,
feedId: Long,
) = feedRemoteDataSource.deleteFeed(accessToken, feedId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ data class FeedPutInfo(
val kcal: Double,
val recommendIntake: Int,
val startDate: String,
val endDate: String,
val endDate: String? = null,
val feedRecordId: Long,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.project.meongcare.feed.model.utils

import android.content.Context
import android.net.Uri
import android.widget.TextView
import com.google.gson.Gson
import com.project.meongcare.feed.model.entities.FeedInfo
import com.project.meongcare.feed.model.entities.FeedPutInfo
Expand Down Expand Up @@ -44,4 +45,27 @@ object FeedInfoUtils {

return MultipartBody.Part.createFormData("file", file.name, requestFile)
}

fun calculateRecommendDailyIntake(
weight: Double,
feedKcal: Double,
): Double {
val dailyEnergyRequirement = 1.6 * (30 * weight + 70)
val recommendDailyIntake = dailyEnergyRequirement * 1000 / feedKcal
return String.format("%.2f", recommendDailyIntake).toDouble()
}

fun initRecommendDailyIntake(
recommendIntake: Double,
textView: TextView,
) {
textView.apply {
text =
if (recommendIntake == Double.POSITIVE_INFINITY) {
"0"
} else {
"$recommendIntake"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.project.meongcare.feed.model.utils

import android.view.View
import android.view.inputmethod.InputMethodManager
import android.widget.EditText
import android.widget.ScrollView
import android.widget.TextView
import com.project.meongcare.R

object FeedValidationUtils {
fun validationBrandAndFeedName(
editText: EditText,
errorMessage: TextView,
scrollview: ScrollView,
title: TextView,
inputMethodManager: InputMethodManager,
) {
errorMessage.apply {
visibility = View.VISIBLE
scrollview.smoothScrollTo(0, title.top)
setOnClickListener {
visibility = View.GONE
editText.requestFocus()
inputMethodManager.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT)
}
}
}

fun validationIngredient(
errorMessage: TextView,
editText: EditText,
scrollview: ScrollView,
ingredientTitle: TextView,
) {
errorMessage.visibility = View.VISIBLE
editText.apply {
setTextColor(resources.getColor(R.color.sub1, null))
setBackgroundResource(R.drawable.all_rect_gray1_r5_outline_sub1)
scrollview.smoothScrollTo(0, ingredientTitle.top)
requestFocus()
}
}

fun validationTotalIngredient(
errorMessage: TextView,
scrollview: ScrollView,
ingredientTitle: TextView,
) {
errorMessage.apply {
text = "사료 성분 비율의 총합은 100%를 초과할 수 없습니다."
visibility = View.VISIBLE
}
scrollview.smoothScrollTo(0, ingredientTitle.top)
}

fun validationKcal(
editText: EditText,
errorMessage: TextView,
) {
errorMessage.visibility = View.VISIBLE
editText.apply {
setTextColor(resources.getColor(R.color.sub1, null))
setBackgroundResource(R.drawable.all_rect_white_r5_outline_sub1)
requestFocus()
}
}

fun validationIntakePeriod(
textView: TextView,
errorMessage: TextView,
) {
errorMessage.apply {
text = "섭취 기간은 필수 항목입니다."
visibility = View.VISIBLE
}
textView.apply {
setTextColor(resources.getColor(R.color.sub1, null))
setBackgroundResource(R.drawable.all_rect_gray1_r5_outline_sub1)
}
}
}
Loading

0 comments on commit 8e85b8d

Please sign in to comment.