API 1.2.3 meal normalized name, serving
This commit is contained in:
parent
c3bc18fda5
commit
50028cbcec
@ -11,7 +11,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "com.aitrainer"
|
group = "com.aitrainer"
|
||||||
version = "1.2.2"
|
version = "1.2.3"
|
||||||
java.sourceCompatibility = JavaVersion.VERSION_17
|
java.sourceCompatibility = JavaVersion.VERSION_17
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
19
data/db/update_1_2_3.sql
Normal file
19
data/db/update_1_2_3.sql
Normal file
@ -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;
|
@ -40,4 +40,12 @@ class DietUserConsumptionController(private val dietUserConsumptionRepository: D
|
|||||||
return if (list.isEmpty()) ResponseEntity.notFound().build() else
|
return if (list.isEmpty()) ResponseEntity.notFound().build() else
|
||||||
ResponseEntity.ok().body(list)
|
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())
|
||||||
|
}
|
||||||
}
|
}
|
@ -11,6 +11,9 @@ data class DietMeal (
|
|||||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Expose val id: Long = 0,
|
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Expose val id: Long = 0,
|
||||||
@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 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 val meal: String = "",
|
||||||
@Expose @get: NotNull var quantity: Double = 0.0,
|
@Expose @get: NotNull var quantity: Double = 0.0,
|
||||||
@Expose @get: NotNull val quantityUnit: String = "",
|
@Expose @get: NotNull val quantityUnit: String = "",
|
||||||
|
@ -8,8 +8,11 @@ data class Meal (
|
|||||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Expose val id: Long = 0,
|
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Expose val id: Long = 0,
|
||||||
|
|
||||||
@Expose @get: NotNull val name: String = "",
|
@Expose @get: NotNull val name: String = "",
|
||||||
|
@Expose @get: NotNull val normalizedName: String = "",
|
||||||
@Expose @get: NotNull val quantity: Double = 0.0,
|
@Expose @get: NotNull val quantity: Double = 0.0,
|
||||||
@Expose @get: NotNull val quantityUnit: String = "",
|
@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 description: String = "",
|
||||||
@Expose @get: NotNull val calMin: Double = 0.0,
|
@Expose @get: NotNull val calMin: Double = 0.0,
|
||||||
@Expose @get: NotNull val calMax: Double = 0.0,
|
@Expose @get: NotNull val calMax: Double = 0.0,
|
||||||
|
@ -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.2
|
application.version=1.2.3
|
||||||
|
|
||||||
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.2
|
application.version=1.2.3
|
||||||
|
|
||||||
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.2
|
application.version=1.2.3
|
||||||
|
|
||||||
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.2
|
application.version=1.2.3
|
||||||
|
|
||||||
jwt.secret=aitrainer
|
jwt.secret=aitrainer
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.aitrainer.api.test.diet
|
package com.aitrainer.api.test.diet
|
||||||
|
|
||||||
|
import com.aitrainer.api.model.diet.Diet
|
||||||
import com.aitrainer.api.model.diet.DietUserConsumption
|
import com.aitrainer.api.model.diet.DietUserConsumption
|
||||||
import com.aitrainer.api.test.Tokenizer
|
import com.aitrainer.api.test.Tokenizer
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
@ -13,6 +14,7 @@ import org.springframework.boot.test.context.SpringBootTest
|
|||||||
import org.springframework.http.MediaType
|
import org.springframework.http.MediaType
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension
|
import org.springframework.test.context.junit.jupiter.SpringExtension
|
||||||
import org.springframework.test.web.servlet.MockMvc
|
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
|
||||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
|
||||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.*
|
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.*
|
||||||
@ -115,7 +117,6 @@ class DietConsumptionTest {
|
|||||||
.andExpect(jsonPath("$.cal").value(65.0))
|
.andExpect(jsonPath("$.cal").value(65.0))
|
||||||
.andExpect(jsonPath("$.ch").value(44.0))
|
.andExpect(jsonPath("$.ch").value(44.0))
|
||||||
|
|
||||||
// Act & Assert
|
|
||||||
mockMvc.perform(get("/api/diet_user_consumption/5")
|
mockMvc.perform(get("/api/diet_user_consumption/5")
|
||||||
.header("Authorization", "Bearer $authToken")
|
.header("Authorization", "Bearer $authToken")
|
||||||
.contentType(MediaType.APPLICATION_JSON))
|
.contentType(MediaType.APPLICATION_JSON))
|
||||||
@ -124,6 +125,38 @@ class DietConsumptionTest {
|
|||||||
.andExpect(jsonPath("$.[1].name").value("Rozs zsömle"))
|
.andExpect(jsonPath("$.[1].name").value("Rozs zsömle"))
|
||||||
.andExpect(jsonPath("$.[1].ch").value(44))
|
.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 {
|
private fun toJson(obj: Any): String {
|
||||||
|
@ -85,10 +85,14 @@ class DietTest {
|
|||||||
val meal3 = DietMeal(
|
val meal3 = DietMeal(
|
||||||
mealName = "monday|lunch",
|
mealName = "monday|lunch",
|
||||||
meal = "Savanyúkáposzta",
|
meal = "Savanyúkáposzta",
|
||||||
quantity = 2.0,
|
normalizedName = "Savanyukaposzta",
|
||||||
quantityUnit = "tányér",
|
quantity = 222.0,
|
||||||
|
quantityUnit = "gramm",
|
||||||
mealId = 3,
|
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)
|
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[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].normalizedName").value("Savanyukaposzta"))
|
||||||
|
.andExpect(jsonPath("$.meals[2].quantity").value(222.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("gramm"))
|
||||||
|
.andExpect(jsonPath("$.meals[2].servingUnit").value("adag"))
|
||||||
|
|
||||||
// update no_text
|
// update no_text
|
||||||
|
|
||||||
|
@ -45,13 +45,16 @@ class MealTest {
|
|||||||
chMin = 1.0,
|
chMin = 1.0,
|
||||||
chMax = 3.0,
|
chMax = 3.0,
|
||||||
sugar = 0.0,
|
sugar = 0.0,
|
||||||
|
serving = 1.0,
|
||||||
|
servingUnit = "adag",
|
||||||
|
normalizedName = "Tukortojas"
|
||||||
|
|
||||||
)
|
)
|
||||||
private val meal2 = Meal(
|
private val meal2 = Meal(
|
||||||
|
|
||||||
name = "Tigris buci",
|
name = "Tigris buci",
|
||||||
quantity = 3.0,
|
quantity = 233.0,
|
||||||
quantityUnit = "db",
|
quantityUnit = "gram",
|
||||||
calMin = 123.0,
|
calMin = 123.0,
|
||||||
calMax = 140.0,
|
calMax = 140.0,
|
||||||
proteinMin = 19.0,
|
proteinMin = 19.0,
|
||||||
@ -61,6 +64,9 @@ class MealTest {
|
|||||||
chMin = 50.0,
|
chMin = 50.0,
|
||||||
chMax = 60.0,
|
chMax = 60.0,
|
||||||
sugar = 5.0,
|
sugar = 5.0,
|
||||||
|
serving = 3.0,
|
||||||
|
servingUnit = "db",
|
||||||
|
normalizedName = "Tigris buci"
|
||||||
)
|
)
|
||||||
private val meal3 = Meal(
|
private val meal3 = Meal(
|
||||||
|
|
||||||
@ -75,6 +81,9 @@ class MealTest {
|
|||||||
chMin = 1.0,
|
chMin = 1.0,
|
||||||
chMax = 3.0,
|
chMax = 3.0,
|
||||||
sugar = 0.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("$.sugar").value(0.0))
|
||||||
.andExpect(jsonPath("$.quantity").value(90.0))
|
.andExpect(jsonPath("$.quantity").value(90.0))
|
||||||
.andExpect(jsonPath("$.proteinMax").value(25.0))
|
.andExpect(jsonPath("$.proteinMax").value(25.0))
|
||||||
|
.andExpect(jsonPath("$.servingUnit").value("adag"))
|
||||||
|
.andExpect(jsonPath("$.normalizedName").value("Tukortojas"))
|
||||||
|
|
||||||
var mvcResult = mockMvc.perform(
|
var mvcResult = mockMvc.perform(
|
||||||
MockMvcRequestBuilders.post("/api/meal")
|
MockMvcRequestBuilders.post("/api/meal")
|
||||||
@ -127,6 +138,7 @@ class MealTest {
|
|||||||
.contentType(MediaType.APPLICATION_JSON))
|
.contentType(MediaType.APPLICATION_JSON))
|
||||||
.andExpect(status().isOk)
|
.andExpect(status().isOk)
|
||||||
.andExpect(jsonPath("$.[3].name").value("Tükörtojás"))
|
.andExpect(jsonPath("$.[3].name").value("Tükörtojás"))
|
||||||
|
.andExpect(jsonPath("$.[3].normalizedName").value("Tukortojas"))
|
||||||
.andExpect(jsonPath("$.[4].name").value("Tigris buci"))
|
.andExpect(jsonPath("$.[4].name").value("Tigris buci"))
|
||||||
.andExpect(jsonPath("$.[5].quantity").value(330.0))
|
.andExpect(jsonPath("$.[5].quantity").value(330.0))
|
||||||
.andExpect(jsonPath("$.[5].name").value("Töltötttojás"))
|
.andExpect(jsonPath("$.[5].name").value("Töltötttojás"))
|
||||||
@ -172,6 +184,8 @@ class MealTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun toJson(obj: Any): String {
|
private fun toJson(obj: Any): String {
|
||||||
return Gson().toJson(obj)
|
val json = Gson().toJson(obj)
|
||||||
|
println(json)
|
||||||
|
return json
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user