UsersService.java 1.03 KB
Newer Older
Luca Arrotta's avatar
Luca Arrotta committed
1 2 3 4 5 6
package REST.services;


import REST.beans.User;
import REST.beans.Users;

7
import javax.ws.rs.*;
Luca Arrotta's avatar
Luca Arrotta committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
import javax.ws.rs.core.Response;

@Path("users")
public class UsersService {

    //restituisce la lista di utenti
    @GET
    @Produces({"application/json", "application/xml"})
    public Response getUsersList(){
        return Response.ok(Users.getInstance()).build();

    }

    //permette di inserire un utente (nome e cognome)
    @Path("add")
    @POST
    @Consumes({"application/json", "application/xml"})
    public Response addUser(User u){
        Users.getInstance().add(u);
        return Response.ok().build();
    }

30
    //permette di prelevare un utente con un determinato nome
Luca Arrotta's avatar
Luca Arrotta committed
31 32 33 34 35 36 37 38 39 40 41 42 43
    @Path("get/{name}")
    @GET
    @Produces({"application/json", "application/xml"})
    public Response getByName(@PathParam("name") String name){
        User u = Users.getInstance().getByName(name);
        if(u!=null)
            return Response.ok(u).build();
        else
            return Response.status(Response.Status.NOT_FOUND).build();
    }


}