diff options
Diffstat (limited to 'jws/endpoints/src/main')
7 files changed, 173 insertions, 0 deletions
diff --git a/jws/endpoints/src/main/java/fr/epita/assistants/presentation/rest/Endpoints.java b/jws/endpoints/src/main/java/fr/epita/assistants/presentation/rest/Endpoints.java new file mode 100644 index 0000000..cd4a49f --- /dev/null +++ b/jws/endpoints/src/main/java/fr/epita/assistants/presentation/rest/Endpoints.java @@ -0,0 +1,35 @@ +package fr.epita.assistants.presentation.rest; + +import fr.epita.assistants.presentation.rest.request.ReverseRequest; +import fr.epita.assistants.presentation.rest.response.HelloResponse; +import fr.epita.assistants.presentation.rest.response.ReverseResponse; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; +import jakarta.ws.rs.core.Response; + +@Path("/") +public class Endpoints { + @GET + @Path("hello/{name}") + public Response hello(@PathParam("name") String name) { + Response.ResponseBuilder res = Response.ok(new HelloResponse(name)); + if (name == null || name.isEmpty()) + res.status(Response.Status.BAD_REQUEST); + return res.build(); + } + + @POST + @Path("reverse") + public Response reverse(ReverseRequest request) { + if (request == null || request.getContent() == null) { + Response.ResponseBuilder res = Response.status(Response.Status.BAD_REQUEST); + return res.build(); + } + Response.ResponseBuilder res = Response.ok(new ReverseResponse(request.getContent())); + if (request.getContent().isEmpty()) + res.status(Response.Status.BAD_REQUEST); + return res.build(); + } +} diff --git a/jws/endpoints/src/main/java/fr/epita/assistants/presentation/rest/HelloWorldEndpoint.java b/jws/endpoints/src/main/java/fr/epita/assistants/presentation/rest/HelloWorldEndpoint.java new file mode 100644 index 0000000..4f8a59d --- /dev/null +++ b/jws/endpoints/src/main/java/fr/epita/assistants/presentation/rest/HelloWorldEndpoint.java @@ -0,0 +1,15 @@ +package fr.epita.assistants.presentation.rest; + +import jakarta.ws.rs.*; +import jakarta.ws.rs.core.MediaType; + +@Path("/") +@Consumes(MediaType.TEXT_PLAIN) +@Produces(MediaType.TEXT_PLAIN) +public class HelloWorldEndpoint { + @Path("/") + @GET + public String helloWorld() { + return "Hello World!"; + } +} diff --git a/jws/endpoints/src/main/java/fr/epita/assistants/presentation/rest/request/ReverseRequest.java b/jws/endpoints/src/main/java/fr/epita/assistants/presentation/rest/request/ReverseRequest.java new file mode 100644 index 0000000..0a8fc7d --- /dev/null +++ b/jws/endpoints/src/main/java/fr/epita/assistants/presentation/rest/request/ReverseRequest.java @@ -0,0 +1,10 @@ +package fr.epita.assistants.presentation.rest.request; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@AllArgsConstructor +@Getter +public class ReverseRequest { + String content; +} diff --git a/jws/endpoints/src/main/java/fr/epita/assistants/presentation/rest/response/HelloResponse.java b/jws/endpoints/src/main/java/fr/epita/assistants/presentation/rest/response/HelloResponse.java new file mode 100644 index 0000000..2dbc9d0 --- /dev/null +++ b/jws/endpoints/src/main/java/fr/epita/assistants/presentation/rest/response/HelloResponse.java @@ -0,0 +1,12 @@ +package fr.epita.assistants.presentation.rest.response; + +import lombok.Getter; + +@Getter +public class HelloResponse { + String content; + + public HelloResponse(String content) { + this.content = "hello " + content; + } +} diff --git a/jws/endpoints/src/main/java/fr/epita/assistants/presentation/rest/response/ReverseResponse.java b/jws/endpoints/src/main/java/fr/epita/assistants/presentation/rest/response/ReverseResponse.java new file mode 100644 index 0000000..3f1bb9e --- /dev/null +++ b/jws/endpoints/src/main/java/fr/epita/assistants/presentation/rest/response/ReverseResponse.java @@ -0,0 +1,14 @@ +package fr.epita.assistants.presentation.rest.response; + +import lombok.Getter; + +@Getter +public class ReverseResponse { + String original; + String reversed; + + public ReverseResponse(String original) { + this.original = original; + this.reversed = new StringBuilder(original).reverse().toString(); + } +} diff --git a/jws/endpoints/src/main/resources/application.properties b/jws/endpoints/src/main/resources/application.properties new file mode 100644 index 0000000..b3b3d13 --- /dev/null +++ b/jws/endpoints/src/main/resources/application.properties @@ -0,0 +1,7 @@ +%dev.quarkus.http.port=8082 +%dev.quarkus.swagger-ui.enable=true + +quarkus.log.category."org.apache.kafka".level=WARN +quarkus.devservices.enabled=false + +quarkus.http.cors=true diff --git a/jws/endpoints/src/main/resources/openapi.yaml b/jws/endpoints/src/main/resources/openapi.yaml new file mode 100644 index 0000000..7e8ac48 --- /dev/null +++ b/jws/endpoints/src/main/resources/openapi.yaml @@ -0,0 +1,80 @@ +--- +openapi: 3.1.0 +tags: +- name: Greeting +- name: String Operations +servers: + - url: http://localhost:8082/ +components: + schemas: + HelloResponse: + type: object + properties: + content: + type: string + example: "hello test" + ReverseRequest: + type: object + properties: + content: + type: string + example: "hello\ntest" + ReverseResponse: + type: object + properties: + original: + type: string + example: "hello\ntest" + reversed: + type: string + example: "tset\nolleh" +paths: + /hello/{name}: + get: + summary: Greet by name + description: "Returns a greeting message in the format `hello {name}` using\ + \ the provided name." + tags: + - Greeting + parameters: + - name: name + in: path + required: true + schema: + type: string + responses: + "200": + description: Greeting message returned successfully. + content: + application/json: + schema: + $ref: "#/components/schemas/HelloResponse" + "400": + description: "Bad request: The name parameter is null or empty." + /reverse: + post: + summary: Reverse a string + description: "Accepts a JSON request containing a string, reverses the string,\ + \ and returns both the original and reversed versions." + tags: + - String Operations + requestBody: + description: JSON object containing the string to be reversed. + content: + application/json: + schema: + $ref: "#/components/schemas/ReverseRequest" + required: true + responses: + "200": + description: Reversed string returned successfully. + content: + application/json: + schema: + $ref: "#/components/schemas/ReverseResponse" + "400": + description: "Bad request: Request body is null or the string content is\ + \ null or empty." +info: + title: endpoints API + version: "1.0" |
