Added switch and some more endpoints to support installation script.
This commit is contained in:
parent
e7274cb6d0
commit
fe92f2903c
|
@ -0,0 +1,30 @@
|
|||
package nl.andrewl.railsignalapi.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
public class Switch {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
@ManyToOne(optional = false, fetch = FetchType.LAZY)
|
||||
private RailSystem railSystem;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String name;
|
||||
|
||||
@Embedded
|
||||
private Position position;
|
||||
|
||||
@Column(nullable = false)
|
||||
private int state;
|
||||
|
||||
@Column(nullable = false)
|
||||
private int maxStates;
|
||||
}
|
|
@ -25,6 +25,11 @@ public class RailSystemsApiController {
|
|||
return railSystemService.createRailSystem(payload);
|
||||
}
|
||||
|
||||
@GetMapping(path = "/{rsId}")
|
||||
public RailSystemResponse getRailSystem(@PathVariable long rsId) {
|
||||
return railSystemService.getRailSystem(rsId);
|
||||
}
|
||||
|
||||
@DeleteMapping(path = "/{rsId}")
|
||||
public ResponseEntity<?> deleteRailSystem(@PathVariable long rsId) {
|
||||
railSystemService.delete(rsId);
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package nl.andrewl.railsignalapi.rest;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(path = "/api/status")
|
||||
public class StatusController {
|
||||
|
||||
@GetMapping
|
||||
public Map<String, Object> getStatus() {
|
||||
return Map.of("status", "online");
|
||||
}
|
||||
}
|
|
@ -46,4 +46,11 @@ public class RailSystemService {
|
|||
branchRepository.deleteAll(branches);
|
||||
railSystemRepository.delete(rs);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public RailSystemResponse getRailSystem(long rsId) {
|
||||
var rs = railSystemRepository.findById(rsId)
|
||||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
|
||||
return new RailSystemResponse(rs);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue