-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create Configuration and Setup for surrealDB * Store in database resources and pages * Create integration tests and related documentation
- Loading branch information
1 parent
9cd63e0
commit 47d41ea
Showing
40 changed files
with
1,160 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
version: '3.7' | ||
|
||
services: | ||
surrealdb: | ||
image: surrealdb/surrealdb:latest | ||
container_name: surrealdb | ||
ports: | ||
- "8000:8000" | ||
command: start --log trace --user root --pass root | ||
networks: | ||
- app-network | ||
|
||
springboot-app: | ||
build: | ||
context: .. | ||
dockerfile: Dockerfile | ||
container_name: springboot-app | ||
ports: | ||
- "8080:8080" | ||
- "5005:5005" | ||
depends_on: | ||
- surrealdb | ||
environment: | ||
- SURREALDB_USER=root | ||
- SURREALDB_PASS=root | ||
networks: | ||
- app-network | ||
|
||
networks: | ||
app-network: | ||
driver: bridge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/com/wcc/platform/configuration/DatabaseConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.wcc.platform.configuration; | ||
|
||
import com.surrealdb.connection.SurrealWebSocketConnection; | ||
import com.surrealdb.driver.SyncSurrealDriver; | ||
import com.wcc.platform.repository.surrealdb.SurrealDbConfig; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** Database configuration to initialize Driver and connection. */ | ||
@Configuration | ||
public class DatabaseConfig { | ||
|
||
/** Create Sync driver connection for SurrealDB. */ | ||
@Bean | ||
public SyncSurrealDriver getDriver(final SurrealDbConfig config) { | ||
final var conn = | ||
new SurrealWebSocketConnection(config.getHost(), config.getPort(), config.isTls()); | ||
|
||
conn.connect(config.getTimoutSeconds()); | ||
|
||
final var driver = new SyncSurrealDriver(conn); | ||
|
||
driver.signIn(config.getUsername(), config.getPassword()); | ||
|
||
driver.use(config.getNamespace(), config.getDatabase()); | ||
|
||
return driver; | ||
} | ||
|
||
/** SurrealDB Config. */ | ||
@Bean | ||
@ConfigurationProperties(prefix = "surrealdb") | ||
public SurrealDbConfig getDbConfig() { | ||
return new SurrealDbConfig(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 17 additions & 1 deletion
18
src/main/java/com/wcc/platform/configuration/RepositoryConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/main/java/com/wcc/platform/controller/PlatformController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.wcc.platform.controller; | ||
|
||
import com.wcc.platform.domain.platform.ResourceContent; | ||
import com.wcc.platform.service.PlatformService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import java.util.Collection; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
/** Rest controller for event pages API. */ | ||
@RestController | ||
@RequestMapping("/api/platform/v1/") | ||
@Tag(name = "Platform General APIs") | ||
public class PlatformController { | ||
|
||
private final PlatformService service; | ||
|
||
@Autowired | ||
public PlatformController(final PlatformService service) { | ||
this.service = service; | ||
} | ||
|
||
/** Put resources content for a program. */ | ||
@PostMapping("/resource") | ||
@Operation(summary = "/api/v1/resource") | ||
@ResponseStatus(HttpStatus.OK) | ||
public ResponseEntity<ResourceContent> addResource(@RequestBody final ResourceContent resource) { | ||
return ResponseEntity.ok(service.saveResourceContent(resource)); | ||
} | ||
|
||
/** Get all resources content. */ | ||
@GetMapping("/resources") | ||
@Operation(summary = "/api/v1/resources") | ||
@ResponseStatus(HttpStatus.OK) | ||
public ResponseEntity<Collection<ResourceContent>> getAllResources() { | ||
return ResponseEntity.ok(service.getAllResources()); | ||
} | ||
|
||
/** Get all resources content. */ | ||
@GetMapping("/resource") | ||
@Operation(summary = "Get Resource by ID") | ||
@ResponseStatus(HttpStatus.OK) | ||
public ResponseEntity<ResourceContent> getResourceById(@RequestParam final String id) { | ||
return ResponseEntity.ok(service.getResourceById(id)); | ||
} | ||
|
||
/** Delete resource content if exists. */ | ||
@DeleteMapping("/resource/{id}") | ||
@Operation(summary = "Delete resource content if exists") | ||
@ResponseStatus(HttpStatus.OK) | ||
public void deleteResourceById(@PathVariable final String id) { | ||
service.deleteById(id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.