API 1.2+1 DietMeal + fixes
This commit is contained in:
@@ -9,6 +9,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder
|
||||
import org.springframework.context.annotation.Bean
|
||||
|
||||
|
||||
@SpringBootApplication
|
||||
class ApiApplication {
|
||||
@Bean(name = ["jasyptStringEncryptor"])
|
||||
@@ -43,3 +44,5 @@ class ApiApplication {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.aitrainer.api.service.EmailTemplateService
|
||||
import com.aitrainer.api.service.Firebase
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.http.HttpHeaders
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.security.access.annotation.Secured
|
||||
@@ -153,7 +154,7 @@ class CustomerController ( private val customerRepository: CustomerRepository) {
|
||||
}
|
||||
|
||||
@PostMapping("/club_registration")
|
||||
fun clubRegistration(@Valid @RequestBody json: String): ResponseEntity<*> {
|
||||
fun clubRegistration(@Valid @RequestBody json: String, @Value("\${firebase.key}") apiKey: String): ResponseEntity<*> {
|
||||
|
||||
val newUser: ClubUser = ClubUser().fromJson(json)
|
||||
|
||||
@@ -173,7 +174,7 @@ class CustomerController ( private val customerRepository: CustomerRepository) {
|
||||
val stringCharacters = ('0'..'z').toList().toTypedArray()
|
||||
val genPassword = (1..10).map { stringCharacters.random() }.joinToString("")
|
||||
|
||||
val firebase = Firebase()
|
||||
val firebase = Firebase(apiKey)
|
||||
val signupResponse = firebase.signUp(newUser.email, genPassword)
|
||||
?: return ResponseEntity.badRequest().body("Firebase exception ${firebase.error}")
|
||||
|
||||
|
||||
@@ -28,7 +28,8 @@ class CustomerPackageController( private val customerRepository: CustomerReposit
|
||||
private val dietUserConsumptionRepository: DietUserConsumptionRepository,
|
||||
private val dietUserRepository: DietUserRepository,
|
||||
private val dietUserPreferenceRepository: DietUserPreferenceRepository,
|
||||
private val dietUserSensitivityRepository: DietUserSensitivityRepository
|
||||
private val dietUserSensitivityRepository: DietUserSensitivityRepository,
|
||||
private val customerConversationRepository: CustomerConversationRepository
|
||||
|
||||
) {
|
||||
|
||||
@@ -53,16 +54,10 @@ class CustomerPackageController( private val customerRepository: CustomerReposit
|
||||
val customerJson: String = gson.toJson(customer)
|
||||
val dietUserJson: String = gson.toJson(dietUser)
|
||||
|
||||
val listCustomerProperty = customerPropertyRepository.findLastPropertiesByCustomerId(customerId)
|
||||
val listCustomerPropertyJson = gson.toJson(listCustomerProperty)
|
||||
|
||||
val listMembership = customerMembership.findAllByCustomer(customer)
|
||||
val listMembershipJson = gson.toJson(listMembership)
|
||||
|
||||
val listDiet = dietRepository.findByDietUserId(dietUserId)
|
||||
val listDietJson = gson.toJson(listDiet)
|
||||
|
||||
val listDietRawMaterial = dietRawMaterialRepository.findByDietId(dietUserId)
|
||||
val listDietRawMaterial = dietRawMaterialRepository.findByDietMealId(dietUserId)
|
||||
val listDietRawMaterialJson = gson.toJson(listDietRawMaterial)
|
||||
|
||||
val listDietUserConsumption = dietUserConsumptionRepository.findByDietUserId(dietUserId)
|
||||
@@ -74,17 +69,18 @@ class CustomerPackageController( private val customerRepository: CustomerReposit
|
||||
val listDietUserSensitivity = dietUserSensitivityRepository.findByDietUserId(dietUserId)
|
||||
val listDietUserSensitivityJson = gson.toJson(listDietUserSensitivity)
|
||||
|
||||
val packageJson: String =
|
||||
getClassRecord(Customer::class.simpleName, customerJson) +
|
||||
"|||" + getClassRecord(DietUser::class.simpleName, dietUserJson)
|
||||
"|||" + getClassRecord(CustomerProperty::class.simpleName, listCustomerPropertyJson)
|
||||
"|||" + getClassRecord(CustomerMembership::class.simpleName, listMembershipJson)
|
||||
"|||" + 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)
|
||||
val listCustomerConversation = customerConversationRepository.findByCustomerId(customerId)
|
||||
val listCustomerConversationJson = gson.toJson(listCustomerConversation)
|
||||
|
||||
val packageJson: String =
|
||||
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) +
|
||||
"|||" + getClassRecord(CustomerConversation::class.simpleName, listCustomerConversationJson)
|
||||
|
||||
return if (packageJson.isEmpty()) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(packageJson)
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package com.aitrainer.api.controller
|
||||
|
||||
import com.aitrainer.api.model.OpenAI
|
||||
import com.aitrainer.api.openai.OpenAIService
|
||||
import kotlinx.coroutines.*
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
import org.springframework.web.bind.annotation.*
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
@@ -13,10 +12,10 @@ class OpenAIController() {
|
||||
private val logger = LoggerFactory.getLogger(javaClass)
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
@GetMapping("/openai/completion")
|
||||
fun getOpenAIResponse(question: String) : String {
|
||||
@PostMapping("/openai/completion")
|
||||
fun getOpenAIResponse(@RequestBody question: String) : String {
|
||||
var result = ""
|
||||
val openAIService = OpenAIService()
|
||||
val openAIService = OpenAIService(null, null)
|
||||
val deferred = GlobalScope.async {
|
||||
openAIService.completion(question)
|
||||
}
|
||||
@@ -26,5 +25,35 @@ class OpenAIController() {
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
@PostMapping("/openai/completion_with_model")
|
||||
fun getOpenAIResponseWithModel(@RequestBody openai: OpenAI) : String {
|
||||
var result = ""
|
||||
val openAIService = OpenAIService(openai.modelName, openai.temperature)
|
||||
val deferred = GlobalScope.async {
|
||||
openAIService.completion(openai.question)
|
||||
}
|
||||
runBlocking {
|
||||
result = deferred.await()
|
||||
//println("Result: $result" )
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
@GetMapping("/openai/list_models")
|
||||
fun getOpenAIModels(): MutableList<String> {
|
||||
var result = mutableListOf<String>()
|
||||
val openAIService = OpenAIService(null, null)
|
||||
val deferred = GlobalScope.async {
|
||||
openAIService.getModels()
|
||||
}
|
||||
runBlocking {
|
||||
result = deferred.await()
|
||||
//println("Result: $result" )
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,23 @@ class DietController(private val dietRepository: DietRepository) {
|
||||
return ResponseEntity.ok().body(dietRepository.save(diet))
|
||||
}
|
||||
|
||||
@PostMapping("/diet/{id}")
|
||||
fun update(@PathVariable(value = "id") id: Long, @RequestBody diet: Diet): ResponseEntity<Diet> {
|
||||
val existingDiet = dietRepository.findByDietId(id) ?: return ResponseEntity.notFound().build()
|
||||
|
||||
val updatedDiet: Diet = existingDiet.copy(
|
||||
dietId = diet.dietId,
|
||||
dietUserId = diet.dietUserId,
|
||||
dietText = diet.dietText,
|
||||
startDate = diet.startDate
|
||||
)
|
||||
diet.meals.forEach {
|
||||
it.diet = diet
|
||||
updatedDiet.meals.add(it)
|
||||
}
|
||||
return ResponseEntity.ok().body(dietRepository.save(updatedDiet))
|
||||
}
|
||||
|
||||
@GetMapping("/diet/{dietUserId}")
|
||||
fun getByDietUserId(@PathVariable dietUserId: Long): ResponseEntity<List<Diet>> {
|
||||
val list = dietRepository.findByDietUserId(dietUserId)
|
||||
|
||||
@@ -7,11 +7,10 @@ import com.aitrainer.api.model.diet.DietCustomer
|
||||
import com.aitrainer.api.model.diet.DietUser
|
||||
import com.aitrainer.api.repository.CustomerRepository
|
||||
import com.aitrainer.api.repository.diet.DietUserRepository
|
||||
import com.aitrainer.api.service.Email
|
||||
import com.aitrainer.api.service.EmailTemplateService
|
||||
import com.aitrainer.api.service.Firebase
|
||||
import com.aitrainer.api.service.ServiceBeans
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.*
|
||||
import java.time.LocalDateTime
|
||||
@@ -25,11 +24,8 @@ class DietCustomerController(private val dietUserRepository: DietUserRepository,
|
||||
@Autowired
|
||||
var serviceBeans: ServiceBeans? = null
|
||||
|
||||
@Autowired
|
||||
private var emailTemplateService: EmailTemplateService? = null
|
||||
|
||||
@PostMapping("/diet_registration")
|
||||
fun insert(@RequestBody dietCustomerJson: String): ResponseEntity<*> {
|
||||
fun insert(@RequestBody dietCustomerJson: String, @Value("\${firebase.key}") apiKey: String): ResponseEntity<*> {
|
||||
val newDietCustomer: DietCustomer = DietCustomer().fromJson(dietCustomerJson)
|
||||
|
||||
if ( newDietCustomer.email.isEmpty()) {
|
||||
@@ -48,7 +44,7 @@ class DietCustomerController(private val dietUserRepository: DietUserRepository,
|
||||
var existingCustomer: Customer? = customerRepository.findByEmailAndActive(newDietCustomer.email, "Y")
|
||||
|
||||
if (existingCustomer == null ) {
|
||||
val firebase = Firebase()
|
||||
val firebase = Firebase(apiKey)
|
||||
val signupResponse = firebase.signUp(newDietCustomer.email, genPassword)
|
||||
?: return ResponseEntity.badRequest().body("Firebase exception ${firebase.error}")
|
||||
idToken = signupResponse.idToken
|
||||
@@ -125,7 +121,7 @@ class DietCustomerController(private val dietUserRepository: DietUserRepository,
|
||||
}
|
||||
|
||||
// create email link
|
||||
val activationLink = "https://diet4you.andio.hu/welcome/id=$idToken"
|
||||
/*val activationLink = "https://diet4you.andio.hu/welcome/id=$idToken"
|
||||
if ( emailTemplateService == null ) {
|
||||
emailTemplateService = EmailTemplateService()
|
||||
}
|
||||
@@ -134,7 +130,7 @@ class DietCustomerController(private val dietUserRepository: DietUserRepository,
|
||||
|
||||
// send email
|
||||
val email = Email()
|
||||
email.send(newDietCustomer.email, html, subject)
|
||||
email.send(newDietCustomer.email, html, subject)*/
|
||||
|
||||
return ResponseEntity.ok().body(existingCustomer)
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@ class DietRawMaterialController(private val dietRawMaterialRepository: DietRawMa
|
||||
return ResponseEntity.ok().body(dietRawMaterialRepository.save(dietRawMaterial))
|
||||
}
|
||||
|
||||
@GetMapping("/diet_raw_material/{dietId}")
|
||||
fun getByDietUserId(@PathVariable dietId: Long): ResponseEntity<List<DietRawMaterial>> {
|
||||
val list = dietRawMaterialRepository.findByDietId(dietId)
|
||||
@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)
|
||||
}
|
||||
|
||||
@@ -26,7 +26,8 @@ class RecipeController(private val recipeRepository: RecipeRepository) {
|
||||
ch = recipe.ch,
|
||||
fat = recipe.fat,
|
||||
protein = recipe.protein,
|
||||
dietUserId = recipe.dietUserId
|
||||
dietUserId = recipe.dietUserId,
|
||||
mealId = recipe.mealId
|
||||
)
|
||||
recipe.rawMaterials.forEach {
|
||||
it.recipe = recipe
|
||||
@@ -42,13 +43,20 @@ class RecipeController(private val recipeRepository: RecipeRepository) {
|
||||
ResponseEntity.ok().body(list)
|
||||
}
|
||||
|
||||
@GetMapping("/recipe/{dietUserId}")
|
||||
@GetMapping("/recipe/user/{dietUserId}")
|
||||
fun getByDietUserId(@PathVariable dietUserId: Long): ResponseEntity<List<Recipe>> {
|
||||
val list = recipeRepository.findByDietUserId(dietUserId)
|
||||
return if (list == null) ResponseEntity.notFound().build() else
|
||||
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,13 @@
|
||||
package com.aitrainer.api.model
|
||||
|
||||
import com.google.gson.annotations.Expose
|
||||
import jakarta.persistence.*
|
||||
import org.springframework.lang.NonNull
|
||||
|
||||
@Entity
|
||||
data class OpenAI (
|
||||
@Expose @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @get: NonNull var id: Long = 0,
|
||||
@Expose @get: NonNull var question: String,
|
||||
@Expose @get: NonNull var modelName: String? = null,
|
||||
@Expose @get: NonNull var temperature: Double? = null,
|
||||
)
|
||||
@@ -1,27 +1,19 @@
|
||||
package com.aitrainer.api.model.diet
|
||||
|
||||
import com.google.gson.annotations.Expose
|
||||
import jakarta.persistence.*
|
||||
import org.hibernate.annotations.Fetch
|
||||
import org.hibernate.annotations.FetchMode
|
||||
import org.jetbrains.annotations.NotNull
|
||||
|
||||
@Entity
|
||||
data class Diet (
|
||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Expose val dietId: Long = 0,
|
||||
|
||||
@Expose @get: NotNull val dietUserId: Long = 0,
|
||||
|
||||
@Expose @get: NotNull val dietText: String = "",
|
||||
|
||||
@Expose @get: NotNull val monday: String = "",
|
||||
|
||||
@Expose @get: NotNull val tuesday: String = "",
|
||||
|
||||
@Expose @get: NotNull val wednesday: String = "",
|
||||
|
||||
@Expose @get: NotNull val thursday: String = "",
|
||||
|
||||
@Expose @get: NotNull val friday: String = "",
|
||||
|
||||
@Expose @get: NotNull val saturday: String = "",
|
||||
|
||||
@Expose @get: NotNull val sunday: String = ""
|
||||
)
|
||||
@Expose @get: NotNull val startDate: String = "",
|
||||
) {
|
||||
@OneToMany(cascade = [(CascadeType.ALL)], fetch = FetchType.EAGER, mappedBy = "diet")
|
||||
@Fetch(value = FetchMode.SUBSELECT)
|
||||
@Expose val meals: MutableList<DietMeal> = mutableListOf()
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.aitrainer.api.model.diet
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||
import com.google.gson.annotations.Expose
|
||||
import jakarta.persistence.*
|
||||
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 mealName: String = "",
|
||||
@Expose @get: NotNull val meal: String = "",
|
||||
) {
|
||||
@ManyToOne(fetch = FetchType.EAGER, optional = false)
|
||||
@JoinColumn(name = "dietId", nullable = false)
|
||||
@JsonIgnore
|
||||
var diet: Diet? = null
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import org.jetbrains.annotations.NotNull
|
||||
data class DietRawMaterial (
|
||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Expose val id: Long = 0,
|
||||
|
||||
@Expose @get: NotNull val dietId: 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,
|
||||
|
||||
@@ -19,6 +19,7 @@ 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)
|
||||
|
||||
@@ -3,13 +3,15 @@ package com.aitrainer.api.openai
|
||||
import com.aallam.openai.client.OpenAI
|
||||
import com.aallam.openai.api.completion.CompletionRequest
|
||||
import com.aallam.openai.api.completion.TextCompletion
|
||||
import com.aallam.openai.api.logging.LogLevel
|
||||
import com.aallam.openai.api.model.Model
|
||||
import com.aallam.openai.api.model.ModelId
|
||||
import com.aallam.openai.client.OpenAIConfig
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.util.Properties
|
||||
|
||||
class OpenAIService {
|
||||
class OpenAIService(private val modelName: String?, private val temperature: Double?) {
|
||||
|
||||
|
||||
private var openAI: OpenAI? = null
|
||||
@@ -24,7 +26,11 @@ class OpenAIService {
|
||||
|
||||
private var modelId: ModelId? = null
|
||||
private suspend fun connect(modelName: String) {
|
||||
openAI = OpenAI(properties.getProperty("openai.key"))
|
||||
val config = OpenAIConfig(
|
||||
token = properties.getProperty("openai.key"),
|
||||
logLevel = LogLevel.All
|
||||
)
|
||||
openAI = OpenAI(config)
|
||||
modelId = ModelId(modelName)
|
||||
model = openAI!!.model(modelId!!)
|
||||
|
||||
@@ -32,22 +38,46 @@ class OpenAIService {
|
||||
|
||||
suspend fun completion(question: String): String {
|
||||
return withContext(Dispatchers.IO) {
|
||||
if (openAI == null) {
|
||||
connect("text-davinci-003")
|
||||
var realModelName = "text-davinci-003"
|
||||
if ( modelName != null) {
|
||||
realModelName = modelName
|
||||
}
|
||||
var realTemperature = 0.1
|
||||
if ( temperature != null ) {
|
||||
realTemperature = temperature
|
||||
}
|
||||
if (openAI == null) {
|
||||
connect(realModelName)
|
||||
}
|
||||
println("OpenAI Question: $question")
|
||||
val completionRequest = CompletionRequest(
|
||||
model = modelId!!,
|
||||
prompt = question,
|
||||
//echo = true,
|
||||
maxTokens = 128,
|
||||
temperature=0.1,
|
||||
maxTokens = 2048 - question.length,
|
||||
temperature=realTemperature,
|
||||
)
|
||||
val completion: TextCompletion = openAI!!.completion(completionRequest)
|
||||
val result = completion.choices[0].text
|
||||
|
||||
//println("Completion: $result")
|
||||
val result = completion.choices[0].text
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getModels(): MutableList<String> {
|
||||
return withContext(Dispatchers.IO) {
|
||||
if (openAI == null) {
|
||||
openAI = OpenAI(token = properties.getProperty("openai.key"))
|
||||
}
|
||||
|
||||
val list: MutableList<String> = mutableListOf()
|
||||
openAI!!.models().forEach {
|
||||
println(it)
|
||||
list.add(it.id.id)
|
||||
}
|
||||
|
||||
return@withContext list
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,5 +6,5 @@ import org.springframework.stereotype.Repository
|
||||
|
||||
@Repository
|
||||
interface DietRawMaterialRepository : JpaRepository<DietRawMaterial, Long> {
|
||||
fun findByDietId(dietId: Long): List<DietRawMaterial>
|
||||
fun findByDietMealId(dietMealId: Long): List<DietRawMaterial>
|
||||
}
|
||||
@@ -2,9 +2,13 @@ package com.aitrainer.api.repository.diet
|
||||
|
||||
import com.aitrainer.api.model.diet.Diet
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.data.jpa.repository.Query
|
||||
import org.springframework.stereotype.Repository
|
||||
|
||||
@Repository
|
||||
interface DietRepository : JpaRepository<Diet, Long> {
|
||||
fun findByDietUserId(dietUserId: Long): List<Diet>
|
||||
|
||||
@Query(" FROM Diet WHERE dietId = :dietId")
|
||||
fun findByDietId(dietId: Long): Diet?
|
||||
}
|
||||
@@ -9,6 +9,10 @@ interface RecipeRepository : JpaRepository<Recipe, Int> {
|
||||
fun findByName(name: String): List<Recipe>?
|
||||
|
||||
fun findByDietUserId(dietUserId: Long): List<Recipe>?
|
||||
|
||||
@Query(" FROM Recipe WHERE recipeId = :recipeId")
|
||||
fun findByRecipeId(recipeId: Long): Recipe?
|
||||
|
||||
@Query(" FROM Recipe WHERE mealId = :mealId")
|
||||
fun findByMealId(mealId: Long): List<Recipe>?
|
||||
}
|
||||
|
||||
@@ -2,18 +2,22 @@ package com.aitrainer.api.service
|
||||
|
||||
import com.aitrainer.api.model.firebase_response.SignupResponse
|
||||
import com.google.gson.Gson
|
||||
import org.json.JSONObject
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.stereotype.Service
|
||||
import java.net.URI
|
||||
import java.net.http.HttpClient
|
||||
import java.net.http.HttpRequest
|
||||
import java.net.http.HttpResponse
|
||||
import java.nio.charset.StandardCharsets
|
||||
import org.json.JSONObject
|
||||
import java.util.*
|
||||
|
||||
class Firebase {
|
||||
private val apiKey: String = "AIzaSyCUXBWV3_qzvV__ZWZA1siHftrrJpjDKh4"
|
||||
@Service
|
||||
class Firebase(@Value("\${firebase.key}") private val apiKey: String) {
|
||||
private val firebaseBaseUrl: String = "https://identitytoolkit.googleapis.com/v1/accounts"
|
||||
var statusCode: Int = 0
|
||||
var error: String = ""
|
||||
|
||||
fun signUp(email: String, password: String): SignupResponse? {
|
||||
|
||||
val json = JSONObject()
|
||||
@@ -42,6 +46,7 @@ class Firebase {
|
||||
}
|
||||
|
||||
private fun call(command: String, postData: String): String {
|
||||
val apiKey = this.apiKey
|
||||
val url = URI.create("$firebaseBaseUrl:$command?key=$apiKey")
|
||||
|
||||
// Create the HTTP request object
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
#spring.config.activate.on-profile=dev,test,prod,prodtest
|
||||
spring.config.use-legacy-processing = true
|
||||
## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
|
||||
#spring.datasource.url = jdbc:mysql://localhost:3306/aitrainer?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useSSL=false
|
||||
spring.datasource.url = jdbc:mysql://localhost:3306/diet4you?serverTimezone=CET&useSSL=false&characterEncoding=UTF-8&allowMultiQueries=true
|
||||
spring.datasource.username = aitrainer
|
||||
spring.datasource.password = ENC(WZplPYr8WmrLHshesY4T6oXplK3MlUVJ)
|
||||
|
||||
|
||||
## Hibernate Properties
|
||||
|
||||
|
||||
# The SQL dialect makes Hibernate generate better SQL for the chosen database
|
||||
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLDialect
|
||||
|
||||
logging.config=classpath:logback-spring.xml
|
||||
logging.file=logs
|
||||
|
||||
# if the database structure has been changed, increment this version number
|
||||
application.version=1.2.0
|
||||
|
||||
jwt.secret=aitrainer
|
||||
|
||||
openai.key=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
|
||||
firebase.key=AIzaSyBLn7Bz73Z1hB-OhqphBDsskOyGmpI7J8E
|
||||
spring.mail.properties.mail.mime.charset=UTF-8
|
||||
@@ -0,0 +1,22 @@
|
||||
spring.config.activate.on-profile=dietprod
|
||||
spring.config.use-legacy-processing = true
|
||||
|
||||
## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
|
||||
spring.datasource.url = jdbc:mysql://mariadb-shared.db.svc.cluster.local:3306/diet4you?serverTimezone=CET&useSSL=true&characterEncoding=UTF-8&allowPublicKeyRetrieval=true&allowMultiQueries=true
|
||||
spring.datasource.username = aitrainer
|
||||
spring.datasource.password = ENC(WZplPYr8WmrLHshesY4T6oXplK3MlUVJ)
|
||||
|
||||
# The SQL dialect makes Hibernate generate better SQL for the chosen database
|
||||
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLDialect
|
||||
|
||||
|
||||
logging.config=classpath:logback-spring.xml
|
||||
logging.file=logs
|
||||
|
||||
# if the database structue has been changed, increment this version number
|
||||
application.version=1.2.0
|
||||
|
||||
jwt.secret=aitrainer
|
||||
|
||||
firebase.key=AIzaSyCUXBWV3_qzvV__ZWZA1siHftrrJpjDKh4
|
||||
openai.key=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
|
||||
@@ -16,4 +16,7 @@ logging.file=logs
|
||||
# if the database structue has been changed, increment this version number
|
||||
application.version=1.2.0
|
||||
|
||||
jwt.secret=aitrainer
|
||||
jwt.secret=aitrainer
|
||||
|
||||
firebase.key=AIzaSyCUXBWV3_qzvV__ZWZA1siHftrrJpjDKh4
|
||||
openai.key=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
|
||||
@@ -23,3 +23,4 @@ jwt.secret=aitrainer
|
||||
|
||||
openai.key=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
|
||||
spring.mail.properties.mail.mime.charset=UTF-8
|
||||
firebase.key=AIzaSyCUXBWV3_qzvV__ZWZA1siHftrrJpjDKh4
|
||||
Reference in New Issue
Block a user