Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
… into feature/grupoEventosController
  • Loading branch information
Francisco-Paulino-Arruda-Filho committed Dec 6, 2023
2 parents bb39fb4 + 999a4ca commit adc61ec
Showing 1 changed file with 11 additions and 28 deletions.
39 changes: 11 additions & 28 deletions src/main/java/com/casaculturaqxd/sgec/DAO/EventoDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public boolean removerEvento(Evento evento) {
}

public ArrayList<Evento> listarUltimosEventos() throws SQLException {
String sql = "select id_evento,nome_evento,data_inicial, horario, id_service_file from evento where nome_evento <> '' order by data_inicial desc limit 5";
String sql = "SELECT id_evento,nome_evento,data_inicial, horario, id_service_file FROM ultimos_eventos LIMIT 5";
PreparedStatement stmt = connection.prepareStatement(sql);
ArrayList<Evento> eventos = new ArrayList<>();
try {
Expand Down Expand Up @@ -229,7 +229,8 @@ public ArrayList<String> listarNomesEventos() throws SQLException {
}

public ArrayList<Evento> pesquisarEvento(String nome, Date inicioDate, Date fimDate) {
String sql = "select id_evento, nome_evento, inicio, fim from pesquisar_evento where nome_evento ilike ? ";
String sql = "SELECT * FROM pesquisar_evento where nome ilike ? ";

if (inicioDate != null)
sql += "and inicio >= '" + inicioDate.toString() + "' ";

Expand All @@ -245,6 +246,7 @@ public ArrayList<Evento> pesquisarEvento(String nome, Date inicioDate, Date fimD
PreparedStatement stmt = connection.prepareStatement(sql);
stmt.setString(1, "%" + nome + "%");
ResultSet resultSet = stmt.executeQuery();

while (resultSet.next()) {
Evento evento = new Evento(resultSet.getInt("id_evento"));
eventos.add(getPreviewEvento(evento).get());
Expand Down Expand Up @@ -359,9 +361,8 @@ public Optional<Evento> getEvento(String nomeEvento) throws SQLException {
}

public Optional<Evento> getPreviewEvento(Evento evento) throws SQLException {
String sql = "SELECT id_evento,nome_evento,data_inicial, horario, id_service_file FROM evento WHERE id_evento = ?";
String sql = "SELECT id_evento, nome_evento, acessivel_em_libras, data_inicial, horario, id_service_file FROM evento WHERE id_evento = ?";
PreparedStatement preparedStatement = connection.prepareStatement(sql);

try {
preparedStatement.setInt(1, evento.getIdEvento());
ResultSet resultSet = preparedStatement.executeQuery();
Expand All @@ -377,8 +378,12 @@ public Optional<Evento> getPreviewEvento(Evento evento) throws SQLException {
}
EventoBuilder eventoBuilder = new EventoBuilder();

eventoBuilder.setHorario(resultSet.getTime("horario")).setId(resultSet.getInt("id_evento"))
.setNome(resultSet.getString("nome_evento")).setDataInicial(resultSet.getDate("data_inicial"))
eventoBuilder
.setHorario(resultSet.getTime("horario"))
.setAcessivelEmLibras(resultSet.getBoolean("acessivel_em_libras"))
.setId(resultSet.getInt("id_evento"))
.setNome(resultSet.getString("nome_evento"))
.setDataInicial(resultSet.getDate("data_inicial"))
.setImagemCapa(imagemCapa);

return Optional.ofNullable(eventoBuilder.getEvento());
Expand All @@ -394,28 +399,6 @@ public Optional<Evento> getPreviewEvento(Evento evento) throws SQLException {
}
}

public Optional<Evento> getPreviewEvento(String nomeEvento) throws SQLException {
String sql = "SELECT id_evento FROM evento WHERE nome_evento ILIKE ?";
PreparedStatement preparedStatement = connection.prepareStatement(sql);

try {
preparedStatement.setString(1, nomeEvento);
ResultSet resultSet = preparedStatement.executeQuery();
if (resultSet.next()) {
Evento evento = new Evento(resultSet.getInt("id_evento"));

return getPreviewEvento(evento);
} else {
return Optional.empty();
}
} catch (Exception e) {
logException(e);
throw new SQLException("falha buscando evento com nome" + nomeEvento, e);
} finally {
preparedStatement.close();
}
}

private ArrayList<ServiceFile> buscarArquivosPorEvento(Evento evento) throws SQLException {
ServiceFileDAO serviceFileDAO = new ServiceFileDAO(connection);
return serviceFileDAO.listarArquivosEvento(evento);
Expand Down

0 comments on commit adc61ec

Please sign in to comment.