package fr.univnantes.atal.web.trashnao.webservices;

import fr.univnantes.atal.web.trashnao.model.User;
import fr.univnantes.atal.web.trashnao.persistence.PMF;
import fr.univnantes.atal.web.trashnao.security.TokenVerifier;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.jdo.PersistenceManager;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class UserService extends WebService {

    @Override
    protected void get(
            HttpServletRequest request,
            HttpServletResponse response)
            throws ServletException, IOException {
        User user = TokenVerifier.getUser(request);
        Map<String, String> data = new HashMap<>();
        if (user != null) {
            data.put("id", user.getGoogleId());
            data.put("email", user.getEmail());
        } else {
            error(request,
                    response,
                    "Couldn't identify the user thanks to the access_token.");
        }
    }

    @Override
    protected void post(
            HttpServletRequest request,
            HttpServletResponse response)
            throws ServletException, IOException {
        error(request, response, "Unsupported method: POST");
    }

    @Override
    protected void put(
            HttpServletRequest request,
            HttpServletResponse response)
            throws ServletException, IOException {
        error(request, response, "Unsupported method: PUT");
    }

    @Override
    protected void delete(
            HttpServletRequest request,
            HttpServletResponse response)
            throws ServletException, IOException {
        PersistenceManager pm = PMF.get().getPersistenceManager();
        User user = TokenVerifier.getUser(request);
        if (user != null) {
            pm.deletePersistent(user);
        } else {
            error(request,
                    response,
                    "Couldn't identify the user thanks to the access_token.");
        }
        pm.close();
    }
}

@@ -237,32 +237,60 @@
 io.IOException;%0A
+import java.io.PrintWriter;%0A
 import java.util
@@ -933,24 +933,268 @@
 etEmail());%0A
+            response.setContentType(%22application/json%22);%0A            response.setCharacterEncoding(%22UTF-8%22);%0A            try (PrintWriter out = response.getWriter()) %7B%0A                out.println(mapper.writeValueAsString(data));%0A            %7D%0A
         %7D el

fix user webservice