API 1.0.15c CustomerExerciseDevice delete
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user