API 1.0.15c CustomerExerciseDevice delete
This commit is contained in:
parent
11c9a6d112
commit
059c9c7be2
@ -3,7 +3,9 @@ package com.aitrainer.api.controller
|
||||
import com.aitrainer.api.model.CustomerExerciseDevice
|
||||
import com.aitrainer.api.repository.CustomerExerciseDeviceRepository
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.security.access.annotation.Secured
|
||||
import org.springframework.web.bind.annotation.*
|
||||
import javax.validation.Valid
|
||||
|
||||
@ -29,4 +31,18 @@ class CustomerExerciseDeviceController(private val customerExerciseDeviceReposit
|
||||
logger.info("Create new device: $newCustomerExerciseDevice")
|
||||
return ResponseEntity.ok().body(newCustomerExerciseDevice)
|
||||
}
|
||||
|
||||
@Secured
|
||||
@PostMapping("/customer_exercise_device/delete/")
|
||||
fun deleteCustomerExerciseDevice(@Valid @RequestBody customerExerciseDevice: CustomerExerciseDevice) :ResponseEntity<HttpStatus> {
|
||||
val returnDevice = customerExerciseDeviceRepository.findById(customerExerciseDevice.customerExerciseDeviceId).orElse(null)
|
||||
?: return ResponseEntity.notFound().build()
|
||||
try {
|
||||
customerExerciseDeviceRepository.delete(returnDevice)
|
||||
} catch (e: IllegalArgumentException ) {
|
||||
return ResponseEntity.ok().body(HttpStatus.BAD_REQUEST)
|
||||
}
|
||||
|
||||
return ResponseEntity.ok().body(HttpStatus.OK)
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ 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 org.springframework.http.HttpStatus
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@ -56,4 +57,24 @@ class CustomerExerciseDeviceTest {
|
||||
customerExerciseDeviceRepository.delete(customerDeviceNew)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun deleteDevice() {
|
||||
val customerExerciseDevice = CustomerExerciseDevice(
|
||||
exerciseDeviceId = 3,
|
||||
favourite = false,
|
||||
dateAdd = "2020-11-23 04:32:00",
|
||||
customerId = 62
|
||||
)
|
||||
|
||||
|
||||
val controller = CustomerExerciseDeviceController(customerExerciseDeviceRepository)
|
||||
val response = controller.insertDevice(customerExerciseDevice)
|
||||
|
||||
val device = response.body
|
||||
assertTrue(device != null)
|
||||
|
||||
val responseDelete = controller.deleteCustomerExerciseDevice(device)
|
||||
assertEquals(responseDelete.statusCode, HttpStatus.OK)
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user