API 1.2+2 open ai fixes
This commit is contained in:
parent
e3107147a1
commit
cae214f87e
@ -44,26 +44,6 @@ COLLATE='utf8mb4_general_ci'
|
||||
ENGINE=InnoDB
|
||||
;
|
||||
|
||||
CREATE TABLE `diet_raw_material` (
|
||||
`id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`diet_meal_id` INT(11) NOT NULL DEFAULT '0',
|
||||
`raw_material_id` INT(11) NULL DEFAULT '0',
|
||||
`kcal_min` INT(11) NULL DEFAULT '0',
|
||||
`kcal_max` INT(11) NULL DEFAULT '0',
|
||||
`protein_min` INT(11) NULL DEFAULT '0',
|
||||
`protein_max` INT(11) NULL DEFAULT '0',
|
||||
`ch_min` INT(11) NULL DEFAULT '0',
|
||||
`ch_max` INT(11) NULL DEFAULT '0',
|
||||
`fat_min` INT(11) NULL DEFAULT '0',
|
||||
`fat_max` INT(11) NULL DEFAULT '0',
|
||||
`sugar` INT(11) NULL DEFAULT '0',
|
||||
`name` CHAR(50) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
)
|
||||
COLLATE='utf8mb4_general_ci'
|
||||
ENGINE=InnoDB
|
||||
;
|
||||
|
||||
CREATE TABLE `diet_sensitivity` (
|
||||
`id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`name` CHAR(100) NOT NULL DEFAULT '0' COLLATE 'utf8mb4_general_ci',
|
||||
@ -116,22 +96,19 @@ COLLATE='utf8_hungarian_ci'
|
||||
ENGINE=InnoDB
|
||||
;
|
||||
|
||||
|
||||
|
||||
CREATE TABLE `raw_material` (
|
||||
CREATE TABLE `meal` (
|
||||
`id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`name` CHAR(100) NOT NULL COLLATE 'utf8mb4_general_ci',
|
||||
`description` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
|
||||
`kcal_min` INT(11) NULL DEFAULT '0',
|
||||
`kcal_max` INT(11) NULL DEFAULT '0',
|
||||
`protein_min` INT(11) NULL DEFAULT '0',
|
||||
`protein_max` INT(11) NULL DEFAULT '0',
|
||||
`ch_min` INT(11) NULL DEFAULT '0',
|
||||
`ch_max` INT(11) NULL DEFAULT '0',
|
||||
`fat_min` INT(11) NULL DEFAULT '0',
|
||||
`fat_max` INT(11) NULL DEFAULT '0',
|
||||
`sugar` INT(11) NULL DEFAULT '0',
|
||||
`store_id` INT(11) NULL DEFAULT '0',
|
||||
`cal_min` DOUBLE NULL DEFAULT NULL,
|
||||
`cal_max` DOUBLE NULL DEFAULT NULL,
|
||||
`protein_min` DOUBLE NULL DEFAULT NULL,
|
||||
`protein_max` DOUBLE NULL DEFAULT NULL,
|
||||
`ch_min` DOUBLE NULL DEFAULT NULL,
|
||||
`ch_max` DOUBLE NULL DEFAULT NULL,
|
||||
`fat_min` DOUBLE NULL DEFAULT NULL,
|
||||
`fat_max` DOUBLE NULL DEFAULT NULL,
|
||||
`sugar` DOUBLE NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
)
|
||||
COLLATE='utf8mb4_general_ci'
|
||||
|
@ -24,7 +24,6 @@ class CustomerPackageController( private val customerRepository: CustomerReposit
|
||||
private val customerTrainingPlanRepository: CustomerTrainingPlanRepository,
|
||||
private val customerMembership: CustomerMembershipRepository,
|
||||
private val dietRepository: DietRepository,
|
||||
private val dietRawMaterialRepository: DietRawMaterialRepository,
|
||||
private val dietUserConsumptionRepository: DietUserConsumptionRepository,
|
||||
private val dietUserRepository: DietUserRepository,
|
||||
private val dietUserPreferenceRepository: DietUserPreferenceRepository,
|
||||
@ -57,9 +56,6 @@ class CustomerPackageController( private val customerRepository: CustomerReposit
|
||||
val listDiet = dietRepository.findByDietUserId(dietUserId)
|
||||
val listDietJson = gson.toJson(listDiet)
|
||||
|
||||
val listDietRawMaterial = dietRawMaterialRepository.findByDietMealId(dietUserId)
|
||||
val listDietRawMaterialJson = gson.toJson(listDietRawMaterial)
|
||||
|
||||
val listDietUserConsumption = dietUserConsumptionRepository.findByDietUserId(dietUserId)
|
||||
val listDietUserConsumptionJson = gson.toJson(listDietUserConsumption)
|
||||
|
||||
@ -76,7 +72,6 @@ class CustomerPackageController( private val customerRepository: CustomerReposit
|
||||
getClassRecord(Customer::class.simpleName, customerJson) +
|
||||
"|||" + getClassRecord(DietUser::class.simpleName, dietUserJson) +
|
||||
"|||" + getClassRecord(Diet::class.simpleName, listDietJson) +
|
||||
"|||" + getClassRecord(DietRawMaterial::class.simpleName, listDietRawMaterialJson) +
|
||||
"|||" + getClassRecord(DietUserConsumption::class.simpleName, listDietUserConsumptionJson) +
|
||||
"|||" + getClassRecord(DietUserPreference::class.simpleName, listDietUserPreferenceJson) +
|
||||
"|||" + getClassRecord(DietUserSensitivity::class.simpleName, listDietUserSensitivityJson) +
|
||||
|
@ -2,7 +2,7 @@ package com.aitrainer.api.controller
|
||||
|
||||
import com.aitrainer.api.model.*
|
||||
import com.aitrainer.api.model.diet.DietSensitivity
|
||||
import com.aitrainer.api.model.diet.RawMaterial
|
||||
import com.aitrainer.api.model.diet.Meal
|
||||
import com.aitrainer.api.model.diet.Recipe
|
||||
import com.aitrainer.api.model.diet.Store
|
||||
import com.aitrainer.api.repository.*
|
||||
@ -37,7 +37,7 @@ class PackageController(private val exerciseAbilityRepository: ExerciseAbilityRe
|
||||
private val membershipRepository: MembershipRepository,
|
||||
private val storeRepository: StoreRepository,
|
||||
private val recipeRepository: RecipeRepository,
|
||||
private val rawMaterialRepository: RawMaterialRepository,
|
||||
private val mealRepository: MealRepository,
|
||||
private val dietSensitivityRepository: DietSensitivityRepository
|
||||
) {
|
||||
|
||||
@ -60,7 +60,7 @@ class PackageController(private val exerciseAbilityRepository: ExerciseAbilityRe
|
||||
val listRecipe = recipeRepository.findAll()
|
||||
val listRecipeJson = gson.toJson(listRecipe)
|
||||
|
||||
val listRawMaterial = rawMaterialRepository.findAll()
|
||||
val listRawMaterial = mealRepository.findAll()
|
||||
val listRawMaterialJson = gson.toJson(listRawMaterial)
|
||||
|
||||
val listDietSensitivity = dietSensitivityRepository.findAll()
|
||||
@ -71,7 +71,7 @@ class PackageController(private val exerciseAbilityRepository: ExerciseAbilityRe
|
||||
"|||" + getClassRecord(Membership::class.simpleName, listMembershipJson) +
|
||||
"|||" + getClassRecord(Store::class.simpleName, listStoreJson) +
|
||||
"|||" + getClassRecord(Recipe::class.simpleName, listRecipeJson) +
|
||||
"|||" + getClassRecord(RawMaterial::class.simpleName, listRawMaterialJson) +
|
||||
"|||" + getClassRecord(Meal::class.simpleName, listRawMaterialJson) +
|
||||
"|||" + getClassRecord(DietSensitivity::class.simpleName, listDietSensitivityJson)
|
||||
|
||||
return if (packageJson.isEmpty()) ResponseEntity.notFound().build() else
|
||||
|
@ -1,24 +0,0 @@
|
||||
package com.aitrainer.api.controller.diet
|
||||
|
||||
import com.aitrainer.api.model.diet.DietRawMaterial
|
||||
import com.aitrainer.api.repository.diet.DietRawMaterialRepository
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.*
|
||||
import java.util.*
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
class DietRawMaterialController(private val dietRawMaterialRepository: DietRawMaterialRepository) {
|
||||
|
||||
@PostMapping("/diet_raw_material")
|
||||
fun insert(@RequestBody dietRawMaterial: DietRawMaterial): ResponseEntity<*> {
|
||||
return ResponseEntity.ok().body(dietRawMaterialRepository.save(dietRawMaterial))
|
||||
}
|
||||
|
||||
@GetMapping("/diet_raw_material/{dietMealId}")
|
||||
fun getByDietUserId(@PathVariable dietMealId: Long): ResponseEntity<List<DietRawMaterial>> {
|
||||
val list = dietRawMaterialRepository.findByDietMealId(dietMealId)
|
||||
return if (list.isEmpty()) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(list)
|
||||
}
|
||||
}
|
@ -19,7 +19,7 @@ class DietUserConsumptionController(private val dietUserConsumptionRepository: D
|
||||
fun update(@PathVariable(value = "id") id: Long, @RequestBody dietUserConsumption: DietUserConsumption): ResponseEntity<*> {
|
||||
return dietUserConsumptionRepository.findById(id).map { existingConsumption ->
|
||||
val updatedConsumption: DietUserConsumption = existingConsumption.copy(
|
||||
rawMaterialId = dietUserConsumption.rawMaterialId,
|
||||
mealId = dietUserConsumption.mealId,
|
||||
dateConsumption = dietUserConsumption.dateConsumption,
|
||||
name = dietUserConsumption.name,
|
||||
quantity = dietUserConsumption.quantity,
|
||||
|
@ -0,0 +1,39 @@
|
||||
package com.aitrainer.api.controller.diet
|
||||
|
||||
import com.aitrainer.api.model.diet.Meal
|
||||
import com.aitrainer.api.repository.diet.MealRepository
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.*
|
||||
|
||||
@RestController
|
||||
@RequestMapping("api")
|
||||
class MealController(private val mealRepository: MealRepository) {
|
||||
|
||||
@PostMapping ("/meal")
|
||||
fun insert(@RequestBody meal: Meal): ResponseEntity<Meal> {
|
||||
val newMeal = mealRepository.save(meal)
|
||||
return ResponseEntity.ok().body(newMeal)
|
||||
}
|
||||
|
||||
@GetMapping("/meal")
|
||||
fun getAll(): ResponseEntity<List<Meal>> {
|
||||
val list = mealRepository.findAll()
|
||||
return if (list.isEmpty()) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(list)
|
||||
}
|
||||
|
||||
@GetMapping("/meal/{id}")
|
||||
fun getById(@PathVariable id: Long): ResponseEntity<Meal> {
|
||||
val rawMaterial = mealRepository.findById(id)
|
||||
return if (rawMaterial == null) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(rawMaterial)
|
||||
}
|
||||
|
||||
@GetMapping("/meal/by_name/{name}")
|
||||
fun getByName(@PathVariable name: String): ResponseEntity<Meal> {
|
||||
val meal = mealRepository.findByName(name)
|
||||
return if (meal == null) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(meal)
|
||||
}
|
||||
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package com.aitrainer.api.controller.diet
|
||||
|
||||
import com.aitrainer.api.model.diet.RawMaterial
|
||||
import com.aitrainer.api.repository.diet.RawMaterialRepository
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.*
|
||||
|
||||
@RestController
|
||||
@RequestMapping("api")
|
||||
class RawMaterialController(private val rawMaterialRepository: RawMaterialRepository) {
|
||||
|
||||
@PostMapping ("/raw_material")
|
||||
fun insert(@RequestBody rawMaterial: RawMaterial): ResponseEntity<RawMaterial> {
|
||||
val newRawMaterial = rawMaterialRepository.save(rawMaterial)
|
||||
return ResponseEntity.ok().body(newRawMaterial)
|
||||
}
|
||||
|
||||
@GetMapping("/raw_material")
|
||||
fun getAll(): ResponseEntity<List<RawMaterial>> {
|
||||
val list = rawMaterialRepository.findAll()
|
||||
return if (list.isEmpty()) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(list)
|
||||
}
|
||||
|
||||
@GetMapping("/raw_material/{id}")
|
||||
fun getByRawMaterialId(@PathVariable id: Long): ResponseEntity<RawMaterial> {
|
||||
val rawMaterial = rawMaterialRepository.findByRawMaterialId(id)
|
||||
return if (rawMaterial == null) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(rawMaterial)
|
||||
}
|
||||
}
|
@ -27,11 +27,10 @@ class RecipeController(private val recipeRepository: RecipeRepository) {
|
||||
fat = recipe.fat,
|
||||
protein = recipe.protein,
|
||||
dietUserId = recipe.dietUserId,
|
||||
mealId = recipe.mealId
|
||||
)
|
||||
recipe.rawMaterials.forEach {
|
||||
recipe.meals.forEach {
|
||||
it.recipe = recipe
|
||||
updatedRecipe.rawMaterials.add(it)
|
||||
updatedRecipe.meals.add(it)
|
||||
}
|
||||
return ResponseEntity.ok().body(recipeRepository.save(updatedRecipe))
|
||||
}
|
||||
@ -50,13 +49,6 @@ class RecipeController(private val recipeRepository: RecipeRepository) {
|
||||
ResponseEntity.ok().body(list)
|
||||
}
|
||||
|
||||
@GetMapping("/recipe/meal/{mealId}")
|
||||
fun getByMealId(@PathVariable mealId: Long): ResponseEntity<List<Recipe>> {
|
||||
val list = recipeRepository.findByMealId(mealId)
|
||||
return if (list == null) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(list)
|
||||
}
|
||||
|
||||
@GetMapping("/recipe/name/{name}")
|
||||
fun getByName(@PathVariable name: String): ResponseEntity<List<Recipe>> {
|
||||
val list = recipeRepository.findByName(name)
|
||||
|
@ -0,0 +1,17 @@
|
||||
package com.aitrainer.api.controller.diet
|
||||
|
||||
import com.aitrainer.api.model.diet.RecipeMeal
|
||||
import com.aitrainer.api.repository.diet.RecipeMealRepository
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.*
|
||||
|
||||
@RestController
|
||||
@RequestMapping("api")
|
||||
class RecipeMealController(private val recipeMealRepository: RecipeMealRepository) {
|
||||
|
||||
@PostMapping ("/recipe_meal")
|
||||
fun insert(@RequestBody recipeMeal: RecipeMeal): ResponseEntity<RecipeMeal> {
|
||||
val newRecipe = recipeMealRepository.save(recipeMeal)
|
||||
return ResponseEntity.ok().body(recipeMeal)
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package com.aitrainer.api.controller.diet
|
||||
|
||||
import com.aitrainer.api.model.diet.RecipeRawMaterial
|
||||
import com.aitrainer.api.repository.diet.RecipeRawMaterialRepository
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.*
|
||||
|
||||
@RestController
|
||||
@RequestMapping("api")
|
||||
class RecipeRawMaterialController(private val recipeRawMaterialRepository: RecipeRawMaterialRepository) {
|
||||
|
||||
@PostMapping ("/recipe_raw_material")
|
||||
fun insert(@RequestBody recipeRawMaterial: RecipeRawMaterial): ResponseEntity<RecipeRawMaterial> {
|
||||
val newRecipe = recipeRawMaterialRepository.save(recipeRawMaterial)
|
||||
return ResponseEntity.ok().body(recipeRawMaterial)
|
||||
}
|
||||
}
|
@ -8,9 +8,11 @@ import org.jetbrains.annotations.NotNull
|
||||
@Entity
|
||||
data class DietMeal (
|
||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Expose val id: Long = 0,
|
||||
//@Expose @get: NotNull val dietId: Long = 0,
|
||||
@Expose @get: NotNull val mealId: Long = 0,
|
||||
@Expose @get: NotNull val mealName: String = "",
|
||||
@Expose @get: NotNull val meal: String = "",
|
||||
@Expose @get: NotNull val quantity: Double = 0.0,
|
||||
@Expose @get: NotNull val quantityUnit: String = "",
|
||||
) {
|
||||
@ManyToOne(fetch = FetchType.EAGER, optional = false)
|
||||
@JoinColumn(name = "dietId", nullable = false)
|
||||
|
@ -1,22 +0,0 @@
|
||||
package com.aitrainer.api.model.diet
|
||||
import com.google.gson.annotations.Expose
|
||||
import jakarta.persistence.*
|
||||
import org.jetbrains.annotations.NotNull
|
||||
|
||||
@Entity
|
||||
data class DietRawMaterial (
|
||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Expose val id: Long = 0,
|
||||
|
||||
@Expose @get: NotNull val dietMealId: Long = 0,
|
||||
@Expose @get: NotNull val rawMaterialId: Long = 0,
|
||||
@Expose @get: NotNull val name: String = "",
|
||||
@Expose @get: NotNull val kcalMin: Int = 0,
|
||||
@Expose @get: NotNull val kcalMax: Int = 0,
|
||||
@Expose @get: NotNull val proteinMin: Int = 0,
|
||||
@Expose @get: NotNull val proteinMax: Int = 0,
|
||||
@Expose @get: NotNull val fatMin: Int = 0,
|
||||
@Expose @get: NotNull val fatMax: Int = 0,
|
||||
@Expose @get: NotNull val chMin: Int = 0,
|
||||
@Expose @get: NotNull val chMax: Int = 0,
|
||||
@Expose @get: NotNull val sugar: Int = 0,
|
||||
)
|
@ -1,4 +1,5 @@
|
||||
package com.aitrainer.api.model.diet
|
||||
|
||||
import com.google.gson.annotations.Expose
|
||||
import jakarta.persistence.*
|
||||
import org.jetbrains.annotations.NotNull
|
||||
@ -9,14 +10,14 @@ data class DietUserConsumption(
|
||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Expose val id: Long = 0,
|
||||
|
||||
@Expose @get: NotNull val dietUserId: Long = 0,
|
||||
@Expose @get: NotNull val rawMaterialId: Long = 0,
|
||||
@Expose @get: NotNull val mealId: Long = 0,
|
||||
@Expose @get: NotNull val name: String = "",
|
||||
@Expose @get: NonNull var dateConsumption: String = "",
|
||||
|
||||
@Expose @get: NotNull val quantity: Double = 0.0,
|
||||
@Expose @get: NotNull val quantityUnit: String = "",
|
||||
|
||||
@Expose @get: NotNull val cal: Int = 0,
|
||||
@Expose @get: NotNull val cal: Double = 0.0,
|
||||
@Expose @get: NotNull val protein: Double = 0.0,
|
||||
@Expose @get: NotNull val fat: Double = 0.0,
|
||||
@Expose @get: NotNull val ch: Double = 0.0,
|
||||
|
23
src/main/kotlin/com/aitrainer/api/model/diet/Meal.kt
Normal file
23
src/main/kotlin/com/aitrainer/api/model/diet/Meal.kt
Normal file
@ -0,0 +1,23 @@
|
||||
package com.aitrainer.api.model.diet
|
||||
import com.google.gson.annotations.Expose
|
||||
import jakarta.persistence.*
|
||||
import org.jetbrains.annotations.NotNull
|
||||
|
||||
@Entity
|
||||
data class Meal (
|
||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Expose val id: Long = 0,
|
||||
|
||||
@Expose @get: NotNull val name: String = "",
|
||||
@Expose @get: NotNull val quantity: Double = 0.0,
|
||||
@Expose @get: NotNull val quantityUnit: String = "",
|
||||
@Expose @get: NotNull val description: String = "",
|
||||
@Expose @get: NotNull val calMin: Double = 0.0,
|
||||
@Expose @get: NotNull val calMax: Double = 0.0,
|
||||
@Expose @get: NotNull val proteinMin: Double = 0.0,
|
||||
@Expose @get: NotNull val proteinMax: Double = 0.0,
|
||||
@Expose @get: NotNull val fatMin: Double = 0.0,
|
||||
@Expose @get: NotNull val fatMax: Double = 0.0,
|
||||
@Expose @get: NotNull val chMin: Double = 0.0,
|
||||
@Expose @get: NotNull val chMax: Double = 0.0,
|
||||
@Expose @get: NotNull val sugar: Double = 0.0,
|
||||
)
|
@ -1,22 +0,0 @@
|
||||
package com.aitrainer.api.model.diet
|
||||
import com.google.gson.annotations.Expose
|
||||
import jakarta.persistence.*
|
||||
import org.jetbrains.annotations.NotNull
|
||||
|
||||
@Entity
|
||||
data class RawMaterial (
|
||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Expose val id: Long = 0,
|
||||
|
||||
@Expose @get: NotNull val name: String = "",
|
||||
@Expose @get: NotNull val description: String = "",
|
||||
@Expose @get: NotNull val kcalMin: Int = 0,
|
||||
@Expose @get: NotNull val kcalMax: Int = 0,
|
||||
@Expose @get: NotNull val proteinMin: Int = 0,
|
||||
@Expose @get: NotNull val proteinMax: Int = 0,
|
||||
@Expose @get: NotNull val fatMin: Int = 0,
|
||||
@Expose @get: NotNull val fatMax: Int = 0,
|
||||
@Expose @get: NotNull val chMin: Int = 0,
|
||||
@Expose @get: NotNull val chMax: Int = 0,
|
||||
@Expose @get: NotNull val sugar: Int = 0,
|
||||
@Expose @get: NotNull val storeId: Long = 0,
|
||||
)
|
@ -19,9 +19,8 @@ data class Recipe (
|
||||
@Expose @get: NotNull val fat: Double = 0.0,
|
||||
@Expose @get: NotNull val ch: Double = 0.0,
|
||||
@Expose @get: NotNull val dietUserId: Long = 0,
|
||||
@Expose @get: NotNull val mealId: Long = 0,
|
||||
) {
|
||||
@OneToMany(cascade = [(CascadeType.ALL)], fetch = FetchType.EAGER, mappedBy = "recipe")
|
||||
@Fetch(value = FetchMode.SUBSELECT)
|
||||
@Expose val rawMaterials: MutableList<RecipeRawMaterial> = mutableListOf()
|
||||
@Expose val meals: MutableList<RecipeMeal> = mutableListOf()
|
||||
}
|
@ -6,12 +6,11 @@ import jakarta.persistence.*
|
||||
import org.jetbrains.annotations.NotNull
|
||||
|
||||
@Entity
|
||||
data class RecipeRawMaterial (
|
||||
data class RecipeMeal (
|
||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Expose val id: Long = 0,
|
||||
|
||||
@Expose @get: NotNull var rawMaterialId: Int = 0,
|
||||
@Expose @get: NotNull var mealId: Int = 0,
|
||||
@Expose @get: NotNull var quantity: Int = 0,
|
||||
@Expose @get: NotNull var quantityUnit: String = "",
|
||||
) {
|
||||
@ManyToOne(fetch = FetchType.EAGER, optional = false)
|
||||
@JoinColumn(name = "recipeId", nullable = false)
|
@ -1,10 +0,0 @@
|
||||
package com.aitrainer.api.repository.diet
|
||||
|
||||
import com.aitrainer.api.model.diet.DietRawMaterial
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.stereotype.Repository
|
||||
|
||||
@Repository
|
||||
interface DietRawMaterialRepository : JpaRepository<DietRawMaterial, Long> {
|
||||
fun findByDietMealId(dietMealId: Long): List<DietRawMaterial>
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.aitrainer.api.repository.diet
|
||||
|
||||
import com.aitrainer.api.model.diet.Meal
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.data.jpa.repository.Query
|
||||
|
||||
interface MealRepository : JpaRepository<Meal, Int> {
|
||||
@Query(" FROM Meal WHERE id = :id")
|
||||
fun findById(id: Long): Meal?
|
||||
|
||||
@Query(" FROM Meal WHERE name = :name")
|
||||
fun findByName(name: String): Meal?
|
||||
|
||||
@Query(" FROM Meal WHERE name = :name AND quantity = :quantity")
|
||||
fun findByNameAndQuantity(name: String, quantity: Double): Meal?
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package com.aitrainer.api.repository.diet
|
||||
|
||||
import com.aitrainer.api.model.diet.RawMaterial
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.data.jpa.repository.Query
|
||||
|
||||
interface RawMaterialRepository : JpaRepository<RawMaterial, Int> {
|
||||
@Query(" FROM RawMaterial " +
|
||||
" WHERE id = :id"
|
||||
)
|
||||
fun findByRawMaterialId(id: Long): RawMaterial?
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.aitrainer.api.repository.diet
|
||||
|
||||
import com.aitrainer.api.model.diet.RecipeMeal
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
|
||||
interface RecipeMealRepository : JpaRepository<RecipeMeal, Int> {
|
||||
|
||||
fun findByMealId(mealId: Long): List<RecipeMeal>?
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package com.aitrainer.api.repository.diet
|
||||
|
||||
import com.aitrainer.api.model.diet.RecipeRawMaterial
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
|
||||
interface RecipeRawMaterialRepository : JpaRepository<RecipeRawMaterial, Int> {
|
||||
|
||||
fun findByRawMaterialId(rawMaterialId: Long): List<RecipeRawMaterial>?
|
||||
}
|
@ -13,6 +13,4 @@ interface RecipeRepository : JpaRepository<Recipe, Int> {
|
||||
@Query(" FROM Recipe WHERE recipeId = :recipeId")
|
||||
fun findByRecipeId(recipeId: Long): Recipe?
|
||||
|
||||
@Query(" FROM Recipe WHERE mealId = :mealId")
|
||||
fun findByMealId(mealId: Long): List<Recipe>?
|
||||
}
|
||||
|
@ -50,9 +50,6 @@ class AppCustomerPackageTest {
|
||||
@Autowired
|
||||
private lateinit var dietRepository: DietRepository
|
||||
|
||||
@Autowired
|
||||
private lateinit var dietRawMaterialRepository: DietRawMaterialRepository
|
||||
|
||||
@Autowired
|
||||
private lateinit var dietUserConsumptionRepository: DietUserConsumptionRepository
|
||||
|
||||
@ -83,7 +80,6 @@ class AppCustomerPackageTest {
|
||||
customerTrainingPlanRepository,
|
||||
customerMembershipRepository,
|
||||
dietRepository,
|
||||
dietRawMaterialRepository,
|
||||
dietUserConsumptionRepository,
|
||||
dietUserRepository,
|
||||
dietUserPreferenceRepository,
|
||||
@ -109,14 +105,8 @@ class AppCustomerPackageTest {
|
||||
val list: List<Diet> = gson.fromJson(dietJson, type)
|
||||
assertEquals(list[0].dietText, "Test diet text")
|
||||
assertEquals(list[0].meals[0].mealName, "monday|breakfast")
|
||||
}
|
||||
|
||||
record[0] == DietRawMaterial::class.simpleName -> {
|
||||
val dietRawMaterialJson: String = record[1]
|
||||
val type = object : TypeToken<List<DietRawMaterial?>?>() {}.type
|
||||
val list: List<DietRawMaterial> = gson.fromJson(dietRawMaterialJson, type)
|
||||
assertEquals(list[0].name, "Tükörtojás")
|
||||
assertEquals(list[0].kcalMin, 70)
|
||||
assertEquals(list[0].meals[0].quantity, 2.0)
|
||||
assertEquals(list[0].meals[2].quantityUnit, "tányér")
|
||||
}
|
||||
|
||||
record[0] == DietUserConsumption::class.simpleName -> {
|
||||
@ -139,7 +129,7 @@ class AppCustomerPackageTest {
|
||||
val dietUserPreferenceJson: String = record[1]
|
||||
val type = object : TypeToken<List<DietUserPreference?>?>() {}.type
|
||||
val list: List<DietUserPreference> = gson.fromJson(dietUserPreferenceJson, type)
|
||||
assertEquals(list[0].dietUserId, 5)
|
||||
assertEquals(list[0].dietUserId, 2)
|
||||
assertEquals(list[0].temperature, -1)
|
||||
}
|
||||
|
||||
@ -147,7 +137,7 @@ class AppCustomerPackageTest {
|
||||
val dietUserSensitivityJson: String = record[1]
|
||||
val type = object : TypeToken<List<DietUserSensitivity?>?>() {}.type
|
||||
val list: List<DietUserSensitivity> = gson.fromJson(dietUserSensitivityJson, type)
|
||||
assertEquals(list[0].dietUserId, 5)
|
||||
assertEquals(list[0].dietUserId, 2)
|
||||
assertEquals(list[0].sensitivityId, 1)
|
||||
}
|
||||
}
|
||||
@ -169,7 +159,6 @@ class AppCustomerPackageTest {
|
||||
customerTrainingPlanRepository,
|
||||
customerMembershipRepository,
|
||||
dietRepository,
|
||||
dietRawMaterialRepository,
|
||||
dietUserConsumptionRepository,
|
||||
dietUserRepository,
|
||||
dietUserPreferenceRepository,
|
||||
@ -225,7 +214,6 @@ class AppCustomerPackageTest {
|
||||
exerciseResultRepository, customerActivityRepository, customerTrainingPlanRepository,
|
||||
customerMembershipRepository,
|
||||
dietRepository,
|
||||
dietRawMaterialRepository,
|
||||
dietUserConsumptionRepository,
|
||||
dietUserRepository,
|
||||
dietUserPreferenceRepository,
|
||||
|
@ -3,7 +3,7 @@ package com.aitrainer.api.test
|
||||
import com.aitrainer.api.controller.PackageController
|
||||
import com.aitrainer.api.model.*
|
||||
import com.aitrainer.api.model.diet.DietSensitivity
|
||||
import com.aitrainer.api.model.diet.RawMaterial
|
||||
import com.aitrainer.api.model.diet.Meal
|
||||
import com.aitrainer.api.model.diet.Recipe
|
||||
import com.aitrainer.api.model.diet.Store
|
||||
import com.aitrainer.api.repository.*
|
||||
@ -65,7 +65,7 @@ class AppPackageTest {
|
||||
private lateinit var dietSensitivityRepository: DietSensitivityRepository
|
||||
|
||||
@Autowired
|
||||
private lateinit var rawMaterialRepository: RawMaterialRepository
|
||||
private lateinit var mealRepository: MealRepository
|
||||
|
||||
@Autowired
|
||||
private lateinit var recipeRepository: RecipeRepository
|
||||
@ -100,7 +100,7 @@ class AppPackageTest {
|
||||
membershipRepository,
|
||||
storeRepository,
|
||||
recipeRepository,
|
||||
rawMaterialRepository,
|
||||
mealRepository,
|
||||
dietSensitivityRepository,
|
||||
)
|
||||
val response: ResponseEntity<*> = controller.getDietPackageData()
|
||||
@ -139,16 +139,15 @@ class AppPackageTest {
|
||||
assertEquals(list[2].name, "Borsóleves")
|
||||
assertEquals(list[2].protein, 45.0)
|
||||
assertEquals(list[2].dietUserId, 1)
|
||||
} else if ( record[0] == RawMaterial::class.simpleName) {
|
||||
val rawMaterialJson: String = record[1]
|
||||
val type = object : TypeToken<List<RawMaterial?>?>() {}.type
|
||||
val list: List<RawMaterial> = gson.fromJson(rawMaterialJson, type)
|
||||
} else if ( record[0] == Meal::class.simpleName) {
|
||||
val mealJson: String = record[1]
|
||||
val type = object : TypeToken<List<Meal?>?>() {}.type
|
||||
val list: List<Meal> = gson.fromJson(mealJson, type)
|
||||
assertTrue(list.isNotEmpty())
|
||||
assertEquals(list[0].name, "Tükörtojás")
|
||||
assertEquals(list[0].kcalMin, 70)
|
||||
assertEquals(list[0].proteinMax, 25)
|
||||
assertEquals(list[0].storeId, 4)
|
||||
assertEquals(list[1].name, "Tigris buci")
|
||||
assertEquals(list[0].name, "Tükörtojás1")
|
||||
assertEquals(list[0].calMin, 70.0)
|
||||
assertEquals(list[0].proteinMax, 25.0)
|
||||
assertEquals(list[1].name, "Tigris buci1")
|
||||
} else if ( record[0] == DietSensitivity::class.simpleName) {
|
||||
val dietSensitivityJson: String = record[1]
|
||||
val type = object : TypeToken<List<DietSensitivity?>?>() {}.type
|
||||
@ -186,7 +185,7 @@ class AppPackageTest {
|
||||
membershipRepository,
|
||||
storeRepository,
|
||||
recipeRepository,
|
||||
rawMaterialRepository,
|
||||
mealRepository,
|
||||
dietSensitivityRepository,
|
||||
)
|
||||
val response: ResponseEntity<*> = controller.getClubPackageData()
|
||||
@ -246,7 +245,7 @@ class AppPackageTest {
|
||||
membershipRepository,
|
||||
storeRepository,
|
||||
recipeRepository,
|
||||
rawMaterialRepository,
|
||||
mealRepository,
|
||||
dietSensitivityRepository,
|
||||
)
|
||||
val response: ResponseEntity<*> = controller.getPackageData()
|
||||
|
@ -28,14 +28,14 @@ class DietConsumptionTest {
|
||||
private lateinit var mockMvc: MockMvc
|
||||
|
||||
private val dietUserConsumption = DietUserConsumption(
|
||||
id = 1,
|
||||
id = 3,
|
||||
dietUserId = 5,
|
||||
rawMaterialId = 10,
|
||||
mealId = 10,
|
||||
name = "Tükörtojás",
|
||||
dateConsumption = "2023-02-08 17:00",
|
||||
quantity = 120.0,
|
||||
quantityUnit = "g",
|
||||
cal = 70,
|
||||
cal = 70.0,
|
||||
protein = 32.0,
|
||||
fat = 11.0,
|
||||
ch = 1.0,
|
||||
@ -43,14 +43,14 @@ class DietConsumptionTest {
|
||||
)
|
||||
|
||||
private var dietUserConsumption2 = DietUserConsumption(
|
||||
id = 2,
|
||||
id = 4,
|
||||
dietUserId = 5,
|
||||
rawMaterialId = 11,
|
||||
mealId = 11,
|
||||
name = "Rozs zsömle",
|
||||
dateConsumption = "2023-02-08 16:00",
|
||||
quantity = 80.0,
|
||||
quantityUnit = "g",
|
||||
cal = 60,
|
||||
cal = 60.0,
|
||||
protein = 11.0,
|
||||
fat = 4.0,
|
||||
ch = 34.0,
|
||||
@ -76,7 +76,7 @@ class DietConsumptionTest {
|
||||
)
|
||||
.andExpect(status().isOk)
|
||||
.andExpect(jsonPath("$.dietUserId").value(5))
|
||||
.andExpect(jsonPath("$.rawMaterialId").value(10))
|
||||
.andExpect(jsonPath("$.mealId").value(10))
|
||||
.andExpect(jsonPath("$.protein").value(32.0))
|
||||
|
||||
mockMvc.perform(
|
||||
@ -88,14 +88,14 @@ class DietConsumptionTest {
|
||||
|
||||
|
||||
val dietUserConsumption3 = DietUserConsumption(
|
||||
id = 2,
|
||||
id = 4,
|
||||
dietUserId = 5,
|
||||
rawMaterialId = 11,
|
||||
mealId = 11,
|
||||
name = "Rozs zsömle",
|
||||
dateConsumption = "2023-02-08 16:30",
|
||||
quantity = 80.0,
|
||||
quantityUnit = "g",
|
||||
cal = 65, //**
|
||||
cal = 65.0, //**
|
||||
protein = 11.0,
|
||||
fat = 4.0,
|
||||
ch = 44.0, //**
|
||||
@ -103,14 +103,14 @@ class DietConsumptionTest {
|
||||
)
|
||||
|
||||
mockMvc.perform(
|
||||
MockMvcRequestBuilders.post("/api/diet_user_consumption/2")
|
||||
MockMvcRequestBuilders.post("/api/diet_user_consumption/4")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", "Bearer $authToken")
|
||||
.content(toJson(dietUserConsumption3))
|
||||
)
|
||||
.andExpect(status().isOk)
|
||||
.andExpect(jsonPath("$.dietUserId").value(5))
|
||||
.andExpect(jsonPath("$.rawMaterialId").value(11))
|
||||
.andExpect(jsonPath("$.mealId").value(11))
|
||||
.andExpect(jsonPath("$.sugar").value(8.0))
|
||||
.andExpect(jsonPath("$.cal").value(65.0))
|
||||
.andExpect(jsonPath("$.ch").value(44.0))
|
||||
|
@ -1,80 +0,0 @@
|
||||
package com.aitrainer.api.test.diet
|
||||
|
||||
import com.aitrainer.api.model.diet.DietRawMaterial
|
||||
import com.aitrainer.api.test.Tokenizer
|
||||
import com.google.gson.Gson
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
|
||||
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.request.MockMvcRequestBuilders
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
|
||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.*
|
||||
|
||||
|
||||
@ExtendWith(SpringExtension::class)
|
||||
@SpringBootTest
|
||||
@AutoConfigureMockMvc
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
class DietRawMaterialTest {
|
||||
|
||||
@Autowired
|
||||
private lateinit var mockMvc: MockMvc
|
||||
|
||||
private val dietRawMaterial = DietRawMaterial(
|
||||
dietMealId = 1,
|
||||
rawMaterialId = 10,
|
||||
name = "Tükörtojás",
|
||||
kcalMin = 70,
|
||||
kcalMax = 110,
|
||||
proteinMin = 19,
|
||||
proteinMax = 25,
|
||||
fatMin = 12,
|
||||
fatMax = 15,
|
||||
chMin = 1,
|
||||
chMax = 3,
|
||||
sugar = 0,
|
||||
)
|
||||
|
||||
private var authToken: String? = ""
|
||||
|
||||
@BeforeAll
|
||||
fun initTest() {
|
||||
authToken = Tokenizer.getToken()
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun `insert dietRawMaterial successfully`() {
|
||||
|
||||
mockMvc.perform(
|
||||
MockMvcRequestBuilders.post("/api/diet_raw_material")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", "Bearer $authToken")
|
||||
.content(toJson(dietRawMaterial))
|
||||
)
|
||||
.andExpect(status().isOk)
|
||||
.andExpect(jsonPath("$.dietMealId").value(1))
|
||||
.andExpect(jsonPath("$.rawMaterialId").value(10))
|
||||
.andExpect(jsonPath("$.proteinMax").value(25))
|
||||
|
||||
|
||||
// Act & Assert
|
||||
mockMvc.perform(get("/api/diet_raw_material/{dietMealId}", 1)
|
||||
.header("Authorization", "Bearer $authToken")
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk)
|
||||
.andExpect(jsonPath("$.[0].name").value("Tükörtojás"))
|
||||
|
||||
}
|
||||
|
||||
private fun toJson(obj: Any): String {
|
||||
return Gson().toJson(obj)
|
||||
}
|
||||
}
|
@ -33,6 +33,7 @@ class DietTest {
|
||||
private val diet = Diet(
|
||||
dietUserId = 1,
|
||||
dietText = "Test diet text",
|
||||
startDate = "2023-02-02"
|
||||
)
|
||||
|
||||
private var authToken: String? = ""
|
||||
@ -65,18 +66,26 @@ class DietTest {
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk)
|
||||
.andExpect(jsonPath("$.[0].dietText").value("Test diet text"))
|
||||
.andExpect(jsonPath("$.[0].startDate").value("2023-02-02"))
|
||||
|
||||
val meal = DietMeal(
|
||||
mealName = "monday|breakfast",
|
||||
meal = "Főtt tojás"
|
||||
meal = "Főtt tojás",
|
||||
quantity = 2.0,
|
||||
mealId = 0
|
||||
)
|
||||
val meal2 = DietMeal(
|
||||
mealName = "monday|lunch",
|
||||
meal = "Disznópörkölt"
|
||||
meal = "Disznópörkölt",
|
||||
quantity = 120.0,
|
||||
mealId = 0
|
||||
)
|
||||
val meal3 = DietMeal(
|
||||
mealName = "monday|lunch",
|
||||
meal = "Savanyúkáposzta"
|
||||
meal = "Savanyúkáposzta",
|
||||
quantity = 2.0,
|
||||
quantityUnit = "tányér",
|
||||
mealId = 3
|
||||
)
|
||||
|
||||
newDiet.meals.add(meal)
|
||||
@ -93,7 +102,12 @@ class DietTest {
|
||||
.andExpect(status().isOk)
|
||||
.andExpect(jsonPath("$.dietUserId").value(1))
|
||||
.andExpect(jsonPath("$.meals[0].meal").value("Főtt tojás"))
|
||||
.andExpect(jsonPath("$.meals[0].quantity").value(2.0))
|
||||
.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].mealId").value(3))
|
||||
.andExpect(jsonPath("$.meals[2].quantityUnit").value("tányér"))
|
||||
|
||||
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.aitrainer.api.test.diet
|
||||
|
||||
import com.aitrainer.api.model.diet.RawMaterial
|
||||
import com.aitrainer.api.model.diet.Meal
|
||||
import com.aitrainer.api.repository.diet.MealRepository
|
||||
import com.aitrainer.api.test.Tokenizer
|
||||
import com.google.gson.Gson
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
@ -22,52 +23,59 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.*
|
||||
@SpringBootTest
|
||||
@AutoConfigureMockMvc
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
class RawMaterialTest {
|
||||
class MealTest {
|
||||
|
||||
@Autowired
|
||||
private lateinit var mockMvc: MockMvc
|
||||
|
||||
private val rawMaterial = RawMaterial(
|
||||
@Autowired
|
||||
private lateinit var mealRepository: MealRepository
|
||||
|
||||
private val meal = Meal(
|
||||
|
||||
name = "Tükörtojás",
|
||||
kcalMin = 70,
|
||||
kcalMax = 110,
|
||||
proteinMin = 19,
|
||||
proteinMax = 25,
|
||||
fatMin = 12,
|
||||
fatMax = 15,
|
||||
chMin = 1,
|
||||
chMax = 3,
|
||||
sugar = 0,
|
||||
storeId = 4,
|
||||
quantity = 90.0,
|
||||
quantityUnit = "g",
|
||||
calMin = 70.0,
|
||||
calMax = 110.0,
|
||||
proteinMin = 19.0,
|
||||
proteinMax = 25.0,
|
||||
fatMin = 12.0,
|
||||
fatMax = 15.0,
|
||||
chMin = 1.0,
|
||||
chMax = 3.0,
|
||||
sugar = 0.0,
|
||||
|
||||
)
|
||||
private val rawMaterial2 = RawMaterial(
|
||||
private val meal2 = Meal(
|
||||
|
||||
name = "Tigris buci",
|
||||
kcalMin = 123,
|
||||
kcalMax = 140,
|
||||
proteinMin = 19,
|
||||
proteinMax = 25,
|
||||
fatMin = 30,
|
||||
fatMax = 34,
|
||||
chMin = 50,
|
||||
chMax = 60,
|
||||
sugar = 5,
|
||||
storeId = 2,
|
||||
quantity = 3.0,
|
||||
quantityUnit = "db",
|
||||
calMin = 123.0,
|
||||
calMax = 140.0,
|
||||
proteinMin = 19.0,
|
||||
proteinMax = 25.0,
|
||||
fatMin = 30.0,
|
||||
fatMax = 34.0,
|
||||
chMin = 50.0,
|
||||
chMax = 60.0,
|
||||
sugar = 5.0,
|
||||
)
|
||||
private val rawMaterial3 = RawMaterial(
|
||||
private val meal3 = Meal(
|
||||
|
||||
name = "Töltötttojás",
|
||||
quantity = 330.0,
|
||||
calMin = 75.0,
|
||||
calMax = 112.0,
|
||||
proteinMin = 12.0,
|
||||
proteinMax = 20.0,
|
||||
fatMin = 12.0,
|
||||
fatMax = 15.0,
|
||||
chMin = 1.0,
|
||||
chMax = 3.0,
|
||||
sugar = 0.0,
|
||||
|
||||
name = "Tükörtojás",
|
||||
kcalMin = 75,
|
||||
kcalMax = 112,
|
||||
proteinMin = 12,
|
||||
proteinMax = 20,
|
||||
fatMin = 12,
|
||||
fatMax = 15,
|
||||
chMin = 1,
|
||||
chMax = 3,
|
||||
sugar = 0,
|
||||
storeId = 2,
|
||||
)
|
||||
|
||||
private var authToken: String? = ""
|
||||
@ -79,58 +87,68 @@ class RawMaterialTest {
|
||||
|
||||
|
||||
@Test
|
||||
fun `insert rawMaterials successfully`() {
|
||||
fun `insert meals successfully`() {
|
||||
|
||||
mockMvc.perform(
|
||||
MockMvcRequestBuilders.post("/api/raw_material")
|
||||
MockMvcRequestBuilders.post("/api/meal")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", "Bearer $authToken")
|
||||
.content(toJson(rawMaterial))
|
||||
.content(toJson(meal))
|
||||
)
|
||||
.andExpect(status().isOk)
|
||||
.andExpect(jsonPath("$.sugar").value(0))
|
||||
.andExpect(jsonPath("$.storeId").value(4))
|
||||
.andExpect(jsonPath("$.proteinMax").value(25))
|
||||
.andExpect(jsonPath("$.sugar").value(0.0))
|
||||
.andExpect(jsonPath("$.quantity").value(90.0))
|
||||
.andExpect(jsonPath("$.proteinMax").value(25.0))
|
||||
|
||||
val mvcResult = mockMvc.perform(
|
||||
MockMvcRequestBuilders.post("/api/raw_material")
|
||||
MockMvcRequestBuilders.post("/api/meal")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", "Bearer $authToken")
|
||||
.content(toJson(rawMaterial2))
|
||||
.content(toJson(meal2))
|
||||
)
|
||||
.andExpect(status().isOk)
|
||||
.andReturn()
|
||||
|
||||
val gson= Gson()
|
||||
val newRawMaterialJson = mvcResult.response.contentAsString
|
||||
val newRawMaterial = gson.fromJson(newRawMaterialJson, RawMaterial::class.java)
|
||||
val newMeal = gson.fromJson(newRawMaterialJson, Meal::class.java)
|
||||
|
||||
mockMvc.perform(
|
||||
MockMvcRequestBuilders.post("/api/raw_material")
|
||||
MockMvcRequestBuilders.post("/api/meal")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", "Bearer $authToken")
|
||||
.content(toJson(rawMaterial3))
|
||||
.content(toJson(meal3))
|
||||
)
|
||||
.andExpect(status().isOk)
|
||||
|
||||
// Act & Assert
|
||||
mockMvc.perform(get("/api/raw_material" )
|
||||
mockMvc.perform(get("/api/meal" )
|
||||
.header("Authorization", "Bearer $authToken")
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk)
|
||||
.andExpect(jsonPath("$.[0].name").value("Tükörtojás"))
|
||||
.andExpect(jsonPath("$.[1].name").value("Tigris buci"))
|
||||
.andExpect(jsonPath("$.[2].storeId").value(2))
|
||||
.andExpect(jsonPath("$.[2].name").value("Tükörtojás"))
|
||||
.andExpect(jsonPath("$.[3].name").value("Tükörtojás"))
|
||||
.andExpect(jsonPath("$.[4].name").value("Tigris buci"))
|
||||
.andExpect(jsonPath("$.[5].quantity").value(330.0))
|
||||
.andExpect(jsonPath("$.[5].name").value("Töltötttojás"))
|
||||
|
||||
|
||||
// Act & Assert
|
||||
mockMvc.perform(get("/api/raw_material/${newRawMaterial.id}")
|
||||
mockMvc.perform(get("/api/meal/${newMeal.id}")
|
||||
.header("Authorization", "Bearer $authToken")
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk)
|
||||
.andExpect(jsonPath("$.name").value("Tigris buci"))
|
||||
|
||||
mockMvc.perform(get("/api/meal/by_name/Töltötttojás")
|
||||
.header("Authorization", "Bearer $authToken")
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk)
|
||||
.andExpect(jsonPath("$.name").value("Töltötttojás"))
|
||||
.andExpect(jsonPath("$.quantity").value(330.0))
|
||||
|
||||
mealRepository.delete(meal)
|
||||
mealRepository.delete(meal2)
|
||||
mealRepository.delete(meal3)
|
||||
}
|
||||
|
||||
private fun toJson(obj: Any): String {
|
@ -1,7 +1,7 @@
|
||||
package com.aitrainer.api.test.diet
|
||||
|
||||
import com.aitrainer.api.model.diet.Recipe
|
||||
import com.aitrainer.api.model.diet.RecipeRawMaterial
|
||||
import com.aitrainer.api.model.diet.RecipeMeal
|
||||
import com.aitrainer.api.test.Tokenizer
|
||||
import com.google.gson.Gson
|
||||
import org.junit.jupiter.api.AfterAll
|
||||
@ -38,7 +38,6 @@ class RecipeTest {
|
||||
fat = 56.0,
|
||||
ch = 23.0,
|
||||
dietUserId = 4,
|
||||
mealId = 0
|
||||
)
|
||||
private val recipe2 = Recipe(
|
||||
name = "Mákos tészta",
|
||||
@ -58,7 +57,6 @@ class RecipeTest {
|
||||
fat = 30.0,
|
||||
ch = 34.0,
|
||||
dietUserId = 1,
|
||||
mealId = 1
|
||||
)
|
||||
|
||||
private var authToken: String? = ""
|
||||
@ -111,23 +109,21 @@ class RecipeTest {
|
||||
.andExpect(status().isOk)
|
||||
|
||||
|
||||
val recipeRawMaterial1 = RecipeRawMaterial()
|
||||
with(recipeRawMaterial1) {
|
||||
val recipeMeal1 = RecipeMeal()
|
||||
with(recipeMeal1) {
|
||||
quantity = 30
|
||||
quantityUnit = "g"
|
||||
rawMaterialId = 2
|
||||
mealId = 2
|
||||
recipe = recipe1
|
||||
}
|
||||
newRecipe.rawMaterials.add(recipeRawMaterial1)
|
||||
newRecipe.meals.add(recipeMeal1)
|
||||
|
||||
val recipeRawMaterial2 = RecipeRawMaterial()
|
||||
with (recipeRawMaterial2) {
|
||||
val recipeMeal2 = RecipeMeal()
|
||||
with (recipeMeal2) {
|
||||
quantity = 50
|
||||
quantityUnit = "g"
|
||||
rawMaterialId = 3
|
||||
mealId = 3
|
||||
recipe = recipe1
|
||||
}
|
||||
newRecipe.rawMaterials.add(recipeRawMaterial2)
|
||||
newRecipe.meals.add(recipeMeal2)
|
||||
|
||||
mockMvc.perform(
|
||||
MockMvcRequestBuilders.post("/api/recipe/"+newRecipe.recipeId)
|
||||
@ -136,12 +132,12 @@ class RecipeTest {
|
||||
.content(toJson(newRecipe))
|
||||
).andExpect(status().isOk)
|
||||
.andExpect(jsonPath("$.cal").value(180))
|
||||
.andExpect(jsonPath("$.rawMaterials.[0].quantity").value(30))
|
||||
.andExpect(jsonPath("$.rawMaterials.[0].rawMaterialId").value(2))
|
||||
.andExpect(jsonPath("$.rawMaterials.[1].quantity").value(50))
|
||||
.andExpect(jsonPath("$.rawMaterials.[1].rawMaterialId").value(3))
|
||||
.andExpect(jsonPath("$.meals.[0].quantity").value(30))
|
||||
.andExpect(jsonPath("$.meals.[0].mealId").value(2))
|
||||
.andExpect(jsonPath("$.meals.[1].quantity").value(50))
|
||||
.andExpect(jsonPath("$.meals.[1].mealId").value(3))
|
||||
|
||||
|
||||
// Act & Assert
|
||||
mockMvc.perform(get("/api/recipe" )
|
||||
.header("Authorization", "Bearer $authToken")
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
@ -150,19 +146,19 @@ class RecipeTest {
|
||||
.andExpect(jsonPath("$.[1].name").value("Mákos tészta"))
|
||||
.andExpect(jsonPath("$.[2].dietUserId").value(1))
|
||||
.andExpect(jsonPath("$.[2].name").value("Borsóleves"))
|
||||
.andExpect(jsonPath("$.[0].rawMaterials.[0].quantity").value(30))
|
||||
.andExpect(jsonPath("$.[0].rawMaterials.[1].quantity").value(50))
|
||||
.andExpect(jsonPath("$.[0].rawMaterials.[1].rawMaterialId").value(3))
|
||||
.andExpect(jsonPath("$.[0].meals.[0].quantity").value(30))
|
||||
.andExpect(jsonPath("$.[0].meals.[1].quantity").value(50))
|
||||
.andExpect(jsonPath("$.[0].meals.[1].mealId").value(3))
|
||||
|
||||
|
||||
// Act & Assert
|
||||
// GET by User ID
|
||||
mockMvc.perform(get("/api/recipe/user/4")
|
||||
.header("Authorization", "Bearer $authToken")
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk)
|
||||
.andExpect(jsonPath("$.[0].name").value("Bableves"))
|
||||
.andExpect(jsonPath("$.[1].name").value("Mákos tészta"))
|
||||
.andExpect(jsonPath("$.[0].rawMaterials.[1].rawMaterialId").value(3))
|
||||
.andExpect(jsonPath("$.[0].meals.[1].mealId").value(3))
|
||||
|
||||
|
||||
mockMvc.perform(get("/api/recipe/name/leves")
|
||||
@ -171,14 +167,7 @@ class RecipeTest {
|
||||
.andExpect(status().isOk)
|
||||
.andExpect(jsonPath("$.[0].name").value("Bableves"))
|
||||
.andExpect(jsonPath("$.[1].name").value("Borsóleves"))
|
||||
.andExpect(jsonPath("$.[0].rawMaterials.[1].rawMaterialId").value(3))
|
||||
|
||||
// GET by User ID
|
||||
mockMvc.perform(get("/api/recipe/meal/1")
|
||||
.header("Authorization", "Bearer $authToken")
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk)
|
||||
.andExpect(jsonPath("$.[0].name").value("Borsóleves"))
|
||||
.andExpect(jsonPath("$.[0].meals.[1].mealId").value(3))
|
||||
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ class OpenAITest {
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
/* @Test
|
||||
fun `get a question successfully`() {
|
||||
val question = "Who the f. is Alice?"
|
||||
|
||||
@ -47,7 +47,7 @@ class OpenAITest {
|
||||
.andExpect(MockMvcResultMatchers.status().isOk)
|
||||
//.andExpect(MockMvcResultMatchers.content().string("Sorry I dont know"))
|
||||
|
||||
}
|
||||
}*/
|
||||
|
||||
@Test
|
||||
fun `get a question successfully with model name`() {
|
||||
|
Loading…
Reference in New Issue
Block a user