diff --git a/IguideME.Web/Controllers/Apps/TileController.cs b/IguideME.Web/Controllers/Apps/TileController.cs index 35db0992..e571bf32 100644 --- a/IguideME.Web/Controllers/Apps/TileController.cs +++ b/IguideME.Web/Controllers/Apps/TileController.cs @@ -726,6 +726,16 @@ public ActionResult PatchAssignment([FromBody] AppAssignment assignment) return Ok(); } + [Authorize(Policy = "IsInstructor")] + [HttpDelete] + [Route("/external-assignments/{assignmentID}")] + public ActionResult DeleteAssignment(int assignmentID) + { + int courseID = this.GetCourseID(); + _databaseManager.DeleteExternalAssignment(assignmentID, courseID); + return Ok(); + } + [Authorize(Policy = "IsInstructor")] [HttpPatch] [Route("/external-assignments/{assignmentID}/title")] diff --git a/IguideME.Web/Frontend/src/api/entries.ts b/IguideME.Web/Frontend/src/api/entries.ts index 37ef43e2..819ebb7b 100644 --- a/IguideME.Web/Frontend/src/api/entries.ts +++ b/IguideME.Web/Frontend/src/api/entries.ts @@ -54,3 +54,7 @@ export async function patchExternalAssignment(assignment: Assignment): Promise { return await apiClient.patch(`external-assignments/${id}/title`, { title }); } + +export async function deleteExternalAssignment({assignmentID}: {assignmentID: number}): Promise { + return await apiClient.delete(`external-assignments/${assignmentID}`); +} diff --git a/IguideME.Web/Frontend/src/components/pages/admin/datawizard/datawizard.tsx b/IguideME.Web/Frontend/src/components/pages/admin/datawizard/datawizard.tsx index 620f11cd..65873d07 100644 --- a/IguideME.Web/Frontend/src/components/pages/admin/datawizard/datawizard.tsx +++ b/IguideME.Web/Frontend/src/components/pages/admin/datawizard/datawizard.tsx @@ -1,5 +1,5 @@ import { getStudentsByCourse } from '@/api/courses'; -import { getExternalAssignments, patchExternalAssignmentTitle, postExternalAssignment } from '@/api/entries'; +import { getExternalAssignments, patchExternalAssignmentTitle, postExternalAssignment, deleteExternalAssignment } from '@/api/entries'; import AdminTitle from '@/components/atoms/admin-titles/admin-titles'; import UploadManager from '@/components/crystals/upload-manager/upload-manager'; import QueryError from '@/components/particles/QueryError'; @@ -13,6 +13,7 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; import { Button, Input, Tooltip } from 'antd'; import { useState, type FC, type ReactElement } from 'react'; import AssignmentSettingsForm from './assignment-settings-form'; +import Swal from 'sweetalert2'; const DataWizard: FC = (): ReactElement => { return ( @@ -107,16 +108,23 @@ const ViewExternalAssignment: FC = ({ assignment, s const [uploadMenuOpen, setUploadMenuOpen] = useState(false); const queryClient = useQueryClient(); - const { mutate } = useMutation({ + const { mutate: patchExternalAssignment } = useMutation({ mutationFn: patchExternalAssignmentTitle, onSuccess: async () => { await queryClient.invalidateQueries({ queryKey: ['external-assignments'] }); }, }); + const { mutate: deleteExternalAss } = useMutation({ + mutationFn: deleteExternalAssignment, + onSuccess: async () => { + await queryClient.invalidateQueries({ queryKey: ['external-assignments'] }); + }, + }); + return (
-
+
{!uploadMenuOpen && ( - +
+ + +
)}
{uploadMenuOpen && ( diff --git a/IguideME.Web/Services/Constants/DatabaseQueries.cs b/IguideME.Web/Services/Constants/DatabaseQueries.cs index e16d1f5f..ecf2a9c9 100644 --- a/IguideME.Web/Services/Constants/DatabaseQueries.cs +++ b/IguideME.Web/Services/Constants/DatabaseQueries.cs @@ -625,8 +625,15 @@ ORDER BY `sync_id` `grading_type`=@gradingType WHERE `assignments`.`assignment_id`=@ID AND `assignments`.`course_id`=@courseID - ;"; - + ;"; + + public const string DELETE_EXTERNAL_ASSIGNMENT = + @"DELETE FROM `assignments` + WHERE `assignments`.`assignment_id`=@ID + AND `assignments`.`course_id`=@courseID + AND `assignments`.`published`=2 + ;"; + public const string UPDATE_EXTERNAL_ASSIGNMENT_TITLE = @"UPDATE `assignments` SET `title`=@title diff --git a/IguideME.Web/Services/DatabaseManager.cs b/IguideME.Web/Services/DatabaseManager.cs index 6a510f27..9551e1a7 100644 --- a/IguideME.Web/Services/DatabaseManager.cs +++ b/IguideME.Web/Services/DatabaseManager.cs @@ -549,7 +549,7 @@ public void RegisterUser(User user) ); } - public List GetExternalAssignments(int courseID) + public List GetExternalAssignments(int courseID) { List assignments = new(); @@ -633,7 +633,7 @@ public int RegisterExternalAssignment(AppAssignment assignment) ); return assignment_id; - } + } public void UpdateExternalAssignment(AppAssignment assignment) { @@ -645,7 +645,16 @@ public void UpdateExternalAssignment(AppAssignment assignment) new SQLiteParameter("maxGrade", assignment.MaxGrade), new SQLiteParameter("gradingType", assignment.GradingType) ); - } + } + + public void DeleteExternalAssignment(int assignmentID, int courseID) + { + int assignment_id = IDNonQuery( + DatabaseQueries.DELETE_EXTERNAL_ASSIGNMENT, + new SQLiteParameter("ID", assignmentID), + new SQLiteParameter("courseID", courseID) + ); + } public void UpdateExternalAssignmentTitle(int assignmentID, int courseID, string title) { @@ -2764,7 +2773,7 @@ public void CreateLayoutTileGroup(int courseID, string title, int position) // if (cols.Count < 1) return; NonQuery( - DatabaseQueries.REGISTER_TILE_GROUP, + DatabaseQueries.REGISTER_TILE_GROUP, // new SQLiteParameter("columnID", cols[0].ID), new SQLiteParameter("title", title), new SQLiteParameter("order", position),