Skip to content

Commit

Permalink
push
Browse files Browse the repository at this point in the history
  • Loading branch information
DifficultCupid2 committed Jul 18, 2024
1 parent c401ee0 commit 2fd435f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 55 deletions.
4 changes: 4 additions & 0 deletions .idea/misc.xml

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

6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public List<Student> getStudents(@RequestParam(value = "id_project") int id_proj
return students;
}

@CrossOrigin(origins = "http://localhost:5173")
@GetMapping("/getCourses")
public List<Course> getCourses(@RequestParam(value = "cip") String cip) {
return tutorMapper.getCoursesFromTutor(cip);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const TutorDashboard = () =>{
</div>
</div>
<div className={styles.divAddButton}>
<Link to="/tutorDashboard/addCourse">
<Link to="/tutorDashboard/AddCourse">
<button className={styles.buttonForm}>ajouter</button>
</Link>
</div>
Expand Down
90 changes: 36 additions & 54 deletions Frontend/git-diploma/src/widget/addCourse.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,72 +4,54 @@ import api from '../api/axiosConfig';
import { useKeycloak } from '@react-keycloak/web'


const AddCourse = () => {

const [courseNotSet, setCourseNotSet] = useState([]);
const AddCourse = () => {

const [courseNotSet, setCourseNotSet] = useState([]);
const [selectedCourseId, setSelectedCourseId] = useState('');
const [end_Date, setEndDate] = useState('');
const [team_Size, setTeamSize] = useState('');
const [tempEndDates, setTempEndDates] = useState({});
const { keycloak } = useKeycloak()

const handleSelectCourse = (e) => {
setSelectedCourseId(e.target.value);
setEndDate(tempEndDates[e.target.value] || '');
};

const handleEndDateChange = (e) => {
setEndDate(e.target.value);
};

const createTeams = async () => {
try {
await api.get("/api/tutor/createTeams", {
params: {
teamSize: team_Size,
endDate: end_Date,
sigle: selectedCourseId,
},
headers: {
'Authorization': 'Bearer ' + keycloak.token
}
});
console.log("success");
} catch (error) {
console.error("failed :", error);
}
};


const handleTeamSizeChange = (e) => {
setTeamSize(e.target.value);

const handleTeamSizeChange = (e) => {
setTeamSize(e.target.value);
};

const handleSubmit = () => {
console.log(selectedCourseId);
createTeams();

const handleSubmit = async () => {
try {
const response = await api.get("/api/tutor/getCourses", {
headers: {'Authorization': 'Bearer ' + keycloak.token},
params: { cip: keycloak.tokenParsed.preferred_username }
});
console.log(response);
setCours(response.data);
} catch (err) {
console.log("Error fetching data:", err);
}

setTempEndDates({
...tempEndDates,
[selectedCourseId]: endDate
});
console.log(`Temporary End Date set for Course ID: ${selectedCourseId}, End Date: ${endDate}`);
};
const handleEndDateChange = (e) => {
setEndDate(e.target.value);
};

const handleSubmit = () => {
console.log(selectedCourseId);
createTeams();
}

const createTeams = async () => {
try {
await api.get("/api/tutor/createTeams", {
params: {
teamSize: team_Size,
endDate: end_Date,
sigle: selectedCourseId,
},
headers: {
'Authorization': 'Bearer ' + keycloak.token
}
});
console.log("success");
} catch (error) {
console.error("failed :", error);
}
};

const handleCourseNotSet = async () => {
try {
const handleCourseNotSet = async () => {
try {
const response = await api.get("/api/tutor/getCourseWithNoTeams", {
headers: {'Authorization': 'Bearer ' + keycloak.token},
});
Expand All @@ -90,7 +72,7 @@ const createTeams = async () => {
<select onChange={handleSelectCourse} value={selectedCourseId}>
<option value="">Select a course</option>
{courseNotSet.map((course) => (
<option key={course.courseId} value={course.courseId}>
<option key={course.sigle} value={course.courseId}>
{course.name}, {course.code}
</option>
))}
Expand Down

0 comments on commit 2fd435f

Please sign in to comment.