48 lines
1.6 KiB
Java
48 lines
1.6 KiB
Java
package com.example.nto.controller;
|
|
|
|
import com.example.nto.dto.entity.TerminalDTO;
|
|
import com.example.nto.service.TerminalService;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.List;
|
|
|
|
@RestController
|
|
@RequiredArgsConstructor
|
|
@RequestMapping("api/v1/terminals")
|
|
public class TerminalController {
|
|
private final TerminalService terminalService;
|
|
|
|
@GetMapping
|
|
public ResponseEntity<List<TerminalDTO>> getAll() {
|
|
return ResponseEntity.ok(terminalService.getAllTerminal());
|
|
}
|
|
|
|
@GetMapping("/{terminalId}")
|
|
public ResponseEntity<TerminalDTO> getTerminalById(@PathVariable long terminalId) {
|
|
return ResponseEntity.ok(terminalService.getById(terminalId));
|
|
}
|
|
|
|
@GetMapping("/check/{code}")
|
|
public ResponseEntity<TerminalDTO> checkCode(@PathVariable String code) {
|
|
return ResponseEntity.ok(terminalService.checkCode(code));
|
|
}
|
|
|
|
@PostMapping
|
|
public ResponseEntity<TerminalDTO> createTerminal(@RequestBody TerminalDTO terminalDTO) {
|
|
return ResponseEntity.ok(terminalService.create(terminalDTO));
|
|
}
|
|
|
|
@PutMapping("/{terminalId}")
|
|
public ResponseEntity<TerminalDTO> updateTerminal(@PathVariable long terminalId, @RequestBody TerminalDTO terminalDTO) {
|
|
return ResponseEntity.ok(terminalService.update(terminalId, terminalDTO));
|
|
}
|
|
|
|
@DeleteMapping("/{terminalId}")
|
|
public ResponseEntity<Void> deleteTerminal(@PathVariable long terminalId) {
|
|
terminalService.delete(terminalId);
|
|
return ResponseEntity.noContent().build();
|
|
}
|
|
}
|