Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inserindo view de pesquisar evento #213

Merged
merged 1 commit into from
Dec 5, 2023
Merged
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
41 changes: 12 additions & 29 deletions src/main/java/com/casaculturaqxd/sgec/DAO/EventoDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,13 @@ public ArrayList<String> listarNomesEventos() throws SQLException {
}

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

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

if (fimDate != null)
sql += "and data_final <= '" + fimDate.toString() + "' ";
sql += "and fim <= '" + fimDate.toString() + "' ";

if (nome == "" && inicioDate == null && fimDate == null)
sql += "limit 30";
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
Loading