Skip to content

Commit

Permalink
Mandando a materia selecionada para o front
Browse files Browse the repository at this point in the history
  • Loading branch information
VituuDias committed Dec 3, 2023
1 parent 76317b1 commit bf37d98
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 10 deletions.
12 changes: 10 additions & 2 deletions backend/account/serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from rest_framework import serializers
from account.models import User
from account.models import User, MateriaSelecionada
from django.utils.encoding import smart_str, force_bytes, DjangoUnicodeDecodeError
from django.utils.http import urlsafe_base64_decode, urlsafe_base64_encode
from django.contrib.auth.tokens import PasswordResetTokenGenerator
Expand Down Expand Up @@ -114,4 +114,12 @@ def validate(self, attrs):

# Serializador para 'MateriaSelecionada'
class SelecionarMateriaSerializer(serializers.Serializer):
idTurmaProfessor = serializers.IntegerField()
idTurmaProfessor = serializers.IntegerField()


# Serializador para 'MateriaSelecionada'

class MandarMateriaSerializer(serializers.ModelSerializer):
class Meta:
model = MateriaSelecionada
fields = '__all__'
3 changes: 3 additions & 0 deletions backend/account/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
UserPasswordResetView,
processar_horario,
selecionar_materia,
mandar_materiaView,
)

# Definição de padrões de URL para as visualizações correspondentes
Expand All @@ -20,4 +21,6 @@
path('reset-password/<uid>/<token>/', UserPasswordResetView.as_view(), name='reset-password'), # Rota para redefinição de senha
path('horario/', processar_horario, name='processar_horario'), # Rota para processamento de horário
path('selecionar_materia/', selecionar_materia, name='selecionar_materia'), # Rota para seleção de matéria
path('mandar_materias/', mandar_materiaView.as_view(), name='mandar_materia'),

]
12 changes: 11 additions & 1 deletion backend/account/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
UserProfileSerializer,
UserRegistrationSerializer,
SelecionarMateriaSerializer,
MandarMateriaSerializer,
)
from django.contrib.auth import authenticate
from account.renderers import UserRenderer
Expand Down Expand Up @@ -143,4 +144,13 @@ def obter_dados_do_json(id_turma_professor):
# Filtra as chaves que correspondem aos campos do modelo
dados_filtrados = {campo.name: turma[campo.name] for campo in MateriaSelecionada._meta.get_fields() if campo.name in turma}
return dados_filtrados
return None
return None


#manda a materia de volta para o frontend
class mandar_materiaView(APIView):
def get(self, request):
dados = MateriaSelecionada.objects.all()
serializer = MandarMateriaSerializer(dados, many=True)

return Response(serializer.data)
68 changes: 62 additions & 6 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"@testing-library/jest-dom": "^5.16.1",
"@testing-library/react": "^12.1.2",
"@testing-library/user-event": "^13.5.0",
"axios": "^1.6.2",
"papaparse": "^5.4.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
Expand Down
29 changes: 28 additions & 1 deletion frontend/src/pages/Grade.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import Grade from '../styleheets/Grade.css'; // Importe o arquivo de estilo corretamente
import { Grid } from "@mui/material";
import Navbar from "../components/Navbar";
import axios from 'axios';


const Critérios = () => {
Expand All @@ -13,6 +14,19 @@ const Critérios = () => {
['', '', '', '', ''],
]);

const [valoresBack, setValoresBack] = useState([]);
//pegar os dados do back
useEffect(() => {
axios.get('http://127.0.0.1:8000/api/user/mandar_materias')
.then(response => {
console.log(response.data);
setValoresBack(response.data);
})
.catch(error => {
console.error('Erro ao buscar dados:', error);
});
}, []);

const handleInputChange = (row, col, value) => {
const newInputValues = [...inputValues];
newInputValues[row][col] = value;
Expand Down Expand Up @@ -54,13 +68,26 @@ const Critérios = () => {
);
};



return (

<div className="Critérios">
<Navbar />
<h2>Adicione os critérios:</h2>
{renderTable()}
{valoresBack.length > 0 && (
<div>
<p>Horários das matérias:</p>
<ul>
{valoresBack.map((materia, index) => (
<li key={index}>{materia.horario}</li>
))}
</ul>
</div>
)}
</div>

);
};

Expand Down

0 comments on commit bf37d98

Please sign in to comment.