From 84d228eb7ca0b64dbc979010a0ba7220e86a30cc Mon Sep 17 00:00:00 2001 From: Sherwin Price Date: Sat, 13 Dec 2025 19:30:33 -0500 Subject: [PATCH] build openapi endpoint --- Ui/build.gradle | 40 +++++++++++++++++++ .../main/java/edu/inventorym/Application.java | 36 +++++++++++++++++ .../main/java/edu/inventorym/Controller.java | 37 +++++++++++++++++ ...ot.autoconfigure.AutoConfiguration.imports | 0 Ui/src/resources/application.properties | 7 ++++ 5 files changed, 120 insertions(+) create mode 100644 Ui/build.gradle create mode 100644 Ui/src/main/java/edu/inventorym/Application.java create mode 100644 Ui/src/main/java/edu/inventorym/Controller.java create mode 100644 Ui/src/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports create mode 100644 Ui/src/resources/application.properties diff --git a/Ui/build.gradle b/Ui/build.gradle new file mode 100644 index 0000000..0eeb3b2 --- /dev/null +++ b/Ui/build.gradle @@ -0,0 +1,40 @@ +/* + * This file was generated by the Gradle 'init' task. + * + */ + +plugins { + // Apply the application plugin to add support for building a CLI application in Java. + id 'java' + id 'application' +} + +// Apply a specific Java toolchain to ease working on different environments. +java { + toolchain { + languageVersion = JavaLanguageVersion.of(25) + } + + sourceCompatibility = JavaVersion.toVersion("25") + targetCompatibility = JavaVersion.toVersion("25") +} + +application { + // Define the main class for the application. + mainClass = 'edu.inventorym.Ui' +} + +repositories { + // Use Maven Central for resolving dependencies. + mavenCentral() +} + +dependencies { + implementation 'io.netty:netty-common:4.2.8.Final' + implementation 'org.springframework.boot:spring-boot-starter-webflux:4.0.0' + implementation 'org.springdoc:springdoc-openapi-starter-webflux-api:3.0.0' + implementation 'org.springdoc:springdoc-openapi-starter-webflux-ui:3.0.0' + implementation 'jakarta.json.bind:jakarta.json.bind-api:3.0.1' + implementation project(':Model') +} + diff --git a/Ui/src/main/java/edu/inventorym/Application.java b/Ui/src/main/java/edu/inventorym/Application.java new file mode 100644 index 0000000..9a4ad9f --- /dev/null +++ b/Ui/src/main/java/edu/inventorym/Application.java @@ -0,0 +1,36 @@ +/** + * license: GPLv3 + edu.inventorym +*/ +package edu.inventorym; + +import org.springframework.boot.WebApplicationType; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.reactor.netty.NettyReactiveWebServerFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.web.reactive.config.EnableWebFlux; + +import io.swagger.v3.oas.annotations.OpenAPIDefinition; +import io.swagger.v3.oas.annotations.info.Info; + +@EnableWebFlux +@SpringBootApplication +@OpenAPIDefinition(info = @Info(title = "Model API", version = "3.0.0", description = "Documentation Model API v1.0")) +public class Application { + + public static void main(String[] args) { + new SpringApplicationBuilder() + .profiles("dev") + .web(WebApplicationType.REACTIVE) + .sources(Application.class, Controller.class) + .run(args); + } + + @Bean + public NettyReactiveWebServerFactory nettyServerFactory() { + NettyReactiveWebServerFactory factory = new NettyReactiveWebServerFactory(); + return factory; + } + +} diff --git a/Ui/src/main/java/edu/inventorym/Controller.java b/Ui/src/main/java/edu/inventorym/Controller.java new file mode 100644 index 0000000..1735266 --- /dev/null +++ b/Ui/src/main/java/edu/inventorym/Controller.java @@ -0,0 +1,37 @@ +package edu.inventorym; + +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; +import reactor.core.publisher.Flux; + +import java.time.Duration; +import java.time.LocalDateTime; +import java.util.List; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/events") +public class Controller { + + @Operation(summary = "Get all events", description = "Returns a list of all events.") + @ApiResponse(responseCode = "200", description = "Events found") + @GetMapping + public List getAllEvents() { + return List.of("Event 1", "Event 2"); + } + + @GetMapping(value = "/event-details", produces = MediaType.TEXT_EVENT_STREAM_VALUE) + public Flux streamDetails() { + // Flux.interval emits a Long every 1 second + return Flux.interval(Duration.ofSeconds(1)) + .map(sequence -> "Current Stock Price at " + LocalDateTime.now()); + } + +} + + + diff --git a/Ui/src/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/Ui/src/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 0000000..e69de29 diff --git a/Ui/src/resources/application.properties b/Ui/src/resources/application.properties new file mode 100644 index 0000000..0945125 --- /dev/null +++ b/Ui/src/resources/application.properties @@ -0,0 +1,7 @@ +spring.profiles.active=dev + +springdoc.packages-to-scan=edu.inventorym, + +springdoc.swagger-ui.path=/api-docs +springdoc.api-docs.path=/v3/api-docs.json +springdoc.version=3.0.0 \ No newline at end of file