API 1.2+2 open ai fixes
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
+2
-3
@@ -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>?
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user