Merge branch 'tibor' into 'master'
API 1.0.15 CustomerExerciseDevice See merge request bossanyit/aitrainer_server!24
This commit is contained in:
commit
868bd97840
@ -11,7 +11,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "com.aitrainer"
|
group = "com.aitrainer"
|
||||||
version = "1.0.14"
|
version = "1.0.15"
|
||||||
java.sourceCompatibility = JavaVersion.VERSION_1_8
|
java.sourceCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
@ -381,26 +381,27 @@ ENGINE=InnoDB
|
|||||||
;
|
;
|
||||||
|
|
||||||
CREATE TABLE `exercise_device` (
|
CREATE TABLE `exercise_device` (
|
||||||
`device_id` INT(11) NOT NULL AUTO_INCREMENT,
|
`exercise_device_id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||||
`name` CHAR(50) NULL DEFAULT NULL COLLATE 'utf8_hungarian_ci',
|
`name` CHAR(50) NULL DEFAULT NULL COLLATE 'utf8_hungarian_ci',
|
||||||
`description` VARCHAR(200) NULL DEFAULT NULL COLLATE 'utf8_hungarian_ci',
|
`description` VARCHAR(200) NULL DEFAULT NULL COLLATE 'utf8_hungarian_ci',
|
||||||
`image_url` CHAR(100) NULL DEFAULT NULL COLLATE 'utf8_hungarian_ci',
|
`image_url` CHAR(100) NULL DEFAULT NULL COLLATE 'utf8_hungarian_ci',
|
||||||
PRIMARY KEY (`device_id`) USING BTREE
|
PRIMARY KEY (`exercise_device_id`) USING BTREE
|
||||||
)
|
)
|
||||||
COLLATE='utf8_hungarian_ci'
|
COLLATE='utf8_hungarian_ci'
|
||||||
ENGINE=InnoDB
|
ENGINE=InnoDB
|
||||||
;
|
;
|
||||||
|
|
||||||
INSERT INTO `exercise_device` (`device_id`, `name`, `description`, `image_url`) VALUES (1, 'Weight', NULL, NULL);
|
INSERT INTO `exercise_device` (`exercise_device_id`, `name`, `description`, `image_url`) VALUES (1, 'Weight', NULL, NULL);
|
||||||
INSERT INTO `exercise_device` (`device_id`, `name`, `description`, `image_url`) VALUES (2, 'Own Weight', NULL, NULL);
|
INSERT INTO `exercise_device` (`exercise_device_id`, `name`, `description`, `image_url`) VALUES (2, 'Own Weight', NULL, NULL);
|
||||||
|
|
||||||
|
|
||||||
CREATE TABLE `exercise_device_translation` (
|
CREATE TABLE `exercise_device_translation` (
|
||||||
`translation_id` INT(11) NOT NULL AUTO_INCREMENT,
|
`translation_id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||||
`device_id` INT(11) NULL DEFAULT NULL,
|
`exercise_device_id` INT(11) NULL DEFAULT NULL,
|
||||||
`language_code` CHAR(2) NULL DEFAULT NULL COLLATE 'utf8_hungarian_ci',
|
`language_code` CHAR(2) NULL DEFAULT NULL COLLATE 'utf8_hungarian_ci',
|
||||||
`name` CHAR(100) NULL DEFAULT NULL COLLATE 'utf8_hungarian_ci',
|
`name` CHAR(100) NULL DEFAULT NULL COLLATE 'utf8_hungarian_ci',
|
||||||
PRIMARY KEY (`translation_id`) USING BTREE
|
PRIMARY KEY (`translation_id`) USING BTREE,
|
||||||
|
INDEX `exercise_device_id` (`exercise_device_id`) USING BTREE
|
||||||
)
|
)
|
||||||
COLLATE='utf8_hungarian_ci'
|
COLLATE='utf8_hungarian_ci'
|
||||||
ENGINE=InnoDB
|
ENGINE=InnoDB
|
||||||
@ -414,10 +415,10 @@ INSERT INTO `exercise_device_translation` (`translation_id`, `device_id`, `langu
|
|||||||
CREATE TABLE `exercise_type_device` (
|
CREATE TABLE `exercise_type_device` (
|
||||||
`exercise_type_device_id` INT(11) NOT NULL AUTO_INCREMENT,
|
`exercise_type_device_id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||||
`exercise_type_id` INT(11) NOT NULL DEFAULT '0',
|
`exercise_type_id` INT(11) NOT NULL DEFAULT '0',
|
||||||
`device_id` INT(11) NOT NULL DEFAULT '0',
|
`exercise_device_id` INT(11) NOT NULL DEFAULT '0',
|
||||||
PRIMARY KEY (`exercise_type_device_id`) USING BTREE,
|
PRIMARY KEY (`exercise_type_device_id`) USING BTREE,
|
||||||
INDEX `exercise_type_id` (`exercise_type_id`) USING BTREE,
|
INDEX `exercise_type_id` (`exercise_type_id`) USING BTREE,
|
||||||
INDEX `exercise_device_id` (`device_id`) USING BTREE
|
INDEX `exercise_device_id` (`exercise_device_id`) USING BTREE
|
||||||
)
|
)
|
||||||
COLLATE='utf8_hungarian_ci'
|
COLLATE='utf8_hungarian_ci'
|
||||||
ENGINE=InnoDB
|
ENGINE=InnoDB
|
||||||
@ -425,6 +426,17 @@ ENGINE=InnoDB
|
|||||||
|
|
||||||
INSERT INTO `exercise_type_device` (`exercise_type_device_id`, `exercise_type_id`, `exercise_device_id`) VALUES (1, 37, 1);
|
INSERT INTO `exercise_type_device` (`exercise_type_device_id`, `exercise_type_id`, `exercise_device_id`) VALUES (1, 37, 1);
|
||||||
|
|
||||||
|
CREATE TABLE `customer_exercise_device` (
|
||||||
|
`customer_exercise_device_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
`customer_id` INT(11) NOT NULL DEFAULT '0',
|
||||||
|
`exercise_device_id` INT(11) NOT NULL DEFAULT '0',
|
||||||
|
`date_add` DATETIME NULL DEFAULT NULL,
|
||||||
|
`favourite` TINYINT(4) NULL DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`customer_exercise_device_id`) USING BTREE
|
||||||
|
)
|
||||||
|
COLLATE='utf8_hungarian_ci'
|
||||||
|
ENGINE=InnoDB
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
/*!40000 ALTER TABLE `exercise_type` ENABLE KEYS */;
|
/*!40000 ALTER TABLE `exercise_type` ENABLE KEYS */;
|
||||||
|
@ -35,7 +35,7 @@ CREATE TABLE `exercise_type_device` (
|
|||||||
`exercise_device_id` INT(11) NOT NULL DEFAULT '0',
|
`exercise_device_id` INT(11) NOT NULL DEFAULT '0',
|
||||||
PRIMARY KEY (`exercise_type_device_id`) USING BTREE,
|
PRIMARY KEY (`exercise_type_device_id`) USING BTREE,
|
||||||
INDEX `exercise_type_id` (`exercise_type_id`) USING BTREE,
|
INDEX `exercise_type_id` (`exercise_type_id`) USING BTREE,
|
||||||
INDEX `device_id` (`device_id`) USING BTREE
|
INDEX `exercise_device_id` (`exercise_device_id`) USING BTREE
|
||||||
)
|
)
|
||||||
COLLATE='utf8_hungarian_ci'
|
COLLATE='utf8_hungarian_ci'
|
||||||
ENGINE=InnoDB
|
ENGINE=InnoDB
|
||||||
|
27
data/db/update_1_0_15.sql
Normal file
27
data/db/update_1_0_15.sql
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
CREATE TABLE `customer_exercise_device` (
|
||||||
|
`customer_exercise_device_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
`customer_id` INT(11) NOT NULL DEFAULT '0',
|
||||||
|
`exercise_device_id` INT(11) NOT NULL DEFAULT '0',
|
||||||
|
`date_add` DATETIME NULL DEFAULT NULL,
|
||||||
|
`favourite` TINYINT(4) NULL DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`customer_exercise_device_id`) USING BTREE
|
||||||
|
)
|
||||||
|
COLLATE='utf8_hungarian_ci'
|
||||||
|
ENGINE=InnoDB
|
||||||
|
;
|
||||||
|
|
||||||
|
INSERT INTO `customer_exercise_device` (`customer_exercise_device_id`, `customer_id`, `exercise_device_id`, `date_add`, `favourite`) VALUES (1, 90, 1, NULL, NULL);
|
||||||
|
INSERT INTO `customer_exercise_device` (`customer_exercise_device_id`, `customer_id`, `exercise_device_id`, `date_add`, `favourite`) VALUES (2, 90, 2, NULL, NULL);
|
||||||
|
|
||||||
|
ALTER TABLE `exercise_device`
|
||||||
|
CHANGE COLUMN `device_id` `exercise_device_id` INT(11) NOT NULL AUTO_INCREMENT FIRST,
|
||||||
|
DROP PRIMARY KEY,
|
||||||
|
ADD PRIMARY KEY (`exercise_device_id`) USING BTREE;
|
||||||
|
|
||||||
|
ALTER TABLE `exercise_device_translation`
|
||||||
|
CHANGE COLUMN `device_id` `exercise_device_id` INT(11) NULL DEFAULT NULL AFTER `translation_id`;
|
||||||
|
|
||||||
|
ALTER TABLE `exercise_device_translation`
|
||||||
|
ADD INDEX `exercise_device_id` (`exercise_device_id`);
|
||||||
|
|
||||||
|
UPDATE configuration set config_value = "1.0.15", date_change=CURRENT_DATE WHERE config_key = "db_version";
|
@ -103,4 +103,10 @@ class ControllerAspect {
|
|||||||
Singleton.checkDBUpdate(configurationRepository, properties)
|
Singleton.checkDBUpdate(configurationRepository, properties)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Before("execution(* com.aitrainer.api.controller.ExerciseDeviceController.*(..))")
|
||||||
|
fun exerciseDeviceControllerAspect(joinPoint: JoinPoint) {
|
||||||
|
println("exerciseDevice controller")
|
||||||
|
Singleton.checkDBUpdate(configurationRepository, properties)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -2,6 +2,7 @@ package com.aitrainer.api.controller
|
|||||||
|
|
||||||
import com.aitrainer.api.model.Customer
|
import com.aitrainer.api.model.Customer
|
||||||
import com.aitrainer.api.model.User
|
import com.aitrainer.api.model.User
|
||||||
|
import com.aitrainer.api.repository.CustomerExerciseDeviceRepository
|
||||||
import com.aitrainer.api.service.ServiceBeans
|
import com.aitrainer.api.service.ServiceBeans
|
||||||
import com.aitrainer.api.repository.CustomerRepository
|
import com.aitrainer.api.repository.CustomerRepository
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
@ -10,13 +11,13 @@ import org.springframework.http.HttpHeaders
|
|||||||
import org.springframework.http.ResponseEntity
|
import org.springframework.http.ResponseEntity
|
||||||
import org.springframework.security.access.annotation.Secured
|
import org.springframework.security.access.annotation.Secured
|
||||||
import org.springframework.web.bind.annotation.*
|
import org.springframework.web.bind.annotation.*
|
||||||
import java.util.*
|
|
||||||
import javax.validation.Valid
|
import javax.validation.Valid
|
||||||
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api")
|
@RequestMapping("/api")
|
||||||
class CustomerController ( private val customerRepository: CustomerRepository ) {
|
class CustomerController ( private val customerRepository: CustomerRepository,
|
||||||
|
private val customerExerciseDeviceRepository: CustomerExerciseDeviceRepository ) {
|
||||||
private val logger = LoggerFactory.getLogger(javaClass)
|
private val logger = LoggerFactory.getLogger(javaClass)
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -35,15 +36,22 @@ class CustomerController ( private val customerRepository: CustomerRepository )
|
|||||||
@Secured
|
@Secured
|
||||||
@GetMapping("/customers/{id}")
|
@GetMapping("/customers/{id}")
|
||||||
fun getCustomerById(@PathVariable(value = "id") customerId: Long, @RequestHeader headers: HttpHeaders): ResponseEntity<Customer> {
|
fun getCustomerById(@PathVariable(value = "id") customerId: Long, @RequestHeader headers: HttpHeaders): ResponseEntity<Customer> {
|
||||||
return customerRepository.findById(customerId).map { customer ->
|
val customer: Customer? = customerRepository.findById(customerId).orElse(null)
|
||||||
ResponseEntity.ok(customer)
|
if ( customer != null) {
|
||||||
}.orElse(ResponseEntity.notFound().build())
|
val list = customerExerciseDeviceRepository.findByCustomerId(customer.customerId)
|
||||||
|
customer.exerciseDevices = list
|
||||||
|
}
|
||||||
|
return if (customer == null) ResponseEntity.notFound().build() else ResponseEntity.ok().body(customer)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Secured
|
@Secured
|
||||||
@GetMapping("/customers/find_by_firebaseuid/{uid}")
|
@GetMapping("/customers/find_by_firebaseuid/{uid}")
|
||||||
fun getCustomerByFirebaseUid(@PathVariable(value = "uid") firebaseUid: String): ResponseEntity<Customer> {
|
fun getCustomerByFirebaseUid(@PathVariable(value = "uid") firebaseUid: String): ResponseEntity<Customer> {
|
||||||
val customer: Customer? = customerRepository.findByFirebaseUid(firebaseUid)
|
val customer: Customer? = customerRepository.findByFirebaseUid(firebaseUid)
|
||||||
|
if ( customer != null) {
|
||||||
|
val list = customerExerciseDeviceRepository.findByCustomerId(customer.customerId)
|
||||||
|
customer.exerciseDevices = list
|
||||||
|
}
|
||||||
return if (customer == null) ResponseEntity.notFound().build() else ResponseEntity.ok().body(customer)
|
return if (customer == null) ResponseEntity.notFound().build() else ResponseEntity.ok().body(customer)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,6 +59,10 @@ class CustomerController ( private val customerRepository: CustomerRepository )
|
|||||||
@GetMapping("/customers/find_by_email/{email}")
|
@GetMapping("/customers/find_by_email/{email}")
|
||||||
fun getCustomerByEmail(@PathVariable(value = "email") email: String): ResponseEntity<Customer> {
|
fun getCustomerByEmail(@PathVariable(value = "email") email: String): ResponseEntity<Customer> {
|
||||||
val customer: Customer? = customerRepository.findByEmail(email)
|
val customer: Customer? = customerRepository.findByEmail(email)
|
||||||
|
if ( customer != null) {
|
||||||
|
val list = customerExerciseDeviceRepository.findByCustomerId(customer.customerId)
|
||||||
|
customer.exerciseDevices = list
|
||||||
|
}
|
||||||
return if (customer == null) ResponseEntity.notFound().build() else ResponseEntity.ok().body(customer)
|
return if (customer == null) ResponseEntity.notFound().build() else ResponseEntity.ok().body(customer)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,9 +76,9 @@ class CustomerController ( private val customerRepository: CustomerRepository )
|
|||||||
@GetMapping("/customers/trainees/{id}")
|
@GetMapping("/customers/trainees/{id}")
|
||||||
fun getCustomerListByTrainerId(@PathVariable(value = "id") trainerId: Long, @RequestHeader headers: HttpHeaders):
|
fun getCustomerListByTrainerId(@PathVariable(value = "id") trainerId: Long, @RequestHeader headers: HttpHeaders):
|
||||||
ResponseEntity<List<Customer>> {
|
ResponseEntity<List<Customer>> {
|
||||||
val list = customerRepository.findByTrainerId(trainerId)
|
val customerList: List<Customer> = customerRepository.findByTrainerId(trainerId)
|
||||||
|
|
||||||
return if (list.isEmpty()) ResponseEntity.notFound().build() else ResponseEntity.ok().body(list)
|
return if (customerList.isEmpty()) ResponseEntity.notFound().build() else ResponseEntity.ok().body(customerList)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Secured
|
@Secured
|
||||||
@ -101,8 +113,8 @@ class CustomerController ( private val customerRepository: CustomerRepository )
|
|||||||
birthYear = newCustomer.birthYear,
|
birthYear = newCustomer.birthYear,
|
||||||
fitnessLevel = newCustomer.fitnessLevel,
|
fitnessLevel = newCustomer.fitnessLevel,
|
||||||
bodyType = newCustomer.bodyType,
|
bodyType = newCustomer.bodyType,
|
||||||
goal = newCustomer.goal,
|
goal = newCustomer.goal
|
||||||
weight = newCustomer.weight
|
//weight = newCustomer.weight
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
updatedCustomer =
|
updatedCustomer =
|
||||||
@ -114,8 +126,8 @@ class CustomerController ( private val customerRepository: CustomerRepository )
|
|||||||
birthYear = newCustomer.birthYear,
|
birthYear = newCustomer.birthYear,
|
||||||
fitnessLevel = newCustomer.fitnessLevel,
|
fitnessLevel = newCustomer.fitnessLevel,
|
||||||
bodyType = newCustomer.bodyType,
|
bodyType = newCustomer.bodyType,
|
||||||
goal = newCustomer.goal,
|
goal = newCustomer.goal
|
||||||
weight = newCustomer.weight
|
//weight = newCustomer.weight
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
package com.aitrainer.api.model
|
package com.aitrainer.api.model
|
||||||
|
|
||||||
import javax.persistence.Entity
|
import org.hibernate.annotations.Fetch
|
||||||
import javax.persistence.GeneratedValue
|
import org.hibernate.annotations.FetchMode
|
||||||
import javax.persistence.GenerationType
|
import javax.persistence.*
|
||||||
import javax.persistence.Id
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
data class Customer (
|
data class Customer (
|
||||||
@ -21,7 +20,7 @@ data class Customer (
|
|||||||
var trainerId: Long = 0,
|
var trainerId: Long = 0,
|
||||||
var password: String? = "",
|
var password: String? = "",
|
||||||
var birthYear:Int = 0,
|
var birthYear:Int = 0,
|
||||||
var weight: Int = 0,
|
// var weight: Int = 0,
|
||||||
var goal: String? = null,
|
var goal: String? = null,
|
||||||
var fitnessLevel: String = "beginner",
|
var fitnessLevel: String = "beginner",
|
||||||
var bodyType: String? = null,
|
var bodyType: String? = null,
|
||||||
@ -29,4 +28,8 @@ data class Customer (
|
|||||||
|
|
||||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
|
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
var customerId: Long = 0
|
var customerId: Long = 0
|
||||||
)
|
) {
|
||||||
|
@OneToMany(cascade = [(CascadeType.ALL)], fetch = FetchType.EAGER, mappedBy = "customer")
|
||||||
|
@Fetch(value = FetchMode.SUBSELECT)
|
||||||
|
var exerciseDevices: List<CustomerExerciseDevice> = mutableListOf<CustomerExerciseDevice>()
|
||||||
|
}
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
package com.aitrainer.api.model
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||||
|
import org.hibernate.annotations.Fetch
|
||||||
|
import org.hibernate.annotations.FetchMode
|
||||||
|
import javax.persistence.*
|
||||||
|
import javax.validation.constraints.NotNull
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
data class CustomerExerciseDevice (
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
val customerExerciseDeviceId: Long = 0,
|
||||||
|
@get: NotNull var exerciseDeviceId: Long?,
|
||||||
|
//@get: NotNull var customerId: Long?,
|
||||||
|
@get: NotNull var favourite: Boolean?,
|
||||||
|
@get: NotNull var dateAdd: String? = null
|
||||||
|
|
||||||
|
) {
|
||||||
|
@ManyToOne(fetch = FetchType.EAGER, optional = false)
|
||||||
|
@JoinColumn(name = "customerId", nullable = false)
|
||||||
|
@JsonIgnore
|
||||||
|
val customer: Customer? = null
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,5 @@
|
|||||||
package com.aitrainer.api.model
|
package com.aitrainer.api.model
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
|
||||||
import org.hibernate.annotations.Fetch
|
import org.hibernate.annotations.Fetch
|
||||||
import org.hibernate.annotations.FetchMode
|
import org.hibernate.annotations.FetchMode
|
||||||
import javax.persistence.*
|
import javax.persistence.*
|
||||||
@ -10,7 +9,7 @@ import javax.validation.constraints.NotBlank
|
|||||||
data class ExerciseDevice (
|
data class ExerciseDevice (
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
val deviceId: Long = 0,
|
val exerciseDeviceId: Long = 0,
|
||||||
|
|
||||||
@get: NotBlank var name: String = "",
|
@get: NotBlank var name: String = "",
|
||||||
@get: NotBlank var description: String = "",
|
@get: NotBlank var description: String = "",
|
||||||
|
@ -16,7 +16,7 @@ data class ExerciseDeviceTranslation (
|
|||||||
|
|
||||||
) {
|
) {
|
||||||
@ManyToOne(fetch = FetchType.EAGER, optional = false)
|
@ManyToOne(fetch = FetchType.EAGER, optional = false)
|
||||||
@JoinColumn(name = "deviceId", nullable = false)
|
@JoinColumn(name = "exerciseDeviceId", nullable = false)
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
val exerciseDevice: ExerciseDevice? = null
|
val exerciseDevice: ExerciseDevice? = null
|
||||||
|
|
||||||
|
@ -32,8 +32,4 @@ data class ExerciseType(
|
|||||||
@Fetch(value = FetchMode.SUBSELECT)
|
@Fetch(value = FetchMode.SUBSELECT)
|
||||||
val translations: List<ExerciseTypeTranslation> = mutableListOf<ExerciseTypeTranslation>()
|
val translations: List<ExerciseTypeTranslation> = mutableListOf<ExerciseTypeTranslation>()
|
||||||
|
|
||||||
@OneToMany(cascade = [(CascadeType.ALL)], fetch = FetchType.EAGER, mappedBy = "exerciseType")
|
|
||||||
@Fetch(value = FetchMode.SUBSELECT)
|
|
||||||
val exerciseDevices: List<ExerciseTypeDevice> = mutableListOf<ExerciseTypeDevice>()
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.aitrainer.api.model
|
package com.aitrainer.api.model
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||||
import org.springframework.lang.NonNull
|
|
||||||
import javax.persistence.*
|
import javax.persistence.*
|
||||||
import javax.validation.constraints.NotBlank
|
import javax.validation.constraints.NotBlank
|
||||||
|
|
||||||
@ -11,7 +10,6 @@ data class ExerciseTypeTranslation (
|
|||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
val translationId: Long = 0,
|
val translationId: Long = 0,
|
||||||
|
|
||||||
//@get: NonNull var exerciseTypeId: Integer?,
|
|
||||||
@get: NotBlank var languageCode: String?,
|
@get: NotBlank var languageCode: String?,
|
||||||
@get: NotBlank var name: String = "",
|
@get: NotBlank var name: String = "",
|
||||||
@get: NotBlank var description: String = ""
|
@get: NotBlank var description: String = ""
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.aitrainer.api.repository
|
||||||
|
|
||||||
|
import com.aitrainer.api.model.CustomerExerciseDevice
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository
|
||||||
|
import org.springframework.data.jpa.repository.Query
|
||||||
|
import org.springframework.stereotype.Repository
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
interface CustomerExerciseDeviceRepository: JpaRepository<CustomerExerciseDevice, Long> {
|
||||||
|
@Query(" FROM CustomerExerciseDevice " +
|
||||||
|
" WHERE customer.customerId = :customerId"
|
||||||
|
)
|
||||||
|
fun findByCustomerId(customerId: Long): List<CustomerExerciseDevice>
|
||||||
|
}
|
@ -2,6 +2,7 @@ package com.aitrainer.api.repository
|
|||||||
|
|
||||||
import com.aitrainer.api.model.Customer
|
import com.aitrainer.api.model.Customer
|
||||||
import org.springframework.data.jpa.repository.JpaRepository
|
import org.springframework.data.jpa.repository.JpaRepository
|
||||||
|
import org.springframework.data.jpa.repository.Query
|
||||||
import org.springframework.stereotype.Repository
|
import org.springframework.stereotype.Repository
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
|
@ -8,7 +8,7 @@ import org.springframework.stereotype.Repository
|
|||||||
@Repository
|
@Repository
|
||||||
interface ExerciseDeviceRepository: JpaRepository<ExerciseDevice, Long> {
|
interface ExerciseDeviceRepository: JpaRepository<ExerciseDevice, Long> {
|
||||||
@Query("FROM ExerciseDevice as e " +
|
@Query("FROM ExerciseDevice as e " +
|
||||||
"LEFT JOIN ExerciseDeviceTranslation as t ON e.deviceId = t.exerciseDevice AND t.languageCode = 'hu' " +
|
"LEFT JOIN ExerciseDeviceTranslation as t ON e.exerciseDeviceId = t.exerciseDevice AND t.languageCode = 'hu' " +
|
||||||
"ORDER BY e.deviceId ")
|
"ORDER BY e.exerciseDeviceId ")
|
||||||
fun getExerciseDevices(): List<ExerciseDevice>
|
fun getExerciseDevices(): List<ExerciseDevice>
|
||||||
}
|
}
|
@ -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.14
|
application.version=1.0.15
|
||||||
|
|
||||||
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.14
|
application.version=1.0.15
|
||||||
|
|
||||||
jwt.secret=aitrainer
|
jwt.secret=aitrainer
|
@ -3,6 +3,7 @@ package com.aitrainer.api.test
|
|||||||
import com.aitrainer.api.controller.CustomerController
|
import com.aitrainer.api.controller.CustomerController
|
||||||
import com.aitrainer.api.model.Customer
|
import com.aitrainer.api.model.Customer
|
||||||
import com.aitrainer.api.model.User
|
import com.aitrainer.api.model.User
|
||||||
|
import com.aitrainer.api.repository.CustomerExerciseDeviceRepository
|
||||||
import com.aitrainer.api.repository.CustomerRepository
|
import com.aitrainer.api.repository.CustomerRepository
|
||||||
import com.aitrainer.api.service.ServiceBeans
|
import com.aitrainer.api.service.ServiceBeans
|
||||||
import org.junit.jupiter.api.BeforeAll
|
import org.junit.jupiter.api.BeforeAll
|
||||||
@ -30,6 +31,10 @@ class CustomerTests {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private lateinit var customerRepository: CustomerRepository
|
private lateinit var customerRepository: CustomerRepository
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private lateinit var customerExerciseDeviceRepository: CustomerExerciseDeviceRepository
|
||||||
|
|
||||||
private var insertedId: Long? = null
|
private var insertedId: Long? = null
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -37,6 +42,17 @@ class CustomerTests {
|
|||||||
val id: Long = 7
|
val id: Long = 7
|
||||||
val customer: Customer = customerRepository.findById( id ).orElse(null)
|
val customer: Customer = customerRepository.findById( id ).orElse(null)
|
||||||
assertEquals( customer.name, "Átlag 18 éves fiú")
|
assertEquals( customer.name, "Átlag 18 éves fiú")
|
||||||
|
|
||||||
|
val id2: Long = 90
|
||||||
|
val controller = CustomerController(customerRepository, customerExerciseDeviceRepository)
|
||||||
|
val response = controller.getCustomerById(id2, HttpHeaders.EMPTY)
|
||||||
|
|
||||||
|
val customer2: Customer = response.body as Customer
|
||||||
|
assertNotNull (customer2)
|
||||||
|
|
||||||
|
assertEquals(customer2.email, "sw@andio.biz")
|
||||||
|
assertEquals(customer2.exerciseDevices.size, 2)
|
||||||
|
assertEquals(customer2.exerciseDevices[0].exerciseDeviceId, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -45,6 +61,7 @@ class CustomerTests {
|
|||||||
val customers: List<Customer> = customerRepository.findByTrainerId( id )
|
val customers: List<Customer> = customerRepository.findByTrainerId( id )
|
||||||
assertEquals(customers.count(), 3)
|
assertEquals(customers.count(), 3)
|
||||||
assertEquals( customers[0].name, "Átlag 13 éves fiú")
|
assertEquals( customers[0].name, "Átlag 13 éves fiú")
|
||||||
|
assertEquals(customers[0].exerciseDevices.size, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -62,7 +79,7 @@ class CustomerTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun testUpdate( customerId: Long ) {
|
fun testUpdate( customerId: Long ) {
|
||||||
val id: Long? = customerId
|
val id: Long = customerId
|
||||||
assertNotNull(id)
|
assertNotNull(id)
|
||||||
|
|
||||||
val updatedCustomer: Customer = customerRepository.findById( id ).orElse(null)
|
val updatedCustomer: Customer = customerRepository.findById( id ).orElse(null)
|
||||||
@ -114,15 +131,15 @@ class CustomerTests {
|
|||||||
customer.admin = 1
|
customer.admin = 1
|
||||||
customer.sex = "m"
|
customer.sex = "m"
|
||||||
customer.fitnessLevel = "intermediate"
|
customer.fitnessLevel = "intermediate"
|
||||||
customer.weight = 79
|
//customer.weight = 79
|
||||||
customer.birthYear = 1972
|
customer.birthYear = 1972
|
||||||
|
|
||||||
val customerController = CustomerController(customerRepository)
|
val customerController = CustomerController(customerRepository, customerExerciseDeviceRepository)
|
||||||
var response: ResponseEntity<*> = customerController.updateCustomerById(id, customer, HttpHeaders.readOnlyHttpHeaders(HttpHeaders.EMPTY) )
|
var response: ResponseEntity<*> = customerController.updateCustomerById(id, customer, HttpHeaders.readOnlyHttpHeaders(HttpHeaders.EMPTY) )
|
||||||
print ("body " + response.body)
|
print ("body " + response.body)
|
||||||
var newCustomer: Customer? = response.body as Customer
|
var newCustomer: Customer? = response.body as Customer
|
||||||
assertEquals(response.statusCode, HttpStatus.OK)
|
assertEquals(response.statusCode, HttpStatus.OK)
|
||||||
assertEquals(newCustomer?.weight, 79)
|
//assertEquals(newCustomer?.weight, 79)
|
||||||
assertEquals(newCustomer?.password, "123456789")
|
assertEquals(newCustomer?.password, "123456789")
|
||||||
assertEquals(newCustomer?.firstname, "Tib")
|
assertEquals(newCustomer?.firstname, "Tib")
|
||||||
|
|
||||||
@ -157,21 +174,19 @@ class CustomerTests {
|
|||||||
password = user.password
|
password = user.password
|
||||||
firebaseUid = user.firebaseUid
|
firebaseUid = user.firebaseUid
|
||||||
}
|
}
|
||||||
val customerController = CustomerController(customerRepository)
|
val customerController = CustomerController(customerRepository,customerExerciseDeviceRepository)
|
||||||
customerController.serviceBeans = serviceBean
|
customerController.serviceBeans = serviceBean
|
||||||
var response: ResponseEntity<*> = customerController.registration(json)
|
var response: ResponseEntity<*> = customerController.registration(json)
|
||||||
print("body " + response.body)
|
print("body " + response.body)
|
||||||
val newCustomer: Customer? = response.body as Customer
|
val newCustomer: Customer = response.body as Customer
|
||||||
assertEquals(response.statusCode, HttpStatus.OK)
|
assertEquals(response.statusCode, HttpStatus.OK)
|
||||||
assertEquals(newCustomer?.firebaseUid, "3Firebase8Uid")
|
assertEquals(newCustomer.firebaseUid, "3Firebase8Uid")
|
||||||
|
|
||||||
val json2 = "{\"username\":\"bosi2@example.com\",\"password\":\"934345\",\"firebaseUid\":\"3Firebase8Uid\"}"
|
val json2 = "{\"username\":\"bosi2@example.com\",\"password\":\"934345\",\"firebaseUid\":\"3Firebase8Uid\"}"
|
||||||
response = customerController.registration(json2)
|
response = customerController.registration(json2)
|
||||||
assertEquals(response.statusCode, HttpStatus.BAD_REQUEST)
|
assertEquals(response.statusCode, HttpStatus.BAD_REQUEST)
|
||||||
|
|
||||||
if ( newCustomer != null) {
|
customerRepository.delete(newCustomer)
|
||||||
customerRepository.delete(newCustomer)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -182,11 +197,11 @@ class CustomerTests {
|
|||||||
|
|
||||||
insertedId = savedCustomer.customerId
|
insertedId = savedCustomer.customerId
|
||||||
|
|
||||||
val customerController = CustomerController(customerRepository)
|
val customerController = CustomerController(customerRepository,customerExerciseDeviceRepository)
|
||||||
val response: ResponseEntity<*> = customerController.updateCustomerFirebaseUidById(insertedId!!, "3FirebusaeId4")
|
val response: ResponseEntity<*> = customerController.updateCustomerFirebaseUidById(insertedId!!, "3FirebusaeId4")
|
||||||
val newCustomer2: Customer? = response.body as Customer
|
val newCustomer2: Customer = response.body as Customer
|
||||||
assertEquals(response.statusCode, HttpStatus.OK)
|
assertEquals(response.statusCode, HttpStatus.OK)
|
||||||
assertEquals(newCustomer2!!.firebaseUid, "3FirebusaeId4")
|
assertEquals(newCustomer2.firebaseUid, "3FirebusaeId4")
|
||||||
assertEquals(newCustomer2.firstname, "Tibor")
|
assertEquals(newCustomer2.firstname, "Tibor")
|
||||||
assertEquals(newCustomer2.name, "Bossanyi2")
|
assertEquals(newCustomer2.name, "Bossanyi2")
|
||||||
assertEquals(newCustomer2.age, 48)
|
assertEquals(newCustomer2.age, 48)
|
||||||
@ -197,11 +212,11 @@ class CustomerTests {
|
|||||||
@Test
|
@Test
|
||||||
fun testGetCustomerByFirebaseUid() {
|
fun testGetCustomerByFirebaseUid() {
|
||||||
val uid = "3FirebaseU1d"
|
val uid = "3FirebaseU1d"
|
||||||
val customerController = CustomerController(customerRepository)
|
val customerController = CustomerController(customerRepository,customerExerciseDeviceRepository)
|
||||||
val response: ResponseEntity<*> = customerController.getCustomerByFirebaseUid(uid)
|
val response: ResponseEntity<*> = customerController.getCustomerByFirebaseUid(uid)
|
||||||
assertEquals(response.statusCode, HttpStatus.OK)
|
assertEquals(response.statusCode, HttpStatus.OK)
|
||||||
val newCustomer: Customer? = response.body as Customer
|
val newCustomer: Customer = response.body as Customer
|
||||||
assertEquals(newCustomer!!.name, "Bos")
|
assertEquals(newCustomer.name, "Bos")
|
||||||
assertEquals(newCustomer.email, "sw2@andio.biz")
|
assertEquals(newCustomer.email, "sw2@andio.biz")
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -209,13 +224,16 @@ class CustomerTests {
|
|||||||
@Test
|
@Test
|
||||||
fun testGetCustomerByEmail() {
|
fun testGetCustomerByEmail() {
|
||||||
val email = "sw2@andio.biz"
|
val email = "sw2@andio.biz"
|
||||||
val customerController = CustomerController(customerRepository)
|
val customerController = CustomerController(customerRepository,customerExerciseDeviceRepository)
|
||||||
val response: ResponseEntity<*> = customerController.getCustomerByEmail(email)
|
val response: ResponseEntity<*> = customerController.getCustomerByEmail(email)
|
||||||
assertEquals(response.statusCode, HttpStatus.OK)
|
assertEquals(response.statusCode, HttpStatus.OK)
|
||||||
val newCustomer: Customer? = response.body as Customer
|
|
||||||
assertEquals(newCustomer!!.name, "Bos")
|
val newCustomer: Customer = response.body as Customer
|
||||||
|
|
||||||
|
assertEquals(newCustomer.name, "Bos")
|
||||||
assertEquals(newCustomer.email, "sw2@andio.biz")
|
assertEquals(newCustomer.email, "sw2@andio.biz")
|
||||||
assertEquals(newCustomer.firebaseUid, "3FirebaseU1d")
|
assertEquals(newCustomer.firebaseUid, "3FirebaseU1d")
|
||||||
|
assertEquals(newCustomer.exerciseDevices.size, 0)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ class ExerciseDeviceTest {
|
|||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testGetProperties() {
|
fun testGetExerciseDevices() {
|
||||||
val controller = ExerciseDeviceController(exerciseDeviceRepository )
|
val controller = ExerciseDeviceController(exerciseDeviceRepository )
|
||||||
val response = controller.getDevicesWithTranslation()
|
val response = controller.getDevicesWithTranslation()
|
||||||
|
|
||||||
|
@ -73,7 +73,6 @@ class ExerciseTypeTest {
|
|||||||
assertEquals(exerciseType.name, "Chest Press")
|
assertEquals(exerciseType.name, "Chest Press")
|
||||||
assertEquals(exerciseType.images[0].url, "images/2.2.1.1.chestpress.png")
|
assertEquals(exerciseType.images[0].url, "images/2.2.1.1.chestpress.png")
|
||||||
assertEquals(responseEntity.body!![2].translations[0].name, "Tricepsz")
|
assertEquals(responseEntity.body!![2].translations[0].name, "Tricepsz")
|
||||||
assertEquals(exerciseType.exerciseDevices[0].exerciseDeviceId, 1)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user