Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions rest-pokemon/WebContent/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Class-Path:

26 changes: 26 additions & 0 deletions rest-pokemon/WebContent/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
<display-name>rest-pokemon</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>

</welcome-file-list>

<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>br.bruno.pokemon.rest</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
822 changes: 822 additions & 0 deletions rest-pokemon/db_pokemon.csv

Large diffs are not rendered by default.

76 changes: 76 additions & 0 deletions rest-pokemon/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pokemon</groupId>
<artifactId>rest-pokemon</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.22.1</version>
</dependency>

<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
<version>2.22.1</version>
</dependency>

<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.22.1</version>
</dependency>

<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>

<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.0.3</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>



</dependencies>
</project>
16 changes: 16 additions & 0 deletions rest-pokemon/src/br/bruno/pokemon/config/DBConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package br.bruno.pokemon.config;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBConfig {

public static Connection getConnection() throws SQLException, ClassNotFoundException {
Class.forName("com.mysql.jdbc.Driver");
return DriverManager.getConnection("jdbc:mysql://localhost:3306/db_pokemon", "root", "");



}
}
78 changes: 78 additions & 0 deletions rest-pokemon/src/br/bruno/pokemon/dao/PokeDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package br.bruno.pokemon.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import br.bruno.pokemon.config.DBConfig;
import br.bruno.pokemon.entity.Pokemon;

public class PokeDao {

public List<Pokemon> buscarPokemonPaginado(String searchName, String type, int page, int size) throws Exception {
Pokemon pokemon = null;
List<Pokemon> lista = new ArrayList<>();
Connection conexao = DBConfig.getConnection();
String sql = null;
PreparedStatement statement;
if (type != null) {
sql = "SELECT * FROM tb_pokemon WHERE type_1 = ? ";
statement = conexao.prepareStatement(sql);
statement.setString(1, type);
} else if (searchName != null) {
sql = "SELECT * FROM tb_pokemon WHERE nome = ?";
statement = conexao.prepareStatement(sql);
statement.setString(1, searchName);
} else {
sql = "SELECT * FROM tb_pokemon";
statement = conexao.prepareStatement(sql);
}

ResultSet rs = statement.executeQuery();

while (rs.next()) {
pokemon = new Pokemon();

pokemon.setCodPokemon(rs.getInt("cod_pokemon"));
pokemon.setNome(rs.getString("nome"));
pokemon.setPokedexNumber(rs.getInt("pokedex_number"));
pokemon.setImgName(rs.getString("Img_name"));
pokemon.setGeneration(rs.getInt("generation"));
pokemon.setEvolutionStage(rs.getString("evolution_stage"));
pokemon.setEvolved(rs.getInt("evolved"));
pokemon.setFamilyId(rs.getString("family_id"));
pokemon.setCrossGen(rs.getInt("cross_gen"));
pokemon.setType1(rs.getString("type_1"));
pokemon.setType2(rs.getString("type_2"));
pokemon.setWeather1(rs.getString("weather_1"));
pokemon.setWeather2(rs.getString("weather_2"));
pokemon.setStatTotal(rs.getInt("stat_total"));
pokemon.setAtk(rs.getInt("ATK"));
pokemon.setDef(rs.getInt("DEF"));
pokemon.setSta(rs.getInt("STA"));
pokemon.setLegendary(rs.getInt("legendary"));
pokemon.setAquireable(rs.getInt("aquireable"));
pokemon.setSpawns(rs.getInt("spawns"));
pokemon.setRegional(rs.getInt("regional"));
pokemon.setRaidable(rs.getInt("raidable"));
pokemon.setHatchable(rs.getInt("hatchable"));
pokemon.setShiny(rs.getInt("shiny"));
pokemon.setNest(rs.getInt("nest"));
pokemon.setNeww(rs.getInt("new"));
pokemon.setNotGettable(rs.getInt("not_gettable"));
pokemon.setFutureEvolve(rs.getInt("Future_Evolve"));
pokemon.setTotalCp40(rs.getInt("total_CP_40"));
pokemon.setTotalCp39(rs.getInt("total_CP_39"));
lista.add(pokemon);
}
int fromIndex = page * size;
int toIndex = fromIndex + size;
if (page + size > lista.size())
return new ArrayList<Pokemon>();
return lista.subList(fromIndex, toIndex);

}

}
Loading