API 1.0.30 CustomerActivity, Sort ExercisePlanTemplateDetail.sort

This commit is contained in:
Bossanyi Tibor
2021-04-14 21:54:09 +02:00
parent b1dc434e96
commit f1aee3904f
20 changed files with 281 additions and 236 deletions
@@ -28,12 +28,6 @@ class ControllerAspect {
Singleton.checkDBUpdate(configurationRepository, properties)
}
@Before("execution(* com.aitrainer.api.controller.CustomerInformationController.*(..))")
fun customerInformationControllerAspect(joinPoint: JoinPoint) {
println("customer information controller")
Singleton.checkDBUpdate(configurationRepository, properties)
}
@Before("execution(* com.aitrainer.api.controller.CustomerPropertyController.*(..))")
fun customerPropertyControllerAspect(joinPoint: JoinPoint) {
println("customer property controller")
@@ -0,0 +1,21 @@
package com.aitrainer.api.controller
import com.aitrainer.api.model.CustomerActivity
import com.aitrainer.api.repository.CustomerActivityRepository
import org.slf4j.LoggerFactory
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
import javax.validation.Valid
@RestController
@RequestMapping("/api")
class CustomerActivityController(private val customerActivityRepository: CustomerActivityRepository) {
private val logger = LoggerFactory.getLogger(javaClass)
@PostMapping("/customer_activity")
fun insertActivity(@Valid @RequestBody customerActivity: CustomerActivity): ResponseEntity<CustomerActivity> {
val newActivity = customerActivityRepository.save(customerActivity)
logger.info("Create new activity: $newActivity")
return ResponseEntity.ok().body(newActivity)
}
}
@@ -92,34 +92,31 @@ class CustomerController ( private val customerRepository: CustomerRepository) {
val returnCustomer: Customer = customerRepository.findById(customerId).orElse(null)
?: return ResponseEntity.notFound().build()
val password: String? = newCustomer.password
val updatedCustomer: Customer
if ( password == null || password.isEmpty() ) {
updatedCustomer =
returnCustomer.copy(
name = newCustomer.name,
firstname = newCustomer.firstname,
sex = newCustomer.sex,
birthYear = newCustomer.birthYear,
fitnessLevel = newCustomer.fitnessLevel,
bodyType = newCustomer.bodyType,
goal = newCustomer.goal,
dateChange = newCustomer.dateChange
)
} else {
updatedCustomer =
returnCustomer.copy(
name = newCustomer.name,
firstname = newCustomer.firstname,
password = newCustomer.password,
sex = newCustomer.sex,
birthYear = newCustomer.birthYear,
fitnessLevel = newCustomer.fitnessLevel,
bodyType = newCustomer.bodyType,
goal = newCustomer.goal,
dateChange = newCustomer.dateChange
)
}
val updatedCustomer = returnCustomer.copy()
if (newCustomer.email != null) {
updatedCustomer.email = newCustomer.email
}
if (newCustomer.name != null) {
updatedCustomer.name = newCustomer.name
}
if (newCustomer.firstname != null) {
updatedCustomer.firstname = newCustomer.firstname
}
if (newCustomer.goal != null) {
updatedCustomer.goal = newCustomer.goal
}
if (newCustomer.dateChange != null) {
updatedCustomer.dateChange = newCustomer.dateChange
}
if (newCustomer.dataPolicyAllowed != null) {
updatedCustomer.dataPolicyAllowed = newCustomer.dataPolicyAllowed
}
updatedCustomer.sex = newCustomer.sex
updatedCustomer.birthYear = newCustomer.birthYear
updatedCustomer.fitnessLevel = newCustomer.fitnessLevel
return ResponseEntity.ok().body(customerRepository.save(updatedCustomer))
}
@@ -139,6 +136,9 @@ class CustomerController ( private val customerRepository: CustomerRepository) {
password = serviceBeans!!.passwordEncoder().encode(newUser.password)
firebaseUid = newUser.firebaseUid
dateAdd = nowFormatted
firstname = ""
name = ""
email = ""
}
val returnCustomer: Customer? = customerRepository.findByEmail(newUser.username).let {
@@ -1,21 +0,0 @@
package com.aitrainer.api.controller
import com.aitrainer.api.model.CustomerInformation
import com.aitrainer.api.repository.CustomerInformationRepository
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import java.time.LocalDateTime
@RestController
@RequestMapping("/api")
class CustomerInformationController( private val customerInformationRepository: CustomerInformationRepository ) {
@GetMapping("/customer_information")
fun getCustomerInformation(): List<CustomerInformation> {
val dateTime: String = LocalDateTime.now().toString()
return customerInformationRepository.findByDisplayBeginLessThanAndDisplayEndGreaterThan(dateTime, dateTime )
}
}
@@ -17,7 +17,8 @@ class CustomerPackageController( private val customerRepository: CustomerReposit
private val productTestRepository: ProductTestRepository,
private val purchaseRepository: PurchaseRepository,
private val customerPropertyRepository: CustomerPropertyRepository,
private val exerciseResultRepository: ExerciseResultRepository) {
private val exerciseResultRepository: ExerciseResultRepository,
private val customerActivityRepository: CustomerActivityRepository) {
@GetMapping("/app_customer_package/{id}")
fun getCustomerPackageData(@PathVariable(value = "id") customerId: Long): ResponseEntity<String> {
@@ -56,6 +57,9 @@ class CustomerPackageController( private val customerRepository: CustomerReposit
val listExerciseResult = exerciseResultRepository.getAllByCustomerId(customerId)
val listExerciseResultJson = gson.toJson(listExerciseResult)
val listActivityResult = customerActivityRepository.findByCustomerId(customerId)
val listActivityJson = gson.toJson(listActivityResult)
val packageJson: String =
getClassRecord(Customer::class.simpleName, customerJson) +
"|||" + getClassRecord(CustomerExerciseDevice::class.simpleName, listCustomerExerciseDeviceJson) +
@@ -64,7 +68,8 @@ class CustomerPackageController( private val customerRepository: CustomerReposit
"|||" + getClassRecord(Purchase::class.simpleName, listPurchaseJson) +
"|||" + getClassRecord(CustomerProperty::class.simpleName+"All", listCustomerPropertyAllJson) +
"|||" + getClassRecord(CustomerProperty::class.simpleName, listCustomerPropertyJson) +
"|||" + getClassRecord(ExerciseResult::class.simpleName, listExerciseResultJson)
"|||" + getClassRecord(ExerciseResult::class.simpleName, listExerciseResultJson+
"|||" + getClassRecord(CustomerActivity::class.simpleName, listActivityJson))
return if (packageJson.isEmpty()) ResponseEntity.notFound().build() else
ResponseEntity.ok().body(packageJson)
@@ -1,29 +1,30 @@
package com.aitrainer.api.model
import com.google.gson.annotations.Expose
import org.hibernate.annotations.Fetch
import org.hibernate.annotations.FetchMode
import javax.persistence.*
@Entity
data class Customer (
@Expose var name: String = "",
@Expose var firstname: String = "",
@Expose var email: String = "",
@Expose var name: String? = null,
@Expose var firstname: String? = null,
@Expose var email: String? = null,
@Expose var age: Int? = 0,
@Expose var sex: String = "m",
@Expose var active: String = "N",
@Expose var active: String = "Y",
@Expose var dateAdd: String? = null,
@Expose var dateChange: String? = null,
@Expose var dataPolicyAllowed: Int = 0,
@Expose var admin: Int = 0,
@Expose var trainer: Int = 0,
@Expose var trainerId: Long = 0,
@Expose var password: String? = "",
@Expose var dataPolicyAllowed: Int? = 1,
@Expose var admin: Boolean? = null,
@Expose var trainer: Boolean? = null,
@Expose var trainerId: Long? = null,
@Expose var password: String? = null,
@Expose var birthYear:Int = 0,
@Expose var goal: String? = null,
@Expose var fitnessLevel: String = "beginner",
@Expose var bodyType: String? = null,
@Expose var firebaseUid: String? = null,
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
@Expose var customerId: Long = 0
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Expose var customerId: Long = 0
)
@@ -0,0 +1,17 @@
package com.aitrainer.api.model
import com.fasterxml.jackson.annotation.JsonIgnore
import com.google.gson.annotations.Expose
import javax.persistence.*
import javax.validation.constraints.NotNull
@Entity
data class CustomerActivity (
@Expose @Id @GeneratedValue(strategy = GenerationType.IDENTITY) var activityId: Long = 0,
@Expose @get: NotNull var customerId: Long?,
@Expose @get: NotNull var type: String? = null,
@Expose @get: NotNull var dateAdd: String? = null,
@Expose @get: NotNull var skipped: Boolean?
)
@@ -1,21 +0,0 @@
package com.aitrainer.api.model
import javax.persistence.Entity
import javax.persistence.GeneratedValue
import javax.persistence.GenerationType
import javax.persistence.Id
import javax.validation.constraints.NotBlank
@Entity
class CustomerInformation (
@get: NotBlank var title: String = "",
var description: String = "",
var dateAdd: String? = null,
var displayBegin: String? = null,
var displayEnd: String? = null,
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val customerInformationId: Long = 0
)
@@ -13,7 +13,8 @@ data class ExercisePlanTemplateDetail (
@Expose @get: Null var serie: Int? = 0,
@Expose @get: Null var quantity: Double? = 0.0,
@Expose @get: Null var quantityUnitQuantity: Double? = 0.0,
@Expose @get: NonNull var restingTime: String? = null
@Expose @get: NonNull var restingTime: String? = null,
@Expose @get: Null var sort: Int? = 0,
) {
@@ -0,0 +1,15 @@
package com.aitrainer.api.repository
import com.aitrainer.api.model.CustomerActivity
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 CustomerActivityRepository: JpaRepository<CustomerActivity, Long> {
@Query(" FROM CustomerActivity " +
" WHERE customerId = :customerId"
)
fun findByCustomerId(customerId: Long): List<CustomerActivity>
}
@@ -1,11 +0,0 @@
package com.aitrainer.api.repository
import com.aitrainer.api.model.CustomerInformation
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository
@Repository
interface CustomerInformationRepository: JpaRepository<CustomerInformation, Long> {
fun findByDisplayBeginLessThanAndDisplayEndGreaterThan( dateTimeBegin: String, dateTimeEnd: String ):
List<CustomerInformation>
}