-
Notifications
You must be signed in to change notification settings - Fork 1
Driver code done by using Smithy generated code #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
97f17c9
ed06b64
68c07b2
275c918
800653c
fe79c88
7f94979
2feb30f
8f111be
bd98c50
e2a9092
af63583
c72fcea
d3c55ee
c451c42
bab320f
ddbf6a7
8fd0505
501504c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| ROUTE_SERVICE_ENDPOINT="http://0.0.0.0:8888" | ||
| DATABASE_URL="jdbc:postgresql://host:port/postgres?user=postgres&password=password" |
| +7 −0 | README.md | |
| +21 −0 | build.gradle.kts | |
| +3 −13 | model/brand/brand-apis.smithy | |
| +3 −3 | model/brand/brand-io.smithy | |
| +3 −3 | model/brand/brand-types.smithy | |
| +0 −0 | model/errors.smithy | |
| +40 −0 | model/main.smithy | |
| +6 −16 | model/route/route-apis.smithy | |
| +8 −12 | model/route/route-io.smithy | |
| +4 −4 | model/route/route-types.smithy | |
| +3 −19 | model/stand/stand-apis.smithy | |
| +5 −5 | model/stand/stand-io.smithy | |
| +4 −4 | model/stand/stand-types.smithy | |
| +6 −22 | model/store/store-apis.smithy | |
| +10 −10 | model/store/store-io.smithy | |
| +9 −9 | model/store/store-types.smithy | |
| +47 −0 | model/util/util-basic.smithy | |
| +27 −0 | model/util/util-pagination.smithy | |
| +62 −0 | model/util/util-spacetime.smithy | |
| +1 −39 | smithy-build.json | |
| +0 −124 | smithy/model/common.smithy | |
| +0 −17 | smithy/model/main.smithy |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,25 @@ | ||
| # InAndOut-Route-Service | ||
|
|
||
| ## Setup | ||
|
|
||
| This project uses git submodules for API modelling. To ensure the project builds correctly, initialize the submodules when cloning: | ||
|
|
||
| ```bash | ||
| git clone --recurse-submodules <repo-url> | ||
| ``` | ||
|
|
||
| Alternatively, if you've already cloned the repository, run: | ||
|
|
||
| ```bash | ||
| git submodule update --init --recursive | ||
| ``` | ||
|
|
||
| ## Build | ||
|
|
||
| To build the project, use the Gradle wrapper: | ||
|
|
||
| ```bash | ||
| ./gradlew build | ||
| ``` | ||
|
|
||
| It is recommended to install the [Smithy CLI](https://smithy.io/2.0/guides/smithy-cli/cli_installation.html) for diverse model checks and validation. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,96 +1,70 @@ | ||
| plugins { | ||
| java | ||
| application | ||
| id("org.springframework.boot") version "4.0.3" | ||
| id("io.spring.dependency-management") version "1.1.7" | ||
| id("org.graalvm.buildtools.native") version "0.11.4" | ||
| } | ||
| group = "com.shopping.inandout" | ||
| version = "0.0.1" | ||
| description = "A RESTful web service for handling customer queries and computing TSP solutions" | ||
|
|
||
| java { | ||
| toolchain { | ||
| languageVersion = JavaLanguageVersion.of(25) | ||
| } | ||
| allprojects { | ||
| repositories { | ||
| mavenLocal() | ||
| mavenCentral() | ||
| } | ||
| } | ||
|
|
||
| application { | ||
| mainClass = "com.shopping.inandout.routeservice.RouteServiceApplication" | ||
| plugins { | ||
| `java-library` | ||
| application | ||
| id("software.amazon.smithy.gradle.smithy-base") | ||
| jacoco | ||
| } | ||
|
|
||
| configurations { | ||
| compileOnly { | ||
| extendsFrom(configurations.annotationProcessor.get()) | ||
| } | ||
| application { | ||
| mainClass = "com.shopping.inandout.routeservice.RouteServiceWrapper" | ||
| } | ||
|
|
||
| group = "com.shopping.inandout" | ||
| version = "0.0.1-SNAPSHOT" | ||
| description = "A RESTful web service for handling customer queries and computing TSP solutions" | ||
|
|
||
| repositories { | ||
| mavenCentral() | ||
| mavenLocal() | ||
| } | ||
|
|
||
| val smithyJavaVersion: String by project | ||
|
|
||
| dependencies { | ||
| implementation("software.amazon.smithy.java:client-core:0.0.3") | ||
| implementation("software.amazon.smithy.java.codegen:plugins:$smithyJavaVersion") | ||
| // Core library for the Java client | ||
| // Adds the server implementation of the `RestJson1` protocol | ||
| implementation("software.amazon.smithy.java:aws-server-restjson:$smithyJavaVersion") | ||
| val smithyJavaVersion: String by project | ||
|
|
||
| // Smithy java model generation | ||
| smithyBuild("software.amazon.smithy.java.codegen:plugins:$smithyJavaVersion") | ||
| implementation(project(":InAndOut-API-Modelling")) | ||
|
|
||
| // Adds an HTTP server implementation based on netty | ||
| implementation("software.amazon.smithy.java:server-netty:$smithyJavaVersion") | ||
| // Adds the server implementation of the `RestJson1` protocol | ||
| implementation("software.amazon.smithy.java:aws-server-restjson:$smithyJavaVersion") | ||
|
|
||
| implementation("org.springframework.boot:spring-boot-starter-jdbc") | ||
| implementation("org.springframework.boot:spring-boot-starter-r2dbc") | ||
| implementation("org.springframework.boot:spring-boot-starter-restclient") | ||
| implementation("org.springframework.boot:spring-boot-starter-security") | ||
| implementation("org.springframework.boot:spring-boot-starter-security-oauth2-authorization-server") | ||
| implementation("org.springframework.boot:spring-boot-starter-security-oauth2-client") | ||
| implementation("org.springframework.boot:spring-boot-starter-session-jdbc") | ||
| implementation("org.springframework.boot:spring-boot-starter-webclient") | ||
| implementation("org.springframework.boot:spring-boot-starter-webmvc") | ||
| implementation("org.springframework.boot:spring-boot-starter-webservices") | ||
| compileOnly("org.projectlombok:lombok") | ||
| developmentOnly("org.springframework.boot:spring-boot-devtools") | ||
| annotationProcessor("org.projectlombok:lombok") | ||
| testImplementation("org.springframework.boot:spring-boot-starter-jdbc-test") | ||
| testImplementation("org.springframework.boot:spring-boot-starter-r2dbc-test") | ||
| testImplementation("org.springframework.boot:spring-boot-starter-restclient-test") | ||
| testImplementation("org.springframework.boot:spring-boot-starter-security-oauth2-authorization-server-test") | ||
| testImplementation("org.springframework.boot:spring-boot-starter-security-oauth2-client-test") | ||
| testImplementation("org.springframework.boot:spring-boot-starter-security-test") | ||
| testImplementation("org.springframework.boot:spring-boot-starter-session-jdbc-test") | ||
| testImplementation("org.springframework.boot:spring-boot-starter-webclient-test") | ||
| testImplementation("org.springframework.boot:spring-boot-starter-webmvc-test") | ||
| testImplementation("org.springframework.boot:spring-boot-starter-webservices-test") | ||
| testRuntimeOnly("org.junit.platform:junit-platform-launcher") | ||
| testRuntimeOnly("com.h2database:h2") | ||
| testRuntimeOnly("io.r2dbc:r2dbc-h2") | ||
| } | ||
| compileOnly("org.projectlombok:lombok:1.18.30") | ||
| annotationProcessor("org.projectlombok:lombok:1.18.30") | ||
|
|
||
| testCompileOnly("org.projectlombok:lombok:1.18.30") | ||
| testAnnotationProcessor("org.projectlombok:lombok:1.18.30") | ||
|
|
||
| afterEvaluate { | ||
| sourceSets { | ||
| main { | ||
| java.srcDir("build/java-client/java-client-codegen") | ||
| } | ||
| } | ||
| testImplementation("org.junit.jupiter:junit-jupiter:5.7.1") | ||
| testImplementation("org.mockito:mockito-junit-jupiter:3.11.2") | ||
| testImplementation("org.mockito:mockito-core:3.11.2") | ||
| testRuntimeOnly("org.junit.platform:junit-platform-launcher") | ||
| } | ||
|
|
||
| tasks.register<Exec>("smithyBuild") { | ||
| group = "build" | ||
| description = "Java models codegen from Smithy model." | ||
| commandLine("cmd", "/c", "smithy", "build", | ||
| "--config", ".\\InAndOut-API-Modelling\\smithy-build.json", | ||
| "--projection", "java-client", | ||
| "--output", "build/") | ||
| // Add generated source code to the compilation sourceSet | ||
| afterEvaluate { | ||
| val serverPath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-server-codegen") | ||
| sourceSets.main.get().java.srcDir(serverPath) | ||
| } | ||
|
|
||
| tasks.named("compileJava") { | ||
| dependsOn("smithyBuild") | ||
| } | ||
|
|
||
| tasks.withType<Test> { | ||
| useJUnitPlatform() | ||
| } | ||
| tasks.named<Test>("test") { | ||
| useJUnitPlatform() | ||
|
|
||
| maxHeapSize = "1G" | ||
| testLogging { | ||
| events("passed", "skipped", "failed") | ||
| exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,10 @@ | ||
| rootProject.name = "routeservice" | ||
|
|
||
| pluginManagement { | ||
| val smithyGradleVersion: String by settings | ||
| plugins { | ||
| id("software.amazon.smithy.gradle.smithy-jar") version smithyGradleVersion | ||
| id("software.amazon.smithy.gradle.smithy-base") version smithyGradleVersion | ||
| id("software.amazon.smithy.gradle.smithy-jar").version(smithyGradleVersion) | ||
| id("software.amazon.smithy.gradle.smithy-base").version(smithyGradleVersion) | ||
| } | ||
|
|
||
| repositories { | ||
|
|
@@ -12,4 +14,5 @@ pluginManagement { | |
| } | ||
| } | ||
|
|
||
| rootProject.name = "routeservice" | ||
| // Subprojects | ||
| include("InAndOut-API-Modelling") | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we should keep the app as a subproject too. See |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "version": "1.0", | ||
| "plugins": { | ||
| "java-server-codegen": { | ||
| "service": "com.shopping.inandout#RouteService", | ||
| "namespace": "com.shopping.inandout" | ||
| } | ||
| } | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| package com.shopping.inandout.routeservice; | ||
|
|
||
| import com.shopping.inandout.service.RouteService; | ||
|
|
||
| import com.shopping.inandout.routeservice.activities.CreateRouteActivity; | ||
| import com.shopping.inandout.routeservice.activities.DeleteRouteActivity; | ||
| import com.shopping.inandout.routeservice.activities.GetRouteActivity; | ||
|
|
||
| import java.net.URI; | ||
| import java.util.concurrent.CountDownLatch; | ||
| import java.util.concurrent.ExecutionException; | ||
| import java.util.logging.Level; | ||
| import java.util.logging.Logger; | ||
|
|
||
| import software.amazon.smithy.java.server.Service; | ||
| import software.amazon.smithy.java.server.Server; | ||
|
|
||
| public class RouteServiceWrapper implements Runnable { | ||
| private static final Logger LOGGER = Logger.getLogger(RouteServiceWrapper.class.getName()); | ||
|
|
||
| public static void main(String... args) throws RuntimeException { | ||
| new RouteServiceWrapper().run(); | ||
| } | ||
|
|
||
| @Override | ||
| public void run() { | ||
| URI uri = URI.create( | ||
| System.getenv() | ||
| .getOrDefault("ROUTE_SERVICE_ENDPOINT", "http://0.0.0.0:8888")); | ||
|
|
||
| Service service = RouteService.builder() | ||
| .addCreateRouteOperation(new CreateRouteActivity()) | ||
| .addDeleteRouteOperation(new DeleteRouteActivity()) | ||
| .addGetRouteOperation(new GetRouteActivity()) | ||
| .build(); | ||
|
|
||
| Server server = Server.builder() | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe this can be cool https://dagger.dev/dev-guide/ |
||
| .endpoints(uri) | ||
| .addService(service) | ||
| .build(); | ||
petrubraha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| CountDownLatch latch = new CountDownLatch(1); | ||
| Runtime.getRuntime().addShutdownHook( | ||
| new Thread(() -> shutdownServer(server, latch))); | ||
|
|
||
| LOGGER.info("Starting server..."); | ||
| server.start(); | ||
|
|
||
| try { | ||
| latch.await(); | ||
| } catch (InterruptedException e) { | ||
| Thread.currentThread().interrupt(); | ||
| } | ||
| } | ||
|
|
||
| private void shutdownServer(Server server, CountDownLatch latch) { | ||
| LOGGER.info("Stopping server..."); | ||
| try { | ||
| server.shutdown().get(); | ||
| } catch (InterruptedException e) { | ||
| LOGGER.log(Level.SEVERE, "Error shutting down server", e); | ||
| Thread.currentThread().interrupt(); | ||
| } catch (ExecutionException e) { | ||
| LOGGER.log(Level.SEVERE, "Error shutting down server", e); | ||
| } finally { | ||
| latch.countDown(); | ||
| } | ||
petrubraha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.shopping.inandout.routeservice.activities; | ||
|
|
||
| import com.shopping.inandout.service.CreateRouteOperation; | ||
| import com.shopping.inandout.model.CreateRouteInput; | ||
| import com.shopping.inandout.model.CreateRouteOutput; | ||
|
|
||
| import software.amazon.smithy.java.server.RequestContext; | ||
|
|
||
| public class CreateRouteActivity implements CreateRouteOperation { | ||
| public CreateRouteOutput createRoute(CreateRouteInput input, RequestContext context) { | ||
| throw new UnsupportedOperationException("Not (yet) supported operation"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.shopping.inandout.routeservice.activities; | ||
|
|
||
| import com.shopping.inandout.service.DeleteRouteOperation; | ||
| import com.shopping.inandout.model.DeleteRouteInput; | ||
| import com.shopping.inandout.model.DeleteRouteOutput; | ||
|
|
||
| import software.amazon.smithy.java.server.RequestContext; | ||
|
|
||
| public class DeleteRouteActivity implements DeleteRouteOperation { | ||
| public DeleteRouteOutput deleteRoute(DeleteRouteInput input, RequestContext context) { | ||
| throw new UnsupportedOperationException("Not (yet) supported operation"); | ||
petrubraha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.shopping.inandout.routeservice.activities; | ||
|
|
||
| import com.shopping.inandout.service.GetRouteOperation; | ||
| import com.shopping.inandout.model.GetRouteInput; | ||
| import com.shopping.inandout.model.GetRouteOutput; | ||
|
|
||
| import software.amazon.smithy.java.server.RequestContext; | ||
|
|
||
| public class GetRouteActivity implements GetRouteOperation { | ||
| public GetRouteOutput getRoute(GetRouteInput input, RequestContext context) { | ||
| throw new UnsupportedOperationException("Not (yet) supported operation"); | ||
| } | ||
| } |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package com.shopping.inandout.routeservice; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
Check warning on line 3 in src/test/java/com/shopping/inandout/routeservice/RouteServiceWrapperTest.java
|
||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.mockito.Mock; | ||
|
Check warning on line 5 in src/test/java/com/shopping/inandout/routeservice/RouteServiceWrapperTest.java
|
||
| import org.mockito.junit.jupiter.MockitoExtension; | ||
| import software.amazon.smithy.java.server.Server; | ||
|
Check warning on line 7 in src/test/java/com/shopping/inandout/routeservice/RouteServiceWrapperTest.java
|
||
|
|
||
| import java.lang.reflect.Method; | ||
| import java.util.concurrent.CompletableFuture; | ||
|
Check warning on line 10 in src/test/java/com/shopping/inandout/routeservice/RouteServiceWrapperTest.java
|
||
| import java.util.concurrent.CountDownLatch; | ||
|
Check warning on line 11 in src/test/java/com/shopping/inandout/routeservice/RouteServiceWrapperTest.java
|
||
| import java.util.concurrent.ExecutionException; | ||
|
Check warning on line 12 in src/test/java/com/shopping/inandout/routeservice/RouteServiceWrapperTest.java
|
||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
Check warning on line 14 in src/test/java/com/shopping/inandout/routeservice/RouteServiceWrapperTest.java
|
||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
Check warning on line 15 in src/test/java/com/shopping/inandout/routeservice/RouteServiceWrapperTest.java
|
||
| import static org.mockito.Mockito.mock; | ||
|
Check warning on line 16 in src/test/java/com/shopping/inandout/routeservice/RouteServiceWrapperTest.java
|
||
| import static org.mockito.Mockito.verify; | ||
|
Check warning on line 17 in src/test/java/com/shopping/inandout/routeservice/RouteServiceWrapperTest.java
|
||
| import static org.mockito.Mockito.when; | ||
|
Check warning on line 18 in src/test/java/com/shopping/inandout/routeservice/RouteServiceWrapperTest.java
|
||
|
|
||
| @ExtendWith(MockitoExtension.class) | ||
| class RouteServiceWrapperTest { | ||
|
Check failure on line 21 in src/test/java/com/shopping/inandout/routeservice/RouteServiceWrapperTest.java
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.