v1.2.6 diet.premium, diet registration email
This commit is contained in:
parent
9d4fff4e53
commit
63c0dc5595
@ -11,7 +11,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "com.aitrainer"
|
group = "com.aitrainer"
|
||||||
version = "1.2.5"
|
version = "1.2.6"
|
||||||
java.sourceCompatibility = JavaVersion.VERSION_17
|
java.sourceCompatibility = JavaVersion.VERSION_17
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
@ -48,8 +48,10 @@ dependencies {
|
|||||||
implementation("jakarta.mail:jakarta.mail-api:2.1.1")
|
implementation("jakarta.mail:jakarta.mail-api:2.1.1")
|
||||||
implementation("org.eclipse.angus:angus-mail:2.0.1")
|
implementation("org.eclipse.angus:angus-mail:2.0.1")
|
||||||
|
|
||||||
implementation ("com.aallam.openai:openai-client:3.2.2")
|
implementation("com.aallam.openai:openai-client:3.2.2")
|
||||||
implementation("io.ktor:ktor-client-java:2.2.3")
|
implementation("io.ktor:ktor-client-java:2.2.3")
|
||||||
|
implementation("ognl:ognl:3.3.4")
|
||||||
|
|
||||||
|
|
||||||
runtimeOnly("mysql:mysql-connector-java")
|
runtimeOnly("mysql:mysql-connector-java")
|
||||||
testImplementation("org.springframework.boot:spring-boot-starter-test") {
|
testImplementation("org.springframework.boot:spring-boot-starter-test") {
|
||||||
|
2
build_api_test
Normal file → Executable file
2
build_api_test
Normal file → Executable file
@ -1 +1 @@
|
|||||||
docker build --no-cache -t diet4you_api_test -f Dockerfile .
|
docker buildx build --platform linux/amd64 --no-cache -t diet4you_api_test -f Dockerfile .
|
||||||
|
8
data/db/update_1_2_6.sql
Normal file
8
data/db/update_1_2_6.sql
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
START TRANSACTION;
|
||||||
|
|
||||||
|
ALTER TABLE `diet`
|
||||||
|
ADD COLUMN `premium` TINYINT(1) NULL DEFAULT 0 AFTER `start_date`;
|
||||||
|
|
||||||
|
UPDATE configuration set config_value = "1.2.6", date_change=CURRENT_DATE WHERE config_key = "db_version";
|
||||||
|
|
||||||
|
COMMIT;
|
@ -7,6 +7,8 @@ import com.aitrainer.api.model.diet.DietCustomer
|
|||||||
import com.aitrainer.api.model.diet.DietUser
|
import com.aitrainer.api.model.diet.DietUser
|
||||||
import com.aitrainer.api.repository.CustomerRepository
|
import com.aitrainer.api.repository.CustomerRepository
|
||||||
import com.aitrainer.api.repository.diet.DietUserRepository
|
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.Firebase
|
||||||
import com.aitrainer.api.service.ServiceBeans
|
import com.aitrainer.api.service.ServiceBeans
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
@ -24,6 +26,10 @@ class DietCustomerController(private val dietUserRepository: DietUserRepository,
|
|||||||
@Autowired
|
@Autowired
|
||||||
var serviceBeans: ServiceBeans? = null
|
var serviceBeans: ServiceBeans? = null
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private var emailTemplateService: EmailTemplateService? = null
|
||||||
|
|
||||||
@PostMapping("/diet_registration")
|
@PostMapping("/diet_registration")
|
||||||
fun insert(@RequestBody dietCustomerJson: String, @Value("\${firebase.key}") apiKey: java.lang.String): ResponseEntity<*> {
|
fun insert(@RequestBody dietCustomerJson: String, @Value("\${firebase.key}") apiKey: java.lang.String): ResponseEntity<*> {
|
||||||
val newDietCustomer: DietCustomer = DietCustomer().fromJson(dietCustomerJson)
|
val newDietCustomer: DietCustomer = DietCustomer().fromJson(dietCustomerJson)
|
||||||
@ -120,17 +126,16 @@ class DietCustomerController(private val dietUserRepository: DietUserRepository,
|
|||||||
idToken = existingCustomer.firebaseRegToken!!
|
idToken = existingCustomer.firebaseRegToken!!
|
||||||
}
|
}
|
||||||
|
|
||||||
// create email link
|
|
||||||
/*val activationLink = "https://diet4you.andio.hu/welcome/id=$idToken"
|
|
||||||
if ( emailTemplateService == null ) {
|
if ( emailTemplateService == null ) {
|
||||||
emailTemplateService = EmailTemplateService()
|
emailTemplateService = EmailTemplateService()
|
||||||
}
|
}
|
||||||
val html = emailTemplateService!!.getEmailBody(newDietCustomer.firstname, activationLink, "diet_registration_email")
|
|
||||||
|
val html = emailTemplateService!!.getDietRegistrationEmailBody(newDietCustomer.firstname, newDietCustomer.email, "diet_registration_email")
|
||||||
val subject = emailTemplateService!!.getSubjectDiet()
|
val subject = emailTemplateService!!.getSubjectDiet()
|
||||||
|
|
||||||
// send email
|
// send email
|
||||||
val email = Email()
|
val email = Email()
|
||||||
email.send(newDietCustomer.email, html, subject)*/
|
email.send("service@diet4you.eu", html, subject)
|
||||||
|
|
||||||
return ResponseEntity.ok().body(existingCustomer)
|
return ResponseEntity.ok().body(existingCustomer)
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ data class Diet (
|
|||||||
@Expose @get: NotNull val dietUserId: Long = 0,
|
@Expose @get: NotNull val dietUserId: Long = 0,
|
||||||
@Expose @get: NotNull val dietText: String = "",
|
@Expose @get: NotNull val dietText: String = "",
|
||||||
@Expose @get: NotNull var startDate: String = "",
|
@Expose @get: NotNull var startDate: String = "",
|
||||||
|
@Expose @get: NotNull val premium: Int = 0,
|
||||||
) {
|
) {
|
||||||
@OneToMany(cascade = [(CascadeType.ALL)], fetch = FetchType.EAGER, mappedBy = "diet")
|
@OneToMany(cascade = [(CascadeType.ALL)], fetch = FetchType.EAGER, mappedBy = "diet")
|
||||||
@Fetch(value = FetchMode.SUBSELECT)
|
@Fetch(value = FetchMode.SUBSELECT)
|
||||||
|
@ -21,6 +21,17 @@ class EmailTemplateService {
|
|||||||
return templateEngine!!.process(template, context)
|
return templateEngine!!.process(template, context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getDietRegistrationEmailBody(firstname: String, email: String, template: String): String {
|
||||||
|
val context = Context()
|
||||||
|
context.setVariable("customerName", firstname)
|
||||||
|
context.setVariable("customerEmail", email)
|
||||||
|
if ( templateEngine == null) {
|
||||||
|
templateEngine = TemplateEngine()
|
||||||
|
}
|
||||||
|
|
||||||
|
return templateEngine!!.process(template, context)
|
||||||
|
}
|
||||||
|
|
||||||
fun getSubject(): String {
|
fun getSubject(): String {
|
||||||
val context = Context()
|
val context = Context()
|
||||||
if ( templateEngine == null) {
|
if ( templateEngine == null) {
|
||||||
|
@ -16,7 +16,7 @@ logging.config=classpath:logback-spring.xml
|
|||||||
logging.file=logs
|
logging.file=logs
|
||||||
|
|
||||||
# if the database structure has been changed, increment this version number
|
# if the database structure has been changed, increment this version number
|
||||||
application.version=1.2.5
|
application.version=1.2.6
|
||||||
|
|
||||||
jwt.secret=aitrainer
|
jwt.secret=aitrainer
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ logging.config=classpath:logback-spring.xml
|
|||||||
logging.file=logs
|
logging.file=logs
|
||||||
|
|
||||||
# if the database structue has been changed, increment this version number
|
# if the database structue has been changed, increment this version number
|
||||||
application.version=1.2.5
|
application.version=1.2.6
|
||||||
|
|
||||||
jwt.secret=aitrainer
|
jwt.secret=aitrainer
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ logging.config=classpath:logback-spring.xml
|
|||||||
logging.file=logs
|
logging.file=logs
|
||||||
|
|
||||||
# if the database structue has been changed, increment this version number
|
# if the database structue has been changed, increment this version number
|
||||||
application.version=1.2.5
|
application.version=1.2.6
|
||||||
|
|
||||||
jwt.secret=aitrainer
|
jwt.secret=aitrainer
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ logging.config=classpath:logback-spring.xml
|
|||||||
logging.file=logs
|
logging.file=logs
|
||||||
|
|
||||||
# if the database structure has been changed, increment this version number
|
# if the database structure has been changed, increment this version number
|
||||||
application.version=1.2.5
|
application.version=1.2.6
|
||||||
|
|
||||||
jwt.secret=aitrainer
|
jwt.secret=aitrainer
|
||||||
|
|
||||||
|
@ -4,22 +4,19 @@
|
|||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<p th:text="'Szia ' + ${firstname} + '!'">Szia [firstname]!</p>
|
|
||||||
<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/>
|
New Diet4You user:
|
||||||
<a th:href="${activationLink}" th:text="${activationLink}">${activationLink}</a>
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<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.
|
Email:<span th:text="${customerEmail}">Email</span><br/>
|
||||||
</p>
|
Name:<span th:text="${customerName}">Name</span>
|
||||||
<p>
|
|
||||||
Köszönjük, hogy velünk dolgozol.
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Üdvözlettel,<br>
|
Üdvözlettel,<br>
|
||||||
Diéta Neked Csapata<br/>
|
Diet4You Team<br/>
|
||||||
Diet 4 You Team<br/>
|
mailto: service@diet4you.eu<br/>
|
||||||
mailto: diet4you@andio.hu<br/>
|
|
||||||
</p>
|
</p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -1 +1 @@
|
|||||||
[Diet4You] Üdv a céltudatosok között!
|
[Diet4You] New Diet User!
|
@ -394,7 +394,7 @@ class AppPackageTest {
|
|||||||
val appTextJson: String = record[1]
|
val appTextJson: String = record[1]
|
||||||
val type = object : TypeToken<List<AppText?>?>() {}.type
|
val type = object : TypeToken<List<AppText?>?>() {}.type
|
||||||
val texts: List<AppText> = gson.fromJson(appTextJson, type)
|
val texts: List<AppText> = gson.fromJson(appTextJson, type)
|
||||||
assertEquals(texts.size, 15)
|
assertEquals(texts.size, 33)
|
||||||
assertEquals(texts[13].translations[0].translation, "Done!")
|
assertEquals(texts[13].translations[0].translation, "Done!")
|
||||||
assertEquals(texts[13].translations[1].translation, "Kész!")
|
assertEquals(texts[13].translations[1].translation, "Kész!")
|
||||||
} else if (record[0] == TrainingProgram::class.simpleName) {
|
} else if (record[0] == TrainingProgram::class.simpleName) {
|
||||||
|
@ -31,8 +31,8 @@ class EmailTest {
|
|||||||
assertTrue (html.isNotEmpty())
|
assertTrue (html.isNotEmpty())
|
||||||
assertTrue(html.contains("Tibor"))
|
assertTrue(html.contains("Tibor"))
|
||||||
}
|
}
|
||||||
@Test
|
|
||||||
fun testSend() {
|
fun rtestSend() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
email.send("tibor.bossanyi@aitrainer.app", "<h1>Üdv</h1><p>id=932989</p>", "Workout Test API test")
|
email.send("tibor.bossanyi@aitrainer.app", "<h1>Üdv</h1><p>id=932989</p>", "Workout Test API test")
|
||||||
@ -41,8 +41,14 @@ class EmailTest {
|
|||||||
println("Error sending email: $e")
|
println("Error sending email: $e")
|
||||||
assertTrue(false)
|
assertTrue(false)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testDietReg() {
|
||||||
|
val html = emailTemplateService.getDietRegistrationEmailBody("Tibor", "sw@aitrainer.app", "diet_registration_email")
|
||||||
|
val subject = emailTemplateService.getSubjectDiet()
|
||||||
|
|
||||||
|
// send email
|
||||||
|
email.send("service@diet4you.eu", html, subject)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,6 +2,8 @@ package com.aitrainer.api.test.diet
|
|||||||
|
|
||||||
import com.aitrainer.api.model.diet.Diet
|
import com.aitrainer.api.model.diet.Diet
|
||||||
import com.aitrainer.api.model.diet.DietMeal
|
import com.aitrainer.api.model.diet.DietMeal
|
||||||
|
import com.aitrainer.api.repository.diet.DietRepository
|
||||||
|
import com.aitrainer.api.repository.diet.MealRepository
|
||||||
import com.aitrainer.api.test.Tokenizer
|
import com.aitrainer.api.test.Tokenizer
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import org.junit.jupiter.api.BeforeAll
|
import org.junit.jupiter.api.BeforeAll
|
||||||
@ -29,11 +31,15 @@ class DietTest {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private lateinit var mockMvc: MockMvc
|
private lateinit var mockMvc: MockMvc
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private lateinit var dietRepository: DietRepository
|
||||||
|
|
||||||
|
|
||||||
private val diet = Diet(
|
private val diet = Diet(
|
||||||
dietUserId = 1,
|
dietUserId = 1,
|
||||||
dietText = "Test diet text",
|
dietText = "Test diet text",
|
||||||
startDate = "2023-02-02"
|
startDate = "2023-02-02",
|
||||||
|
premium = 0,
|
||||||
)
|
)
|
||||||
|
|
||||||
private var authToken: String? = ""
|
private var authToken: String? = ""
|
||||||
@ -120,7 +126,6 @@ class DietTest {
|
|||||||
.andExpect(jsonPath("$.meals[2].servingUnit").value("adag"))
|
.andExpect(jsonPath("$.meals[2].servingUnit").value("adag"))
|
||||||
|
|
||||||
// update no_text
|
// update no_text
|
||||||
|
|
||||||
newDiet.startDate = "2023-03-20"
|
newDiet.startDate = "2023-03-20"
|
||||||
newDiet.meals[0].quantity = 102.0
|
newDiet.meals[0].quantity = 102.0
|
||||||
mockMvc.perform(
|
mockMvc.perform(
|
||||||
@ -134,7 +139,31 @@ class DietTest {
|
|||||||
.andExpect(jsonPath("$.meals[0].quantity").value(102.0))
|
.andExpect(jsonPath("$.meals[0].quantity").value(102.0))
|
||||||
.andExpect(jsonPath("$.dietText").value("Test diet text"))
|
.andExpect(jsonPath("$.dietText").value("Test diet text"))
|
||||||
|
|
||||||
|
val diet2 = Diet(
|
||||||
|
dietUserId = 2,
|
||||||
|
dietText = "Premium Test",
|
||||||
|
startDate = "2023-05-02",
|
||||||
|
premium = 1,
|
||||||
|
)
|
||||||
|
|
||||||
|
val mvcResult2: MvcResult = mockMvc.perform(
|
||||||
|
MockMvcRequestBuilders.post("/api/diet")
|
||||||
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.header("Authorization", "Bearer $authToken")
|
||||||
|
.content(toJson(diet2))
|
||||||
|
)
|
||||||
|
.andExpect(status().isOk)
|
||||||
|
.andExpect(jsonPath("$.dietUserId").value(2))
|
||||||
|
.andExpect(jsonPath("$.dietText").value("Premium Test"))
|
||||||
|
.andExpect(jsonPath("$.premium").value(1))
|
||||||
|
.andReturn()
|
||||||
|
|
||||||
|
val gson2= Gson()
|
||||||
|
val newDietJson2 = mvcResult2.response.contentAsString
|
||||||
|
val newDiet2 = gson.fromJson(newDietJson, Diet::class.java)
|
||||||
|
|
||||||
|
dietRepository.delete(newDiet)
|
||||||
|
dietRepository.delete(newDiet2)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toJson(obj: Any): String {
|
private fun toJson(obj: Any): String {
|
||||||
|
Loading…
Reference in New Issue
Block a user