v1.2.9.2 fix on generated diet JSON handling
This commit is contained in:
parent
d2ef1415a1
commit
4362988c4a
@ -94,7 +94,7 @@ class DietController(private val dietRepository: DietRepository, private val mea
|
||||
println("new diet: $diet.dietId")
|
||||
}
|
||||
|
||||
val result: String?
|
||||
var result: String?
|
||||
this.openAiKey = openaiKey
|
||||
if ( !test) {
|
||||
val systemInput = "Te egy táplálkozási szakértő vagy. A feladat egy étrend elkészítése ebben a 3 lépésben:\n" +
|
||||
@ -115,9 +115,10 @@ class DietController(private val dietRepository: DietRepository, private val mea
|
||||
}
|
||||
runBlocking {
|
||||
result = deferred.await().toString()
|
||||
result = extractJson(result!!)
|
||||
}
|
||||
|
||||
if (result == null) {
|
||||
if (result == null || result!!.isEmpty()) {
|
||||
return ResponseEntity.badRequest().build<String>()
|
||||
}
|
||||
} else {
|
||||
@ -268,10 +269,9 @@ class DietController(private val dietRepository: DietRepository, private val mea
|
||||
}
|
||||
|
||||
val gson = Gson()
|
||||
diet.dietText = result
|
||||
diet.dietText = result!!
|
||||
diet.startDate = todayString
|
||||
diet.premium = 1
|
||||
diet.generating = 0
|
||||
|
||||
val dietSaved = dietRepository.save(diet)
|
||||
|
||||
@ -306,10 +306,23 @@ class DietController(private val dietRepository: DietRepository, private val mea
|
||||
index++
|
||||
}
|
||||
|
||||
dietSaved.generating = 0
|
||||
|
||||
val dietSavedWithMeals = dietRepository.save(dietSaved)
|
||||
return ResponseEntity.ok().body(dietSavedWithMeals)
|
||||
}
|
||||
|
||||
fun extractJson(input: String): String {
|
||||
val jsonStart = input.indexOf("{")
|
||||
val jsonEnd = input.lastIndexOf("}")
|
||||
|
||||
return if(jsonStart != -1 && jsonEnd != -1) {
|
||||
input.substring(jsonStart, jsonEnd + 1)
|
||||
} else {
|
||||
""
|
||||
}
|
||||
}
|
||||
|
||||
fun addTemporaryQuantity(dietCustom: DietCustom): DietCustom {
|
||||
for (i in 0 until dietCustom.meals.size) {
|
||||
var sum = 400
|
||||
|
@ -70,7 +70,7 @@ enum class WeekDays {
|
||||
|
||||
companion object WeekDaysExt {
|
||||
private fun WeekDays.enumToString(): String {
|
||||
return this.toString().toLowerCase()
|
||||
return this.toString().lowercase(Locale.getDefault())
|
||||
}
|
||||
|
||||
fun WeekDays.equalsStringTo(dayName: String): Boolean {
|
||||
@ -79,14 +79,13 @@ enum class WeekDays {
|
||||
|
||||
private fun WeekDays.getWeekdayNumber(): Int {
|
||||
return when (this) {
|
||||
WeekDays.monday -> 1
|
||||
WeekDays.tuesday -> 2
|
||||
WeekDays.wednesday -> 3
|
||||
WeekDays.thursday -> 4
|
||||
WeekDays.friday -> 5
|
||||
WeekDays.saturday -> 6
|
||||
WeekDays.sunday -> 7
|
||||
else -> 1
|
||||
monday -> 1
|
||||
tuesday -> 2
|
||||
wednesday -> 3
|
||||
thursday -> 4
|
||||
friday -> 5
|
||||
saturday -> 6
|
||||
sunday -> 7
|
||||
}
|
||||
}
|
||||
|
||||
@ -161,12 +160,8 @@ object DietFunctions {
|
||||
)
|
||||
|
||||
var englishWord = ""
|
||||
var found = false
|
||||
for (element in hungarianWord) {
|
||||
englishWord += diacriticals[element] ?: element
|
||||
if (diacriticals.containsKey(element)) {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
|
||||
return englishWord.lowercase(Locale.getDefault())
|
||||
|
Loading…
Reference in New Issue
Block a user