Merge branch 'tibor' into 'master'

API 1.0.28+2 ExercisePlan type

See merge request bossanyit/aitrainer_server!44
This commit is contained in:
Bossányi Tibor 2021-03-25 20:01:04 +00:00
commit 368edfe2ab
3 changed files with 22 additions and 13 deletions

View File

@ -1,7 +1,5 @@
package com.aitrainer.api.model
import org.hibernate.annotations.Fetch
import org.hibernate.annotations.FetchMode
import org.springframework.lang.NonNull
import javax.persistence.*
@ -12,18 +10,12 @@ data class ExercisePlan(
@get: NonNull var description: String? = null,
@get: NonNull var private: Boolean = false,
@get: NonNull var dateAdd: String? = null,
@get: NonNull var dateUpd: String? = null
@get: NonNull var dateUpd: String? = null,
@get: NonNull var type: String? = null,
) {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
var exercisePlanId: Int = 0
/* @OneToMany(fetch = FetchType.LAZY, mappedBy = "exercisePlan")
@Fetch(value = FetchMode.SUBSELECT)
val planDetailList: List<ExercisePlanDetail> = mutableListOf<ExercisePlanDetail>()
*/
}

View File

@ -8,8 +8,8 @@ import org.springframework.stereotype.Repository
@Repository
interface ExercisePlanRepository: JpaRepository<ExercisePlan, Int> {
@Query(" FROM ExercisePlan" +
" WHERE customerId = :customerId AND private = 1" +
" AND dateAdd in (select Max(dateAdd) from ExercisePlan where customerId = :customerId and private = 1) "+
" WHERE customerId = :customerId AND private = 1 AND type is NULL" +
" AND dateAdd in (select Max(dateAdd) from ExercisePlan where customerId = :customerId and private = 1 AND type is NULL) "+
" GROUP BY customerId"
)
fun getLastExercisePlan(customerId: Long): ExercisePlan?

View File

@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.RequestHeader
import java.util.*
import kotlin.test.assertEquals
import kotlin.test.assertNull
import kotlin.test.assertTrue
@SpringBootTest
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@ -35,7 +36,23 @@ class ExercisePlanTest {
val savedPlan: ExercisePlan = exercisePlanRepository.save(exercisePlan)
assertEquals(savedPlan.customerId, 90)
exercisePlanRepository.delete(savedPlan);
assertTrue(savedPlan.type == null)
exercisePlanRepository.delete(savedPlan)
val exercisePlan2 = ExercisePlan (
name = "Bossanyi private 3",
description = "",
customerId = 90,
private = true,
type = "custom",
dateAdd = "2021-03-25 17:00"
)
val savedPlan2: ExercisePlan = exercisePlanRepository.save(exercisePlan2)
assertEquals(savedPlan2.customerId, 90)
assertTrue(savedPlan2.type == "custom")
exercisePlanRepository.delete(savedPlan2);
}