Merge branch 'tibor' into 'master'
ExercisePlan, Detail Update, Delete See merge request bossanyit/aitrainer_server!15
This commit is contained in:
commit
479a5f07f6
@ -1,9 +1,9 @@
|
|||||||
ALTER TABLE `exercise_plan`
|
ALTER TABLE `exercise_plan`
|
||||||
ADD COLUMN `customer_id` INT(11) NOT NULL DEFAULT '0' AFTER `exercise_plan_id`,
|
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 `private` TINYINT(4) NULL DEFAULT '0' AFTER `description`,
|
||||||
ADD COLUMN `date_add` DATETIME NOT NULL AFTER `private`;
|
ADD COLUMN `date_add` DATETIME NULL AFTER `private`;
|
||||||
|
|
||||||
ALTER TABLE `exercise_plan_detail`
|
ALTER TABLE `exercise_plan_detail`
|
||||||
CHANGE COLUMN `repeat` `repeats` INT(11) NULL DEFAULT NULL AFTER `serie`;
|
CHANGE COLUMN `repeat` `repeats` INT(11) NULL DEFAULT NULL AFTER `serie`;
|
||||||
|
|
||||||
UPDATE configuration set config_value = "1.0.7" WHERE config_key = "db_version";
|
UPDATE configuration set config_value = "1.0.7", date_change=CURRENT_DATE WHERE config_key = "db_version";
|
4
data/db/update_1_0_8.sql
Normal file
4
data/db/update_1_0_8.sql
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
ALTER TABLE `exercise_plan`
|
||||||
|
ADD COLUMN `date_upd` DATETIME NULL AFTER `date_add`;
|
||||||
|
|
||||||
|
UPDATE configuration set config_value = "1.0.8", date_change=CURRENT_DATE WHERE config_key = "db_version";
|
@ -4,6 +4,7 @@ import com.aitrainer.api.model.ExercisePlan
|
|||||||
import com.aitrainer.api.repository.ExercisePlanRepository
|
import com.aitrainer.api.repository.ExercisePlanRepository
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.http.ResponseEntity
|
import org.springframework.http.ResponseEntity
|
||||||
|
import org.springframework.security.access.annotation.Secured
|
||||||
import org.springframework.web.bind.annotation.*
|
import org.springframework.web.bind.annotation.*
|
||||||
import javax.validation.Valid
|
import javax.validation.Valid
|
||||||
|
|
||||||
@ -29,4 +30,23 @@ class ExercisePlanController( private val exercisePlanRepository: ExercisePlanRe
|
|||||||
ResponseEntity.ok().body(exercisePlan) else
|
ResponseEntity.ok().body(exercisePlan) else
|
||||||
ResponseEntity.notFound().build()
|
ResponseEntity.notFound().build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Secured
|
||||||
|
@PostMapping("/exercise_plan/{exercisePlanId}")
|
||||||
|
fun updateExercisePlanById(@PathVariable(value = "exercisePlanId") exercisePlanId: Long,
|
||||||
|
@Valid @RequestBody exercisePlan: ExercisePlan,
|
||||||
|
@RequestHeader requestHeader: RequestHeader?
|
||||||
|
): ResponseEntity<ExercisePlan> {
|
||||||
|
val returnPlan = exercisePlanRepository.findById(exercisePlanId).orElse(null)
|
||||||
|
?: return ResponseEntity.notFound().build()
|
||||||
|
val updatedPlan = returnPlan.copy(
|
||||||
|
customerId = exercisePlan.customerId,
|
||||||
|
name = exercisePlan.name,
|
||||||
|
dateAdd = exercisePlan.dateAdd,
|
||||||
|
description = exercisePlan.description
|
||||||
|
)
|
||||||
|
updatedPlan.exercisePlanId = exercisePlan.exercisePlanId
|
||||||
|
logger.info("-- updateExercisePlanById id: $updatedPlan ")
|
||||||
|
return ResponseEntity.ok().body(exercisePlanRepository.save(updatedPlan))
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,10 +1,13 @@
|
|||||||
package com.aitrainer.api.controller
|
package com.aitrainer.api.controller
|
||||||
|
|
||||||
|
import com.aitrainer.api.model.ExercisePlan
|
||||||
import com.aitrainer.api.model.ExercisePlanDetail
|
import com.aitrainer.api.model.ExercisePlanDetail
|
||||||
import com.aitrainer.api.model.ExerciseType
|
import com.aitrainer.api.model.ExerciseType
|
||||||
import com.aitrainer.api.repository.ExercisePlanDetailRepository
|
import com.aitrainer.api.repository.ExercisePlanDetailRepository
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
import org.springframework.http.HttpStatus
|
||||||
import org.springframework.http.ResponseEntity
|
import org.springframework.http.ResponseEntity
|
||||||
|
import org.springframework.security.access.annotation.Secured
|
||||||
import org.springframework.web.bind.annotation.*
|
import org.springframework.web.bind.annotation.*
|
||||||
import javax.validation.Valid
|
import javax.validation.Valid
|
||||||
|
|
||||||
@ -25,4 +28,43 @@ class ExercisePlanDetailController( private val exercisePlanDetailRepository: Ex
|
|||||||
logger.info("-- getExercisePlanByCustomerId id: $customerId -- $list")
|
logger.info("-- getExercisePlanByCustomerId id: $customerId -- $list")
|
||||||
return ResponseEntity.ok().body(list)
|
return ResponseEntity.ok().body(list)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Secured
|
||||||
|
@PostMapping("/exercise_plan_detail/{exercisePlanDetailId}")
|
||||||
|
fun updateExercisePlanDetailById(@PathVariable(value = "exercisePlanDetailId") exercisePlanDetailId: Long,
|
||||||
|
@Valid @RequestBody exercisePlanDetail: ExercisePlanDetail,
|
||||||
|
@RequestHeader requestHeader: RequestHeader?
|
||||||
|
): ResponseEntity<ExercisePlanDetail> {
|
||||||
|
val returnPlanDetail = exercisePlanDetailRepository.findById(exercisePlanDetailId).orElse(null)
|
||||||
|
?: return ResponseEntity.notFound().build()
|
||||||
|
|
||||||
|
val updatedPlanDetail = returnPlanDetail.copy(
|
||||||
|
exercisePlan = exercisePlanDetail.exercisePlan,
|
||||||
|
exerciseTypeId = exercisePlanDetail.exerciseTypeId,
|
||||||
|
serie = exercisePlanDetail.serie,
|
||||||
|
repeats = exercisePlanDetail.repeats,
|
||||||
|
weightEquation = exercisePlanDetail.weightEquation
|
||||||
|
)
|
||||||
|
updatedPlanDetail.exercisePlanDetailId = exercisePlanDetail.exercisePlanDetailId
|
||||||
|
logger.info("-- updateExercisePlanDetailById id: $updatedPlanDetail ")
|
||||||
|
return ResponseEntity.ok().body(exercisePlanDetailRepository.save(updatedPlanDetail))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Secured
|
||||||
|
@PostMapping("/exercise_plan_detail/delete/{exercisePlanDetailId}")
|
||||||
|
fun deleteExercisePlanDetailById(@PathVariable(value = "exercisePlanDetailId") exercisePlanDetailId: Long,
|
||||||
|
@Valid @RequestBody exercisePlanDetail: ExercisePlanDetail)
|
||||||
|
:ResponseEntity<HttpStatus> {
|
||||||
|
val returnPlanDetail = exercisePlanDetailRepository.findById(exercisePlanDetailId).orElse(null)
|
||||||
|
if (returnPlanDetail == null) {
|
||||||
|
return ResponseEntity.ok().body(HttpStatus.NOT_FOUND)
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
exercisePlanDetailRepository.delete(returnPlanDetail)
|
||||||
|
} catch (e: IllegalArgumentException ) {
|
||||||
|
return ResponseEntity.ok().body(HttpStatus.BAD_REQUEST)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResponseEntity.ok().body(HttpStatus.OK)
|
||||||
|
}
|
||||||
}
|
}
|
@ -11,7 +11,8 @@ data class ExercisePlan(
|
|||||||
@get: NonNull var name: String? = null,
|
@get: NonNull var name: String? = null,
|
||||||
@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
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
@ -19,5 +19,5 @@ data class ExercisePlanDetail (
|
|||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
val exercisePlanDetailId: Long = 0
|
var exercisePlanDetailId: Long = 0
|
||||||
}
|
}
|
@ -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.6
|
application.version=1.0.8
|
||||||
|
|
||||||
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.6
|
application.version=1.0.8
|
||||||
|
|
||||||
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.7
|
application.version=1.0.8
|
||||||
|
|
||||||
jwt.secret=aitrainer
|
jwt.secret=aitrainer
|
@ -1,5 +1,7 @@
|
|||||||
package com.aitrainer.api.test
|
package com.aitrainer.api.test
|
||||||
|
|
||||||
|
import com.aitrainer.api.controller.ExercisePlanController
|
||||||
|
import com.aitrainer.api.controller.ExercisePlanDetailController
|
||||||
import com.aitrainer.api.model.ExercisePlan
|
import com.aitrainer.api.model.ExercisePlan
|
||||||
import com.aitrainer.api.model.ExercisePlanDetail
|
import com.aitrainer.api.model.ExercisePlanDetail
|
||||||
import com.aitrainer.api.repository.ExercisePlanDetailRepository
|
import com.aitrainer.api.repository.ExercisePlanDetailRepository
|
||||||
@ -8,7 +10,11 @@ import org.junit.jupiter.api.TestInstance
|
|||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
import org.springframework.boot.test.context.SpringBootTest
|
import org.springframework.boot.test.context.SpringBootTest
|
||||||
|
import org.springframework.http.HttpStatus
|
||||||
|
import org.springframework.http.ResponseEntity
|
||||||
|
import java.util.*
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
import kotlin.test.assertNotNull
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
@ -47,5 +53,58 @@ class ExercisePlanDetailTest {
|
|||||||
val exercisePlanDetail: ExercisePlanDetail = exercisePlanDetailList[0]
|
val exercisePlanDetail: ExercisePlanDetail = exercisePlanDetailList[0]
|
||||||
assertEquals(exercisePlanDetail.weightEquation, "40")
|
assertEquals(exercisePlanDetail.weightEquation, "40")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testUpdatePlanDetail() {
|
||||||
|
val planDetail: ExercisePlanDetail = exercisePlanDetailRepository.findById(4).orElse(null)
|
||||||
|
assertEquals(planDetail.exerciseTypeId, 39)
|
||||||
|
assertEquals(planDetail.serie, 3)
|
||||||
|
planDetail.weightEquation = "50%"
|
||||||
|
planDetail.repeats = 30
|
||||||
|
|
||||||
|
|
||||||
|
val planDetailController = ExercisePlanDetailController(exercisePlanDetailRepository)
|
||||||
|
val response: ResponseEntity<*> = planDetailController.updateExercisePlanDetailById(4, planDetail, null)
|
||||||
|
val updatedPlanDetail = response.body as ExercisePlanDetail
|
||||||
|
assertEquals(planDetail.weightEquation, "50%")
|
||||||
|
assertEquals(planDetail.repeats, 30)
|
||||||
|
assertEquals(planDetail.exercisePlan?.exercisePlanId, 6)
|
||||||
|
assertEquals(planDetail.exercisePlanDetailId, 4)
|
||||||
|
|
||||||
|
updatedPlanDetail.weightEquation = "40"
|
||||||
|
updatedPlanDetail.repeats = 1
|
||||||
|
planDetailController.updateExercisePlanDetailById(4, updatedPlanDetail, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testDeletePlanDetail() {
|
||||||
|
val plan = ExercisePlan(
|
||||||
|
|
||||||
|
)
|
||||||
|
plan.exercisePlanId = 6;
|
||||||
|
|
||||||
|
val planDetail = ExercisePlanDetail(
|
||||||
|
exerciseTypeId = 63,
|
||||||
|
serie = 3,
|
||||||
|
repeats = 120,
|
||||||
|
weightEquation = "90",
|
||||||
|
exercisePlan = plan
|
||||||
|
)
|
||||||
|
val savedDetail: ExercisePlanDetail = exercisePlanDetailRepository.save(planDetail)
|
||||||
|
assertEquals(savedDetail.weightEquation, "90")
|
||||||
|
val newPlanDetailId = savedDetail.exercisePlanDetailId
|
||||||
|
print(" --- new plan for delete $newPlanDetailId")
|
||||||
|
|
||||||
|
val planDetailController = ExercisePlanDetailController(exercisePlanDetailRepository)
|
||||||
|
|
||||||
|
val planDetailToDelete: ExercisePlanDetail = exercisePlanDetailRepository.findById(newPlanDetailId).orElse(null)
|
||||||
|
assertNotNull(planDetailToDelete)
|
||||||
|
|
||||||
|
val response: ResponseEntity<*> = planDetailController.deleteExercisePlanDetailById(newPlanDetailId, planDetailToDelete)
|
||||||
|
assertEquals(response.body, HttpStatus.OK)
|
||||||
|
|
||||||
|
val response2: ResponseEntity<*> = planDetailController.deleteExercisePlanDetailById(9999, planDetailToDelete)
|
||||||
|
assertEquals(response2.body, HttpStatus.NOT_FOUND)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
package com.aitrainer.api.test
|
package com.aitrainer.api.test
|
||||||
|
|
||||||
|
import com.aitrainer.api.controller.ExercisePlanController
|
||||||
import com.aitrainer.api.model.ExercisePlan
|
import com.aitrainer.api.model.ExercisePlan
|
||||||
import com.aitrainer.api.repository.ExercisePlanRepository
|
import com.aitrainer.api.repository.ExercisePlanRepository
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.api.TestInstance
|
import org.junit.jupiter.api.TestInstance
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
import org.springframework.boot.test.context.SpringBootTest
|
import org.springframework.boot.test.context.SpringBootTest
|
||||||
|
import org.springframework.http.ResponseEntity
|
||||||
|
import org.springframework.web.bind.annotation.RequestHeader
|
||||||
|
import java.util.*
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@ -42,4 +46,24 @@ class ExercisePlanTest {
|
|||||||
val exercisePlan2: ExercisePlan? = exercisePlanRepository.getLastExercisePlan(91)
|
val exercisePlan2: ExercisePlan? = exercisePlanRepository.getLastExercisePlan(91)
|
||||||
assertEquals(exercisePlan2, null)
|
assertEquals(exercisePlan2, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testUpdatePlan() {
|
||||||
|
val plan: ExercisePlan = exercisePlanRepository.findById(6).orElse(null)
|
||||||
|
assertEquals(plan.name, "Boss private")
|
||||||
|
assertEquals(plan.customerId, 90)
|
||||||
|
plan.dateUpd = Date().toString()
|
||||||
|
plan.description = "Bossanyi updated"
|
||||||
|
|
||||||
|
val planController = ExercisePlanController(exercisePlanRepository)
|
||||||
|
val response: ResponseEntity<*> = planController.updateExercisePlanById(6, plan, null)
|
||||||
|
val updatedPlan = response.body as ExercisePlan
|
||||||
|
assertEquals(plan.name, "Boss private")
|
||||||
|
assertEquals(plan.customerId, 90)
|
||||||
|
assertEquals(plan.description, "Bossanyi updated")
|
||||||
|
assertEquals(plan.exercisePlanId, 6)
|
||||||
|
|
||||||
|
updatedPlan.description = ""
|
||||||
|
planController.updateExercisePlanById(6, updatedPlan, null)
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user