diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CourseController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CourseController.java index f85980c..e3c3e0e 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CourseController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CourseController.java @@ -6,10 +6,7 @@ import org.springframework.web.bind.annotation.*; import ovh.herisson.Clyde.Repositories.CurriculumCourseRepository; import ovh.herisson.Clyde.Responses.UnauthorizedResponse; import ovh.herisson.Clyde.Services.*; -import ovh.herisson.Clyde.Tables.Course; -import ovh.herisson.Clyde.Tables.Role; -import ovh.herisson.Clyde.Tables.User; -import ovh.herisson.Clyde.Tables.UserCurriculum; +import ovh.herisson.Clyde.Tables.*; import java.util.ArrayList; import java.util.HashMap; @@ -28,15 +25,18 @@ public class CourseController { private final UserService userService; + private final CurriculumService curriculumService; + private final UserCurriculumService userCurriculumService; private final CurriculumCourseRepository curriculumCourseRepository; private final CurriculumCourseService curriculumCourseService; - public CourseController(CourseService courseServ, TeacherCourseService teacherCourseServ, AuthenticatorService authServ, UserService userService, UserCurriculumService userCurriculumService, CurriculumCourseRepository curriculumCourseRepository, CurriculumCourseService curriculumCourseService) { + public CourseController(CourseService courseServ, TeacherCourseService teacherCourseServ, AuthenticatorService authServ, UserService userService, CurriculumService curriculumService, UserCurriculumService userCurriculumService, CurriculumCourseRepository curriculumCourseRepository, CurriculumCourseService curriculumCourseService) { this.courseServ = courseServ; this.teacherCourseServ = teacherCourseServ; this.authServ = authServ; this.userService = userService; + this.curriculumService = curriculumService; this.userCurriculumService = userCurriculumService; this.curriculumCourseRepository = curriculumCourseRepository; this.curriculumCourseService = curriculumCourseService; @@ -82,16 +82,18 @@ public class CourseController { } - @PostMapping("/course") + @PostMapping("/course/curriculum/{id}") public ResponseEntity> postCourse(@RequestHeader("Authorization") String token, - @RequestBody Course course) + @RequestBody Course course,@PathVariable long id) { if (authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin},token)) return new UnauthorizedResponse<>(null); Course createdCourse = courseServ.save(course); - if (createdCourse == null) + Curriculum curriculum = curriculumService.findById(id); + if (createdCourse == null || curriculum == null) return new ResponseEntity<>(null,HttpStatus.BAD_REQUEST); - + CurriculumCourse curriculumCourse = new CurriculumCourse(curriculum,course); + curriculumCourseService.save(curriculumCourse); return new ResponseEntity<>(ProtectionService.courseWithoutPassword(createdCourse), HttpStatus.CREATED); } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/CurriculumCourseRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/CurriculumCourseRepository.java index c99f50b..5d4f7b6 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Repositories/CurriculumCourseRepository.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/CurriculumCourseRepository.java @@ -1,5 +1,7 @@ package ovh.herisson.Clyde.Repositories; +import jakarta.transaction.Transactional; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; import ovh.herisson.Clyde.Tables.Course; @@ -14,4 +16,10 @@ public interface CurriculumCourseRepository extends CrudRepository findDistinctCurriculums(); + + @Modifying + @Transactional + @Query("delete from CurriculumCourse cc where cc.course =?1") + void delete(Course course); + } diff --git a/frontend/src/Apps/ManageCourses.vue b/frontend/src/Apps/ManageCourses.vue index 387dfba..bba81ce 100644 --- a/frontend/src/Apps/ManageCourses.vue +++ b/frontend/src/Apps/ManageCourses.vue @@ -3,26 +3,22 @@ import {reactive , ref} from 'vue' import { getCourses,deleteCourse,alterCourse,createCourse } from "@/rest/courses.js" import {getUser, getSelf, getTeachers } from "@/rest/Users.js" + import {getAllCurriculums} from "@/rest/curriculum.js"; const self = await getSelf(); const curriculum = ref(await getCourses(self.role)); const profList = await getTeachers(); - + const allCurriculums = ref(await getAllCurriculums()); const createMod = ref(false) const deleteMod = ref(false) const editElementID = ref("") - function editItem(id){ - editElementID.value = id; - } - - //Juste pour montrer le Create Mode - const pattern = { + "id":null, "title":null, "credits":null, "owner":null, @@ -41,7 +37,8 @@ } if (!isnull){ - await createCourse(toAdd.title,toAdd.credits,toAdd.owner); + await createCourse(toAdd.id,toAdd.title,toAdd.credits,toAdd.owner); + toAdd= Object.assign({},pattern); curriculum.value = await getCourses(self.role); @@ -102,7 +99,12 @@
- +
+ {{i18n("Curriculum")}} + +
{{i18n("name")}} : diff --git a/frontend/src/Apps/ManageOwnLessons.vue b/frontend/src/Apps/ManageOwnLessons.vue index ba762ef..cd6f778 100644 --- a/frontend/src/Apps/ManageOwnLessons.vue +++ b/frontend/src/Apps/ManageOwnLessons.vue @@ -136,7 +136,7 @@ async function askChanges(i){
{{i18n("schedule")}} :
diff --git a/frontend/src/rest/courses.js b/frontend/src/rest/courses.js index 3a87f5c..4a5f869 100644 --- a/frontend/src/rest/courses.js +++ b/frontend/src/rest/courses.js @@ -7,8 +7,8 @@ import { restGet, restPost, restDelete, restPatch } from './restConsumer.js' /** * Create a new course */ -export async function createCourse(name, credits, owner){ - return restPost("/course", {title: name, credits: credits, owner} ) +export async function createCourse(id,name, credits, owner){ + return restPost("/course/curriculum/" + id, {title: name, credits: credits, owner} ) } /** @@ -19,7 +19,7 @@ export async function deleteCourse(id){ } /** - * Get informations on a particular course + * Get information on a particular course * * @param id identification of the course *