Skip to content

Commit be60e75

Browse files
authored
Merge pull request #137 from Coding-Club-IITG/aditya2
Aditya2
2 parents 69284d2 + 3a1ad8e commit be60e75

4 files changed

Lines changed: 338 additions & 66 deletions

File tree

admin/src/apis/courses.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const fetchCourses = async () => {
1717
};
1818

1919
// Update course name
20-
export const updateCourseName = async (code, newName) => {
20+
export const updateCourseName = async (code, newName, newCode) => {
2121
try {
2222
const safeCode = code.toLowerCase().trim();
2323
const response = await fetch(`${API_BASE_URL}api/admin/course/${safeCode}`, {
@@ -26,7 +26,7 @@ export const updateCourseName = async (code, newName) => {
2626
"Content-Type": "application/json",
2727
Authorization: "Bearer admin-coursehub-cc23-golang",
2828
},
29-
body: JSON.stringify({ name: newName }),
29+
body: JSON.stringify({ name: newName, newCode }),
3030
credentials: "include",
3131
});
3232
return await response.json();
@@ -129,3 +129,28 @@ export const bulkSyncCourses = async (courses, analysis, onProgress = null) => {
129129

130130
return results;
131131
};
132+
133+
// Delete a course
134+
export const deleteCourse = async (code) => {
135+
try {
136+
const safeCode = code.toLowerCase().trim();
137+
const response = await fetch(`${API_BASE_URL}api/admin/course/${safeCode}/delete`, {
138+
method: "DELETE",
139+
headers: {
140+
"Content-Type": "application/json",
141+
Authorization: "Bearer admin-coursehub-cc23-golang",
142+
},
143+
credentials: "include",
144+
});
145+
146+
if (!response.ok) {
147+
const errorData = await response.json();
148+
throw new Error(errorData.message || "Failed to delete course");
149+
}
150+
151+
return await response.json();
152+
} catch (error) {
153+
console.error("Error deleting course:", error);
154+
throw error;
155+
}
156+
};

0 commit comments

Comments
 (0)