Exercise.getAllByCustomerId fix, HTTP test

This commit is contained in:
Bossanyi Tibor 2020-05-12 16:14:52 +02:00
parent 5a4dda676b
commit 17183bda07
6 changed files with 19 additions and 9 deletions

View File

@ -43,7 +43,7 @@ connect:
script:
- apt-get update && apt-get --assume-yes install mysql-client
- mysql --user=root --password="$MYSQL_ROOT_PASSWORD" --host=mysql -e "use $MYSQL_DATABASE; show tables;"
- mysql --user=root --password="$MYSQL_ROOT_PASSWORD" --host=mysql -e "use $MYSQL_DATABASE; DROP table CUSTOMER; DROP table EXERCISES; DROP table EXERCISE_TYPE; DROP table exercise_ages;"
- mysql --user=root --password="$MYSQL_ROOT_PASSWORD" --host=mysql -e "use $MYSQL_DATABASE; DROP table customer; DROP table exercises; DROP table exercise_type; DROP table exercise_ages;"
- mysql --user=root --password="$MYSQL_ROOT_PASSWORD" --host=mysql < "data/db/install.sql" #first time
test:

View File

@ -6,10 +6,19 @@ import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
import javax.validation.Valid
@RestController
@RequestMapping("/api")
class ExerciesController(private val exercisesRepository: ExercisesRepository) {
@GetMapping("/exercises/{id}")
fun getExerciseById(@PathVariable(value = "id") exerciseId: Long): ResponseEntity<Exercises> {
return exercisesRepository.findById(exerciseId).map { exercise ->
ResponseEntity.ok(exercise)
}.orElse(ResponseEntity.notFound().build())
}
@GetMapping("/exercises/customer/{id}")
fun getAllExersicesByCustomerId(customerId: Long): List<Exercises> =
fun getAllExersicesByCustomerId(@PathVariable( value = "id" ) customerId: Long? ): List<Exercises> =
exercisesRepository.getAllByCustomerId(customerId)
@PostMapping("/exercises")

View File

@ -6,5 +6,5 @@ import org.springframework.stereotype.Repository
@Repository
interface ExercisesRepository : JpaRepository<Exercises, Long> {
fun getAllByCustomerId( customerId: Long ):List<Exercises>
fun getAllByCustomerId( customerId: Long? ):List<Exercises>
}

View File

@ -5,6 +5,6 @@ import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.query.Param
interface ExerciseService {
@Query("FROM Exercises WHERE customer_id = :customerId")
fun findAllByCustomerId( @Param("customerId") customerId: Long): List<Exercises>
@Query("FROM exercises WHERE customer_id = :customerId")
fun findAllByCustomerId( @Param("customerId") customerId: Long? ): List<Exercises>
}

View File

@ -22,9 +22,9 @@ class AitrainerDBTest(configuration: ApplicationConfiguration) {
this.username = this.conf.username.orEmpty()
this.password = this.conf.password.orEmpty()
this.datasourceUrl = this.conf.url.orEmpty()
assertTrue ("username should not be empty", { this.username.isNotEmpty() })
assertTrue ("password should not be empty", { this.password.isNotEmpty() })
assertTrue ("url should not be empty", { this.datasourceUrl.isNotEmpty() })
assertTrue ("username should not be empty") { this.username.isNotEmpty() }
assertTrue ("password should not be empty") { this.password.isNotEmpty() }
assertTrue ("url should not be empty") { this.datasourceUrl.isNotEmpty() }
this.getConnection()

View File

@ -12,6 +12,7 @@ class ExerciseTypeTest {
@Autowired
private lateinit var exerciseTypeRepository: ExerciseTypeRepository
private var insertedId: Long = 0
@Test
fun testGet() {
@ -24,7 +25,7 @@ class ExerciseTypeTest {
val savedEx: ExerciseType = exerciseTypeRepository.save(newEx)
assertEquals(savedEx.name, "Húzodszkodás")
val insertedId: Long = savedEx.exerciseTypeId
this.insertedId = savedEx.exerciseTypeId
val extype: ExerciseType = exerciseTypeRepository.findById( savedEx.exerciseTypeId ).orElse(null)
assertEquals( extype.name, "Húzodszkodás")