API 1.1 WT Club, add customer_membership

This commit is contained in:
Tibor Bossanyi
2023-02-05 09:35:17 +01:00
parent 564e749bc2
commit cf3abdaf01
15 changed files with 71 additions and 102 deletions
@@ -190,24 +190,26 @@ class CustomerController ( private val customerRepository: CustomerRepository) {
val signupResponse = firebase.signUp(newUser.email, genPassword)
?: return ResponseEntity.badRequest().body("Firebase exception ${firebase.error}")
val saving_customer = Customer()
val savingCustomer = Customer()
if ( serviceBeans == null ) {
serviceBeans = ServiceBeans()
}
with (saving_customer) {
with (savingCustomer) {
email = newUser.email
password = serviceBeans!!.passwordEncoder().encode(genPassword)
idToken = signupResponse.idToken
firebaseRegToken = signupResponse.idToken
firebaseUid = signupResponse.localId
dateAdd = nowFormatted
firstname = newUser.firstname
name = ""
goal = newUser.goal
fitnessLevel = newUser.fitnessLevel
birthYear = newUser.birthYear
sex = newUser.sex
}
val newCustomer = customerRepository.save(saving_customer)
val newCustomer = customerRepository.save(savingCustomer)
if ( newUser.weight != 0.0 ) {
val property = CustomerPropertyProperty()
@@ -225,13 +227,24 @@ class CustomerController ( private val customerRepository: CustomerRepository) {
with (property) {
propertyId = 2
propertyValue = newUser.height
dateAdd= nowFormatted
dateAdd = nowFormatted
goal = false
customer = newCustomer
}
newCustomer.properties.add(property)
}
val newMembershipId = newUser.membershipId
if ( newMembershipId != 0L) {
val membership = CustomerMembership()
with(membership) {
customer = newCustomer
membershipId = newMembershipId
startDate = nowFormatted
}
newCustomer.memberships.add(membership)
}
customerRepository.save(newCustomer)
// create email link
@@ -2,6 +2,7 @@ package com.aitrainer.api.controller
import com.aitrainer.api.model.CustomerMembership
import com.aitrainer.api.repository.CustomerMembershipRepository
import com.aitrainer.api.repository.CustomerRepository
import org.slf4j.LoggerFactory
import org.springframework.http.ResponseEntity
import org.springframework.security.access.annotation.Secured
@@ -10,7 +11,7 @@ import javax.validation.Valid
@RestController
@RequestMapping("/api")
class CustomerMembershipController(private val customerMembershipRepository: CustomerMembershipRepository) {
class CustomerMembershipController(private val customerMembershipRepository: CustomerMembershipRepository, private val customerRepository: CustomerRepository) {
private val logger = LoggerFactory.getLogger(javaClass)
@PostMapping("/customer_membership")
@@ -19,25 +20,12 @@ class CustomerMembershipController(private val customerMembershipRepository: Cus
return ResponseEntity.ok().body(customerMembershipRepository.save(customerMembership))
}
@Secured
@PostMapping("customer_membership/update/{id}")
fun updateCustomerMembership(@PathVariable(value = "id") membershipId: Long,
@Valid @RequestBody membershipToUpdate: CustomerMembership): ResponseEntity<CustomerMembership> {
val customerMembership = customerMembershipRepository.findById(membershipId).orElse(null)
?: return ResponseEntity.notFound().build()
val updatedCustomerMembership = customerMembership.copy(
trainingPlanId = membershipToUpdate.trainingPlanId,
days = membershipToUpdate.days,
)
return ResponseEntity.ok().body(customerMembershipRepository.save(updatedCustomerMembership))
}
@GetMapping("/customer_membership/{customer_id}")
fun getAllByCustomerId(@PathVariable(value = "customer_id") customerId: Long): ResponseEntity<List<CustomerMembership>> {
val customer = customerRepository.findByCustomerIdAndActive(customerId, "Y")
?: return ResponseEntity.notFound().build()
val membershipList: List<CustomerMembership> = customerMembershipRepository.findAllByCustomerId(customerId)
val membershipList: List<CustomerMembership> = customerMembershipRepository.findAllByCustomer(customer)
logger.info("Get all customer_membership by by customerId")
return if(membershipList.isNotEmpty())
@@ -47,7 +47,7 @@ class CustomerPackageController( private val customerRepository: CustomerReposit
val listTrainingPlan = customerTrainingPlanRepository.findAllByCustomerId(customerId)
val listTrainingPlanJson = gson.toJson(listTrainingPlan)
val listMembership = customerMembership.findAllByCustomerId(customerId)
val listMembership = customerMembership.findAllByCustomer(customer)
val listMembershipJson = gson.toJson(listMembership)
val packageJson: String =