Submission exercise-endpoints-20ab7bc
This commit is contained in:
parent
20ab7bc8b2
commit
c7629264b4
4 changed files with 45 additions and 15 deletions
|
|
@ -1,5 +1,30 @@
|
|||
package fr.epita.assistants.presentation.rest;
|
||||
|
||||
public class Endpoints {
|
||||
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.*;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
@Path("/")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public class Endpoints {
|
||||
String content;
|
||||
@Path("/hello/{name}")
|
||||
@GET
|
||||
public Response greeting(@PathParam("name") String name) {
|
||||
if (name == null || name.isEmpty()) {
|
||||
return Response.status(400).build();
|
||||
}
|
||||
HelloResponse response = new HelloResponse("Hello " + name);
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
@Path("/reverse")
|
||||
@POST
|
||||
public Response reverse(ReverseRequest r) {
|
||||
return Response.ok(new ReverseResponse(r.content)).build();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
package fr.epita.assistants.presentation.rest.request;
|
||||
|
||||
public class ReverseRequest {
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class ReverseRequest {
|
||||
public String content;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,12 @@
|
|||
package fr.epita.assistants.presentation.rest.response;
|
||||
|
||||
import jakarta.ws.rs.Consumes;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
@Path("/hello")
|
||||
@Consumes(MediaType.TEXT_PLAIN)
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
@AllArgsConstructor
|
||||
public class HelloResponse {
|
||||
@Path("/{name}")
|
||||
@GET
|
||||
public String greeting(@PathParam("name") String name) {
|
||||
String content
|
||||
Response.accepted();
|
||||
}
|
||||
public String content;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,15 @@
|
|||
package fr.epita.assistants.presentation.rest.response;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class ReverseResponse {
|
||||
public String original;
|
||||
public String reverse;
|
||||
|
||||
public ReverseResponse(String original) {
|
||||
this.original = original;
|
||||
this.reverse = new StringBuilder(original).reverse().toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue