Created
March 8, 2016 14:29
-
-
Save lazaropj/a08cc3809121a7298a16 to your computer and use it in GitHub Desktop.
Refactor Java pro Ivazim
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PerguntaService { | |
//METODO QUE DEVE SER TESTADO, POIS A LOGIDA DE OBTER A LISTA TA AQUI | |
public List<Pergunta> listarPerguntas(){ | |
return List<Pergunta> perguntas = LogicaParaObterEssaLista(); | |
} | |
//METODO UNICAMENTE FEITO PARA TRATAR E FAZER O RETORNO PARA O CONTROLLER | |
public Result respostaPraController(){ | |
if (perguntas != null && !perguntas.isEmpty()) { | |
String json = gson.toJson(perguntas, type); | |
return Response.ok(json).build(); | |
} else { | |
return Response.noContent().build(); | |
} | |
//TODO: fazer o Try/Catch aqui para ver se tem erro. Não fazer isso lá na Controller | |
} | |
} | |
//CONTOLLER BURRO DO JEITO QUE ACHO Q DEVE SER; | |
@GET | |
@Produces(MediaType.APPLICATION_JSON) | |
@ApiOperation(produces="application/json",httpMethod="GET", value = "lista perguntas") | |
@ApiResponses(value={@ApiResponse(code=204,message="no content"), @ApiResponse(code=200,message="ok"),@ApiResponse(code=200,message="internal error")}) | |
public Response listarPerguntas() { | |
Gson gson = new Gson(); | |
Type type = new TypeToken<List<Pergunta>>() { | |
}.getType(); | |
Result result = perguntaService.respostaPraController | |
return Responde.result(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment