API 1.0.31 sports
This commit is contained in:
@@ -111,6 +111,12 @@ class CustomerController ( private val customerRepository: CustomerRepository) {
|
||||
if (newCustomer.dataPolicyAllowed != null) {
|
||||
updatedCustomer.dataPolicyAllowed = newCustomer.dataPolicyAllowed
|
||||
}
|
||||
if (newCustomer.sportId != null) {
|
||||
updatedCustomer.sportId = newCustomer.sportId
|
||||
}
|
||||
if (newCustomer.emailSubscription != null) {
|
||||
updatedCustomer.emailSubscription = newCustomer.emailSubscription
|
||||
}
|
||||
updatedCustomer.sex = newCustomer.sex
|
||||
updatedCustomer.birthYear = newCustomer.birthYear
|
||||
updatedCustomer.fitnessLevel = newCustomer.fitnessLevel
|
||||
|
||||
@@ -20,7 +20,8 @@ class PackageController(private val exerciseAbilityRepository: ExerciseAbilityRe
|
||||
private val exerciseDeviceRepository: ExerciseDeviceRepository,
|
||||
private val exerciseTreeParentsRepository: ExerciseTreeParentsRepository,
|
||||
private val exercisePlanTemplateRepository: ExercisePlanTemplateRepository,
|
||||
private val evaluationRepository: EvaluationRepository
|
||||
private val evaluationRepository: EvaluationRepository,
|
||||
private val sportRepository: SportRepository
|
||||
) {
|
||||
private val logger = LoggerFactory.getLogger(javaClass)
|
||||
|
||||
@@ -59,6 +60,8 @@ class PackageController(private val exerciseAbilityRepository: ExerciseAbilityRe
|
||||
val listEvaluations = evaluationRepository.findAll()
|
||||
val listEvaluationJson: String = gson.toJson(listEvaluations)
|
||||
|
||||
val listSports = sportRepository.getSports()
|
||||
val listSportsJson: String = gson.toJson((listSports))
|
||||
|
||||
val packageJson: String =
|
||||
getClassRecord(ExerciseDevice::class.simpleName, listDevicesJson) +
|
||||
@@ -69,7 +72,8 @@ class PackageController(private val exerciseAbilityRepository: ExerciseAbilityRe
|
||||
"|||" + getClassRecord(ExerciseAbility::class.simpleName, listExerciseAbilityJson) +
|
||||
"|||" + getClassRecord(ExerciseTreeParents::class.simpleName, listExerciseTreeParentsJson) +
|
||||
"|||" + getClassRecord(ExercisePlanTemplate::class.simpleName, listPlanTemplateJson) +
|
||||
"|||" + getClassRecord(Evaluation::class.simpleName, listEvaluationJson)
|
||||
"|||" + getClassRecord(Evaluation::class.simpleName, listEvaluationJson) +
|
||||
"|||" + getClassRecord(Sport::class.simpleName, listSportsJson)
|
||||
|
||||
return if (packageJson.isEmpty()) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(packageJson)
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.aitrainer.api.controller
|
||||
|
||||
import com.aitrainer.api.model.Sport
|
||||
import com.aitrainer.api.repository.SportRepository
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
class SportController(private val sportRepository: SportRepository) {
|
||||
private val logger = LoggerFactory.getLogger(javaClass)
|
||||
|
||||
@GetMapping("/sports")
|
||||
fun getSportsWithTranslation(): ResponseEntity<List<Sport>> {
|
||||
val list = sportRepository.getSports()
|
||||
|
||||
logger.info(" -- Get All sports $list")
|
||||
return if (list.isEmpty()) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(list)
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,8 @@ data class Customer (
|
||||
@Expose var fitnessLevel: String = "beginner",
|
||||
@Expose var bodyType: String? = null,
|
||||
@Expose var firebaseUid: String? = null,
|
||||
@Expose var sportId: Int? = null,
|
||||
@Expose var emailSubscription: Int? = 0,
|
||||
|
||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Expose var customerId: Long = 0
|
||||
)
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.aitrainer.api.model
|
||||
|
||||
import com.google.gson.annotations.Expose
|
||||
import org.hibernate.annotations.Fetch
|
||||
import org.hibernate.annotations.FetchMode
|
||||
import org.springframework.lang.NonNull
|
||||
import javax.persistence.*
|
||||
|
||||
@Entity
|
||||
data class Sport (
|
||||
@Expose @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @get: NonNull var sportId: Long = 0,
|
||||
@Expose @get: NonNull var name: String = "",
|
||||
) {
|
||||
@OneToMany(cascade = [(CascadeType.ALL)], fetch = FetchType.EAGER, mappedBy = "sport")
|
||||
@Fetch(value = FetchMode.SUBSELECT)
|
||||
@Expose val translations: List<SportTranslation> = mutableListOf<SportTranslation>().toList()
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.aitrainer.api.model
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||
import com.google.gson.annotations.Expose
|
||||
import javax.persistence.*
|
||||
import javax.validation.constraints.NotBlank
|
||||
|
||||
@Entity
|
||||
data class SportTranslation (
|
||||
@Expose @Id @GeneratedValue(strategy = GenerationType.IDENTITY) val translationId: Long = 0,
|
||||
|
||||
@Expose @get: NotBlank var languageCode: String?,
|
||||
@Expose @get: NotBlank var sportName: String = "",
|
||||
|
||||
) {
|
||||
@ManyToOne(fetch = FetchType.LAZY, optional = false)
|
||||
@JoinColumn(name = "sportId", nullable = false)
|
||||
@JsonIgnore
|
||||
val sport: Sport? = null
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.aitrainer.api.repository
|
||||
|
||||
import com.aitrainer.api.model.Sport
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.data.jpa.repository.Query
|
||||
import org.springframework.stereotype.Repository
|
||||
|
||||
@Repository
|
||||
interface SportRepository: JpaRepository<Sport, Long> {
|
||||
@Query("FROM Sport as e " +
|
||||
"LEFT JOIN SportTranslation as t ON e.sportId = t.sport AND t.languageCode = 'hu' "+
|
||||
"ORDER BY name")
|
||||
fun getSports(): List<Sport>
|
||||
}
|
||||
@@ -17,6 +17,6 @@ logging.config=classpath:logback-spring.xml
|
||||
logging.file=logs
|
||||
|
||||
# if the database structure has been changed, increment this version number
|
||||
application.version=1.0.30
|
||||
application.version=1.0.31
|
||||
|
||||
jwt.secret=aitrainer
|
||||
@@ -17,6 +17,6 @@ logging.config=classpath:logback-spring.xml
|
||||
logging.file=logs
|
||||
|
||||
# if the database structure has been changed, increment this version number
|
||||
application.version=1.0.30
|
||||
application.version=1.0.31
|
||||
|
||||
jwt.secret=aitrainer
|
||||
@@ -35,6 +35,8 @@ class AppPackageTest {
|
||||
private lateinit var exercisePlanTemplateRepository: ExercisePlanTemplateRepository
|
||||
@Autowired
|
||||
private lateinit var evaluationRepository: EvaluationRepository
|
||||
@Autowired
|
||||
private lateinit var sportRepository: SportRepository
|
||||
|
||||
@Test
|
||||
fun testAppPackage() {
|
||||
@@ -49,7 +51,8 @@ class AppPackageTest {
|
||||
exerciseDeviceRepository,
|
||||
exerciseTreeParentsRepository,
|
||||
exercisePlanTemplateRepository,
|
||||
evaluationRepository
|
||||
evaluationRepository,
|
||||
sportRepository
|
||||
)
|
||||
val response: ResponseEntity<*> = controller.getPackageData()
|
||||
|
||||
@@ -112,6 +115,16 @@ class AppPackageTest {
|
||||
assertEquals(evaluations[0].name, "PushUps")
|
||||
assertEquals(evaluations[0].attributes.size, 18)
|
||||
assertEquals(evaluations[0].attributes[1].name, "Fekvőtámasz_ffi_17-19_fair")
|
||||
} else if (record[0] == Sport::class.simpleName) {
|
||||
val sportJson: String = record[1]
|
||||
val type = object : TypeToken<List<Sport?>?>() {}.type
|
||||
val sports: List<Sport> = gson.fromJson(sportJson, type)
|
||||
assertEquals(sports.size, 4)
|
||||
assertEquals(sports[1].name, "Football")
|
||||
assertEquals(sports[1].translations[0].sportName, "Labdarúgás")
|
||||
assertEquals(sports[2].name, "Footgolf")
|
||||
assertEquals(sports[2].translations[0].sportName, "Footgolf")
|
||||
assertEquals(sports[3].translations[0].sportName, "Tenisz")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -112,6 +112,8 @@ class CustomerTests {
|
||||
customer.fitnessLevel = "advanced"
|
||||
customer.dateChange = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"))
|
||||
customer.email = "mr@aitrainer.app"
|
||||
customer.emailSubscription = 1
|
||||
customer.sportId = 2
|
||||
|
||||
|
||||
var updatedCustomer = customerRepository.save(customer)
|
||||
@@ -121,6 +123,8 @@ class CustomerTests {
|
||||
assertTrue(customer.dateChange != null)
|
||||
assertEquals(updatedCustomer.email, "mr@aitrainer.app")
|
||||
assertEquals(updatedCustomer.dataPolicyAllowed, 1)
|
||||
assertEquals(updatedCustomer.emailSubscription, 1)
|
||||
assertEquals(updatedCustomer.sportId, 2)
|
||||
|
||||
|
||||
customer.email = "sw@andio.biz"
|
||||
@@ -168,6 +172,7 @@ class CustomerTests {
|
||||
customer.firstname = "Kakadu"
|
||||
customer.name = "Bos"
|
||||
customer.email = "mr@aitrainer.app"
|
||||
customer.sportId = 4
|
||||
response = customerController.updateCustomerById(id, customer, HttpHeaders.readOnlyHttpHeaders(HttpHeaders.EMPTY) )
|
||||
assertEquals(response.statusCode, HttpStatus.OK)
|
||||
newCustomer = response.body as Customer
|
||||
@@ -176,10 +181,12 @@ class CustomerTests {
|
||||
assertEquals(newCustomer.name, "Bos")
|
||||
assertEquals(newCustomer.email, "mr@aitrainer.app")
|
||||
assertEquals(newCustomer.dataPolicyAllowed, 1)
|
||||
assertEquals(newCustomer.sportId, 4)
|
||||
|
||||
val customer2 = newCustomer.copy()
|
||||
customer2.email = "sw2@andio.biz"
|
||||
customer2.customerId = 103
|
||||
customer2.sportId = 0
|
||||
val updatedCustomer = customerRepository.save(customer2)
|
||||
assertEquals(updatedCustomer.email, "sw2@andio.biz")
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.aitrainer.api.test
|
||||
|
||||
import com.aitrainer.api.controller.SportController
|
||||
import com.aitrainer.api.repository.SportRepository
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@SpringBootTest
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
class SportTest {
|
||||
|
||||
@Autowired
|
||||
private lateinit var sportRepository: SportRepository
|
||||
|
||||
|
||||
@Test
|
||||
fun testGetSports() {
|
||||
val controller = SportController(sportRepository )
|
||||
val response = controller.getSportsWithTranslation()
|
||||
|
||||
val sports = response.body
|
||||
|
||||
assertTrue(sports is List)
|
||||
assertTrue(sports.isNotEmpty())
|
||||
assertEquals(sports.size, 4)
|
||||
assertEquals(sports[1].name, "Football")
|
||||
assertEquals(sports[1].translations[0].sportName, "Labdarúgás")
|
||||
assertEquals(sports[2].name, "Footgolf")
|
||||
assertEquals(sports[2].translations[0].sportName, "Footgolf")
|
||||
assertEquals(sports[3].translations[0].sportName, "Tenisz")
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user