Skip to content

Commit

Permalink
Merge pull request #59 from ES2-UFPI/henrique
Browse files Browse the repository at this point in the history
recovering classes on database to frontend #48
  • Loading branch information
dataskeptic authored Mar 21, 2023
2 parents b4c1b0b + 3587327 commit b48a32a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
14 changes: 12 additions & 2 deletions server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ app.post('/createAvaliation', async (req: Request, res: Response) => {
app.get('/getAvaliations', async (req: Request, res: Response) => {
try {
const Avaliations = await AvaliationModel.find();
res.status(200).json({ message: 'Form found successfully', Avaliations });
res.status(200).json({ message: 'Avaliations found successfully', Avaliations });
} catch (error) {
console.error(error);
res.status(500).json({ message: 'Error finding form' });
res.status(500).json({ message: 'Error finding Avaliations' });
}
});

Expand Down Expand Up @@ -87,6 +87,16 @@ app.post('/createClass', async (req: Request, res: Response) => {
}
});

app.get('/getClasses', async (req: Request, res: Response) => {
try {
const classes: IClass[] = await Class.find({});
res.status(200).json({ classes });
} catch (err) {
console.error(err);
res.status(500).send('Server error');
}
});


mongoose.connect(`${process.env.MONGO_URL}`).then(() => {
console.log(`listening on port ${PORT}`);
Expand Down
21 changes: 21 additions & 0 deletions vite-client/src/Pages/ViewClasses/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
import { useEffect, useState } from 'react';
import { Wrapper } from '../../styles/Layout'
import { Classes } from './styles'

interface iClasses {
_id: string;
className: string;
classSummary: string;
}

export function ViewClasses(){

const [classes, setClasses] = useState<iClasses[]>([]);

useEffect(() => {
const fetchForms = async () => {
const response = await fetch('http://localhost:3000/getClasses');
const data = await response.json();
console.log(data.classes);
setClasses(data.classes);
};
fetchForms();
console.log(classes);
}, []);

return (
<Classes>
<Wrapper>
Expand Down

0 comments on commit b48a32a

Please sign in to comment.