Commit 63737548 authored by Thiwanka K.A.T's avatar Thiwanka K.A.T 🎯

Merge branch 'IT19076362' into 'master'

It19076362

See merge request !80
parents 69e8391d 16bfceb2
No preview for this file type
......@@ -25,6 +25,23 @@ def create_module():
}}), HTTP_201_CREATED
@module.get('/')
def get_modules():
module_obj = Module.query.all()
modules = []
print(module_obj)
for module in module_obj:
modules.append({"id": module.id, "name": module.name, "code": module.code, "created_at": module.created_at, "updated_at": module.updated_at})
print(modules)
if module_obj is None:
return jsonify({'err': "Module does not exist"}), HTTP_400_BAD_REQUEST
return jsonify({'msg': 'Module found', 'modules': modules}), HTTP_200_OK
@module.get('/<module_id>')
def get_module(module_id):
if not module_id:
......@@ -33,9 +50,9 @@ def get_module(module_id):
module_obj = Module.query.filter_by(id=module_id).first()
if module_obj is None:
return jsonify({'err': "Module does not exist"}), HTTP_400_BAD_REQUEST
return jsonify({'err': "Modules does not exist"}), HTTP_400_BAD_REQUEST
return jsonify({'msg': 'Module found', 'module': {
return jsonify({'msg': 'Modules found', 'module': {
'name': module_obj.name,
'code': module_obj.code,
'created_at': module_obj.created_at,
......
import React, { useEffect, useState } from "react";
import { Link } from "react-router-dom";
import axios from "axios";
import { RiDeleteBinLine } from "react-icons/ri";
import axios from "axios";
import Sidebar from "../components/sidebar/Sidebar";
import Spinner from "../components/loading/Spinner";
......@@ -10,21 +10,16 @@ import TopNav from "../components/topnav/TopNav";
import "../assets/css/Usercreate.css";
const ManageClasses = () => {
const ManageModules = () => {
const [btnState, setBtnState] = useState(false);
const [error, setError] = useState("");
const [isLoading, setIsLoading] = useState(true);
const [material, setMaterial] = useState({ code: "", name: "" });
const [materials, setMaterials] = useState([]);
const [module, setModule] = useState({ code: "", name: "" });
const [modules, setModules] = useState([]);
const fields = ["", "Module Code", "Module Name", "Created At", "Actions"];
const renderOrderHead = (item, index) => <th key={index}>{item}</th>;
const classes = [
{ code: "A001", name: "CTSE", createdAt: "2022-04-05" },
{ code: "A002", name: "CTSE", createdAt: "2022-04-05" },
{ code: "A003", name: "CTSE", createdAt: "2022-04-05" },
];
const renderOrderBody = (item, index) => (
<tr key={index}>
<td>{index + 1}</td>
......@@ -40,7 +35,7 @@ const ManageClasses = () => {
className="action-btn x"
style={{ marginLeft: "2rem" }}
onClick={() => {
if (window.confirm("Are you sure to delete this class?")) {
if (window.confirm("Are you sure to delete this module?")) {
deleteHandler(item._id, item.username);
}
}}
......@@ -56,37 +51,35 @@ const ManageClasses = () => {
e.preventDefault();
setBtnState(true);
for (let key of Object.keys(material)) {
if (!material[key]) {
for (let key of Object.keys(module)) {
if (!module[key]) {
setBtnState(false);
return setError("Please fill all the fields");
}
}
try {
const res = await axios.post("materials", material);
const res = await axios.post("/modules/create", module);
console.log(res);
setMaterial({
code: "",
name: "",
});
getAllMaterial();
setModule({ code: "", name: "" });
getAllModules();
setError("");
window.alert("Class added successfully");
window.alert("Module added successfully");
setBtnState(false);
setIsLoading(true);
} catch (err) {
setBtnState(false);
setError(err.response.data.message);
console.log(err.response);
}
};
const deleteHandler = async (id, username) => {
try {
const res = await axios.delete(`materials/${id}`);
const res = await axios.delete(`modules/${id}`);
if (res.statusText === "OK") {
getAllMaterial();
getAllModules();
setError("");
window.alert("Class has been successfully deleted");
setIsLoading(true);
......@@ -96,17 +89,19 @@ const ManageClasses = () => {
}
};
const getAllMaterial = async () => {
const getAllModules = async () => {
setIsLoading(true);
try {
const res = await axios.get(`materials`);
setMaterials(res.data.materials);
const res = await axios.get("modules");
console.log(res);
setModules(res.data.modules);
setIsLoading(false);
} catch (err) {
console.log(err.response);
}
};
useEffect(() => getAllMaterial(), []);
useEffect(() => getAllModules(), []);
return (
<div>
......@@ -129,10 +124,10 @@ const ManageClasses = () => {
<input
type="text"
placeholder="Module Code"
value={material.code}
value={module.code}
onChange={e =>
setMaterial({
...material,
setModule({
...module,
code: e.target.value,
})
}
......@@ -145,10 +140,10 @@ const ManageClasses = () => {
<input
type="text"
placeholder="Module Name"
value={material.name}
value={module.name}
onChange={e =>
setMaterial({
...material,
setModule({
...module,
name: e.target.value,
})
}
......@@ -167,14 +162,14 @@ const ManageClasses = () => {
</div>
<div className="card col-12">
<h2>Created Modules</h2>
{false ? (
{isLoading ? (
<Spinner />
) : (
<Table
limit="5"
headData={fields}
renderHead={(item, index) => renderOrderHead(item, index)}
bodyData={classes}
bodyData={modules}
renderBody={(item, index) => renderOrderBody(item, index)}
/>
)}
......@@ -185,4 +180,4 @@ const ManageClasses = () => {
);
};
export default ManageClasses;
export default ManageModules;
......@@ -13,7 +13,7 @@ import ManagerApprovedOrders from "../pages/ManagerApprovedOrders";
import TeacherDashboard from "../pages/TeacherDashboard";
import ManageServices from "../pages/ManageServices";
import ManageStudents from "../pages/ManageStudents";
import ManageClasses from "../pages/ManageClasses";
import ManageModules from "../pages/ManageModules";
import OfficerDashboard from "../pages/OfficerDashboard";
import OfficerOrders from "../pages/OfficerOrders";
import Register from "../pages/Register";
......@@ -38,7 +38,7 @@ const Routes = () => {
<Route exact path="/auth/teacher/dashboard" component={TeacherDashboard} />
<Route exact path="/auth/teacher/students" component={ManageStudents} />
<Route exact path="/auth/teacher/modules" component={ManageClasses} />
<Route exact path="/auth/teacher/modules" component={ManageModules} />
<Route exact path="/auth/teacher/assignments" component={ManageAssignments} />
<Route exact path="/auth/teacher/assignments/:id" component={ViewAssignment} />
<Route exact path="/auth/teacher/assignments/:id/diagrams" component={GeneratedDiagrams} />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment