API 1.0.28+2 ExercisePlan type
This commit is contained in:
parent
2bb531afcd
commit
4d9f2307aa
@ -1,7 +1,5 @@
|
|||||||
package com.aitrainer.api.model
|
package com.aitrainer.api.model
|
||||||
|
|
||||||
import org.hibernate.annotations.Fetch
|
|
||||||
import org.hibernate.annotations.FetchMode
|
|
||||||
import org.springframework.lang.NonNull
|
import org.springframework.lang.NonNull
|
||||||
import javax.persistence.*
|
import javax.persistence.*
|
||||||
|
|
||||||
@ -12,18 +10,12 @@ data class ExercisePlan(
|
|||||||
@get: NonNull var description: String? = null,
|
@get: NonNull var description: String? = null,
|
||||||
@get: NonNull var private: Boolean = false,
|
@get: NonNull var private: Boolean = false,
|
||||||
@get: NonNull var dateAdd: String? = null,
|
@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
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
var exercisePlanId: Int = 0
|
var exercisePlanId: Int = 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* @OneToMany(fetch = FetchType.LAZY, mappedBy = "exercisePlan")
|
|
||||||
@Fetch(value = FetchMode.SUBSELECT)
|
|
||||||
val planDetailList: List<ExercisePlanDetail> = mutableListOf<ExercisePlanDetail>()
|
|
||||||
|
|
||||||
*/
|
|
||||||
}
|
}
|
@ -8,8 +8,8 @@ import org.springframework.stereotype.Repository
|
|||||||
@Repository
|
@Repository
|
||||||
interface ExercisePlanRepository: JpaRepository<ExercisePlan, Int> {
|
interface ExercisePlanRepository: JpaRepository<ExercisePlan, Int> {
|
||||||
@Query(" FROM ExercisePlan" +
|
@Query(" 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 dateAdd in (select Max(dateAdd) from ExercisePlan where customerId = :customerId and private = 1 AND type is NULL) "+
|
||||||
" GROUP BY customerId"
|
" GROUP BY customerId"
|
||||||
)
|
)
|
||||||
fun getLastExercisePlan(customerId: Long): ExercisePlan?
|
fun getLastExercisePlan(customerId: Long): ExercisePlan?
|
||||||
|
@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.RequestHeader
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertNull
|
import kotlin.test.assertNull
|
||||||
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
@ -35,7 +36,23 @@ class ExercisePlanTest {
|
|||||||
|
|
||||||
val savedPlan: ExercisePlan = exercisePlanRepository.save(exercisePlan)
|
val savedPlan: ExercisePlan = exercisePlanRepository.save(exercisePlan)
|
||||||
assertEquals(savedPlan.customerId, 90)
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user