API 1.0.19 ExerciseResult
This commit is contained in:
parent
8711988902
commit
d331f660cd
@ -11,7 +11,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "com.aitrainer"
|
group = "com.aitrainer"
|
||||||
version = "1.0.18"
|
version = "1.0.19"
|
||||||
java.sourceCompatibility = JavaVersion.VERSION_1_8
|
java.sourceCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
@ -873,6 +873,26 @@ REPLACE INTO `purchase` (`purchase_id`, `customer_id`, `product_id`, `date_add`,
|
|||||||
(7, 1, 2, '2020-11-05 12:00:00', 2000, 'HUF');
|
(7, 1, 2, '2020-11-05 12:00:00', 2000, 'HUF');
|
||||||
/*!40000 ALTER TABLE `purchase` ENABLE KEYS */;
|
/*!40000 ALTER TABLE `purchase` ENABLE KEYS */;
|
||||||
|
|
||||||
|
CREATE TABLE `exercise_result` (
|
||||||
|
`exercise_result_id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`customer_id` INT(11) NOT NULL DEFAULT '0',
|
||||||
|
`exercise_id` INT(11) NULL DEFAULT '0',
|
||||||
|
`exercise_plan_id` INT(11) NULL DEFAULT '0',
|
||||||
|
`result_type` CHAR(50) NOT NULL DEFAULT '' COLLATE 'utf8_hungarian_ci',
|
||||||
|
`value` DOUBLE NOT NULL,
|
||||||
|
`date_from` DATETIME NULL DEFAULT NULL,
|
||||||
|
`date_to` DATETIME NULL DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`exercise_result_id`) USING BTREE
|
||||||
|
)
|
||||||
|
COLLATE='utf8_hungarian_ci'
|
||||||
|
ENGINE=InnoDB
|
||||||
|
;
|
||||||
|
|
||||||
|
INSERT INTO `exercise_result` (`exercise_result_id`, `customer_id`, `exercise_id`, `exercise_plan_id`, `result_type`, `value`, `date_from`, `date_to`) VALUES (1, 90, 1, 0, 'calorie', 134, '2020-12-12 10:56:45', NULL);
|
||||||
|
INSERT INTO `exercise_result` (`exercise_result_id`, `customer_id`, `exercise_id`, `exercise_plan_id`, `result_type`, `value`, `date_from`, `date_to`) VALUES (2, 90, 2, 0, 'fatburn', 31, '2020-12-12 10:57:00', NULL);
|
||||||
|
INSERT INTO `exercise_result` (`exercise_result_id`, `customer_id`, `exercise_id`, `exercise_plan_id`, `result_type`, `value`, `date_from`, `date_to`) VALUES (3, 90, 1, 0, 'development', 11.1, '2020-12-12 10:57:28', NULL);
|
||||||
|
INSERT INTO `exercise_result` (`exercise_result_id`, `customer_id`, `exercise_id`, `exercise_plan_id`, `result_type`, `value`, `date_from`, `date_to`) VALUES (4, 90, 1, 0, 'bpm_min', 113, '2020-12-12 10:57:52', NULL);
|
||||||
|
|
||||||
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
|
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
|
||||||
/*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */;
|
/*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */;
|
||||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||||
|
18
data/db/update_1_0_19.sql
Normal file
18
data/db/update_1_0_19.sql
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
CREATE TABLE `exercise_result` (
|
||||||
|
`exercise_result_id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`customer_id` INT(11) NOT NULL DEFAULT '0',
|
||||||
|
`exercise_id` INT(11) NULL DEFAULT '0',
|
||||||
|
`exercise_plan_id` INT(11) NULL DEFAULT '0',
|
||||||
|
`result_type` CHAR(50) NOT NULL DEFAULT '' COLLATE 'utf8_hungarian_ci',
|
||||||
|
`value` DOUBLE NOT NULL,
|
||||||
|
`date_from` DATETIME NULL DEFAULT NULL,
|
||||||
|
`date_to` DATETIME NULL DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`exercise_result_id`) USING BTREE
|
||||||
|
)
|
||||||
|
COLLATE='utf8_hungarian_ci'
|
||||||
|
ENGINE=InnoDB
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
UPDATE configuration set config_value = "1.0.19", date_change=CURRENT_DATE WHERE config_key = "db_version";
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.aitrainer.api.controller
|
||||||
|
|
||||||
|
import com.aitrainer.api.model.ExerciseResult
|
||||||
|
import com.aitrainer.api.model.Exercises
|
||||||
|
import com.aitrainer.api.repository.ExerciseResultRepository
|
||||||
|
import com.aitrainer.api.repository.ExercisesRepository
|
||||||
|
import org.springframework.http.HttpStatus
|
||||||
|
import org.springframework.http.ResponseEntity
|
||||||
|
import org.springframework.web.bind.annotation.*
|
||||||
|
import javax.validation.Valid
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api")
|
||||||
|
class ExerciseResultController(private val exerciseResultRepository: ExerciseResultRepository) {
|
||||||
|
|
||||||
|
@GetMapping("/exercise_result/{id}")
|
||||||
|
fun getExerciseResultsByCustomerId(@PathVariable(value = "id") customerId: Long): ResponseEntity<List<ExerciseResult>> {
|
||||||
|
val list = exerciseResultRepository.getAllByCustomerId(customerId)
|
||||||
|
return if (list.isEmpty() ) ResponseEntity.notFound().build() else
|
||||||
|
ResponseEntity.ok().body(list)
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/exercise_result")
|
||||||
|
fun createNewExerciseResult(@Valid @RequestBody exerciseResult: ExerciseResult): ResponseEntity<ExerciseResult> {
|
||||||
|
return ResponseEntity.ok().body(exerciseResultRepository.save(exerciseResult))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
22
src/main/kotlin/com/aitrainer/api/model/ExerciseResult.kt
Normal file
22
src/main/kotlin/com/aitrainer/api/model/ExerciseResult.kt
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package com.aitrainer.api.model
|
||||||
|
|
||||||
|
import org.springframework.lang.NonNull
|
||||||
|
import javax.persistence.Entity
|
||||||
|
import javax.persistence.GeneratedValue
|
||||||
|
import javax.persistence.GenerationType
|
||||||
|
import javax.persistence.Id
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
data class ExerciseResult(
|
||||||
|
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
val exerciseResultId: Long = 0,
|
||||||
|
|
||||||
|
@get: NonNull var customerId: Long = 0,
|
||||||
|
@get: NonNull var exerciseId: Long = 0,
|
||||||
|
@get: NonNull var exercisePlanId: Long? = null,
|
||||||
|
@get: NonNull var resultType: String? = null,
|
||||||
|
@get: NonNull var value: Double? = null,
|
||||||
|
@get: NonNull var dateFrom: String? = null,
|
||||||
|
@get: NonNull var dateTo: String? = null
|
||||||
|
|
||||||
|
)
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.aitrainer.api.repository
|
||||||
|
|
||||||
|
import com.aitrainer.api.model.ExerciseResult
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository
|
||||||
|
import org.springframework.stereotype.Repository
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
interface ExerciseResultRepository : JpaRepository<ExerciseResult, Long> {
|
||||||
|
fun getAllByCustomerId( customerId: Long? ):List<ExerciseResult>
|
||||||
|
}
|
@ -16,6 +16,6 @@ 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.0.18
|
application.version=1.0.19
|
||||||
|
|
||||||
jwt.secret=aitrainer
|
jwt.secret=aitrainer
|
@ -16,6 +16,6 @@ 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.0.18
|
application.version=1.0.19
|
||||||
|
|
||||||
jwt.secret=aitrainer
|
jwt.secret=aitrainer
|
62
src/test/kotlin/com/aitrainer/api/test/ExerciseResultTest.kt
Normal file
62
src/test/kotlin/com/aitrainer/api/test/ExerciseResultTest.kt
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
package com.aitrainer.api.test
|
||||||
|
|
||||||
|
import com.aitrainer.api.controller.ExerciseController
|
||||||
|
import com.aitrainer.api.controller.ExerciseResultController
|
||||||
|
import com.aitrainer.api.model.ExerciseResult
|
||||||
|
import com.aitrainer.api.model.Exercises
|
||||||
|
import com.aitrainer.api.repository.ExerciseResultRepository
|
||||||
|
import com.aitrainer.api.repository.ExercisesRepository
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest
|
||||||
|
import org.springframework.http.HttpStatus
|
||||||
|
import org.springframework.http.ResponseEntity
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
class ExerciseResultTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private lateinit var exerciseResultRepository: ExerciseResultRepository
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testGet() {
|
||||||
|
val controller = ExerciseResultController(exerciseResultRepository)
|
||||||
|
val response = controller.getExerciseResultsByCustomerId(90)
|
||||||
|
|
||||||
|
val exerciseResults = response.body
|
||||||
|
assertTrue(exerciseResults is List)
|
||||||
|
assertEquals(exerciseResults.size, 4)
|
||||||
|
assertEquals(exerciseResults[0].customerId, 90)
|
||||||
|
assertEquals(exerciseResults[0].exerciseId, 1)
|
||||||
|
assertEquals(exerciseResults[0].value, 134.0)
|
||||||
|
assertEquals(exerciseResults[2].resultType, "development")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testInsert() {
|
||||||
|
val result = ExerciseResult(
|
||||||
|
exerciseId = 3,
|
||||||
|
customerId = 103,
|
||||||
|
value = 100.0,
|
||||||
|
dateFrom = "2020-05-13 04:32:00",
|
||||||
|
resultType = "calorie"
|
||||||
|
)
|
||||||
|
|
||||||
|
val controller = ExerciseResultController(exerciseResultRepository)
|
||||||
|
|
||||||
|
val response = controller.createNewExerciseResult(result)
|
||||||
|
|
||||||
|
val exerciseNew = response.body
|
||||||
|
|
||||||
|
assertTrue(exerciseNew is ExerciseResult)
|
||||||
|
assertTrue(exerciseNew.exercisePlanId == null)
|
||||||
|
assertEquals(exerciseNew.customerId, 103)
|
||||||
|
assertEquals(exerciseNew.resultType, "calorie")
|
||||||
|
|
||||||
|
exerciseResultRepository.delete(exerciseNew)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -39,7 +39,7 @@ class ExerciseTreeParentsTest {
|
|||||||
|
|
||||||
assertTrue(responseEntity.body!!.isNotEmpty())
|
assertTrue(responseEntity.body!!.isNotEmpty())
|
||||||
val exerciseTreeParentList = responseEntity.body!!
|
val exerciseTreeParentList = responseEntity.body!!
|
||||||
assertEquals(exerciseTreeParentList.size, 27)
|
assertEquals(exerciseTreeParentList.size, 20)
|
||||||
assertEquals(exerciseTreeParentList[4].exerciseTreeParentId, 3)
|
assertEquals(exerciseTreeParentList[4].exerciseTreeParentId, 3)
|
||||||
assertEquals(exerciseTreeParentList[4].exerciseTreeChildId, 7)
|
assertEquals(exerciseTreeParentList[4].exerciseTreeChildId, 7)
|
||||||
|
|
||||||
|
@ -65,17 +65,4 @@ class ExerciseTypeTest {
|
|||||||
logger.info("Delete 'Húzodszkodás 2")
|
logger.info("Delete 'Húzodszkodás 2")
|
||||||
exerciseTypeRepository.delete(extype)
|
exerciseTypeRepository.delete(extype)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testActiveExercises() {
|
|
||||||
val exerciseTypeController = ExerciseTypeController(exerciseTypeRepository)
|
|
||||||
val responseEntity: ResponseEntity<List<ExerciseType>> = exerciseTypeController.getActiveExerciseType()
|
|
||||||
|
|
||||||
val exerciseType = responseEntity.body!![0]
|
|
||||||
assertEquals(exerciseType.name, "Chest Press")
|
|
||||||
assertEquals(exerciseType.images[0].url, "images/2.2.1.1.chestpress.png")
|
|
||||||
assertEquals(responseEntity.body!![2].translations[0].name, "Fekvenyomás")
|
|
||||||
assertEquals(responseEntity.body!![2].devices[0].exerciseDeviceId, 4)
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user