Skip to content

Commit

Permalink
[REFACTOR] #102 : presentation 계층으로 인식된 텍스트를 포함하는 로직 추가 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
jeongjaino committed Nov 17, 2023
1 parent b042c3a commit e91d50d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.healthc.domain.usecase.detection

import com.healthc.domain.model.auth.Allergy
import com.healthc.domain.model.detection.AllergyTextDetection
import com.healthc.domain.repository.DetectionRepository
import com.healthc.domain.repository.UserRepository
import javax.inject.Inject
Expand All @@ -9,23 +10,27 @@ class CheckAllergiesInEnglishTextUseCase @Inject constructor(
private val userRepository: UserRepository,
private val detectionRepository: DetectionRepository
){
suspend operator fun invoke(imageUri: String) : Result<List<Allergy>> {
suspend operator fun invoke(imageUri: String) : Result<AllergyTextDetection> {
return runCatching {
val response = userRepository.getUser().getOrThrow()
val userAllergies = response.allergies.map { allergy ->
allergy.toEnglish()
}

val recognizedText =
detectionRepository.getDetectedEnglishText(imageUri).getOrThrow().toString()
detectionRepository.getDetectedEnglishText(imageUri).getOrThrow().recognizedText

val detectedAllergies = mutableListOf<Allergy>()
userAllergies.forEach { allergy ->
if (recognizedText.contains(allergy.allergy)) {
detectedAllergies.add(allergy)
}
}
detectedAllergies

AllergyTextDetection(
allergies = detectedAllergies,
recognizedText = recognizedText,
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.healthc.domain.usecase.detection

import com.healthc.domain.model.auth.Allergy
import com.healthc.domain.model.detection.AllergyTextDetection
import com.healthc.domain.repository.DetectionRepository
import com.healthc.domain.repository.UserRepository
import javax.inject.Inject
Expand All @@ -9,20 +10,23 @@ class CheckAllergiesInKoreanTextUseCase @Inject constructor(
private val userRepository: UserRepository,
private val detectionRepository: DetectionRepository
){
suspend operator fun invoke(imageUri: String) : Result<List<Allergy>> {
suspend operator fun invoke(imageUri: String) : Result<AllergyTextDetection> {
return runCatching {
val user = userRepository.getUser().getOrThrow()

val recognizedText =
detectionRepository.getDetectedKoreanText(imageUri).getOrThrow().toString()
detectionRepository.getDetectedKoreanText(imageUri).getOrThrow().recognizedText

val detectedAllergies = mutableListOf<Allergy>()
user.allergies.forEach { allergy ->
if (recognizedText.contains(allergy.allergy)) {
detectedAllergies.add(allergy)
}
}
detectedAllergies
AllergyTextDetection(
allergies = detectedAllergies,
recognizedText = recognizedText,
)
}
}
}

0 comments on commit e91d50d

Please sign in to comment.