summaryrefslogtreecommitdiff
path: root/jws/endpoints/src/main/java/fr/epita/assistants/presentation/rest/Endpoints.java
blob: cd4a49fe6aa12c9f69cec0f23765fc4adb1ab677 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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();
    }
}