API 1.2 Diet tables, Open AI API
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
package com.aitrainer.api.controller
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.stereotype.Component
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
|
||||
@RestController
|
||||
@RequestMapping
|
||||
@Component
|
||||
class ApplicationProperties {
|
||||
|
||||
@Value("\${application.version}")
|
||||
@@ -21,7 +23,8 @@ class ApplicationProperties {
|
||||
@Value("\${spring.datasource.password}")
|
||||
private lateinit var datasourcePassword: String
|
||||
|
||||
|
||||
@Value("\${openai.key}")
|
||||
private lateinit var apiKey: String
|
||||
|
||||
@GetMapping("/version")
|
||||
fun getVersion(): String {
|
||||
@@ -42,4 +45,11 @@ class ApplicationProperties {
|
||||
fun getDatasourcePassword(): String {
|
||||
return this.datasourcePassword
|
||||
}
|
||||
|
||||
@GetMapping("/openAIKey")
|
||||
fun getOpenAIKey(): String {
|
||||
return this.apiKey
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -12,13 +12,9 @@ import org.springframework.http.HttpHeaders
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.security.access.annotation.Secured
|
||||
import org.springframework.web.bind.annotation.*
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.nio.charset.StandardCharsets.UTF_8
|
||||
import java.time.LocalDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.util.*
|
||||
import java.util.zip.GZIPInputStream
|
||||
import java.util.zip.GZIPOutputStream
|
||||
import javax.validation.Valid
|
||||
|
||||
|
||||
@@ -159,15 +155,6 @@ class CustomerController ( private val customerRepository: CustomerRepository) {
|
||||
@PostMapping("/club_registration")
|
||||
fun clubRegistration(@Valid @RequestBody json: String): ResponseEntity<*> {
|
||||
|
||||
fun gzip(content: String): String {
|
||||
val bos = ByteArrayOutputStream()
|
||||
GZIPOutputStream(bos).bufferedWriter(UTF_8).use { it.write(content) }
|
||||
return bos.toByteArray().toString()
|
||||
}
|
||||
|
||||
fun unzip(content: ByteArray): String =
|
||||
GZIPInputStream(content.inputStream()).bufferedReader(UTF_8).use { it.readText() }
|
||||
|
||||
val newUser: ClubUser = ClubUser().fromJson(json)
|
||||
|
||||
if ( newUser.email.isEmpty()) {
|
||||
@@ -252,7 +239,7 @@ class CustomerController ( private val customerRepository: CustomerRepository) {
|
||||
if ( emailTemplateService == null ) {
|
||||
emailTemplateService = EmailTemplateService()
|
||||
}
|
||||
val html = emailTemplateService!!.getEmailBody(newUser.firstname, activationLink)
|
||||
val html = emailTemplateService!!.getEmailBody(newUser.firstname, activationLink, "registration_email")
|
||||
val subject = emailTemplateService!!.getSubject()
|
||||
|
||||
// send email
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.aitrainer.api.controller
|
||||
|
||||
import com.aitrainer.api.model.CustomerConversation
|
||||
import com.aitrainer.api.repository.CustomerConversationRepository
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.*
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
class CustomerConversationController (private val customerConversationRepository: CustomerConversationRepository
|
||||
) {
|
||||
|
||||
@PostMapping("/customer_conversation")
|
||||
fun insert(@RequestBody customerConversation: CustomerConversation): ResponseEntity<CustomerConversation> {
|
||||
return ResponseEntity.ok().body(customerConversationRepository.save(customerConversation))
|
||||
}
|
||||
|
||||
@GetMapping("/customer_conversation/{customerId}")
|
||||
fun getByCustomerId(@PathVariable customerId: Long): ResponseEntity<List<CustomerConversation>> {
|
||||
val list = customerConversationRepository.findByCustomerId(customerId)
|
||||
return if (list.isEmpty()) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(list)
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,9 @@ package com.aitrainer.api.controller
|
||||
|
||||
import com.aitrainer.api.model.*
|
||||
import com.aitrainer.api.model.CustomerMembership
|
||||
import com.aitrainer.api.model.diet.*
|
||||
import com.aitrainer.api.repository.*
|
||||
import com.aitrainer.api.repository.diet.*
|
||||
import com.google.gson.GsonBuilder
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
@@ -21,8 +23,73 @@ class CustomerPackageController( private val customerRepository: CustomerReposit
|
||||
private val customerActivityRepository: CustomerActivityRepository,
|
||||
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,
|
||||
private val dietUserSensitivityRepository: DietUserSensitivityRepository
|
||||
|
||||
) {
|
||||
|
||||
@GetMapping("/diet_customer_package/{id}")
|
||||
fun getDietCustomerPackageData(@PathVariable(value = "id") dietUserId: Long): ResponseEntity<String> {
|
||||
if (dietUserId <= 0) {
|
||||
return ResponseEntity.notFound().build()
|
||||
}
|
||||
|
||||
val gson = GsonBuilder()
|
||||
.excludeFieldsWithoutExposeAnnotation()
|
||||
.setPrettyPrinting()
|
||||
.create()
|
||||
|
||||
val dietUser: DietUser = dietUserRepository.findByDietUserId(dietUserId)
|
||||
?: return ResponseEntity.notFound().build()
|
||||
|
||||
val customerId = dietUser.customerId
|
||||
val customer: Customer = customerRepository.findByCustomerIdAndActive(customerId, "Y")
|
||||
?: return ResponseEntity.notFound().build()
|
||||
|
||||
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 listDietRawMaterialJson = gson.toJson(listDietRawMaterial)
|
||||
|
||||
val listDietUserConsumption = dietUserConsumptionRepository.findByDietUserId(dietUserId)
|
||||
val listDietUserConsumptionJson = gson.toJson(listDietUserConsumption)
|
||||
|
||||
val listDietUserPreference = dietUserPreferenceRepository.findByDietUserId(dietUserId)
|
||||
val listDietUserPreferenceJson = gson.toJson(listDietUserPreference)
|
||||
|
||||
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)
|
||||
|
||||
|
||||
return if (packageJson.isEmpty()) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(packageJson)
|
||||
}
|
||||
|
||||
@GetMapping("/club_customer_package/{id}")
|
||||
fun getCustomerClubPackageData(@PathVariable(value = "id") customerId: Long): ResponseEntity<String> {
|
||||
if (customerId <= 0) {
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package com.aitrainer.api.controller
|
||||
|
||||
import com.aitrainer.api.model.Evaluation
|
||||
import com.aitrainer.api.model.ExerciseTree
|
||||
import com.aitrainer.api.repository.EvaluationRepository
|
||||
import com.aitrainer.api.repository.ExerciseTreeParentsRepository
|
||||
import com.aitrainer.api.repository.ExerciseTreeRepository
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.aitrainer.api.controller
|
||||
|
||||
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
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
class OpenAIController() {
|
||||
private val logger = LoggerFactory.getLogger(javaClass)
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
@GetMapping("/openai/completion")
|
||||
fun getOpenAIResponse(question: String) : String {
|
||||
var result = ""
|
||||
val openAIService = OpenAIService()
|
||||
val deferred = GlobalScope.async {
|
||||
openAIService.completion(question)
|
||||
}
|
||||
runBlocking {
|
||||
result = deferred.await()
|
||||
//println("Result: $result" )
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
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.Recipe
|
||||
import com.aitrainer.api.model.diet.Store
|
||||
import com.aitrainer.api.repository.*
|
||||
import com.aitrainer.api.repository.diet.*
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
@@ -29,9 +34,50 @@ class PackageController(private val exerciseAbilityRepository: ExerciseAbilityRe
|
||||
private val trainingPlanDayRepository: TrainingPlanDayRepository,
|
||||
private val appTextRepository: AppTextRepository,
|
||||
private val trainingProgramRepository: TrainingProgramRepository,
|
||||
private val membershipRepository: MembershipRepository
|
||||
private val membershipRepository: MembershipRepository,
|
||||
private val storeRepository: StoreRepository,
|
||||
private val recipeRepository: RecipeRepository,
|
||||
private val rawMaterialRepository: RawMaterialRepository,
|
||||
private val dietSensitivityRepository: DietSensitivityRepository
|
||||
) {
|
||||
|
||||
@GetMapping("/diet_package")
|
||||
fun getDietPackageData(): ResponseEntity<String> {
|
||||
val gson = GsonBuilder()
|
||||
.excludeFieldsWithoutExposeAnnotation()
|
||||
.setPrettyPrinting()
|
||||
.create()
|
||||
|
||||
val listProperty:List<Property> = propertyRepository.getProperties()
|
||||
val listPropertyJson: String = gson.toJson(listProperty)
|
||||
|
||||
val listMembership = membershipRepository.findAll()
|
||||
val listMembershipJson = gson.toJson(listMembership)
|
||||
|
||||
val listStore = storeRepository.findAll()
|
||||
val listStoreJson = gson.toJson(listStore)
|
||||
|
||||
val listRecipe = recipeRepository.findAll()
|
||||
val listRecipeJson = gson.toJson(listRecipe)
|
||||
|
||||
val listRawMaterial = rawMaterialRepository.findAll()
|
||||
val listRawMaterialJson = gson.toJson(listRawMaterial)
|
||||
|
||||
val listDietSensitivity = dietSensitivityRepository.findAll()
|
||||
val listDietSensitivityJson = gson.toJson(listDietSensitivity)
|
||||
|
||||
val packageJson: String =
|
||||
getClassRecord(Property::class.simpleName, listPropertyJson) +
|
||||
"|||" + getClassRecord(Membership::class.simpleName, listMembershipJson) +
|
||||
"|||" + getClassRecord(Store::class.simpleName, listStoreJson) +
|
||||
"|||" + getClassRecord(Recipe::class.simpleName, listRecipeJson) +
|
||||
"|||" + getClassRecord(RawMaterial::class.simpleName, listRawMaterialJson) +
|
||||
"|||" + getClassRecord(DietSensitivity::class.simpleName, listDietSensitivityJson)
|
||||
|
||||
return if (packageJson.isEmpty()) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(packageJson)
|
||||
}
|
||||
|
||||
@GetMapping("/club_package")
|
||||
fun getClubPackageData(): ResponseEntity<String> {
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.aitrainer.api.controller.diet
|
||||
|
||||
import com.aitrainer.api.model.diet.Diet
|
||||
import com.aitrainer.api.repository.diet.DietRepository
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.*
|
||||
import java.util.*
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
class DietController(private val dietRepository: DietRepository) {
|
||||
|
||||
@PostMapping("/diet")
|
||||
fun insert(@RequestBody diet: Diet): ResponseEntity<*> {
|
||||
return ResponseEntity.ok().body(dietRepository.save(diet))
|
||||
}
|
||||
|
||||
@GetMapping("/diet/{dietUserId}")
|
||||
fun getByDietUserId(@PathVariable dietUserId: Long): ResponseEntity<List<Diet>> {
|
||||
val list = dietRepository.findByDietUserId(dietUserId)
|
||||
return if (list.isEmpty()) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(list)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package com.aitrainer.api.controller.diet
|
||||
|
||||
import com.aitrainer.api.model.Customer
|
||||
import com.aitrainer.api.model.CustomerMembership
|
||||
import com.aitrainer.api.model.CustomerPropertyProperty
|
||||
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.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.*
|
||||
import java.time.LocalDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.util.*
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
class DietCustomerController(private val dietUserRepository: DietUserRepository, private val customerRepository: CustomerRepository) {
|
||||
|
||||
@Autowired
|
||||
var serviceBeans: ServiceBeans? = null
|
||||
|
||||
@Autowired
|
||||
private var emailTemplateService: EmailTemplateService? = null
|
||||
|
||||
@PostMapping("/diet_registration")
|
||||
fun insert(@RequestBody dietCustomerJson: String): ResponseEntity<*> {
|
||||
val newDietCustomer: DietCustomer = DietCustomer().fromJson(dietCustomerJson)
|
||||
|
||||
if ( newDietCustomer.email.isEmpty()) {
|
||||
return ResponseEntity.badRequest().body("No Email")
|
||||
}
|
||||
|
||||
val current = LocalDateTime.now()
|
||||
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")
|
||||
val nowFormatted = current.format(formatter)
|
||||
|
||||
val stringCharacters = ('0'..'z').toList().toTypedArray()
|
||||
val genPassword = (1..10).map { stringCharacters.random() }.joinToString("")
|
||||
|
||||
val idToken: String?
|
||||
|
||||
var existingCustomer: Customer? = customerRepository.findByEmailAndActive(newDietCustomer.email, "Y")
|
||||
|
||||
if (existingCustomer == null ) {
|
||||
val firebase = Firebase()
|
||||
val signupResponse = firebase.signUp(newDietCustomer.email, genPassword)
|
||||
?: return ResponseEntity.badRequest().body("Firebase exception ${firebase.error}")
|
||||
idToken = signupResponse.idToken
|
||||
|
||||
val savingCustomer = Customer()
|
||||
|
||||
if ( serviceBeans == null ) {
|
||||
serviceBeans = ServiceBeans()
|
||||
}
|
||||
with (savingCustomer) {
|
||||
email = newDietCustomer.email
|
||||
password = serviceBeans!!.passwordEncoder().encode(genPassword)
|
||||
firebaseRegToken = signupResponse.idToken
|
||||
firebaseUid = signupResponse.localId
|
||||
dateAdd = nowFormatted
|
||||
firstname = newDietCustomer.firstname
|
||||
name = ""
|
||||
goal = newDietCustomer.goal
|
||||
fitnessLevel = newDietCustomer.fitnessLevel
|
||||
birthYear = newDietCustomer.birthYear
|
||||
sex = newDietCustomer.sex
|
||||
}
|
||||
|
||||
val newCustomer = customerRepository.save(savingCustomer)
|
||||
|
||||
if ( newDietCustomer.weight != 0.0 ) {
|
||||
val property = CustomerPropertyProperty()
|
||||
with (property) {
|
||||
propertyId = 1
|
||||
propertyValue = newDietCustomer.weight
|
||||
dateAdd= nowFormatted
|
||||
goal = false
|
||||
customer = newCustomer
|
||||
}
|
||||
newCustomer.properties.add(property)
|
||||
}
|
||||
if ( newDietCustomer.height != 0.0 ) {
|
||||
val property = CustomerPropertyProperty()
|
||||
with (property) {
|
||||
propertyId = 2
|
||||
propertyValue = newDietCustomer.height
|
||||
dateAdd = nowFormatted
|
||||
goal = false
|
||||
customer = newCustomer
|
||||
}
|
||||
newCustomer.properties.add(property)
|
||||
}
|
||||
|
||||
val newMembershipId = newDietCustomer.membershipId
|
||||
if ( newMembershipId != 0L) {
|
||||
val membership = CustomerMembership()
|
||||
with(membership) {
|
||||
customer = newCustomer
|
||||
membershipId = newMembershipId
|
||||
startDate = nowFormatted
|
||||
}
|
||||
newCustomer.memberships.add(membership)
|
||||
}
|
||||
|
||||
customerRepository.save(newCustomer)
|
||||
existingCustomer = newCustomer
|
||||
} else {
|
||||
val existingDietUser = dietUserRepository.findByCustomerId(existingCustomer.customerId)
|
||||
if ( existingDietUser != null ) {
|
||||
return ResponseEntity.badRequest().body("DietCustomer exists")
|
||||
} else {
|
||||
val newDietUser = DietUser(
|
||||
customerId = existingCustomer.customerId
|
||||
)
|
||||
dietUserRepository.save(newDietUser)
|
||||
|
||||
}
|
||||
idToken = existingCustomer.firebaseRegToken!!
|
||||
}
|
||||
|
||||
// create email link
|
||||
val activationLink = "https://diet4you.andio.hu/welcome/id=$idToken"
|
||||
if ( emailTemplateService == null ) {
|
||||
emailTemplateService = EmailTemplateService()
|
||||
}
|
||||
val html = emailTemplateService!!.getEmailBody(newDietCustomer.firstname, activationLink, "diet_registration_email")
|
||||
val subject = emailTemplateService!!.getSubjectDiet()
|
||||
|
||||
// send email
|
||||
val email = Email()
|
||||
email.send(newDietCustomer.email, html, subject)
|
||||
|
||||
return ResponseEntity.ok().body(existingCustomer)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
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/{dietId}")
|
||||
fun getByDietUserId(@PathVariable dietId: Long): ResponseEntity<List<DietRawMaterial>> {
|
||||
val list = dietRawMaterialRepository.findByDietId(dietId)
|
||||
return if (list.isEmpty()) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(list)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.aitrainer.api.controller.diet
|
||||
|
||||
import com.aitrainer.api.model.diet.DietSensitivity
|
||||
import com.aitrainer.api.repository.diet.DietSensitivityRepository
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.*
|
||||
|
||||
@RestController
|
||||
@RequestMapping("api")
|
||||
class DietSensitivityController(private val dietSensitivityRepository: DietSensitivityRepository) {
|
||||
|
||||
@PostMapping ("/diet_sensitivity")
|
||||
fun insert(@RequestBody dietSensitivity: DietSensitivity): ResponseEntity<DietSensitivity> {
|
||||
val newDietSensitivity = dietSensitivityRepository.save(dietSensitivity)
|
||||
return ResponseEntity.ok().body(newDietSensitivity)
|
||||
}
|
||||
|
||||
@GetMapping("/diet_sensitivity")
|
||||
fun getAll(): ResponseEntity<List<DietSensitivity>> {
|
||||
val list = dietSensitivityRepository.findAll()
|
||||
return if (list.isEmpty()) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(list)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.aitrainer.api.controller.diet
|
||||
|
||||
import com.aitrainer.api.model.diet.DietUserConsumption
|
||||
import com.aitrainer.api.repository.diet.DietUserConsumptionRepository
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.*
|
||||
import java.util.*
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
class DietUserConsumptionController(private val dietUserConsumptionRepository: DietUserConsumptionRepository) {
|
||||
|
||||
@PostMapping("/diet_user_consumption")
|
||||
fun insert(@RequestBody dietUserConsumption: DietUserConsumption): ResponseEntity<*> {
|
||||
return ResponseEntity.ok().body(dietUserConsumptionRepository.save(dietUserConsumption))
|
||||
}
|
||||
|
||||
@PostMapping("/diet_user_consumption/{id}")
|
||||
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,
|
||||
dateConsumption = dietUserConsumption.dateConsumption,
|
||||
name = dietUserConsumption.name,
|
||||
quantity = dietUserConsumption.quantity,
|
||||
quantityUnit = dietUserConsumption.quantityUnit,
|
||||
cal = dietUserConsumption.cal,
|
||||
protein = dietUserConsumption.protein,
|
||||
fat = dietUserConsumption.fat,
|
||||
ch = dietUserConsumption.ch,
|
||||
sugar = dietUserConsumption.sugar
|
||||
)
|
||||
ResponseEntity.ok().body(dietUserConsumptionRepository.save(updatedConsumption))
|
||||
}.orElse(ResponseEntity.notFound().build())
|
||||
}
|
||||
|
||||
@GetMapping("/diet_user_consumption/{dietUserId}")
|
||||
fun getByDietUserId(@PathVariable dietUserId: Long): ResponseEntity<List<DietUserConsumption>> {
|
||||
val list = dietUserConsumptionRepository.findByDietUserId(dietUserId)
|
||||
return if (list.isEmpty()) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(list)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.aitrainer.api.controller.diet
|
||||
|
||||
import com.aitrainer.api.model.diet.DietUser
|
||||
import com.aitrainer.api.repository.diet.DietUserRepository
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.*
|
||||
|
||||
@RestController
|
||||
@RequestMapping("api")
|
||||
class DietUserController(private val dietUserRepository: DietUserRepository) {
|
||||
|
||||
@PostMapping ("/diet_user")
|
||||
fun insert(@RequestBody dietUser: DietUser): ResponseEntity<DietUser> {
|
||||
val newDietUser = dietUserRepository.save(dietUser)
|
||||
return ResponseEntity.ok().body(newDietUser)
|
||||
}
|
||||
|
||||
@GetMapping("/diet_user/{customerId}")
|
||||
fun getByCustomerId(@PathVariable customerId: Long): ResponseEntity<DietUser> {
|
||||
val dietUser = dietUserRepository.findByCustomerId(customerId)
|
||||
return if (dietUser == null) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(dietUser)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.aitrainer.api.controller.diet
|
||||
|
||||
import com.aitrainer.api.model.diet.DietUserPreference
|
||||
import com.aitrainer.api.repository.diet.DietUserPreferenceRepository
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.*
|
||||
import java.util.*
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
class DietUserPreferenceController(private val dietUserPreferenceRepository: DietUserPreferenceRepository) {
|
||||
|
||||
@PostMapping("/diet_user_preference")
|
||||
fun insert(@RequestBody dietUserPreference: DietUserPreference): ResponseEntity<*> {
|
||||
return ResponseEntity.ok().body(dietUserPreferenceRepository.save(dietUserPreference))
|
||||
}
|
||||
|
||||
@GetMapping("/diet_user_preference/{dietUserId}")
|
||||
fun getByDietUserId(@PathVariable dietUserId: Long): ResponseEntity<List<DietUserPreference>> {
|
||||
val list = dietUserPreferenceRepository.findByDietUserId(dietUserId)
|
||||
return if (list.isEmpty()) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(list)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.aitrainer.api.controller.diet
|
||||
|
||||
import com.aitrainer.api.model.diet.DietUserSensitivity
|
||||
import com.aitrainer.api.repository.diet.DietUserSensitivityRepository
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.*
|
||||
import java.util.*
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
class DietUserSensitivityController(private val dietUserSensitivityRepository: DietUserSensitivityRepository) {
|
||||
|
||||
@PostMapping("/diet_user_sensitivity")
|
||||
fun insert(@RequestBody dietUserSensitivity: DietUserSensitivity): ResponseEntity<*> {
|
||||
return ResponseEntity.ok().body(dietUserSensitivityRepository.save(dietUserSensitivity))
|
||||
}
|
||||
|
||||
@GetMapping("/diet_user_sensitivity/{dietUserId}")
|
||||
fun getByDietUserId(@PathVariable dietUserId: Long): ResponseEntity<List<DietUserSensitivity>> {
|
||||
val list = dietUserSensitivityRepository.findByDietUserId(dietUserId)
|
||||
return if (list.isEmpty()) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(list)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.aitrainer.api.controller.diet
|
||||
|
||||
import com.aitrainer.api.model.diet.Recipe
|
||||
import com.aitrainer.api.repository.diet.RecipeRepository
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.*
|
||||
|
||||
@RestController
|
||||
@RequestMapping("api")
|
||||
class RecipeController(private val recipeRepository: RecipeRepository) {
|
||||
|
||||
@PostMapping ("/recipe")
|
||||
fun insert(@RequestBody recipe: Recipe): ResponseEntity<Recipe> {
|
||||
val newRecipe = recipeRepository.save(recipe)
|
||||
return ResponseEntity.ok().body(newRecipe)
|
||||
}
|
||||
|
||||
@PostMapping("/recipe/{id}")
|
||||
fun update(@PathVariable(value = "id") id: Long, @RequestBody recipe: Recipe): ResponseEntity<Recipe> {
|
||||
val existingRecipe = recipeRepository.findByRecipeId(id) ?: return ResponseEntity.notFound().build()
|
||||
|
||||
val updatedRecipe: Recipe = existingRecipe.copy(
|
||||
name = recipe.name,
|
||||
description = recipe.description,
|
||||
cal = recipe.cal,
|
||||
ch = recipe.ch,
|
||||
fat = recipe.fat,
|
||||
protein = recipe.protein,
|
||||
dietUserId = recipe.dietUserId
|
||||
)
|
||||
recipe.rawMaterials.forEach {
|
||||
it.recipe = recipe
|
||||
updatedRecipe.rawMaterials.add(it)
|
||||
}
|
||||
return ResponseEntity.ok().body(recipeRepository.save(updatedRecipe))
|
||||
}
|
||||
|
||||
@GetMapping("/recipe")
|
||||
fun getAll(): ResponseEntity<List<Recipe>> {
|
||||
val list = recipeRepository.findAll()
|
||||
return if (list.isEmpty()) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(list)
|
||||
}
|
||||
|
||||
@GetMapping("/recipe/{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/name/{name}")
|
||||
fun getByName(@PathVariable name: String): ResponseEntity<List<Recipe>> {
|
||||
val list = recipeRepository.findByName(name)
|
||||
return if (list == null) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(list)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.aitrainer.api.controller.diet
|
||||
|
||||
import com.aitrainer.api.model.diet.Store
|
||||
import com.aitrainer.api.repository.diet.StoreRepository
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.*
|
||||
|
||||
@RestController
|
||||
@RequestMapping("api")
|
||||
class StoreController(private val storeRepository: StoreRepository) {
|
||||
|
||||
@PostMapping ("/store")
|
||||
fun insert(@RequestBody store: Store): ResponseEntity<Store> {
|
||||
val newStore = storeRepository.save(store)
|
||||
return ResponseEntity.ok().body(newStore)
|
||||
}
|
||||
|
||||
@GetMapping("/store")
|
||||
fun getAll(): ResponseEntity<List<Store>> {
|
||||
val list = storeRepository.findAll()
|
||||
return if (list.isEmpty()) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(list)
|
||||
}
|
||||
|
||||
@GetMapping("/store/{name}/{country}")
|
||||
fun getByNameAndCountry(@PathVariable name: String, @PathVariable country: String ): ResponseEntity<Store> {
|
||||
val store = storeRepository.findByNameAndCountry(name, country)
|
||||
return if (store == null) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(store)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.aitrainer.api.model
|
||||
|
||||
import com.google.gson.annotations.Expose
|
||||
import jakarta.persistence.Entity
|
||||
import jakarta.persistence.GeneratedValue
|
||||
import jakarta.persistence.GenerationType
|
||||
import jakarta.persistence.Id
|
||||
import javax.validation.constraints.NotNull
|
||||
|
||||
@Entity
|
||||
data class CustomerConversation(
|
||||
@Expose @Id @GeneratedValue(strategy = GenerationType.IDENTITY) var id: Long = 0,
|
||||
@Expose @get: NotNull val customerId: Long,
|
||||
@Expose @get: NotNull val conversationDate: String = "",
|
||||
@Expose @get: NotNull val question: String = "",
|
||||
@Expose @get: NotNull val answer: String = ""
|
||||
)
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.aitrainer.api.model.diet
|
||||
import com.google.gson.annotations.Expose
|
||||
import jakarta.persistence.*
|
||||
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 = ""
|
||||
)
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.aitrainer.api.model.diet
|
||||
|
||||
import com.google.gson.annotations.Expose
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
@Serializable
|
||||
data class DietCustomer(
|
||||
@Expose var firstname: String = "",
|
||||
@Expose var email: String = "",
|
||||
@Expose var sex: String = "m",
|
||||
@Expose var goal: String = "",
|
||||
@Expose var fitnessLevel: String = "beginner",
|
||||
@Expose var birthYear: Int = 0,
|
||||
@Expose var weight: Double = 0.0,
|
||||
@Expose var height: Double = 0.0,
|
||||
@Expose var membershipId: Long = 0,
|
||||
|
||||
){
|
||||
fun fromJson(json: String): DietCustomer {
|
||||
return Json.decodeFromString(serializer(), json)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
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 dietId: 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,
|
||||
)
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.aitrainer.api.model.diet
|
||||
|
||||
import com.google.gson.annotations.Expose
|
||||
import jakarta.persistence.Entity
|
||||
import jakarta.persistence.GeneratedValue
|
||||
import jakarta.persistence.GenerationType
|
||||
import jakarta.persistence.Id
|
||||
import javax.validation.constraints.NotNull
|
||||
|
||||
@Entity
|
||||
data class DietSensitivity(
|
||||
@Expose @Id @GeneratedValue(strategy = GenerationType.IDENTITY) var id: Long = 0,
|
||||
@Expose @get: NotNull val name: String = "",
|
||||
)
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.aitrainer.api.model.diet
|
||||
|
||||
import com.google.gson.annotations.Expose
|
||||
import jakarta.persistence.Entity
|
||||
import jakarta.persistence.GeneratedValue
|
||||
import jakarta.persistence.GenerationType
|
||||
import jakarta.persistence.Id
|
||||
import javax.validation.constraints.NotNull
|
||||
|
||||
@Entity
|
||||
data class DietUser(
|
||||
@Expose @Id @GeneratedValue(strategy = GenerationType.IDENTITY) var dietUserId: Long = 0,
|
||||
@Expose @get: NotNull val customerId: Long
|
||||
)
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.aitrainer.api.model.diet
|
||||
import com.google.gson.annotations.Expose
|
||||
import jakarta.persistence.*
|
||||
import org.jetbrains.annotations.NotNull
|
||||
import org.springframework.lang.NonNull
|
||||
|
||||
@Entity
|
||||
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 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 protein: Double = 0.0,
|
||||
@Expose @get: NotNull val fat: Double = 0.0,
|
||||
@Expose @get: NotNull val ch: Double = 0.0,
|
||||
@Expose @get: NotNull val sugar: Double = 0.0,
|
||||
)
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.aitrainer.api.model.diet
|
||||
|
||||
import com.google.gson.annotations.Expose
|
||||
import jakarta.persistence.Entity
|
||||
import jakarta.persistence.GeneratedValue
|
||||
import jakarta.persistence.GenerationType
|
||||
import jakarta.persistence.Id
|
||||
import javax.validation.constraints.NotNull
|
||||
|
||||
@Entity
|
||||
data class DietUserPreference(
|
||||
@Expose @Id @GeneratedValue(strategy = GenerationType.IDENTITY) var id: Long = 0,
|
||||
@Expose @get: NotNull val dietUserId: Long = 0,
|
||||
@Expose @get: NotNull val rawMaterialId: Long = 0,
|
||||
@Expose @get: NotNull val temperature: Byte = 0,
|
||||
)
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.aitrainer.api.model.diet
|
||||
|
||||
import com.google.gson.annotations.Expose
|
||||
import jakarta.persistence.Entity
|
||||
import jakarta.persistence.GeneratedValue
|
||||
import jakarta.persistence.GenerationType
|
||||
import jakarta.persistence.Id
|
||||
import javax.validation.constraints.NotNull
|
||||
|
||||
@Entity
|
||||
data class DietUserSensitivity(
|
||||
@Expose @Id @GeneratedValue(strategy = GenerationType.IDENTITY) var id: Long = 0,
|
||||
@Expose @get: NotNull val dietUserId: Long = 0,
|
||||
@Expose @get: NotNull val sensitivityId: Long = 0,
|
||||
)
|
||||
@@ -0,0 +1,22 @@
|
||||
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,
|
||||
)
|
||||
@@ -0,0 +1,26 @@
|
||||
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 Recipe (
|
||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Expose val recipeId: Long = 0,
|
||||
|
||||
@Expose @get: NotNull val name: String = "",
|
||||
@Expose @get: NotNull val description: String = "",
|
||||
|
||||
@Expose @get: NotNull val cal: Int = 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,
|
||||
@Expose @get: NotNull val dietUserId: Long = 0,
|
||||
) {
|
||||
@OneToMany(cascade = [(CascadeType.ALL)], fetch = FetchType.EAGER, mappedBy = "recipe")
|
||||
@Fetch(value = FetchMode.SUBSELECT)
|
||||
@Expose val rawMaterials: MutableList<RecipeRawMaterial> = mutableListOf()
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
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 RecipeRawMaterial (
|
||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Expose val id: Long = 0,
|
||||
|
||||
@Expose @get: NotNull var rawMaterialId: 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)
|
||||
@JsonIgnore
|
||||
var recipe: Recipe? = null
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.aitrainer.api.model.diet
|
||||
|
||||
import com.google.gson.annotations.Expose
|
||||
import jakarta.persistence.*
|
||||
import org.jetbrains.annotations.NotNull
|
||||
|
||||
@Entity
|
||||
data class Store (
|
||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Expose val storeId: Long = 0,
|
||||
|
||||
@Expose @get: NotNull val storeName: String = "",
|
||||
@Expose @get: NotNull val country: String = "",
|
||||
)
|
||||
@@ -0,0 +1,53 @@
|
||||
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.model.Model
|
||||
import com.aallam.openai.api.model.ModelId
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.util.Properties
|
||||
|
||||
class OpenAIService {
|
||||
|
||||
|
||||
private var openAI: OpenAI? = null
|
||||
var model: Model? = null
|
||||
private val properties = Properties()
|
||||
|
||||
init {
|
||||
val inputStream = ClassLoader.getSystemResourceAsStream("application.properties")
|
||||
properties.load(inputStream)
|
||||
inputStream?.close()
|
||||
}
|
||||
|
||||
private var modelId: ModelId? = null
|
||||
private suspend fun connect(modelName: String) {
|
||||
openAI = OpenAI(properties.getProperty("openai.key"))
|
||||
modelId = ModelId(modelName)
|
||||
model = openAI!!.model(modelId!!)
|
||||
|
||||
}
|
||||
|
||||
suspend fun completion(question: String): String {
|
||||
return withContext(Dispatchers.IO) {
|
||||
if (openAI == null) {
|
||||
connect("text-davinci-003")
|
||||
}
|
||||
val completionRequest = CompletionRequest(
|
||||
model = modelId!!,
|
||||
prompt = question,
|
||||
//echo = true,
|
||||
maxTokens = 128,
|
||||
temperature=0.1,
|
||||
)
|
||||
val completion: TextCompletion = openAI!!.completion(completionRequest)
|
||||
val result = completion.choices[0].text
|
||||
|
||||
//println("Completion: $result")
|
||||
result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.aitrainer.api.repository
|
||||
|
||||
import com.aitrainer.api.model.CustomerConversation
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.stereotype.Repository
|
||||
|
||||
@Repository
|
||||
interface CustomerConversationRepository : JpaRepository<CustomerConversation, Long> {
|
||||
fun findByCustomerId(customerId: Long): List<CustomerConversation>
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
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 findByDietId(dietId: Long): List<DietRawMaterial>
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.aitrainer.api.repository.diet
|
||||
|
||||
import com.aitrainer.api.model.diet.Diet
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.stereotype.Repository
|
||||
|
||||
@Repository
|
||||
interface DietRepository : JpaRepository<Diet, Long> {
|
||||
fun findByDietUserId(dietUserId: Long): List<Diet>
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.aitrainer.api.repository.diet
|
||||
|
||||
import com.aitrainer.api.model.diet.DietSensitivity
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
|
||||
interface DietSensitivityRepository : JpaRepository<DietSensitivity, Int>
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.aitrainer.api.repository.diet
|
||||
|
||||
import com.aitrainer.api.model.diet.DietUserConsumption
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.stereotype.Repository
|
||||
|
||||
@Repository
|
||||
interface DietUserConsumptionRepository : JpaRepository<DietUserConsumption, Long> {
|
||||
fun findByDietUserId(dietUserId: Long): List<DietUserConsumption>
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.aitrainer.api.repository.diet
|
||||
|
||||
import com.aitrainer.api.model.diet.DietUserPreference
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.stereotype.Repository
|
||||
|
||||
@Repository
|
||||
interface DietUserPreferenceRepository : JpaRepository<DietUserPreference, Long> {
|
||||
fun findByDietUserId(dietUserId: Long): List<DietUserPreference>
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.aitrainer.api.repository.diet
|
||||
|
||||
import com.aitrainer.api.model.diet.DietUser
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
|
||||
interface DietUserRepository : JpaRepository<DietUser, Int> {
|
||||
fun findByCustomerId(customerId: Long): DietUser?
|
||||
|
||||
fun findByDietUserId(dietUserId: Long): DietUser?
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.aitrainer.api.repository.diet
|
||||
|
||||
import com.aitrainer.api.model.diet.DietUserSensitivity
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.stereotype.Repository
|
||||
|
||||
@Repository
|
||||
interface DietUserSensitivityRepository : JpaRepository<DietUserSensitivity, Long> {
|
||||
fun findByDietUserId(dietUserId: Long): List<DietUserSensitivity>
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
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.RecipeRawMaterial
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
|
||||
interface RecipeRawMaterialRepository : JpaRepository<RecipeRawMaterial, Int> {
|
||||
|
||||
fun findByRawMaterialId(rawMaterialId: Long): List<RecipeRawMaterial>?
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.aitrainer.api.repository.diet
|
||||
|
||||
import com.aitrainer.api.model.diet.Recipe
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.data.jpa.repository.Query
|
||||
|
||||
interface RecipeRepository : JpaRepository<Recipe, Int> {
|
||||
@Query(" FROM Recipe WHERE name like %:name%")
|
||||
fun findByName(name: String): List<Recipe>?
|
||||
|
||||
fun findByDietUserId(dietUserId: Long): List<Recipe>?
|
||||
@Query(" FROM Recipe WHERE recipeId = :recipeId")
|
||||
fun findByRecipeId(recipeId: Long): Recipe?
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.aitrainer.api.repository.diet
|
||||
|
||||
import com.aitrainer.api.model.diet.Store
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.data.jpa.repository.Query
|
||||
|
||||
interface StoreRepository : JpaRepository<Store, Int> {
|
||||
@Query(" FROM Store WHERE storeName = :name and country = :country")
|
||||
fun findByNameAndCountry(name: String, country: String ): Store?
|
||||
|
||||
}
|
||||
@@ -3,9 +3,6 @@ package com.aitrainer.api.service
|
||||
import java.util.Properties
|
||||
import jakarta.mail.*
|
||||
import jakarta.mail.internet.*
|
||||
import org.jasypt.encryption.StringEncryptor
|
||||
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor
|
||||
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig
|
||||
|
||||
class Email {
|
||||
|
||||
@@ -19,23 +16,9 @@ class Email {
|
||||
put("mail.smtp.port", "587")
|
||||
}
|
||||
|
||||
fun getEncryptor(): StringEncryptor {
|
||||
val encryptor = PooledPBEStringEncryptor()
|
||||
val config = SimpleStringPBEConfig()
|
||||
config.password = "workouttest"
|
||||
config.algorithm = "PBEWithMD5AndDES"
|
||||
config.setKeyObtentionIterations("1000")
|
||||
config.setPoolSize("1")
|
||||
config.providerName = "SunJCE"
|
||||
config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator")
|
||||
config.stringOutputType = "base64"
|
||||
encryptor.setConfig(config)
|
||||
return encryptor
|
||||
}
|
||||
|
||||
val session: Session = Session.getInstance(properties, object : Authenticator() {
|
||||
override fun getPasswordAuthentication(): PasswordAuthentication {
|
||||
return PasswordAuthentication("service@workouttest.com", getEncryptor().decrypt(encodedPassword))
|
||||
return PasswordAuthentication("service@workouttest.com", Encryptor.getEncryptor().decrypt(encodedPassword))
|
||||
}
|
||||
})
|
||||
|
||||
@@ -47,7 +30,7 @@ class Email {
|
||||
}
|
||||
|
||||
val bodyPart = MimeBodyPart().apply {
|
||||
setContent(emailBody, "text/html")
|
||||
setContent(emailBody, "text/html; charset=UTF-8")
|
||||
}
|
||||
|
||||
val multipart = MimeMultipart().apply {
|
||||
|
||||
@@ -10,14 +10,15 @@ class EmailTemplateService {
|
||||
@Autowired
|
||||
private var templateEngine: TemplateEngine? = null
|
||||
|
||||
fun getEmailBody(firstname: String, activationLink: String): String {
|
||||
fun getEmailBody(firstname: String, activationLink: String, template: String): String {
|
||||
val context = Context()
|
||||
context.setVariable("firstname", firstname)
|
||||
context.setVariable("activationLink", activationLink)
|
||||
if ( templateEngine == null) {
|
||||
templateEngine = TemplateEngine()
|
||||
}
|
||||
return templateEngine!!.process("registration_email", context)
|
||||
|
||||
return templateEngine!!.process(template, context)
|
||||
}
|
||||
|
||||
fun getSubject(): String {
|
||||
@@ -27,5 +28,12 @@ class EmailTemplateService {
|
||||
}
|
||||
return templateEngine!!.process("registration_subject", context)
|
||||
}
|
||||
fun getSubjectDiet(): String {
|
||||
val context = Context()
|
||||
if ( templateEngine == null) {
|
||||
templateEngine = TemplateEngine()
|
||||
}
|
||||
return templateEngine!!.process("diet_registration_subject", context)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.aitrainer.api.service
|
||||
|
||||
import org.jasypt.encryption.StringEncryptor
|
||||
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor
|
||||
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig
|
||||
|
||||
object Encryptor {
|
||||
fun getEncryptor(): StringEncryptor {
|
||||
val encryptor = PooledPBEStringEncryptor()
|
||||
val config = SimpleStringPBEConfig()
|
||||
config.password = "workouttest"
|
||||
config.algorithm = "PBEWithMD5AndDES"
|
||||
config.setKeyObtentionIterations("1000")
|
||||
config.setPoolSize("1")
|
||||
config.providerName = "SunJCE"
|
||||
config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator")
|
||||
config.stringOutputType = "base64"
|
||||
encryptor.setConfig(config)
|
||||
return encryptor
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,6 @@ logging.config=classpath:logback-spring.xml
|
||||
logging.file=logs
|
||||
|
||||
# if the database structue has been changed, increment this version number
|
||||
application.version=1.1.0
|
||||
application.version=1.2.0
|
||||
|
||||
jwt.secret=aitrainer
|
||||
@@ -17,6 +17,9 @@ logging.config=classpath:logback-spring.xml
|
||||
logging.file=logs
|
||||
|
||||
# if the database structure has been changed, increment this version number
|
||||
application.version=1.1.0
|
||||
application.version=1.2.0
|
||||
|
||||
jwt.secret=aitrainer
|
||||
|
||||
openai.key=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
|
||||
spring.mail.properties.mail.mime.charset=UTF-8
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
</appender>
|
||||
|
||||
|
||||
<!-- <logger name="org.springframework" level="DEBUG" />
|
||||
<!--<logger name="org.springframework" level="DEBUG" />
|
||||
<logger name="org.apache.tomcat" level="DEBUG"/>
|
||||
<logger name="org.apache.coyote" level="DEBUG"/>
|
||||
<logger name="com.github.ulisesbocchio" level="DEBUG" />
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<html lang="hu" xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<title>Registration</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
</head>
|
||||
<body>
|
||||
<p th:text="'Szia ' + ${firstname} + '!'">Szia [firstname]!</p>
|
||||
<p>
|
||||
Üdvözlünk a Diet 4 You (Diéta Neked) tagjai között! Örülünk, hogy velünk vagy. Az étrended a Diet4You zárt felületén tudod elérni. A belépéshez használd ezt a linket:<br/><br/>
|
||||
<a th:href="${activationLink}" th:text="${activationLink}">${activationLink}</a>
|
||||
</p>
|
||||
<p>
|
||||
Kérlek, kattints a linkre a fiókod aktiválásához. Ha bármilyen problémád van, ne habozz velünk kapcsolatba lépni.
|
||||
</p>
|
||||
<p>
|
||||
Köszönjük, hogy velünk dolgozol.
|
||||
</p>
|
||||
<p>
|
||||
Üdvözlettel,<br>
|
||||
Diéta Neked Csapata<br/>
|
||||
Diet 4 You Team<br/>
|
||||
mailto: diet4you@andio.hu<br/>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1 @@
|
||||
[Diet4You] Üdv a céltudatosok között!
|
||||
@@ -1,6 +1,10 @@
|
||||
<html lang="hu" xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<title>Registration</title>
|
||||
<meta charset="utf-8" />
|
||||
</head>
|
||||
<body>
|
||||
<p th:text="'Szia ' + ${firstname}">Szia [firstname]!</p>
|
||||
<p th:text="'Szia ' + ${firstname} + '!'">Szia [firstname]!</p>
|
||||
<p>
|
||||
Üdvözlünk a Workout Test Club tagjai között! Örülünk, hogy velünk vagy. A Workout Test Club-ba való belépéshez használad ezt a linket:<br/><br/>
|
||||
<a th:href="${activationLink}" th:text="${activationLink}">${activationLink}</a>
|
||||
|
||||
Reference in New Issue
Block a user