Skip to content
This repository was archived by the owner on Jul 14, 2026. It is now read-only.

Commit b0faeb2

Browse files
authored
Merge pull request #76 from bright-room/claude/issue-60-20260309-1819
Close #60: Add WebFlux custom provider database (R2DBC) example
2 parents 122ce0f + 850a8df commit b0faeb2

8 files changed

Lines changed: 118 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
plugins {
2+
id("example-base")
3+
id("spotless-java")
4+
}
5+
6+
dependencies {
7+
implementation(project(":spring:spring-webflux"))
8+
implementation(libs.spring.boot.starter.webflux)
9+
implementation("org.springframework.boot:spring-boot-starter-data-r2dbc")
10+
runtimeOnly("org.postgresql:r2dbc-postgresql")
11+
implementation("org.springframework.boot:spring-boot-docker-compose")
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package net.brightroom.example.customprovider;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class CustomProviderDatabaseExampleApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(CustomProviderDatabaseExampleApplication.class, args);
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package net.brightroom.example.customprovider;
2+
3+
import net.brightroom.endpointgate.reactive.core.provider.ReactiveEndpointGateProvider;
4+
import org.springframework.stereotype.Component;
5+
import reactor.core.publisher.Mono;
6+
7+
@Component
8+
public class DatabaseReactiveEndpointGateProvider implements ReactiveEndpointGateProvider {
9+
10+
private final GateManagementRepository repository;
11+
12+
public DatabaseReactiveEndpointGateProvider(GateManagementRepository repository) {
13+
this.repository = repository;
14+
}
15+
16+
@Override
17+
public Mono<Boolean> isGateEnabled(String gateId) {
18+
return repository.findById(gateId).map(GateManagementEntity::isEnabled);
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package net.brightroom.example.customprovider;
2+
3+
import net.brightroom.endpointgate.core.annotation.EndpointGate;
4+
import org.springframework.web.bind.annotation.GetMapping;
5+
import org.springframework.web.bind.annotation.RestController;
6+
import reactor.core.publisher.Mono;
7+
8+
@RestController
9+
public class ExperimentalController {
10+
11+
@EndpointGate("experimental")
12+
@GetMapping("/api/experimental")
13+
public Mono<String> experimental() {
14+
return Mono.just("Experimental feature");
15+
}
16+
17+
@EndpointGate("development")
18+
@GetMapping("/api/development")
19+
public Mono<String> development() {
20+
return Mono.just("Development feature");
21+
}
22+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package net.brightroom.example.customprovider;
2+
3+
import org.springframework.data.annotation.Id;
4+
import org.springframework.data.relational.core.mapping.Column;
5+
import org.springframework.data.relational.core.mapping.Table;
6+
7+
@Table("gate_management")
8+
public class GateManagementEntity {
9+
10+
@Id
11+
@Column("gate_id")
12+
private String gateId;
13+
14+
@Column("enabled")
15+
private boolean enabled;
16+
17+
public String getGateId() {
18+
return gateId;
19+
}
20+
21+
public void setGateId(String gateId) {
22+
this.gateId = gateId;
23+
}
24+
25+
public boolean isEnabled() {
26+
return enabled;
27+
}
28+
29+
public void setEnabled(boolean enabled) {
30+
this.enabled = enabled;
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package net.brightroom.example.customprovider;
2+
3+
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
4+
import org.springframework.stereotype.Repository;
5+
6+
@Repository
7+
public interface GateManagementRepository
8+
extends ReactiveCrudRepository<GateManagementEntity, String> {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
spring:
2+
docker:
3+
compose:
4+
file: ../../docker/compose.yaml
5+
r2dbc:
6+
url: r2dbc:postgresql://localhost:5432/postgres
7+
username: postgres
8+
password: postgres
9+
10+
endpoint-gate:
11+
default-enabled: false

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ include(
5353
"examples:webflux:fail-behavior",
5454
"examples:webflux:error-handling",
5555
"examples:webflux:custom-provider",
56+
"examples:webflux:custom-provider-database",
5657
"examples:webflux:actuator-endpoint",
5758
"examples:webflux:health-indicator",
5859
"examples:webflux:basic-usage",

0 commit comments

Comments
 (0)