API 1.2+5 open ai chat completion fixes
This commit is contained in:
parent
c2cc98eeb7
commit
1f8cfe0bba
@ -11,7 +11,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "com.aitrainer"
|
group = "com.aitrainer"
|
||||||
version = "1.2.0"
|
version = "1.2.1"
|
||||||
java.sourceCompatibility = JavaVersion.VERSION_17
|
java.sourceCompatibility = JavaVersion.VERSION_17
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
7
data/db/update_1_2_1.sql
Normal file
7
data/db/update_1_2_1.sql
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
START TRANSACTION;
|
||||||
|
ALTER TABLE `diet_meal`
|
||||||
|
ADD COLUMN `meal_date` DATETIME NULL DEFAULT NULL AFTER `quantity_unit`;
|
||||||
|
|
||||||
|
UPDATE configuration set config_value = "1.2.1", date_change=CURRENT_DATE WHERE config_key = "db_version";
|
||||||
|
|
||||||
|
COMMIT;
|
@ -0,0 +1,22 @@
|
|||||||
|
package com.aitrainer.api.controller
|
||||||
|
|
||||||
|
import com.aitrainer.api.model.AppText
|
||||||
|
import com.aitrainer.api.repository.AppTextRepository
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
|
import org.springframework.http.ResponseEntity
|
||||||
|
import org.springframework.web.bind.annotation.*
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api")
|
||||||
|
class CustomerAppTextController(private val appTextRepository: AppTextRepository) {
|
||||||
|
private val logger = LoggerFactory.getLogger(javaClass)
|
||||||
|
|
||||||
|
@GetMapping("/app_text")
|
||||||
|
fun getAppTextWithTranslation(): ResponseEntity<List<AppText>> {
|
||||||
|
val list = appTextRepository.findAllWithTranslation()
|
||||||
|
|
||||||
|
logger.info(" -- Get All app texts $list")
|
||||||
|
return if (list.isEmpty()) ResponseEntity.notFound().build() else
|
||||||
|
ResponseEntity.ok().body(list)
|
||||||
|
}
|
||||||
|
}
|
@ -50,6 +50,7 @@ class OpenAIController() {
|
|||||||
var result: String
|
var result: String
|
||||||
val openAIService = OpenAIService(openaiKey, openai.modelName, openai.temperature)
|
val openAIService = OpenAIService(openaiKey, openai.modelName, openai.temperature)
|
||||||
val deferred = GlobalScope.async {
|
val deferred = GlobalScope.async {
|
||||||
|
println(openai.messages)
|
||||||
openAIService.chatCompletion(openai.messages)
|
openAIService.chatCompletion(openai.messages)
|
||||||
}
|
}
|
||||||
runBlocking {
|
runBlocking {
|
||||||
|
@ -66,13 +66,17 @@ class PackageController(private val exerciseAbilityRepository: ExerciseAbilityRe
|
|||||||
val listDietSensitivity = dietSensitivityRepository.findAll()
|
val listDietSensitivity = dietSensitivityRepository.findAll()
|
||||||
val listDietSensitivityJson = gson.toJson(listDietSensitivity)
|
val listDietSensitivityJson = gson.toJson(listDietSensitivity)
|
||||||
|
|
||||||
|
val listAppText = appTextRepository.findAllWithTranslation()
|
||||||
|
val listAppTextJson = gson.toJson(listAppText)
|
||||||
|
|
||||||
val packageJson: String =
|
val packageJson: String =
|
||||||
getClassRecord(Property::class.simpleName, listPropertyJson) +
|
getClassRecord(Property::class.simpleName, listPropertyJson) +
|
||||||
"|||" + getClassRecord(Membership::class.simpleName, listMembershipJson) +
|
"|||" + getClassRecord(Membership::class.simpleName, listMembershipJson) +
|
||||||
"|||" + getClassRecord(Store::class.simpleName, listStoreJson) +
|
"|||" + getClassRecord(Store::class.simpleName, listStoreJson) +
|
||||||
"|||" + getClassRecord(Recipe::class.simpleName, listRecipeJson) +
|
"|||" + getClassRecord(Recipe::class.simpleName, listRecipeJson) +
|
||||||
"|||" + getClassRecord(Meal::class.simpleName, listRawMaterialJson) +
|
"|||" + getClassRecord(Meal::class.simpleName, listRawMaterialJson) +
|
||||||
"|||" + getClassRecord(DietSensitivity::class.simpleName, listDietSensitivityJson)
|
"|||" + getClassRecord(DietSensitivity::class.simpleName, listDietSensitivityJson) +
|
||||||
|
"|||" + getClassRecord(AppText::class.simpleName, listAppTextJson)
|
||||||
|
|
||||||
return if (packageJson.isEmpty()) ResponseEntity.notFound().build() else
|
return if (packageJson.isEmpty()) ResponseEntity.notFound().build() else
|
||||||
ResponseEntity.ok().body(packageJson)
|
ResponseEntity.ok().body(packageJson)
|
||||||
|
@ -2,6 +2,7 @@ package com.aitrainer.api.controller.diet
|
|||||||
|
|
||||||
import com.aitrainer.api.model.diet.Diet
|
import com.aitrainer.api.model.diet.Diet
|
||||||
import com.aitrainer.api.repository.diet.DietRepository
|
import com.aitrainer.api.repository.diet.DietRepository
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.http.ResponseEntity
|
import org.springframework.http.ResponseEntity
|
||||||
import org.springframework.web.bind.annotation.*
|
import org.springframework.web.bind.annotation.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@ -9,6 +10,7 @@ import java.util.*
|
|||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api")
|
@RequestMapping("/api")
|
||||||
class DietController(private val dietRepository: DietRepository) {
|
class DietController(private val dietRepository: DietRepository) {
|
||||||
|
private val logger = LoggerFactory.getLogger(javaClass)
|
||||||
|
|
||||||
@PostMapping("/diet")
|
@PostMapping("/diet")
|
||||||
fun insert(@RequestBody diet: Diet): ResponseEntity<*> {
|
fun insert(@RequestBody diet: Diet): ResponseEntity<*> {
|
||||||
@ -32,9 +34,26 @@ class DietController(private val dietRepository: DietRepository) {
|
|||||||
return ResponseEntity.ok().body(dietRepository.save(updatedDiet))
|
return ResponseEntity.ok().body(dietRepository.save(updatedDiet))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/diet/no_text/{id}")
|
||||||
|
fun updateNoText(@PathVariable(value = "id") id: Long, @RequestBody diet: Diet): ResponseEntity<Diet> {
|
||||||
|
val existingDiet = dietRepository.findByDietId(id) ?: return ResponseEntity.notFound().build()
|
||||||
|
|
||||||
|
val updatedDiet: Diet = existingDiet.copy(
|
||||||
|
dietId = diet.dietId,
|
||||||
|
dietUserId = diet.dietUserId,
|
||||||
|
startDate = diet.startDate
|
||||||
|
)
|
||||||
|
diet.meals.forEach {
|
||||||
|
it.diet = diet
|
||||||
|
updatedDiet.meals.add(it)
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok().body(dietRepository.save(updatedDiet))
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/diet/{dietUserId}")
|
@GetMapping("/diet/{dietUserId}")
|
||||||
fun getByDietUserId(@PathVariable dietUserId: Long): ResponseEntity<List<Diet>> {
|
fun getByDietUserId(@PathVariable dietUserId: Long): ResponseEntity<List<Diet>> {
|
||||||
val list = dietRepository.findByDietUserId(dietUserId)
|
val list = dietRepository.findByDietUserId(dietUserId)
|
||||||
|
|
||||||
return if (list.isEmpty()) ResponseEntity.notFound().build() else
|
return if (list.isEmpty()) ResponseEntity.notFound().build() else
|
||||||
ResponseEntity.ok().body(list)
|
ResponseEntity.ok().body(list)
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ data class Diet (
|
|||||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Expose val dietId: Long = 0,
|
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Expose val dietId: Long = 0,
|
||||||
@Expose @get: NotNull val dietUserId: Long = 0,
|
@Expose @get: NotNull val dietUserId: Long = 0,
|
||||||
@Expose @get: NotNull val dietText: String = "",
|
@Expose @get: NotNull val dietText: String = "",
|
||||||
@Expose @get: NotNull val startDate: String = "",
|
@Expose @get: NotNull var startDate: String = "",
|
||||||
) {
|
) {
|
||||||
@OneToMany(cascade = [(CascadeType.ALL)], fetch = FetchType.EAGER, mappedBy = "diet")
|
@OneToMany(cascade = [(CascadeType.ALL)], fetch = FetchType.EAGER, mappedBy = "diet")
|
||||||
@Fetch(value = FetchMode.SUBSELECT)
|
@Fetch(value = FetchMode.SUBSELECT)
|
||||||
|
@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore
|
|||||||
import com.google.gson.annotations.Expose
|
import com.google.gson.annotations.Expose
|
||||||
import jakarta.persistence.*
|
import jakarta.persistence.*
|
||||||
import org.jetbrains.annotations.NotNull
|
import org.jetbrains.annotations.NotNull
|
||||||
|
import org.springframework.lang.NonNull
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
data class DietMeal (
|
data class DietMeal (
|
||||||
@ -11,8 +12,9 @@ data class DietMeal (
|
|||||||
@Expose @get: NotNull val mealId: Long = 0,
|
@Expose @get: NotNull val mealId: Long = 0,
|
||||||
@Expose @get: NotNull val mealName: String = "",
|
@Expose @get: NotNull val mealName: String = "",
|
||||||
@Expose @get: NotNull val meal: String = "",
|
@Expose @get: NotNull val meal: String = "",
|
||||||
@Expose @get: NotNull val quantity: Double = 0.0,
|
@Expose @get: NotNull var quantity: Double = 0.0,
|
||||||
@Expose @get: NotNull val quantityUnit: String = "",
|
@Expose @get: NotNull val quantityUnit: String = "",
|
||||||
|
@Expose @get: NonNull var mealDate: String = "",
|
||||||
) {
|
) {
|
||||||
@ManyToOne(fetch = FetchType.EAGER, optional = false)
|
@ManyToOne(fetch = FetchType.EAGER, optional = false)
|
||||||
@JoinColumn(name = "dietId", nullable = false)
|
@JoinColumn(name = "dietId", nullable = false)
|
||||||
|
@ -2,8 +2,12 @@ package com.aitrainer.api.repository
|
|||||||
|
|
||||||
import com.aitrainer.api.model.AppText
|
import com.aitrainer.api.model.AppText
|
||||||
import org.springframework.data.jpa.repository.JpaRepository
|
import org.springframework.data.jpa.repository.JpaRepository
|
||||||
|
import org.springframework.data.jpa.repository.Query
|
||||||
import org.springframework.stereotype.Repository
|
import org.springframework.stereotype.Repository
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
interface AppTextRepository: JpaRepository<AppText, Long> {
|
interface AppTextRepository: JpaRepository<AppText, Long> {
|
||||||
|
@Query("FROM AppText as e " +
|
||||||
|
"LEFT JOIN AppTextTranslation as t ON e.textId = t.appText AND t.languageCode = 'hu' ")
|
||||||
|
fun findAllWithTranslation(): List<AppText>
|
||||||
}
|
}
|
@ -16,7 +16,7 @@ logging.config=classpath:logback-spring.xml
|
|||||||
logging.file=logs
|
logging.file=logs
|
||||||
|
|
||||||
# if the database structure has been changed, increment this version number
|
# if the database structure has been changed, increment this version number
|
||||||
application.version=1.2.0
|
application.version=1.2.1
|
||||||
|
|
||||||
jwt.secret=aitrainer
|
jwt.secret=aitrainer
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ logging.config=classpath:logback-spring.xml
|
|||||||
logging.file=logs
|
logging.file=logs
|
||||||
|
|
||||||
# if the database structue has been changed, increment this version number
|
# if the database structue has been changed, increment this version number
|
||||||
application.version=1.2.0
|
application.version=1.2.1
|
||||||
|
|
||||||
jwt.secret=aitrainer
|
jwt.secret=aitrainer
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ logging.config=classpath:logback-spring.xml
|
|||||||
logging.file=logs
|
logging.file=logs
|
||||||
|
|
||||||
# if the database structue has been changed, increment this version number
|
# if the database structue has been changed, increment this version number
|
||||||
application.version=1.2.0
|
application.version=1.2.1
|
||||||
|
|
||||||
jwt.secret=aitrainer
|
jwt.secret=aitrainer
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ logging.config=classpath:logback-spring.xml
|
|||||||
logging.file=logs
|
logging.file=logs
|
||||||
|
|
||||||
# if the database structure has been changed, increment this version number
|
# if the database structure has been changed, increment this version number
|
||||||
application.version=1.2.0
|
application.version=1.2.1
|
||||||
|
|
||||||
jwt.secret=aitrainer
|
jwt.secret=aitrainer
|
||||||
|
|
||||||
|
@ -111,6 +111,7 @@ class AppPackageTest {
|
|||||||
|
|
||||||
val packages = dietPackageJson.split("|||").toTypedArray()
|
val packages = dietPackageJson.split("|||").toTypedArray()
|
||||||
|
|
||||||
|
var appText = false
|
||||||
packages.forEach {
|
packages.forEach {
|
||||||
val record = it.split("***")
|
val record = it.split("***")
|
||||||
if (record[0] == Membership::class.simpleName) {
|
if (record[0] == Membership::class.simpleName) {
|
||||||
@ -155,8 +156,20 @@ class AppPackageTest {
|
|||||||
assertTrue(list.isNotEmpty())
|
assertTrue(list.isNotEmpty())
|
||||||
assertEquals(list[0].name, "Nut Allergy")
|
assertEquals(list[0].name, "Nut Allergy")
|
||||||
assertEquals(list[1].name, "Penicillin sensitivity")
|
assertEquals(list[1].name, "Penicillin sensitivity")
|
||||||
|
} else if ( record[0] == AppText::class.simpleName) {
|
||||||
|
val appTextJson: String = record[1]
|
||||||
|
val type = object : TypeToken<List<AppText?>?>() {}.type
|
||||||
|
val list: List<AppText> = gson.fromJson(appTextJson, type)
|
||||||
|
assertTrue(list.isNotEmpty())
|
||||||
|
assertEquals(list[0].textKey, "monday")
|
||||||
|
assertEquals(list[1].translations[0].translation, "kedd")
|
||||||
|
assertEquals(list[6].textKey, "sunday")
|
||||||
|
appText = true
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assertEquals(appText, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -72,20 +72,23 @@ class DietTest {
|
|||||||
mealName = "monday|breakfast",
|
mealName = "monday|breakfast",
|
||||||
meal = "Főtt tojás",
|
meal = "Főtt tojás",
|
||||||
quantity = 2.0,
|
quantity = 2.0,
|
||||||
mealId = 0
|
mealId = 0,
|
||||||
|
mealDate = "2023-03-07 08:00:00"
|
||||||
)
|
)
|
||||||
val meal2 = DietMeal(
|
val meal2 = DietMeal(
|
||||||
mealName = "monday|lunch",
|
mealName = "monday|lunch",
|
||||||
meal = "Disznópörkölt",
|
meal = "Disznópörkölt",
|
||||||
quantity = 120.0,
|
quantity = 120.0,
|
||||||
mealId = 0
|
mealId = 0,
|
||||||
|
mealDate = "2023-03-07 12:00:00"
|
||||||
)
|
)
|
||||||
val meal3 = DietMeal(
|
val meal3 = DietMeal(
|
||||||
mealName = "monday|lunch",
|
mealName = "monday|lunch",
|
||||||
meal = "Savanyúkáposzta",
|
meal = "Savanyúkáposzta",
|
||||||
quantity = 2.0,
|
quantity = 2.0,
|
||||||
quantityUnit = "tányér",
|
quantityUnit = "tányér",
|
||||||
mealId = 3
|
mealId = 3,
|
||||||
|
mealDate = "2023-03-07 12:00:00"
|
||||||
)
|
)
|
||||||
|
|
||||||
newDiet.meals.add(meal)
|
newDiet.meals.add(meal)
|
||||||
@ -103,12 +106,27 @@ class DietTest {
|
|||||||
.andExpect(jsonPath("$.dietUserId").value(1))
|
.andExpect(jsonPath("$.dietUserId").value(1))
|
||||||
.andExpect(jsonPath("$.meals[0].meal").value("Főtt tojás"))
|
.andExpect(jsonPath("$.meals[0].meal").value("Főtt tojás"))
|
||||||
.andExpect(jsonPath("$.meals[0].quantity").value(2.0))
|
.andExpect(jsonPath("$.meals[0].quantity").value(2.0))
|
||||||
|
.andExpect(jsonPath("$.meals[0].mealDate").value("2023-03-07 08:00:00"))
|
||||||
.andExpect(jsonPath("$.meals[1].mealName").value("monday|lunch"))
|
.andExpect(jsonPath("$.meals[1].mealName").value("monday|lunch"))
|
||||||
.andExpect(jsonPath("$.meals[2].meal").value("Savanyúkáposzta"))
|
.andExpect(jsonPath("$.meals[2].meal").value("Savanyúkáposzta"))
|
||||||
.andExpect(jsonPath("$.meals[2].quantity").value(2.0))
|
.andExpect(jsonPath("$.meals[2].quantity").value(2.0))
|
||||||
.andExpect(jsonPath("$.meals[2].mealId").value(3))
|
.andExpect(jsonPath("$.meals[2].mealId").value(3))
|
||||||
.andExpect(jsonPath("$.meals[2].quantityUnit").value("tányér"))
|
.andExpect(jsonPath("$.meals[2].quantityUnit").value("tányér"))
|
||||||
|
|
||||||
|
// update no_text
|
||||||
|
|
||||||
|
newDiet.startDate = "2023-03-20"
|
||||||
|
newDiet.meals[0].quantity = 102.0
|
||||||
|
mockMvc.perform(
|
||||||
|
MockMvcRequestBuilders.post("/api/diet/no_text/${newDiet.dietId}")
|
||||||
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.header("Authorization", "Bearer $authToken")
|
||||||
|
.content(toJson(newDiet))
|
||||||
|
)
|
||||||
|
.andExpect(status().isOk)
|
||||||
|
.andExpect(jsonPath("$.startDate").value("2023-03-20"))
|
||||||
|
.andExpect(jsonPath("$.meals[0].quantity").value(102.0))
|
||||||
|
.andExpect(jsonPath("$.dietText").value("Test diet text"))
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user