From cb7936a9b87c6e787711f7dd66c19acf9a271ec1 Mon Sep 17 00:00:00 2001 From: lucas cardoso Date: Tue, 16 Aug 2022 15:23:45 -0400 Subject: [PATCH] Add new filters in Users repository --- app/Repositories/UsuarioRepository.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/app/Repositories/UsuarioRepository.php b/app/Repositories/UsuarioRepository.php index 8865235..b1da959 100644 --- a/app/Repositories/UsuarioRepository.php +++ b/app/Repositories/UsuarioRepository.php @@ -21,9 +21,29 @@ class UsuarioRepository extends Repository $query .= " AND matricula = :matricula "; $dados['matricula'] = $params['matricula']; } + if ($params['email']) { + $query .= " AND email = :email "; + $dados['email'] = $params['email']; + } + return $this->db->read($query, $dados)->fetchAll(); + } + + function get(array $params = []) + { + $table = $this->table; + $query = "SELECT * FROM $table WHERE 1=1"; + if ($params['matricula']) { + $query .= " AND matricula = :matricula "; + $dados['matricula'] = $params['matricula']; + } + + if ($params['id']) { + $query .= " AND id = :id "; + $dados['id'] = $params['id']; + } if (empty($params['matricula'])) { throw new Exception('Parâmetro matricula é obrigatório'); } - return $this->db->read($query, $params)->fetchAll(); + return $this->db->read($query, $dados)->fetchAll(); } } \ No newline at end of file