1
0
forked from PGL/Clyde

Add course to a curriculum when created

This commit is contained in:
Wawilski 2024-04-21 19:55:39 +02:00
parent ca10084400
commit 05ed28626a
5 changed files with 34 additions and 22 deletions

View File

@ -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<Map<String ,Object>> 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);
}

View File

@ -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<CurriculumCou
@Query("select distinct cc.curriculum from CurriculumCourse cc")
Iterable<Curriculum> findDistinctCurriculums();
@Modifying
@Transactional
@Query("delete from CurriculumCourse cc where cc.course =?1")
void delete(Course course);
}

View File

@ -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 @@
</div>
<div v-if="createMod">
<form class="listElement" style="width:40%;margin-right:auto;margin-left:auto;">
<div style="margin-bottom: 20px">
{{i18n("Curriculum")}}
<select v-model="toAdd.id">
<option v-for="element in allCurriculums" :value="element.curriculumId">{{element.option}}-{{element.year}}</option>
</select>
</div>
<div style="margin-bottom:20px;">
{{i18n("name")}} :
<input v-model="toAdd.title">

View File

@ -136,7 +136,7 @@ async function askChanges(i){
<div style="margin-bottom:20px;">
{{i18n("schedule")}} :
<select @change="setCourses()"v-model="curriculum">
<option v-for="item in allSchedules" :value='item.curriculum'>{{item.curriculum.option}}</option>
<option v-for="item in allSchedules" :value='item.curriculum'>{{item.curriculum.option}}-{{item.curriculum.year}}</option>
</select>
</div>
<div style="margin-bottom:20px;">

View File

@ -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
*