Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions react_frontend/src/api/GetPastTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const GetUpcomingTests = () => {


const fetchUpcomingTests = async () => {
//fetching past tests from backend
try {
const response = await axios.get<Test[]>(
"http://127.0.0.1:8000/test/api/tests/",
Expand All @@ -44,6 +45,8 @@ const GetUpcomingTests = () => {
// fetchUpcomingTests();
const obj = useContext(AuthContext);
const testID = useContext(TestContext);

//fetching marks
const fetchmarks = async () => {

const userdata = {
Expand Down
14 changes: 7 additions & 7 deletions react_frontend/src/api/GetTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const GetTest: React.FC = () => {
// const history = useHistory();
const obj=useContext(AuthContext);
const { selectedTestPk, setSelectedTestPk } = useContext(TestContext) || { selectedTestPk: null, setSelectedTestPk: () => {} };

//fetching the tests from backend
useEffect(() => {
axios
.get<Test[]>("http://127.0.0.1:8000/test/api/tests/", {
Expand All @@ -58,19 +60,17 @@ const GetTest: React.FC = () => {

const handleFinalSubmit = async () => {
console.log()
// Assuming you have a mechanism to collect user answers (selectedAnswers)
if (!selectedTest) {
alert("Please select a test to submit.");
return;
}
console.log(obj.user.user_id,selectedTest.pk);
const testData = {
user: obj.user.user_id, // Replace with actual user ID
user: obj.user.user_id,
test: selectedTest.pk,
// Add user answers here (replace with your logic)
// answers: selectedAnswers, // Replace with your answer collection logic
};

//handling test submission
try {
const response = await axios.post(
"http://127.0.0.1:8000/test/api/calc_marks/", // Replace with your endpoint
Expand All @@ -82,8 +82,8 @@ const GetTest: React.FC = () => {
}
);

const marks = response.data.marks; // Assuming 'marks' is returned by the API
alert("Test submitted successfully! Your marks are: " + marks); // Display marks
const marks = response.data.marks;
alert("Test submitted successfully! Your marks are: " + marks);
navigate("/studentUpcomingTest");
} catch (error) {
console.error("Submission error:", error);
Expand All @@ -107,7 +107,7 @@ const GetTest: React.FC = () => {
// testId = {test.pk}
/>
}
<button className="bg-blue-500 text-white rounded py-2 px-4 mb-2" onClick={handleFinalSubmit} // Pass the onClick handler function
<button className="bg-blue-500 text-white rounded py-2 px-4 mb-2" onClick={handleFinalSubmit}
>Submit Test</button>


Expand Down
1 change: 1 addition & 0 deletions react_frontend/src/api/GetUpcomingTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const GetUpcomingTests = () => {

useEffect(() => {
const fetchUpcomingTests = async () => {
//fetching tests from backend
try {
const response = await axios.get<Test[]>(
"http://127.0.0.1:8000/test/api/tests/",
Expand Down
1 change: 1 addition & 0 deletions react_frontend/src/api/createIQ.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface IQ {

const CreateIQ =async (IQ : IQ) : Promise<number> => {
const { question, correctOption } = IQ;
//Creating a integer type question object
try {
const response = await axios
.post(
Expand Down
1 change: 1 addition & 0 deletions react_frontend/src/api/createMCQ.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const CreateMCQ= async (MCQ:MCQ):Promise<number>=> {
const { question, option1, option2, option3, option4, correctOptions } = MCQ;
try {
const response = await axios
//Creating a multiple correct question object
.post(
"http://127.0.0.1:8000/questions/multiple/",
{
Expand Down
2 changes: 1 addition & 1 deletion react_frontend/src/api/createQRef.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface Response {
const CreateQRef = async (props: props): Promise<Response> => {
const { arrqType } = props;


//fetching question reference table objects
try {
const response = await axios.post(
"http://127.0.0.1:8000/questions/qref/",
Expand Down
1 change: 1 addition & 0 deletions react_frontend/src/api/createSCQ.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface SCQ {

const CreateSCQ= async (SCQ:SCQ): Promise<number> =>{
const {question,option1,option2,option3,option4,correctOption}=SCQ;
//Creating a single correct question object
try {
const response = await axios
.post(
Expand Down
12 changes: 5 additions & 7 deletions react_frontend/src/api/getMCQ.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,14 @@ const GetMCQ: React.FC<Props> = ({ url, submitUrl }) => {

const handleSubmit = () => {
if (question && selectedOptions.length > 0) {
// Create a tuple where the first element is the question pk
// and the second element is the array of selected options.
const solTuple = [selectedOptions];

const data = {
user: new URLSearchParams({user_id: obj.user.user_id}).toString(), // Placeholder - adjust as necessary
test: testID, // Placeholder - adjust as necessary
qid: question.pk, // You might not need this separately since it's included in the tuple
qt: "MCQ", // Question type
sol: solTuple, // The tuple as the solution
user: new URLSearchParams({user_id: obj.user.user_id}).toString(),
test: testID,
qid: question.pk,
qt: "MCQ",
sol: solTuple,
};

axios.post(submitUrl, data, {
Expand Down
3 changes: 3 additions & 0 deletions react_frontend/src/api/getQ.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const GetQ: React.FC<props> = (props) => {
const [mcqs, setmcqs]: [MCQ[], (mcqs: MCQ[]) => void] = useState(MCQs);
const [iqs, setiqs]: [IQ[], (iqs: IQ[]) => void] = useState(IQs);
useEffect(() => {
//fetching single correct questions
axios
.get<SCQ[]>("http://127.0.0.1:8000/questions/single/", {
headers: {
Expand All @@ -101,6 +102,7 @@ const GetQ: React.FC<props> = (props) => {
});
}, []);
useEffect(() => {
//fetching multiple correct questions
axios
.get<MCQ[]>("http://127.0.0.1:8000/questions/multiple/", {
headers: {
Expand All @@ -112,6 +114,7 @@ const GetQ: React.FC<props> = (props) => {
});
}, []);
useEffect(() => {
//fetching integer type questions
axios
.get<IQ[]>("http://127.0.0.1:8000/questions/integer/", {
headers: {
Expand Down
3 changes: 3 additions & 0 deletions react_frontend/src/context/AuthContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const AuthProvider = ({ children }) => {

const navigate = useNavigate(); // Use useNavigate instead of useHistory

//sending login credentials to backend
const loginUser = async (email, password) => {
const response = await fetch("http://127.0.0.1:8000/token/", {
method: "POST",
Expand Down Expand Up @@ -72,6 +73,7 @@ export const AuthProvider = ({ children }) => {
}
};

//sending registration credentials to backend
const registerUser = async (email, username, password, password2) => {
const response = await fetch("http://127.0.0.1:8000/register/", {
method: "POST",
Expand Down Expand Up @@ -108,6 +110,7 @@ export const AuthProvider = ({ children }) => {
}
}

//implementing logout feature
const logoutUser = () => {
setAuthTokens(null)
setUser(null)
Expand Down
2 changes: 1 addition & 1 deletion react_frontend/src/pages/Loginpage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const LoginPage: React.FC = () => {
const password = e.currentTarget.password.value;

if (email.length > 0) {
loginUser(email, password);
loginUser(email, password); //implement login feature
}

console.log(email);
Expand Down
2 changes: 1 addition & 1 deletion react_frontend/src/pages/signuppage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const SignUpPage: React.FC = () => {

const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
registerUser(email, username, password, password2);
registerUser(email, username, password, password2); //implement registration feature
};

return (
Expand Down