Merge branch 'tibor' into 'master'
Tibor See merge request bossanyit/aitrainer_server!8
This commit is contained in:
commit
0a6654003c
@ -6,10 +6,19 @@ import org.springframework.http.ResponseEntity
|
|||||||
import org.springframework.web.bind.annotation.*
|
import org.springframework.web.bind.annotation.*
|
||||||
import javax.validation.Valid
|
import javax.validation.Valid
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api")
|
||||||
class ExerciesController(private val exercisesRepository: ExercisesRepository) {
|
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}")
|
@GetMapping("/exercises/customer/{id}")
|
||||||
fun getAllExersicesByCustomerId(customerId: Long): List<Exercises> =
|
fun getAllExersicesByCustomerId(@PathVariable( value = "id" ) customerId: Long? ): List<Exercises> =
|
||||||
exercisesRepository.getAllByCustomerId(customerId)
|
exercisesRepository.getAllByCustomerId(customerId)
|
||||||
|
|
||||||
@PostMapping("/exercises")
|
@PostMapping("/exercises")
|
||||||
|
@ -6,5 +6,5 @@ import org.springframework.stereotype.Repository
|
|||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
interface ExercisesRepository : JpaRepository<Exercises, Long> {
|
interface ExercisesRepository : JpaRepository<Exercises, Long> {
|
||||||
fun getAllByCustomerId( customerId: Long ):List<Exercises>
|
fun getAllByCustomerId( customerId: Long? ):List<Exercises>
|
||||||
}
|
}
|
@ -5,6 +5,6 @@ import org.springframework.data.jpa.repository.Query
|
|||||||
import org.springframework.data.repository.query.Param
|
import org.springframework.data.repository.query.Param
|
||||||
|
|
||||||
interface ExerciseService {
|
interface ExerciseService {
|
||||||
@Query("FROM Exercises WHERE customer_id = :customerId")
|
@Query("FROM exercises WHERE customer_id = :customerId")
|
||||||
fun findAllByCustomerId( @Param("customerId") customerId: Long): List<Exercises>
|
fun findAllByCustomerId( @Param("customerId") customerId: Long? ): List<Exercises>
|
||||||
}
|
}
|
@ -22,9 +22,9 @@ class AitrainerDBTest(configuration: ApplicationConfiguration) {
|
|||||||
this.username = this.conf.username.orEmpty()
|
this.username = this.conf.username.orEmpty()
|
||||||
this.password = this.conf.password.orEmpty()
|
this.password = this.conf.password.orEmpty()
|
||||||
this.datasourceUrl = this.conf.url.orEmpty()
|
this.datasourceUrl = this.conf.url.orEmpty()
|
||||||
assertTrue ("username should not be empty", { this.username.isNotEmpty() })
|
assertTrue ("username should not be empty") { this.username.isNotEmpty() }
|
||||||
assertTrue ("password should not be empty", { this.password.isNotEmpty() })
|
assertTrue ("password should not be empty") { this.password.isNotEmpty() }
|
||||||
assertTrue ("url should not be empty", { this.datasourceUrl.isNotEmpty() })
|
assertTrue ("url should not be empty") { this.datasourceUrl.isNotEmpty() }
|
||||||
|
|
||||||
this.getConnection()
|
this.getConnection()
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ class ExerciseTypeTest {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private lateinit var exerciseTypeRepository: ExerciseTypeRepository
|
private lateinit var exerciseTypeRepository: ExerciseTypeRepository
|
||||||
|
private var insertedId: Long = 0
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testGet() {
|
fun testGet() {
|
||||||
@ -24,7 +25,7 @@ class ExerciseTypeTest {
|
|||||||
val savedEx: ExerciseType = exerciseTypeRepository.save(newEx)
|
val savedEx: ExerciseType = exerciseTypeRepository.save(newEx)
|
||||||
assertEquals(savedEx.name, "Húzodszkodás")
|
assertEquals(savedEx.name, "Húzodszkodás")
|
||||||
|
|
||||||
val insertedId: Long = savedEx.exerciseTypeId
|
this.insertedId = savedEx.exerciseTypeId
|
||||||
|
|
||||||
val extype: ExerciseType = exerciseTypeRepository.findById( savedEx.exerciseTypeId ).orElse(null)
|
val extype: ExerciseType = exerciseTypeRepository.findById( savedEx.exerciseTypeId ).orElse(null)
|
||||||
assertEquals( extype.name, "Húzodszkodás")
|
assertEquals( extype.name, "Húzodszkodás")
|
||||||
|
Loading…
Reference in New Issue
Block a user