Added switch and some more endpoints to support installation script.

This commit is contained in:
Andrew Lalis 2021-11-26 16:54:32 +01:00
parent e7274cb6d0
commit fe92f2903c
4 changed files with 59 additions and 0 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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");
}
}

View File

@ -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);
}
}