Add create router endpoint
This commit is contained in:
@@ -0,0 +1,49 @@
|
|||||||
|
package com.litoralregas.openvpn.router;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
|
||||||
|
public class CreateRouterRequest {
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String serialNumber;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
private String lanIp;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
private String lanSubnet;
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSerialNumber() {
|
||||||
|
return serialNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLanIp() {
|
||||||
|
return lanIp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLanSubnet() {
|
||||||
|
return lanSubnet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSerialNumber(String serialNumber) {
|
||||||
|
this.serialNumber = serialNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLanIp(String lanIp) {
|
||||||
|
this.lanIp = lanIp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLanSubnet(String lanSubnet) {
|
||||||
|
this.lanSubnet = lanSubnet;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,5 +20,73 @@ public class Router {
|
|||||||
private LocalDateTime createdAt;
|
private LocalDateTime createdAt;
|
||||||
private LocalDateTime updatedAt;
|
private LocalDateTime updatedAt;
|
||||||
|
|
||||||
|
public Router() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(UUID id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSerialNumber() {
|
||||||
|
return serialNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSerialNumber(String serialNumber) {
|
||||||
|
this.serialNumber = serialNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLanIp() {
|
||||||
|
return lanIp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLanIp(String lanIp) {
|
||||||
|
this.lanIp = lanIp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLanSubnet() {
|
||||||
|
return lanSubnet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLanSubnet(String lanSubnet) {
|
||||||
|
this.lanSubnet = lanSubnet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(String status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getCreatedAt() {
|
||||||
|
return createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedAt(LocalDateTime createdAt) {
|
||||||
|
this.createdAt = createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getUpdatedAt() {
|
||||||
|
return updatedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdatedAt(LocalDateTime updatedAt) {
|
||||||
|
this.updatedAt = updatedAt;
|
||||||
|
}
|
||||||
|
|
||||||
// getters and setters (for now, no Lombok)
|
// getters and setters (for now, no Lombok)
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,11 @@
|
|||||||
package com.litoralregas.openvpn.router;
|
package com.litoralregas.openvpn.router;
|
||||||
|
|
||||||
|
import jakarta.validation.Valid;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/routers")
|
@RequestMapping("/api/routers")
|
||||||
@@ -18,4 +21,20 @@ public class RouterController {
|
|||||||
public List<Router> getAll() {
|
public List<Router> getAll() {
|
||||||
return repository.findAll();
|
return repository.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public Router create(@Valid @RequestBody CreateRouterRequest request) {
|
||||||
|
Router router = new Router();
|
||||||
|
|
||||||
|
router.setId(UUID.randomUUID());
|
||||||
|
router.setName(request.getName());
|
||||||
|
router.setSerialNumber(request.getSerialNumber());
|
||||||
|
router.setLanIp(request.getLanIp());
|
||||||
|
router.setLanSubnet(request.getLanSubnet());
|
||||||
|
router.setStatus("PENDING");
|
||||||
|
router.setCreatedAt(LocalDateTime.now());
|
||||||
|
router.setUpdatedAt(LocalDateTime.now());
|
||||||
|
|
||||||
|
return repository.save(router);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user