-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
616ecff
commit 60e3585
Showing
7 changed files
with
152 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
59 changes: 59 additions & 0 deletions
59
src/main/java/br/com/pastaeriso/receitas/ServletCalcularReceita.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package br.com.pastaeriso.receitas; | ||
|
||
import java.util.List; | ||
|
||
import java.io.IOException; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.RequestDispatcher; | ||
import org.apache.ibatis.session.SqlSession; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import br.com.pastaeriso.servicos.DatabaseConnection; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import java.io.PrintWriter; | ||
|
||
import java.math.BigDecimal; | ||
|
||
@WebServlet("/calcularReceita") | ||
public class ServletCalcularReceita extends HttpServlet { | ||
|
||
final static Logger logger = LogManager.getLogger(ServletPrepareReceitas.class); | ||
|
||
protected void service (HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
Receita receita = null; | ||
Integer id = -1; | ||
BigDecimal rendimento = new BigDecimal(0); | ||
|
||
try { | ||
id = Integer.parseInt(request.getParameter("id")); | ||
rendimento = new BigDecimal(request.getParameter("rendimento")); | ||
} catch(NullPointerException e) { | ||
id = new Integer(1); | ||
rendimento = new BigDecimal(1); | ||
} | ||
|
||
try (SqlSession sqlSession = DatabaseConnection.getInstance().getSqlSessionFactory().openSession()) { | ||
MapperReceita mapperReceita = sqlSession.getMapper(MapperReceita.class); | ||
receita = mapperReceita.selectReceitaPorId(id); | ||
} | ||
if(receita != null ) { | ||
receita = new Receita(receita,rendimento); | ||
Gson gson = new GsonBuilder() | ||
.serializeNulls() | ||
.create(); | ||
String string = gson.toJson(receita); | ||
response.setContentType("application/json;charset=UTF-8"); | ||
PrintWriter out = response.getWriter(); | ||
out.print(string); | ||
} | ||
|
||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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