API 1.0.15c CustomerExerciseDevice delete

This commit is contained in:
Bossanyi Tibor
2020-11-26 00:04:23 +01:00
parent 11c9a6d112
commit 059c9c7be2
2 changed files with 37 additions and 0 deletions
@@ -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)
}
}