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

Merge US08 -> Devel #56

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
finalizando algumas partes do projeto envolvendo responsividade
Co-authored-by: AJCGassassin <andrezinhojoao3@gmail.com>
Co-authored-by: pedroMADBR <trabalhos.pedromiguel@gmail.com>
Co-authored-by: renantfm4 <renantfm0@gmail.com>
Co-authored-by: Danielle Rodrigues <Danizelle@users.noreply.github.com>
  • Loading branch information
5 people committed Dec 5, 2023
commit 36697222870798762a0d15503b8f4f3efdd2f256
73 changes: 72 additions & 1 deletion back-usuarios/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,25 @@ app.post('/create_favorite', async (req, res) => {

});

app.post('/list_user_favorites', async (req, res) => {
try {
const {userEmail} = req.body;

console.log("aaaaaaaa", userEmail.userEmail);
// Validate input
if (!userEmail) {
return res.status(400).json({ success: false, message: 'Invalid request body.' });
}

const documents = await listUserFavorites(pool, userEmail.userEmail);

res.json({ success: true, documents });
} catch (error) {
console.error('Error:', error.message);
res.status(500).json({ success: false, message: 'Internal server error.' });
}
});

// // app.use("/",userRoutes);
// async function createFavorite(pool, favoritesId, userToken, documentId) {
// const result = await pool.execute(
Expand All @@ -81,7 +100,7 @@ async function createFavorite(pool, favoritesId, userToken, documentId) {
if (result.affectedRows > 0) {
console.log('Favorite added successfully!');
} else {
console.log('Failed to add favorite.');
console.log('Failed to add favorite.\n');
throw new Error('Failed to add favorite.');
}
} catch (error) {
Expand All @@ -90,6 +109,58 @@ async function createFavorite(pool, favoritesId, userToken, documentId) {
}
}

async function listUserFavorites(pool, userEmail) {

const query = util.promisify(pool.query).bind(pool);
try {
const result = await query(
`
SELECT USER.email, DOCUMENT.docName, DOCUMENT.link, DOCUMENT.content, DOCUMENT.docKey, DOCUMENT.creationDate
FROM favorites
INNER JOIN USER ON favorites.userToken = USER.token
INNER JOIN DOCUMENT ON favorites.documentId = DOCUMENT.docKey
WHERE USER.email = (?)
ORDER BY USER.email
`, [userEmail]
);
if (result.affectedRows > 0) {
console.log('Favorite selection was successfull!');
} else {
console.log('Failed to select favorite.');
console.log("userEmail: ", userEmail);
throw new Error('Failed to selecttt favorite.');
}


const [favorites] = await pool.query(query, userEmail.userEmail);

res.json({ success: true, documents });

return favorites;
} catch (error) {
console.log("é aqui o problema?")
console.error('Error executing query:', error.message);
throw error;
}
}


// async function listUserFavorites(pool, userEmail) {
// const [favorites] = await pool.execute(
// `
// SELECT USER.email, DOCUMENT.docName, DOCUMENT.link, DOCUMENT.content, DOCUMENT.docKey, DOCUMENT.creationDate
// FROM favorites
// INNER JOIN USER ON favorites.userToken = USER.token
// INNER JOIN DOCUMENT ON favorites.documentId = DOCUMENT.docKey
// WHERE USER.email = ?
// ORDER BY USER.email
// `,
// [userEmail]
// );

// return favorites;
// }

app.listen(PORT, () =>{
console.log(`Server running on port ${PORT}\n`)
})
Expand Down
23 changes: 23 additions & 0 deletions public/Unbus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<link rel="icon" href="%PUBLIC_URL%/Unbus.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
Expand Down
Binary file removed public/logo192.png
Binary file not shown.
Binary file removed public/logo512.png
Binary file not shown.
1 change: 0 additions & 1 deletion src/components/pages/Error.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
.error_container{
width: 90%;
min-height: 100vh;
padding: 5%;
background-position: center;
background-size: cover;
background-color: #FFFFFF;
Expand Down
6 changes: 1 addition & 5 deletions src/components/pages/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ import bolinha2 from '../img/Bolinha 2.svg';
import bolinha3 from '../img/Bolinha3.svg';
import Plus from '../Plus.js';


const { MeiliSearch } = require('meilisearch');


function Home(){
const [searchResults, setSearchResults] = useState([]);
const { isLoggedIn, logout, user, setUser } = useAuth();
Expand Down Expand Up @@ -53,7 +49,7 @@ function Home(){
{!isLoggedIn && (
<div className={styles.button_login_container}>
<div>
<button className = {styles.botaoLogin}>LOGIN</button>
<button className = {styles.botaoLogin} onClick={() => navigate('/login')}>LOGIN</button>
</div>
</div> )}
{isLoggedIn && (
Expand Down
2 changes: 1 addition & 1 deletion src/components/pages/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function Login() {
// Chame a função login do contexto para salvar as informações do usuário
login({ name: res.data.user[0], email: res.data.user[1] });
// Redirecione para a página desejada após o login
navigate('/pesquisa');
//navigate('/pesquisa');
} else {
console.log("No status");
}
Expand Down
38 changes: 23 additions & 15 deletions src/components/pages/Pesquisa.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import lupa from "../img/lupa.svg";
import onda2 from "../img/Rectangle 22.svg";
import { useAuth } from '../contexts/AuthContext';
import axios from "axios";
// import { useFavoriteContext } from '../contexts/Favorites.js';



function Pesquisa({id}) {
Expand All @@ -29,8 +29,6 @@ function Pesquisa({id}) {
const [filtersVisible, setFiltersVisible] = useState(false);
const [filterControlsVisible, setFilterControlsVisible] = useState(false);
const [selectedDocumentId, setSelectedDocumentId] = useState(null);
//const {favorite, addFavorite} = useFavoriteContext();
// const isFavorite = favorite.some((fav) => fav.id === id)
const [favorite, setFavorite] = useState({
favoritesId: '',
userToken: '',
Expand Down Expand Up @@ -186,9 +184,7 @@ function Pesquisa({id}) {
window.open(resource.link, '_blank');
};

// const handleFavoriteClick = (documentId) => {
// addFavorite({ id: documentId }); // Adiciona ou remove o documento dos favorito
// };

function getRandom() {
return Math.random();
}
Expand All @@ -198,13 +194,11 @@ function Pesquisa({id}) {
userToken: user.token,
documentId: documentId,
});

// const data = {
// favoritesId: "1",
// userToken: userToken,
// documentId: documentId
// };
// console.log(data);

setUserEmail({
userEmail: user.email
})

await axios.post('http://localhost:8800/create_favorite', {
favoritesId: getRandom(4),
userToken: userToken,
Expand All @@ -214,7 +208,7 @@ function Pesquisa({id}) {
}})
.then(res => {
alert("documento adicionado com sucesso!");
console.log("deu certo?");
console.log("deu certo!");
})
.catch(error => {
if (error.response && error.response.status === 404 || error.response.status === 500) {
Expand All @@ -226,6 +220,21 @@ function Pesquisa({id}) {
console.log(error);
}
});

await axios.post('http://localhost:8800/list_user_favorites', {
userEmail: userEmail
}, {headers: {
'Content-Type': 'application/json'
}}).then(res => {
console.log('Favorite Documents:', res.data.documents);
}).catch (error =>{
if(error.response.status === 400){
console.error('Error fetching favorite documents:', error);
console.error(error.config.data);

}

})

};

Expand Down Expand Up @@ -339,7 +348,6 @@ function Pesquisa({id}) {
{isLoggedIn && (
<div
className={styles.botaoFav}
/*onClick={() => handleFavoriteClick(resource.id)}*/
onClick={() => saveFavorite(resource.id)}

>
Expand Down
11 changes: 1 addition & 10 deletions src/components/pages/Pesquisa.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
.search_container{
width: 80%;
min-height: 100vh;
/* padding: 0 2rem; */
background-position: center;
background-size: cover;
background-color: #FFFFFF;
Expand Down Expand Up @@ -106,7 +105,7 @@
.grid {
display: flex;
flex-wrap: wrap;
max-width: 800px;
max-width: 90%;
position: absolute;
top: 40%;
left: 3%;
Expand Down Expand Up @@ -251,16 +250,13 @@
.periodo{
font-family: Poppins, serif;
display: flex;
/* justify-content: flex-start; */
left: 100%;
}

.relevance{
font-family: Poppins, serif;

display: flex;
left: 10%;
/* justify-content: flex-start; */

text-align: center;

Expand All @@ -275,7 +271,6 @@
font-family: Poppins, serif;
left: 400%;
display: flex;
/* justify-content: flex-start; */


}
Expand Down Expand Up @@ -312,9 +307,7 @@
width: 140px;
height: 30px;
position: absolute;
/* display: flexbox; */
justify-content: right;
/* align-items: center; */
background-color: #00305b;
color: #FFFFFF;
font-family: Poppins, serif;
Expand All @@ -333,9 +326,7 @@
width: 140px;
height: 30px;
position: absolute;
/* display: flexbox; */
justify-content: right;
/* align-items: center; */
background-color: #00305b;
color: #FFFFFF;
font-family: Poppins, serif;
Expand Down
Loading