From 50028cbcecb51efdc9ac4f8993f55498357ad35f Mon Sep 17 00:00:00 2001 From: Tibor Bossanyi Date: Wed, 12 Apr 2023 20:10:38 +0200 Subject: [PATCH 1/4] API 1.2.3 meal normalized name, serving --- build.gradle.kts | 2 +- data/db/update_1_2_3.sql | 19 ++++++++++ .../diet/DietUserConsumptionController.kt | 8 +++++ .../com/aitrainer/api/model/diet/DietMeal.kt | 3 ++ .../com/aitrainer/api/model/diet/Meal.kt | 3 ++ .../resources/application-diet.properties | 2 +- .../resources/application-dietprod.properties | 2 +- .../resources/application-prod.properties | 2 +- src/main/resources/application.properties | 2 +- .../api/test/diet/DietConsumptionTest.kt | 35 ++++++++++++++++++- .../com/aitrainer/api/test/diet/DietTest.kt | 16 ++++++--- .../com/aitrainer/api/test/diet/MealTest.kt | 20 +++++++++-- 12 files changed, 100 insertions(+), 14 deletions(-) create mode 100644 data/db/update_1_2_3.sql diff --git a/build.gradle.kts b/build.gradle.kts index e1db83c..12021d3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,7 +11,7 @@ plugins { } group = "com.aitrainer" -version = "1.2.2" +version = "1.2.3" java.sourceCompatibility = JavaVersion.VERSION_17 repositories { diff --git a/data/db/update_1_2_3.sql b/data/db/update_1_2_3.sql new file mode 100644 index 0000000..0c1ed17 --- /dev/null +++ b/data/db/update_1_2_3.sql @@ -0,0 +1,19 @@ +START TRANSACTION; + +ALTER TABLE `meal` + ADD COLUMN `normalized_name` CHAR(100) NOT NULL DEFAULT '0' AFTER `name`, + ADD COLUMN `serving` DOUBLE(10,2) NULL DEFAULT '0.00' AFTER `quantity_unit`, + ADD COLUMN `serving_unit` CHAR(50) NULL DEFAULT '' AFTER `portion`; + +ALTER TABLE `diet_meal` + ADD COLUMN `normalized_name` CHAR(100) NOT NULL DEFAULT '0' AFTER `meal_name`, + ADD COLUMN `serving` DOUBLE(10,2) NULL DEFAULT '0.00' AFTER `quantity_unit`, + ADD COLUMN `serving_unit` CHAR(50) NULL DEFAULT '' AFTER `portion`; + +ALTER TABLE `recipe_meal` + CHANGE COLUMN `quantity` `quantity` DOUBLE NULL DEFAULT NULL AFTER `recipe_id`, + ADD COLUMN `quantity_unit` CHAR(50) NULL DEFAULT NULL AFTER `quantity`; + +UPDATE configuration set config_value = "1.2.3", date_change=CURRENT_DATE WHERE config_key = "db_version"; + +COMMIT; \ No newline at end of file diff --git a/src/main/kotlin/com/aitrainer/api/controller/diet/DietUserConsumptionController.kt b/src/main/kotlin/com/aitrainer/api/controller/diet/DietUserConsumptionController.kt index f856556..e147c21 100644 --- a/src/main/kotlin/com/aitrainer/api/controller/diet/DietUserConsumptionController.kt +++ b/src/main/kotlin/com/aitrainer/api/controller/diet/DietUserConsumptionController.kt @@ -40,4 +40,12 @@ class DietUserConsumptionController(private val dietUserConsumptionRepository: D return if (list.isEmpty()) ResponseEntity.notFound().build() else ResponseEntity.ok().body(list) } + + @PostMapping("/diet_user_consumption/delete/{id}") + fun delete(@PathVariable id: Long): ResponseEntity<*> { + return dietUserConsumptionRepository.findById(id).map { existingConsumption -> + dietUserConsumptionRepository.delete(existingConsumption) + ResponseEntity.ok().body("OK") + }.orElse(ResponseEntity.notFound().build()) + } } \ No newline at end of file diff --git a/src/main/kotlin/com/aitrainer/api/model/diet/DietMeal.kt b/src/main/kotlin/com/aitrainer/api/model/diet/DietMeal.kt index d091650..ed58924 100644 --- a/src/main/kotlin/com/aitrainer/api/model/diet/DietMeal.kt +++ b/src/main/kotlin/com/aitrainer/api/model/diet/DietMeal.kt @@ -11,6 +11,9 @@ data class DietMeal ( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Expose val id: Long = 0, @Expose @get: NotNull val mealId: Long = 0, @Expose @get: NotNull val mealName: String = "", + @Expose @get: NotNull val normalizedName: String = "", + @Expose @get: NotNull val serving: Double = 0.0, + @Expose @get: NotNull val servingUnit: String = "", @Expose @get: NotNull val meal: String = "", @Expose @get: NotNull var quantity: Double = 0.0, @Expose @get: NotNull val quantityUnit: String = "", diff --git a/src/main/kotlin/com/aitrainer/api/model/diet/Meal.kt b/src/main/kotlin/com/aitrainer/api/model/diet/Meal.kt index e9ac4a6..a23c819 100644 --- a/src/main/kotlin/com/aitrainer/api/model/diet/Meal.kt +++ b/src/main/kotlin/com/aitrainer/api/model/diet/Meal.kt @@ -8,8 +8,11 @@ data class Meal ( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Expose val id: Long = 0, @Expose @get: NotNull val name: String = "", + @Expose @get: NotNull val normalizedName: String = "", @Expose @get: NotNull val quantity: Double = 0.0, @Expose @get: NotNull val quantityUnit: String = "", + @Expose @get: NotNull val serving: Double = 0.0, + @Expose @get: NotNull val servingUnit: String = "", @Expose @get: NotNull val description: String = "", @Expose @get: NotNull val calMin: Double = 0.0, @Expose @get: NotNull val calMax: Double = 0.0, diff --git a/src/main/resources/application-diet.properties b/src/main/resources/application-diet.properties index e2dda90..a2b750a 100644 --- a/src/main/resources/application-diet.properties +++ b/src/main/resources/application-diet.properties @@ -16,7 +16,7 @@ logging.config=classpath:logback-spring.xml logging.file=logs # if the database structure has been changed, increment this version number -application.version=1.2.2 +application.version=1.2.3 jwt.secret=aitrainer diff --git a/src/main/resources/application-dietprod.properties b/src/main/resources/application-dietprod.properties index b3fcc55..a8ca6d4 100644 --- a/src/main/resources/application-dietprod.properties +++ b/src/main/resources/application-dietprod.properties @@ -14,7 +14,7 @@ logging.config=classpath:logback-spring.xml logging.file=logs # if the database structue has been changed, increment this version number -application.version=1.2.2 +application.version=1.2.3 jwt.secret=aitrainer diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index d7540d4..17f5373 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -14,7 +14,7 @@ logging.config=classpath:logback-spring.xml logging.file=logs # if the database structue has been changed, increment this version number -application.version=1.2.2 +application.version=1.2.3 jwt.secret=aitrainer diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 9d96bca..c8186dc 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -17,7 +17,7 @@ logging.config=classpath:logback-spring.xml logging.file=logs # if the database structure has been changed, increment this version number -application.version=1.2.2 +application.version=1.2.3 jwt.secret=aitrainer diff --git a/src/test/kotlin/com/aitrainer/api/test/diet/DietConsumptionTest.kt b/src/test/kotlin/com/aitrainer/api/test/diet/DietConsumptionTest.kt index bd68072..a6cd3d6 100644 --- a/src/test/kotlin/com/aitrainer/api/test/diet/DietConsumptionTest.kt +++ b/src/test/kotlin/com/aitrainer/api/test/diet/DietConsumptionTest.kt @@ -1,5 +1,6 @@ package com.aitrainer.api.test.diet +import com.aitrainer.api.model.diet.Diet import com.aitrainer.api.model.diet.DietUserConsumption import com.aitrainer.api.test.Tokenizer import com.google.gson.Gson @@ -13,6 +14,7 @@ import org.springframework.boot.test.context.SpringBootTest import org.springframework.http.MediaType import org.springframework.test.context.junit.jupiter.SpringExtension import org.springframework.test.web.servlet.MockMvc +import org.springframework.test.web.servlet.MvcResult import org.springframework.test.web.servlet.request.MockMvcRequestBuilders import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get import org.springframework.test.web.servlet.result.MockMvcResultMatchers.* @@ -115,7 +117,6 @@ class DietConsumptionTest { .andExpect(jsonPath("$.cal").value(65.0)) .andExpect(jsonPath("$.ch").value(44.0)) - // Act & Assert mockMvc.perform(get("/api/diet_user_consumption/5") .header("Authorization", "Bearer $authToken") .contentType(MediaType.APPLICATION_JSON)) @@ -124,6 +125,38 @@ class DietConsumptionTest { .andExpect(jsonPath("$.[1].name").value("Rozs zsömle")) .andExpect(jsonPath("$.[1].ch").value(44)) + + val dietUserConsumption6 = DietUserConsumption( + dietUserId = 5, + mealId = 11, + name = "Hamburger", + dateConsumption = "2023-04-12 16:30", + quantity = 180.0, + quantityUnit = "g", + cal = 265.0, //** + protein = 31.0, + fat = 24.0, + ch = 34.0, //** + sugar = 8.0, + ) + val mvcResult: MvcResult = mockMvc.perform( + MockMvcRequestBuilders.post("/api/diet_user_consumption") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer $authToken") + .content(toJson(dietUserConsumption6)) + ).andExpect(status().isOk) + .andReturn() + + + val gson= Gson() + val consumptionJson = mvcResult.response.contentAsString + val consumption = gson.fromJson(consumptionJson, DietUserConsumption::class.java) + mockMvc.perform( + MockMvcRequestBuilders.post("/api/diet_user_consumption/delete/"+consumption.id) + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer $authToken") + ).andExpect(status().isOk) + } private fun toJson(obj: Any): String { diff --git a/src/test/kotlin/com/aitrainer/api/test/diet/DietTest.kt b/src/test/kotlin/com/aitrainer/api/test/diet/DietTest.kt index ad45e09..a0eb57f 100644 --- a/src/test/kotlin/com/aitrainer/api/test/diet/DietTest.kt +++ b/src/test/kotlin/com/aitrainer/api/test/diet/DietTest.kt @@ -85,10 +85,14 @@ class DietTest { val meal3 = DietMeal( mealName = "monday|lunch", meal = "Savanyúkáposzta", - quantity = 2.0, - quantityUnit = "tányér", + normalizedName = "Savanyukaposzta", + quantity = 222.0, + quantityUnit = "gramm", mealId = 3, - mealDate = "2023-03-07 12:00:00" + mealDate = "2023-03-07 12:00:00", + serving = 1.0, + servingUnit = "adag" + ) newDiet.meals.add(meal) @@ -109,9 +113,11 @@ class DietTest { .andExpect(jsonPath("$.meals[0].mealDate").value("2023-03-07 08:00:00")) .andExpect(jsonPath("$.meals[1].mealName").value("monday|lunch")) .andExpect(jsonPath("$.meals[2].meal").value("Savanyúkáposzta")) - .andExpect(jsonPath("$.meals[2].quantity").value(2.0)) + .andExpect(jsonPath("$.meals[2].normalizedName").value("Savanyukaposzta")) + .andExpect(jsonPath("$.meals[2].quantity").value(222.0)) .andExpect(jsonPath("$.meals[2].mealId").value(3)) - .andExpect(jsonPath("$.meals[2].quantityUnit").value("tányér")) + .andExpect(jsonPath("$.meals[2].quantityUnit").value("gramm")) + .andExpect(jsonPath("$.meals[2].servingUnit").value("adag")) // update no_text diff --git a/src/test/kotlin/com/aitrainer/api/test/diet/MealTest.kt b/src/test/kotlin/com/aitrainer/api/test/diet/MealTest.kt index 4ac5557..db954dc 100644 --- a/src/test/kotlin/com/aitrainer/api/test/diet/MealTest.kt +++ b/src/test/kotlin/com/aitrainer/api/test/diet/MealTest.kt @@ -45,13 +45,16 @@ class MealTest { chMin = 1.0, chMax = 3.0, sugar = 0.0, + serving = 1.0, + servingUnit = "adag", + normalizedName = "Tukortojas" ) private val meal2 = Meal( name = "Tigris buci", - quantity = 3.0, - quantityUnit = "db", + quantity = 233.0, + quantityUnit = "gram", calMin = 123.0, calMax = 140.0, proteinMin = 19.0, @@ -61,6 +64,9 @@ class MealTest { chMin = 50.0, chMax = 60.0, sugar = 5.0, + serving = 3.0, + servingUnit = "db", + normalizedName = "Tigris buci" ) private val meal3 = Meal( @@ -75,6 +81,9 @@ class MealTest { chMin = 1.0, chMax = 3.0, sugar = 0.0, + serving= 3.0, + servingUnit = "adag" , + normalizedName = "Toltotttojas" ) @@ -99,6 +108,8 @@ class MealTest { .andExpect(jsonPath("$.sugar").value(0.0)) .andExpect(jsonPath("$.quantity").value(90.0)) .andExpect(jsonPath("$.proteinMax").value(25.0)) + .andExpect(jsonPath("$.servingUnit").value("adag")) + .andExpect(jsonPath("$.normalizedName").value("Tukortojas")) var mvcResult = mockMvc.perform( MockMvcRequestBuilders.post("/api/meal") @@ -127,6 +138,7 @@ class MealTest { .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk) .andExpect(jsonPath("$.[3].name").value("Tükörtojás")) + .andExpect(jsonPath("$.[3].normalizedName").value("Tukortojas")) .andExpect(jsonPath("$.[4].name").value("Tigris buci")) .andExpect(jsonPath("$.[5].quantity").value(330.0)) .andExpect(jsonPath("$.[5].name").value("Töltötttojás")) @@ -172,6 +184,8 @@ class MealTest { } private fun toJson(obj: Any): String { - return Gson().toJson(obj) + val json = Gson().toJson(obj) + println(json) + return json } } From 1e9a6018bd8c6055fb2b3f5e0d707542cd45fa66 Mon Sep 17 00:00:00 2001 From: Tibor Bossanyi Date: Sun, 16 Apr 2023 16:41:04 +0200 Subject: [PATCH 2/4] API 1.2.4 delete meal --- data/db/update_1_2_3.sql | 8 ++++-- data/db/update_1_2_4.sql | 9 ++++++ .../api/controller/PackageController.kt | 6 ++-- .../api/controller/diet/MealController.kt | 28 ++++++++++++++++++- .../com/aitrainer/api/model/diet/Meal.kt | 6 ++-- .../com/aitrainer/api/openai/OpenAIService.kt | 3 ++ .../resources/application-diet.properties | 3 +- .../resources/application-dietprod.properties | 1 + .../resources/application-dietwsl.properties | 1 + src/main/resources/application.properties | 3 +- .../com/aitrainer/api/test/diet/MealTest.kt | 25 ++++++++++++++++- 11 files changed, 80 insertions(+), 13 deletions(-) create mode 100644 data/db/update_1_2_4.sql diff --git a/data/db/update_1_2_3.sql b/data/db/update_1_2_3.sql index 0c1ed17..d66556d 100644 --- a/data/db/update_1_2_3.sql +++ b/data/db/update_1_2_3.sql @@ -3,17 +3,21 @@ START TRANSACTION; ALTER TABLE `meal` ADD COLUMN `normalized_name` CHAR(100) NOT NULL DEFAULT '0' AFTER `name`, ADD COLUMN `serving` DOUBLE(10,2) NULL DEFAULT '0.00' AFTER `quantity_unit`, - ADD COLUMN `serving_unit` CHAR(50) NULL DEFAULT '' AFTER `portion`; + ADD COLUMN `serving_unit` CHAR(50) NULL DEFAULT '' AFTER `serving`; ALTER TABLE `diet_meal` ADD COLUMN `normalized_name` CHAR(100) NOT NULL DEFAULT '0' AFTER `meal_name`, ADD COLUMN `serving` DOUBLE(10,2) NULL DEFAULT '0.00' AFTER `quantity_unit`, - ADD COLUMN `serving_unit` CHAR(50) NULL DEFAULT '' AFTER `portion`; + ADD COLUMN `serving_unit` CHAR(50) NULL DEFAULT '' AFTER `serving`; ALTER TABLE `recipe_meal` CHANGE COLUMN `quantity` `quantity` DOUBLE NULL DEFAULT NULL AFTER `recipe_id`, ADD COLUMN `quantity_unit` CHAR(50) NULL DEFAULT NULL AFTER `quantity`; + ALTER TABLE `meal` + DROP INDEX `name_quantity`, + ADD UNIQUE INDEX `id_normalized_name` (`id`, `normalized_name`); + UPDATE configuration set config_value = "1.2.3", date_change=CURRENT_DATE WHERE config_key = "db_version"; COMMIT; \ No newline at end of file diff --git a/data/db/update_1_2_4.sql b/data/db/update_1_2_4.sql new file mode 100644 index 0000000..1d27702 --- /dev/null +++ b/data/db/update_1_2_4.sql @@ -0,0 +1,9 @@ +START TRANSACTION; + + ALTER TABLE `meal` + DROP INDEX `name_quantity`, + ADD UNIQUE INDEX `normalized_name` (`normalized_name`); + +UPDATE configuration set config_value = "1.2.4", date_change=CURRENT_DATE WHERE config_key = "db_version"; + +COMMIT; \ No newline at end of file diff --git a/src/main/kotlin/com/aitrainer/api/controller/PackageController.kt b/src/main/kotlin/com/aitrainer/api/controller/PackageController.kt index f19a5da..2166d23 100644 --- a/src/main/kotlin/com/aitrainer/api/controller/PackageController.kt +++ b/src/main/kotlin/com/aitrainer/api/controller/PackageController.kt @@ -12,8 +12,7 @@ import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController import com.google.gson.GsonBuilder -import org.springframework.web.bind.annotation.CrossOrigin - +import org.springframework.http.MediaType @RestController @RequestMapping("/api") @@ -42,8 +41,7 @@ class PackageController(private val exerciseAbilityRepository: ExerciseAbilityRe private val dietSensitivityRepository: DietSensitivityRepository ) { - @GetMapping("/diet_package") - @CrossOrigin(origins = ["http://localhost:48102"]) + @GetMapping("/diet_package", produces = [MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8"]) fun getDietPackageData(): ResponseEntity { val gson = GsonBuilder() .excludeFieldsWithoutExposeAnnotation() diff --git a/src/main/kotlin/com/aitrainer/api/controller/diet/MealController.kt b/src/main/kotlin/com/aitrainer/api/controller/diet/MealController.kt index dd0c427..32f2dc1 100644 --- a/src/main/kotlin/com/aitrainer/api/controller/diet/MealController.kt +++ b/src/main/kotlin/com/aitrainer/api/controller/diet/MealController.kt @@ -2,6 +2,7 @@ package com.aitrainer.api.controller.diet import com.aitrainer.api.model.diet.Meal import com.aitrainer.api.repository.diet.MealRepository +import org.springframework.http.MediaType import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.* @@ -15,7 +16,7 @@ class MealController(private val mealRepository: MealRepository) { return ResponseEntity.ok().body(newMeal) } - @GetMapping("/meal") + @GetMapping("/meal", produces = [MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8"]) fun getAll(): ResponseEntity> { val list = mealRepository.findAll() return if (list.isEmpty()) ResponseEntity.notFound().build() else @@ -36,4 +37,29 @@ class MealController(private val mealRepository: MealRepository) { ResponseEntity.ok().body(meal) } + @PostMapping("/meal/{id}") + fun update(@PathVariable(value = "id") id: Long, @RequestBody meal: Meal): ResponseEntity { + val existingMeal = mealRepository.findById(id) ?: return ResponseEntity.notFound().build() + + val updatedMeal: Meal = existingMeal.copy( + id = existingMeal.id, + name = existingMeal.name, + normalizedName = meal.normalizedName, + description = meal.description, + calMin = meal.calMin, + calMax = meal.calMax, + chMin = meal.chMin, + chMax = meal.chMax, + proteinMin = meal.proteinMin, + proteinMax = meal.proteinMax, + fatMin = meal.fatMin, + fatMax = meal.fatMax, + sugar = meal.sugar, + serving = meal.serving, + servingUnit = meal.servingUnit + ) + + return ResponseEntity.ok().body(mealRepository.save(updatedMeal)) + } + } \ No newline at end of file diff --git a/src/main/kotlin/com/aitrainer/api/model/diet/Meal.kt b/src/main/kotlin/com/aitrainer/api/model/diet/Meal.kt index a23c819..60beaf0 100644 --- a/src/main/kotlin/com/aitrainer/api/model/diet/Meal.kt +++ b/src/main/kotlin/com/aitrainer/api/model/diet/Meal.kt @@ -8,11 +8,11 @@ data class Meal ( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Expose val id: Long = 0, @Expose @get: NotNull val name: String = "", - @Expose @get: NotNull val normalizedName: String = "", + @Expose @get: NotNull var normalizedName: String = "", @Expose @get: NotNull val quantity: Double = 0.0, @Expose @get: NotNull val quantityUnit: String = "", - @Expose @get: NotNull val serving: Double = 0.0, - @Expose @get: NotNull val servingUnit: String = "", + @Expose @get: NotNull var serving: Double = 0.0, + @Expose @get: NotNull var servingUnit: String = "", @Expose @get: NotNull val description: String = "", @Expose @get: NotNull val calMin: Double = 0.0, @Expose @get: NotNull val calMax: Double = 0.0, diff --git a/src/main/kotlin/com/aitrainer/api/openai/OpenAIService.kt b/src/main/kotlin/com/aitrainer/api/openai/OpenAIService.kt index 155391a..5917d83 100644 --- a/src/main/kotlin/com/aitrainer/api/openai/OpenAIService.kt +++ b/src/main/kotlin/com/aitrainer/api/openai/OpenAIService.kt @@ -80,6 +80,9 @@ class OpenAIService(@Value("\${openai.key}") private val openaiKey: String, priv } val realModelName = "gpt-3.5-turbo" + /*if ( modelName != null) { + realModelName = modelName + }*/ var realTemperature = 0.1 if ( temperature != null ) { realTemperature = temperature diff --git a/src/main/resources/application-diet.properties b/src/main/resources/application-diet.properties index a2b750a..2a78160 100644 --- a/src/main/resources/application-diet.properties +++ b/src/main/resources/application-diet.properties @@ -23,5 +23,6 @@ jwt.secret=aitrainer openai.key=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 firebase.key=AIzaSyBLn7Bz73Z1hB-OhqphBDsskOyGmpI7J8E spring.mail.properties.mail.mime.charset=UTF-8 +spring.http.encoding.charset=UTF-8 -spring.mvc.cors.allowed-origins=* \ No newline at end of file +spring.mvc.cors.allowed-origins=* diff --git a/src/main/resources/application-dietprod.properties b/src/main/resources/application-dietprod.properties index a8ca6d4..2fba647 100644 --- a/src/main/resources/application-dietprod.properties +++ b/src/main/resources/application-dietprod.properties @@ -21,5 +21,6 @@ jwt.secret=aitrainer firebase.key=AIzaSyBLn7Bz73Z1hB-OhqphBDsskOyGmpI7J8E openai.key=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 spring.mail.properties.mail.mime.charset=UTF-8 +spring.http.encoding.charset=UTF-8 spring.mvc.cors.allowed-origins=* \ No newline at end of file diff --git a/src/main/resources/application-dietwsl.properties b/src/main/resources/application-dietwsl.properties index fa04645..a421c79 100644 --- a/src/main/resources/application-dietwsl.properties +++ b/src/main/resources/application-dietwsl.properties @@ -4,3 +4,4 @@ spring.config.use-legacy-processing = true spring.datasource.url = jdbc:mysql://192.168.100.98:3306/diet4you?serverTimezone=CET&useSSL=false&characterEncoding=UTF-8&allowMultiQueries=true spring.datasource.username = aitrainer spring.datasource.password = ENC(WZplPYr8WmrLHshesY4T6oXplK3MlUVJ) +spring.http.encoding.charset=UTF-8 \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index c8186dc..7afeb1a 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -25,4 +25,5 @@ openai.key=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 spring.mail.properties.mail.mime.charset=UTF-8 firebase.key=AIzaSyCUXBWV3_qzvV__ZWZA1siHftrrJpjDKh4 -spring.mvc.cors.allowed-origins=* \ No newline at end of file +spring.mvc.cors.allowed-origins=* +spring.http.encoding.charset=UTF-8 \ No newline at end of file diff --git a/src/test/kotlin/com/aitrainer/api/test/diet/MealTest.kt b/src/test/kotlin/com/aitrainer/api/test/diet/MealTest.kt index db954dc..78f164c 100644 --- a/src/test/kotlin/com/aitrainer/api/test/diet/MealTest.kt +++ b/src/test/kotlin/com/aitrainer/api/test/diet/MealTest.kt @@ -17,6 +17,7 @@ import org.springframework.test.web.servlet.MockMvc import org.springframework.test.web.servlet.request.MockMvcRequestBuilders import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get import org.springframework.test.web.servlet.result.MockMvcResultMatchers.* +import kotlin.test.assertEquals @ExtendWith(SpringExtension::class) @@ -68,7 +69,7 @@ class MealTest { servingUnit = "db", normalizedName = "Tigris buci" ) - private val meal3 = Meal( + private var meal3 = Meal( name = "Töltötttojás", quantity = 330.0, @@ -180,6 +181,28 @@ class MealTest { val newMealJson3 = mvcResult.response.contentAsString val newMeal3 = gson.fromJson(newMealJson3, Meal::class.java) + // update + newMeal3.normalizedName = "Toltott-tojas" + newMeal3.servingUnit = "db" + newMeal3.serving = 5.0 + mvcResult = mockMvc.perform( + MockMvcRequestBuilders.post("/api/meal/${newMeal3.id}") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer $authToken") + .content(toJson(newMeal3)) + ) .andExpect(status().isOk) + .andReturn() + + val newMealJson3Update = mvcResult.response.contentAsString + val newMeal3Update = gson.fromJson(newMealJson3Update, Meal::class.java) + + assertEquals(newMeal3Update.normalizedName,"Toltott-tojas" ) + /* + .andExpect(jsonPath("$.normalizedName").value("Toltott-tojas")) + .andExpect(jsonPath("$.name").value("Töltötttojás")) + .andExpect(jsonPath("$.calMax").value(112.0)) + .andExpect(jsonPath("$.serving").value(5.0))*/ + mealRepository.delete(newMeal3) } From db0c951e0092f8768595cde58d31b7ecce0daa56 Mon Sep 17 00:00:00 2001 From: Tibor Bossanyi Date: Sun, 16 Apr 2023 22:20:48 +0200 Subject: [PATCH 3/4] API 1.2.4.1 v1.2.4 for properties --- build.gradle.kts | 2 +- src/main/resources/application-diet.properties | 2 +- src/main/resources/application-dietprod.properties | 2 +- src/main/resources/application-prod.properties | 2 +- src/main/resources/application.properties | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 12021d3..3b7b31c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,7 +11,7 @@ plugins { } group = "com.aitrainer" -version = "1.2.3" +version = "1.2.4" java.sourceCompatibility = JavaVersion.VERSION_17 repositories { diff --git a/src/main/resources/application-diet.properties b/src/main/resources/application-diet.properties index 2a78160..a944db4 100644 --- a/src/main/resources/application-diet.properties +++ b/src/main/resources/application-diet.properties @@ -16,7 +16,7 @@ logging.config=classpath:logback-spring.xml logging.file=logs # if the database structure has been changed, increment this version number -application.version=1.2.3 +application.version=1.2.4 jwt.secret=aitrainer diff --git a/src/main/resources/application-dietprod.properties b/src/main/resources/application-dietprod.properties index 2fba647..994ee43 100644 --- a/src/main/resources/application-dietprod.properties +++ b/src/main/resources/application-dietprod.properties @@ -14,7 +14,7 @@ logging.config=classpath:logback-spring.xml logging.file=logs # if the database structue has been changed, increment this version number -application.version=1.2.3 +application.version=1.2.4 jwt.secret=aitrainer diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index 17f5373..1efc85d 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -14,7 +14,7 @@ logging.config=classpath:logback-spring.xml logging.file=logs # if the database structue has been changed, increment this version number -application.version=1.2.3 +application.version=1.2.4 jwt.secret=aitrainer diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 7afeb1a..8ce3903 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -17,7 +17,7 @@ logging.config=classpath:logback-spring.xml logging.file=logs # if the database structure has been changed, increment this version number -application.version=1.2.3 +application.version=1.2.4 jwt.secret=aitrainer From 5e0c1df5eb984fad3b1c70ada06220e96ba19779 Mon Sep 17 00:00:00 2001 From: Tibor Bossanyi Date: Mon, 17 Apr 2023 14:36:28 +0200 Subject: [PATCH 4/4] API 1.2.4.2 v1.2.4 openai controller utf8 --- .../kotlin/com/aitrainer/api/controller/OpenAIController.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/aitrainer/api/controller/OpenAIController.kt b/src/main/kotlin/com/aitrainer/api/controller/OpenAIController.kt index 869e3e5..0fcd29c 100644 --- a/src/main/kotlin/com/aitrainer/api/controller/OpenAIController.kt +++ b/src/main/kotlin/com/aitrainer/api/controller/OpenAIController.kt @@ -45,7 +45,7 @@ class OpenAIController() { } @OptIn(BetaOpenAI::class, DelicateCoroutinesApi::class) - @PostMapping("/openai/chat_completion") + @PostMapping("/openai/chat_completion", produces = [org.springframework.http.MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8"]) fun getOpenAIChatCompletion(@RequestBody openai: OpenAIChat, @Value("\${openai.key}") openaiKey: String, ) : String { var result: String val openAIService = OpenAIService(openaiKey, openai.modelName, openai.temperature)