API 1.2.4 delete meal

This commit is contained in:
Tibor Bossanyi
2023-04-16 16:41:04 +02:00
parent 50028cbcec
commit 1e9a6018bd
11 changed files with 80 additions and 13 deletions
@@ -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<String> {
val gson = GsonBuilder()
.excludeFieldsWithoutExposeAnnotation()
@@ -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<List<Meal>> {
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<Meal> {
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))
}
}
@@ -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,
@@ -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
@@ -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=*
spring.mvc.cors.allowed-origins=*
@@ -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=*
@@ -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
+2 -1
View File
@@ -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=*
spring.mvc.cors.allowed-origins=*
spring.http.encoding.charset=UTF-8