Add router duplicate subnet validation
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
package com.litoralregas.openvpn.router;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface RouterRepository extends JpaRepository<Router, UUID> {
|
||||
|
||||
boolean existsByLanSubnet(String lanSubnet);
|
||||
}
|
||||
@@ -20,6 +20,10 @@ public class RouterService {
|
||||
}
|
||||
|
||||
public Router create(CreateRouterRequest request) {
|
||||
if (repository.existsByLanSubnet(request.getLanSubnet())) {
|
||||
throw new IllegalArgumentException("LAN subnet already exists: " + request.getLanSubnet());
|
||||
}
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
Router router = new Router();
|
||||
|
||||
Reference in New Issue
Block a user