Merge branch 'tibor' into 'master'

Tibor

See merge request bossanyit/aitrainer_server!8
This commit is contained in:
Bossanyi Tibor 2020-05-12 14:36:18 +00:00
commit 0a6654003c
5 changed files with 18 additions and 8 deletions

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")