29 lines
1.0 KiB
Kotlin
29 lines
1.0 KiB
Kotlin
package com.cubetiqs.web.controller
|
|
|
|
import com.cubetiqs.web.infrastructure.data.Customer
|
|
import com.cubetiqs.web.infrastructure.repository.CustomerRepository
|
|
import io.swagger.v3.oas.annotations.tags.Tag
|
|
import org.springframework.beans.factory.annotation.Autowired
|
|
import org.springframework.web.bind.annotation.*
|
|
|
|
@Tag(name = "Customer")
|
|
@RestController
|
|
@RequestMapping("/customers")
|
|
class CustomerController @Autowired constructor(
|
|
private val customerRepository: CustomerRepository,
|
|
) {
|
|
@GetMapping
|
|
fun getAll(): List<Customer> = customerRepository.findAll()
|
|
|
|
@GetMapping("/{id}")
|
|
fun getById(@PathVariable id: String): Customer = customerRepository.findById(id).orElse(null)
|
|
|
|
@PostMapping
|
|
fun create(@RequestBody customer: Customer) = customerRepository.save(customer)
|
|
|
|
@DeleteMapping("/{id}")
|
|
fun delete(@PathVariable id: String) = customerRepository.deleteById(id)
|
|
|
|
@PutMapping("/{id}")
|
|
fun update(@PathVariable id: String, @RequestBody customer: Customer) = customerRepository.save(customer)
|
|
} |