Skip to content

Commit

Permalink
Ref #10: tune API for /machines
Browse files Browse the repository at this point in the history
  • Loading branch information
dkazakov committed Feb 27, 2024
1 parent ecd2edf commit 4c11613
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.server.ResponseStatusException

Expand All @@ -13,8 +14,8 @@ class MachineController(
private val repository: MachinesRepository
) {

@GetMapping("/barcode/{barcode}")
fun getMachineByBarcode(@PathVariable barcode: String) =
@GetMapping
fun getMachineByBarcode(@RequestParam barcode: String) =
repository.findMachineByBarcode(barcode) ?: throw ResponseStatusException(
HttpStatus.NOT_FOUND,
"Machine with $barcode barcode does not exist. Did you send the right barcode?"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,7 @@ class ProjectConfiguration {

@Bean
fun databaseInitializer(machineRepository: MachinesRepository) = ApplicationRunner {
var sodickSaved = machineRepository.save(
Machine(
name = "Sodick 360b",
manufacturer = "Sodick",
barcode = "Sodick 360b"
)
)
/* var sodickSaved = machineRepository.save(Machine(
var sodickSaved = machineRepository.save(Machine(
name = "Sodick 360b",
manufacturer = "Sodick",
barcode = "Sodick 360b"
Expand All @@ -27,6 +20,6 @@ class ProjectConfiguration {
name = "Fanuc 2000",
manufacturer = "Fanuc",
barcode = "Fanuc 2000")
)*/
)
}
}

0 comments on commit 4c11613

Please sign in to comment.