Merge branch 'tibor' into 'master'
API: ExercisePlan, ExercisePlanDetail See merge request bossanyit/aitrainer_server!14
This commit is contained in:
commit
665974a793
@ -11,7 +11,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "com.aitrainer"
|
||||
version = "1.0.5"
|
||||
version = "1.0.7"
|
||||
java.sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
|
||||
repositories {
|
||||
|
@ -231,20 +231,29 @@ ENGINE=InnoDB
|
||||
|
||||
CREATE TABLE `exercise_plan` (
|
||||
`exercise_plan_id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`customer_id` INT(11) NOT NULL DEFAULT '0',
|
||||
`name` CHAR(50) NULL DEFAULT '0' COLLATE 'utf8mb4_general_ci',
|
||||
`description` TEXT(65535) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
|
||||
`private` TINYINT(4) NULL DEFAULT '0',
|
||||
`date_add` DATETIME NOT NULL,
|
||||
PRIMARY KEY (`exercise_plan_id`) USING BTREE
|
||||
)
|
||||
COLLATE='utf8mb4_general_ci'
|
||||
ENGINE=InnoDB
|
||||
;
|
||||
|
||||
INSERT INTO `exercise_plan` (`exercise_plan_id`, `customer_id`, `name`, `description`, `private`, `date_add`) VALUES (3, 90, 'Common', 'Common training plan', 0, '0000-00-00 00:00:00');
|
||||
INSERT INTO `exercise_plan` (`exercise_plan_id`, `customer_id`, `name`, `description`, `private`, `date_add`) VALUES (4, 90, 'Chuck Norris Plan', '', 0, '0000-00-00 00:00:00');
|
||||
INSERT INTO `exercise_plan` (`exercise_plan_id`, `customer_id`, `name`, `description`, `private`, `date_add`) VALUES (6, 90, 'Boss private', NULL, 1, '2020-09-05 18:00:00');
|
||||
INSERT INTO `exercise_plan` (`exercise_plan_id`, `customer_id`, `name`, `description`, `private`, `date_add`) VALUES (7, 90, 'Boss private', NULL, 1, '2020-09-06 08:00:00');
|
||||
|
||||
|
||||
CREATE TABLE `exercise_plan_detail` (
|
||||
`exercise_plan_detail_id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`exercise_plan_id` INT(11) NOT NULL DEFAULT '0',
|
||||
`exercise_type_id` INT(11) NOT NULL DEFAULT '0',
|
||||
`serie` INT(11) NOT NULL DEFAULT '0',
|
||||
`repeat` INT(11) NULL DEFAULT NULL,
|
||||
`repeats` INT(11) NULL DEFAULT NULL,
|
||||
`weight_equation` CHAR(50) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
|
||||
PRIMARY KEY (`exercise_plan_detail_id`) USING BTREE
|
||||
)
|
||||
@ -252,6 +261,13 @@ COLLATE='utf8mb4_general_ci'
|
||||
ENGINE=InnoDB
|
||||
;
|
||||
|
||||
INSERT INTO `exercise_plan_detail` (`exercise_plan_detail_id`, `exercise_plan_id`, `exercise_type_id`, `serie`, `repeats`, `weight_equation`) VALUES (1, 3, 35, 3, 20, '75%');
|
||||
INSERT INTO `exercise_plan_detail` (`exercise_plan_detail_id`, `exercise_plan_id`, `exercise_type_id`, `serie`, `repeats`, `weight_equation`) VALUES (2, 3, 36, 3, 50, '75%');
|
||||
INSERT INTO `exercise_plan_detail` (`exercise_plan_detail_id`, `exercise_plan_id`, `exercise_type_id`, `serie`, `repeats`, `weight_equation`) VALUES (3, 4, 37, 3, 12, '85%');
|
||||
INSERT INTO `exercise_plan_detail` (`exercise_plan_detail_id`, `exercise_plan_id`, `exercise_type_id`, `serie`, `repeats`, `weight_equation`) VALUES (4, 6, 39, 3, 1, '40');
|
||||
INSERT INTO `exercise_plan_detail` (`exercise_plan_detail_id`, `exercise_plan_id`, `exercise_type_id`, `serie`, `repeats`, `weight_equation`) VALUES (5, 6, 40, 12, 3, '40');
|
||||
|
||||
|
||||
CREATE TABLE `exercise_plan_translation` (
|
||||
`translation_id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`language_code` CHAR(2) NOT NULL DEFAULT '0' COLLATE 'utf8mb4_general_ci',
|
||||
|
9
data/db/update_1_0_7.sql
Normal file
9
data/db/update_1_0_7.sql
Normal file
@ -0,0 +1,9 @@
|
||||
ALTER TABLE `exercise_plan`
|
||||
ADD COLUMN `customer_id` INT(11) NOT NULL DEFAULT '0' AFTER `exercise_plan_id`,
|
||||
ADD COLUMN `private` TINYINT(4) NULL DEFAULT '0' AFTER `description`,
|
||||
ADD COLUMN `date_add` DATETIME NOT NULL AFTER `private`;
|
||||
|
||||
ALTER TABLE `exercise_plan_detail`
|
||||
CHANGE COLUMN `repeat` `repeats` INT(11) NULL DEFAULT NULL AFTER `serie`;
|
||||
|
||||
UPDATE configuration set config_value = "1.0.7" WHERE config_key = "db_version";
|
@ -41,13 +41,17 @@ class CustomerController ( private val customerRepository: CustomerRepository )
|
||||
|
||||
@Secured
|
||||
@GetMapping("/customers/real")
|
||||
fun getRealCustomers(active: String, @RequestHeader headers: HttpHeaders): List<Customer> =
|
||||
customerRepository.findByActive(active)
|
||||
fun getRealCustomers(active: String, @RequestHeader headers: HttpHeaders): ResponseEntity<List<Customer>> =
|
||||
ResponseEntity.ok().body(customerRepository.findByActive(active))
|
||||
|
||||
@Secured
|
||||
@GetMapping("/customers/trainees/{id}")
|
||||
fun getCustomerListByTrainerId(@PathVariable(value = "id") trainerId: Long, @RequestHeader headers: HttpHeaders): List<Customer> =
|
||||
customerRepository.findByTrainerId(trainerId)
|
||||
fun getCustomerListByTrainerId(@PathVariable(value = "id") trainerId: Long, @RequestHeader headers: HttpHeaders):
|
||||
ResponseEntity<List<Customer>> {
|
||||
val list = customerRepository.findByTrainerId(trainerId)
|
||||
|
||||
return if (list.isEmpty()) ResponseEntity.notFound().build() else ResponseEntity.ok().body(list)
|
||||
}
|
||||
|
||||
@Secured
|
||||
@PostMapping("/customers/{id}")
|
||||
@ -88,21 +92,6 @@ class CustomerController ( private val customerRepository: CustomerRepository )
|
||||
}
|
||||
|
||||
return ResponseEntity.ok().body(customerRepository.save(updatedCustomer))
|
||||
|
||||
/* return customerRepository.findById(customerId).map {
|
||||
existingCustomer ->
|
||||
val updatedCustomer: Customer = existingCustomer
|
||||
.copy(name = newCustomer.name,
|
||||
firstname = newCustomer.firstname,
|
||||
sex = newCustomer.sex,
|
||||
birthYear = newCustomer.birthYear,
|
||||
fitnessLevel = newCustomer.fitnessLevel,
|
||||
bodyType = newCustomer.bodyType,
|
||||
goal = newCustomer.goal,
|
||||
weight = newCustomer.weight
|
||||
)
|
||||
ResponseEntity.ok().body(customerRepository.save(updatedCustomer))
|
||||
}.orElse(ResponseEntity.notFound().build()) */
|
||||
}
|
||||
|
||||
|
||||
|
@ -22,8 +22,8 @@ class ExerciseController(private val exercisesRepository: ExercisesRepository) {
|
||||
exercisesRepository.getAllByCustomerId(customerId)
|
||||
|
||||
@PostMapping("/exercises")
|
||||
fun createNewExercise(@Valid @RequestBody exercise: Exercises): Exercises {
|
||||
return exercisesRepository.save(exercise)
|
||||
fun createNewExercise(@Valid @RequestBody exercise: Exercises): ResponseEntity<Exercises> {
|
||||
return ResponseEntity.ok().body(exercisesRepository.save(exercise))
|
||||
}
|
||||
|
||||
@PutMapping("/exercises/{id}")
|
||||
|
@ -0,0 +1,32 @@
|
||||
package com.aitrainer.api.controller
|
||||
|
||||
import com.aitrainer.api.model.ExercisePlan
|
||||
import com.aitrainer.api.repository.ExercisePlanRepository
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.*
|
||||
import javax.validation.Valid
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
class ExercisePlanController( private val exercisePlanRepository: ExercisePlanRepository) {
|
||||
private val logger = LoggerFactory.getLogger(javaClass)
|
||||
|
||||
@PostMapping("/exercise_plan")
|
||||
fun createNewExercisePlan(@Valid @RequestBody exercisePlan: ExercisePlan): ResponseEntity<ExercisePlan> {
|
||||
val newExercisePlan = exercisePlanRepository.save(exercisePlan)
|
||||
logger.info("Create new exercise plan: $newExercisePlan")
|
||||
return ResponseEntity.ok().body(newExercisePlan)
|
||||
}
|
||||
|
||||
@GetMapping("/exercise_plan/last/{customerId}")
|
||||
fun getLastExercisePlan(@PathVariable(value = "customerId") customerId: Long): ResponseEntity<ExercisePlan> {
|
||||
|
||||
val exercisePlan = exercisePlanRepository.getLastExercisePlan(customerId)
|
||||
logger.info("Get last exercise plan by id $customerId: $exercisePlan")
|
||||
|
||||
return if( exercisePlan != null)
|
||||
ResponseEntity.ok().body(exercisePlan) else
|
||||
ResponseEntity.notFound().build()
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.aitrainer.api.controller
|
||||
|
||||
import com.aitrainer.api.ApiApplication
|
||||
import com.aitrainer.api.repository.ConfigurationRepository
|
||||
import org.aspectj.lang.annotation.Aspect
|
||||
import org.aspectj.lang.annotation.Before
|
||||
import org.aspectj.lang.annotation.Pointcut
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Suppress("unused")
|
||||
@Aspect
|
||||
@Component
|
||||
class ExercisePlanControllerAspect {
|
||||
private val logger = LoggerFactory.getLogger(ApiApplication::class.simpleName)
|
||||
|
||||
@Autowired
|
||||
private lateinit var configurationRepository: ConfigurationRepository
|
||||
@Autowired
|
||||
private lateinit var properties: ApplicationProperties
|
||||
|
||||
@Suppress("unused")
|
||||
@Pointcut("execution(* com.aitrainer.api.controller.ExercisePlanController.*())")
|
||||
fun exercisePlanControllerAspect() {
|
||||
}
|
||||
|
||||
@Before("exercisePlanControllerAspect()")
|
||||
fun loggingAop() {
|
||||
Singleton.checkDBUpdate(configurationRepository, properties)
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.aitrainer.api.controller
|
||||
|
||||
import com.aitrainer.api.model.ExercisePlanDetail
|
||||
import com.aitrainer.api.model.ExerciseType
|
||||
import com.aitrainer.api.repository.ExercisePlanDetailRepository
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.*
|
||||
import javax.validation.Valid
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
class ExercisePlanDetailController( private val exercisePlanDetailRepository: ExercisePlanDetailRepository) {
|
||||
private val logger = LoggerFactory.getLogger(javaClass)
|
||||
|
||||
@PostMapping("/exercise_plan_detail")
|
||||
fun createNewExercisePlanDetail(@Valid @RequestBody exercisePlanDetail: ExercisePlanDetail): ResponseEntity<ExercisePlanDetail> {
|
||||
logger.info("Create new exercise plan: $exercisePlanDetail")
|
||||
return ResponseEntity.ok().body(exercisePlanDetailRepository.save(exercisePlanDetail))
|
||||
}
|
||||
|
||||
@GetMapping("/exercise_plan_detail/last/{customerId}")
|
||||
fun getExercisePlanByCustomerId(@PathVariable(value = "customerId") customerId: Long): ResponseEntity<List<ExercisePlanDetail>> {
|
||||
val list: List<ExercisePlanDetail> = exercisePlanDetailRepository.getLastExercisePlanDetail(customerId)
|
||||
logger.info("-- getExercisePlanByCustomerId id: $customerId -- $list")
|
||||
return ResponseEntity.ok().body(list)
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.aitrainer.api.controller
|
||||
|
||||
import com.aitrainer.api.ApiApplication
|
||||
import com.aitrainer.api.repository.ConfigurationRepository
|
||||
import org.aspectj.lang.annotation.Aspect
|
||||
import org.aspectj.lang.annotation.Before
|
||||
import org.aspectj.lang.annotation.Pointcut
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Suppress("unused")
|
||||
@Aspect
|
||||
@Component
|
||||
class ExercisePlanDetailControllerAspect {
|
||||
private val logger = LoggerFactory.getLogger(ApiApplication::class.simpleName)
|
||||
|
||||
@Autowired
|
||||
private lateinit var configurationRepository: ConfigurationRepository
|
||||
@Autowired
|
||||
private lateinit var properties: ApplicationProperties
|
||||
|
||||
@Suppress("unused")
|
||||
@Pointcut("execution(* com.aitrainer.api.controller.ExercisePlanDetailController.*())")
|
||||
fun exercisePlanDetailControllerAspect() {
|
||||
}
|
||||
|
||||
@Before("exercisePlanDetailControllerAspect()")
|
||||
fun loggingAop() {
|
||||
Singleton.checkDBUpdate(configurationRepository, properties)
|
||||
}
|
||||
|
||||
}
|
@ -3,6 +3,7 @@ package com.aitrainer.api.controller
|
||||
import com.aitrainer.api.model.ExerciseTree
|
||||
import com.aitrainer.api.repository.ExerciseTreeRepository
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
@ -13,9 +14,10 @@ class ExerciseTreeController (private val exerciseTreeRepository: ExerciseTreeRe
|
||||
private val logger = LoggerFactory.getLogger(javaClass)
|
||||
|
||||
@GetMapping("/exercise_tree")
|
||||
fun getAllActiveMenu(): List<ExerciseTree> {
|
||||
fun getAllActiveMenu(): ResponseEntity<List<ExerciseTree>> {
|
||||
val list: List<ExerciseTree> = exerciseTreeRepository.getActiveMenu()
|
||||
logger.info(" -- Get All active Exercise Tree menu.. $list")
|
||||
return list
|
||||
return if (list.isEmpty()) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(list)
|
||||
}
|
||||
}
|
@ -14,18 +14,18 @@ class ExerciseTypeController ( private val exerciseTypeRepository: ExerciseTypeR
|
||||
private val logger = LoggerFactory.getLogger(javaClass)
|
||||
|
||||
@GetMapping("/exercise_type")
|
||||
fun getAllExerciseType(): List<ExerciseType> {
|
||||
fun getAllExerciseType(): ResponseEntity<List<ExerciseType>> {
|
||||
val list: List<ExerciseType> = exerciseTypeRepository.findAll()
|
||||
logger.info(" -- Get All exercise types..")
|
||||
return list
|
||||
return ResponseEntity.ok().body(list)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/exercise_type")
|
||||
fun createNewExerciseType(@Valid @RequestBody exerciseType: ExerciseType): ExerciseType {
|
||||
fun createNewExerciseType(@Valid @RequestBody exerciseType: ExerciseType): ResponseEntity<ExerciseType> {
|
||||
logger.info("Create new exercise type: $exerciseType")
|
||||
return exerciseTypeRepository.save(exerciseType)
|
||||
return ResponseEntity.ok().body(exerciseTypeRepository.save(exerciseType))
|
||||
}
|
||||
|
||||
|
||||
@ -36,19 +36,12 @@ class ExerciseTypeController ( private val exerciseTypeRepository: ExerciseTypeR
|
||||
ResponseEntity.ok(exerciseType)
|
||||
}.orElse(ResponseEntity.notFound().build())
|
||||
}
|
||||
/*
|
||||
@GetMapping("/exercise_type/name/{name}")
|
||||
fun getExerciseTypeByName(@PathVariable(value = "name") name: String): ResponseEntity<ExerciseType> {
|
||||
return exerciseTypeRepository.findByName(name).map { exerciseType ->
|
||||
ResponseEntity.ok(exerciseType)
|
||||
}.orElse(ResponseEntity.notFound().build())
|
||||
}*/
|
||||
|
||||
@GetMapping("exercise_type/active")
|
||||
fun getActiveExerciseType(): List<ExerciseType> {
|
||||
fun getActiveExerciseType(): ResponseEntity<List<ExerciseType>> {
|
||||
val list: List<ExerciseType> = exerciseTypeRepository.getActiveExerciseTypes()
|
||||
logger.info("-- Get Active Exercise Types with Images and Translation -- $list")
|
||||
return list
|
||||
return ResponseEntity.ok().body(list)
|
||||
}
|
||||
|
||||
@PostMapping("/exercise_type/{id}")
|
||||
|
26
src/main/kotlin/com/aitrainer/api/model/ExercisePlan.kt
Normal file
26
src/main/kotlin/com/aitrainer/api/model/ExercisePlan.kt
Normal file
@ -0,0 +1,26 @@
|
||||
package com.aitrainer.api.model
|
||||
|
||||
import org.hibernate.annotations.Fetch
|
||||
import org.hibernate.annotations.FetchMode
|
||||
import org.springframework.lang.NonNull
|
||||
import javax.persistence.*
|
||||
|
||||
@Entity
|
||||
data class ExercisePlan(
|
||||
@get: NonNull var customerId: Long = 0,
|
||||
@get: NonNull var name: String? = null,
|
||||
@get: NonNull var description: String? = null,
|
||||
@get: NonNull var private: Boolean = false,
|
||||
@get: NonNull var dateAdd: String? = null
|
||||
) {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
var exercisePlanId: Long = 0
|
||||
|
||||
|
||||
|
||||
@OneToMany(fetch = FetchType.EAGER, mappedBy = "exercisePlan")
|
||||
@Fetch(value = FetchMode.SUBSELECT)
|
||||
val planDetailList: List<ExercisePlanDetail> = mutableListOf<ExercisePlanDetail>()
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.aitrainer.api.model
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||
import org.springframework.lang.NonNull
|
||||
import javax.persistence.*
|
||||
|
||||
@Entity
|
||||
data class ExercisePlanDetail (
|
||||
@get: NonNull var exerciseTypeId: Long = 0,
|
||||
@get: NonNull var serie: Int = 0,
|
||||
@get: NonNull var repeats: Int = 0,
|
||||
@get: NonNull var weightEquation: String? = "",
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER, optional = false)
|
||||
@JoinColumn(name = "exercisePlanId", nullable = false)
|
||||
@JsonIgnore
|
||||
val exercisePlan: ExercisePlan? = null
|
||||
) {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
val exercisePlanDetailId: Long = 0
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.aitrainer.api.repository
|
||||
|
||||
import com.aitrainer.api.model.ExercisePlanDetail
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.data.jpa.repository.Query
|
||||
import org.springframework.stereotype.Repository
|
||||
|
||||
@Repository
|
||||
interface ExercisePlanDetailRepository: JpaRepository<ExercisePlanDetail, Long> {
|
||||
|
||||
@Query("FROM ExercisePlanDetail as d " +
|
||||
"INNER JOIN ExercisePlan as p ON p.exercisePlanId = d.exercisePlan " +
|
||||
"WHERE p.private = 1 " +
|
||||
"AND p.customerId = :customerId " +
|
||||
"ORDER BY p.dateAdd DESC ")
|
||||
fun getLastExercisePlanDetail(customerId: Long): List<ExercisePlanDetail>
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.aitrainer.api.repository
|
||||
|
||||
import com.aitrainer.api.model.ExercisePlan
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.data.jpa.repository.Query
|
||||
import org.springframework.stereotype.Repository
|
||||
|
||||
@Repository
|
||||
interface ExercisePlanRepository: JpaRepository<ExercisePlan, Long> {
|
||||
@Query(" FROM ExercisePlan" +
|
||||
" WHERE customerId = :customerId AND private = 1" +
|
||||
" AND dateAdd in (select Max(dateAdd) from ExercisePlan where customerId = :customerId and private = 1) "+
|
||||
" GROUP BY customerId"
|
||||
)
|
||||
fun getLastExercisePlan(customerId: Long): ExercisePlan?
|
||||
}
|
@ -5,6 +5,6 @@ import org.springframework.data.jpa.repository.Query
|
||||
import org.springframework.data.repository.query.Param
|
||||
|
||||
interface ExerciseService {
|
||||
@Query("FROM exercises WHERE customer_id = :customerId")
|
||||
@Query("FROM exercises WHERE customer_id = :customerId ORDER BY dateAdd DESC")
|
||||
fun findAllByCustomerId( @Param("customerId") customerId: Long? ): List<Exercises>
|
||||
}
|
@ -16,6 +16,6 @@ logging.config=classpath:logback-spring.xml
|
||||
logging.file=logs
|
||||
|
||||
# if the database structure has been changed, increment this version number
|
||||
application.version=1.0.6
|
||||
application.version=1.0.7
|
||||
|
||||
jwt.secret=aitrainer
|
@ -0,0 +1,51 @@
|
||||
package com.aitrainer.api.test
|
||||
|
||||
import com.aitrainer.api.model.ExercisePlan
|
||||
import com.aitrainer.api.model.ExercisePlanDetail
|
||||
import com.aitrainer.api.repository.ExercisePlanDetailRepository
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@SpringBootTest
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
class ExercisePlanDetailTest {
|
||||
private val logger = LoggerFactory.getLogger(javaClass)
|
||||
|
||||
@Autowired
|
||||
private lateinit var exercisePlanDetailRepository: ExercisePlanDetailRepository
|
||||
|
||||
@Test
|
||||
fun testInsert() {
|
||||
val plan = ExercisePlan(
|
||||
|
||||
)
|
||||
plan.exercisePlanId = 6;
|
||||
|
||||
val planDetail = ExercisePlanDetail(
|
||||
exerciseTypeId = 41,
|
||||
serie = 3,
|
||||
repeats = 12,
|
||||
weightEquation = "50",
|
||||
exercisePlan = plan
|
||||
)
|
||||
val savedDetail: ExercisePlanDetail = exercisePlanDetailRepository.save(planDetail)
|
||||
assertEquals(savedDetail.repeats, 12)
|
||||
assertEquals(savedDetail.weightEquation, "50")
|
||||
exercisePlanDetailRepository.delete(savedDetail)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetLastExercisePlanDetail() {
|
||||
val exercisePlanDetailList: List<ExercisePlanDetail> = exercisePlanDetailRepository.getLastExercisePlanDetail(90)
|
||||
logger.info(" ****** list: $exercisePlanDetailList")
|
||||
assertEquals(exercisePlanDetailList.size, 2)
|
||||
|
||||
val exercisePlanDetail: ExercisePlanDetail = exercisePlanDetailList[0]
|
||||
assertEquals(exercisePlanDetail.weightEquation, "40")
|
||||
}
|
||||
}
|
||||
|
45
src/test/kotlin/com/aitrainer/api/test/ExercisePlanTest.kt
Normal file
45
src/test/kotlin/com/aitrainer/api/test/ExercisePlanTest.kt
Normal file
@ -0,0 +1,45 @@
|
||||
package com.aitrainer.api.test
|
||||
|
||||
import com.aitrainer.api.model.ExercisePlan
|
||||
import com.aitrainer.api.repository.ExercisePlanRepository
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@SpringBootTest
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
class ExercisePlanTest {
|
||||
|
||||
@Autowired
|
||||
private lateinit var exercisePlanRepository: ExercisePlanRepository
|
||||
|
||||
|
||||
@Test
|
||||
fun testInsert() {
|
||||
val exercisePlan = ExercisePlan (
|
||||
name = "Bossanyi private",
|
||||
description = "",
|
||||
customerId = 90,
|
||||
private = true,
|
||||
dateAdd = "2020-09-05 17:00"
|
||||
)
|
||||
|
||||
|
||||
val savedPlan: ExercisePlan = exercisePlanRepository.save(exercisePlan)
|
||||
assertEquals(savedPlan.customerId, 90)
|
||||
exercisePlanRepository.delete(savedPlan);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetLastPlan() {
|
||||
val exercisePlan: ExercisePlan? = exercisePlanRepository.getLastExercisePlan(90)
|
||||
assertEquals(exercisePlan?.name, "Boss private")
|
||||
assertEquals(exercisePlan?.dateAdd, "2020-09-06 08:00:00")
|
||||
|
||||
val exercisePlan2: ExercisePlan? = exercisePlanRepository.getLastExercisePlan(91)
|
||||
assertEquals(exercisePlan2, null)
|
||||
}
|
||||
}
|
@ -2,16 +2,17 @@ package com.aitrainer.api.test
|
||||
|
||||
|
||||
import com.aitrainer.api.controller.ExerciseTreeController
|
||||
import com.aitrainer.api.model.ExerciseTree
|
||||
import com.aitrainer.api.repository.ExerciseTreeRepository
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import org.springframework.http.ResponseEntity
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@SpringBootTest
|
||||
class ExerciseTreeTest {
|
||||
private val logger = LoggerFactory.getLogger(javaClass)
|
||||
|
||||
@Autowired
|
||||
private lateinit var exerciseTreeRepository: ExerciseTreeRepository
|
||||
@ -19,12 +20,13 @@ class ExerciseTreeTest {
|
||||
@Test
|
||||
fun testActiveExercises() {
|
||||
val exerciseTreeController = ExerciseTreeController(exerciseTreeRepository)
|
||||
val exerciseTree = exerciseTreeController.getAllActiveMenu()
|
||||
logger.info("Tree $exerciseTree")
|
||||
val responseEntity: ResponseEntity<List<ExerciseTree>> = exerciseTreeController.getAllActiveMenu()
|
||||
assertTrue(responseEntity.body!!.isNotEmpty())
|
||||
|
||||
val exerciseTreeItem = exerciseTree[0]
|
||||
|
||||
val exerciseTreeItem = responseEntity.body!![0]
|
||||
assertEquals(exerciseTreeItem.name, "Cardio")
|
||||
assertEquals(exerciseTree[1].translations[0].name, "Erő")
|
||||
assertEquals(responseEntity.body!![1].translations[0].name, "Erő")
|
||||
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package com.aitrainer.api.test
|
||||
|
||||
import com.aitrainer.api.controller.CustomerController
|
||||
import com.aitrainer.api.controller.ExerciseTypeController
|
||||
import com.aitrainer.api.model.ExerciseType
|
||||
import com.aitrainer.api.repository.ExerciseTypeRepository
|
||||
@ -8,6 +7,7 @@ import org.junit.jupiter.api.Test
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import org.springframework.http.ResponseEntity
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@SpringBootTest
|
||||
@ -67,12 +67,12 @@ class ExerciseTypeTest {
|
||||
@Test
|
||||
fun testActiveExercises() {
|
||||
val exerciseTypeController = ExerciseTypeController(exerciseTypeRepository)
|
||||
val exerciseTypes = exerciseTypeController.getActiveExerciseType()
|
||||
val responseEntity: ResponseEntity<List<ExerciseType>> = exerciseTypeController.getActiveExerciseType()
|
||||
|
||||
val exerciseType = exerciseTypes[0]
|
||||
val exerciseType = responseEntity.body!![0]
|
||||
assertEquals(exerciseType.name, "Chest Press")
|
||||
assertEquals(exerciseType.images[0].url, "images/2.2.1.1.chestpress.png")
|
||||
assertEquals(exerciseTypes[2].translations[0].name, "Tricepsz")
|
||||
assertEquals(responseEntity.body!![2].translations[0].name, "Tricepsz")
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user