Compare commits

...

3 Commits

Author SHA1 Message Date
881c935c00 Merge branch 'master' into StudentInscription
All checks were successful
Build and test backend / Build-backend (pull_request) Successful in 1m22s
Build and test FrontEnd / Build-frontend (pull_request) Successful in 26s
2024-04-21 03:10:49 +02:00
8097f5314f Merge pull request 'Implement an endpoint to get all the courses of an user' (#165) from CoursesEndpoint into master
Some checks failed
Build and test backend / Build-backend (push) Successful in 1m23s
deploy to production / deploy-frontend (push) Successful in 26s
deploy to production / deploy-backend (push) Failing after 2m6s
Build and test FrontEnd / Build-frontend (push) Successful in 24s
Reviewed-on: #165
2024-04-20 23:32:03 +02:00
1e2efac5bc Implement an endpoint to get all the courses of an user
All checks were successful
Build and test backend / Build-backend (pull_request) Successful in 1m21s
Build and test FrontEnd / Build-frontend (pull_request) Successful in 26s
2024-04-20 23:29:22 +02:00
5 changed files with 57 additions and 6 deletions

View File

@ -3,14 +3,15 @@ package ovh.herisson.Clyde.EndPoints;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import ovh.herisson.Clyde.Repositories.CurriculumCourseRepository;
import ovh.herisson.Clyde.Responses.UnauthorizedResponse; import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
import ovh.herisson.Clyde.Services.AuthenticatorService; import ovh.herisson.Clyde.Services.*;
import ovh.herisson.Clyde.Services.CourseService;
import ovh.herisson.Clyde.Services.ProtectionService;
import ovh.herisson.Clyde.Services.TeacherCourseService;
import ovh.herisson.Clyde.Tables.Course; import ovh.herisson.Clyde.Tables.Course;
import ovh.herisson.Clyde.Tables.Role; import ovh.herisson.Clyde.Tables.Role;
import ovh.herisson.Clyde.Tables.User; import ovh.herisson.Clyde.Tables.User;
import ovh.herisson.Clyde.Tables.UserCurriculum;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -24,10 +25,20 @@ public class CourseController {
private final AuthenticatorService authServ; private final AuthenticatorService authServ;
public CourseController(CourseService courseServ, TeacherCourseService teacherCourseServ, AuthenticatorService authServ) { private final UserService userService;
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) {
this.courseServ = courseServ; this.courseServ = courseServ;
this.teacherCourseServ = teacherCourseServ; this.teacherCourseServ = teacherCourseServ;
this.authServ = authServ; this.authServ = authServ;
this.userService = userService;
this.userCurriculumService = userCurriculumService;
this.curriculumCourseRepository = curriculumCourseRepository;
this.curriculumCourseService = curriculumCourseService;
} }
@GetMapping("/course/{id}") @GetMapping("/course/{id}")
@ -136,4 +147,28 @@ public class CourseController {
return new ResponseEntity<>(HttpStatus.OK); return new ResponseEntity<>(HttpStatus.OK);
} }
//Get all the courses followed by an user
@GetMapping("/usercourses/{userId}")
public ResponseEntity<ArrayList<Course>> getAllUserCourses(@PathVariable long userId){
User u = userService.getUserById(userId);
//We get all the actual curriculums of the user
ArrayList<UserCurriculum> userCurricula = userCurriculumService.findByStudentAndActual(u, true);
ArrayList<Course> toReturn = new ArrayList<>();
//We iterate through all the curriculums and we extract the courses
for (int i = 0; i < userCurricula.size(); i++){
curriculumCourseRepository.findCoursesByCurriculum(userCurricula.get(i).getCurriculum()).forEach((item) -> {
//We need this to eliminate clones because a course can belong to several curriculums
if(!toReturn.contains(item)){
toReturn.add(item);
}
});
}
return new ResponseEntity<>(toReturn, HttpStatus.OK);
}
} }

View File

@ -16,4 +16,6 @@ public interface UserCurriculumRepository extends CrudRepository<UserCurriculum,
ArrayList<UserCurriculum> findByUserOrderByCurriculum(User student); ArrayList<UserCurriculum> findByUserOrderByCurriculum(User student);
UserCurriculum findByUserAndCurriculumAndActual(User user, Curriculum curriculum, boolean actual); UserCurriculum findByUserAndCurriculumAndActual(User user, Curriculum curriculum, boolean actual);
ArrayList<UserCurriculum> findByUserAndActual(User user, boolean actual);
} }

View File

@ -49,5 +49,7 @@ public class UserCurriculumService {
return toReturn; return toReturn;
} }
public ArrayList<UserCurriculum> findByStudentAndActual(User u, boolean actual){
return userCurriculumRepository.findByUserAndActual(u, actual);
}
} }

View File

@ -5,6 +5,7 @@
import {ref} from "vue"; import {ref} from "vue";
import ExternalCurriculumList from "@/Apps/Inscription/ExternalCurriculumList.vue"; import ExternalCurriculumList from "@/Apps/Inscription/ExternalCurriculumList.vue";
import {getExternalCurriculumByUser} from "@/rest/externalCurriculum.js"; import {getExternalCurriculumByUser} from "@/rest/externalCurriculum.js";
import {getUserActualCourses} from "@/rest/courses.js";
const props = defineProps(['target']) const props = defineProps(['target'])
const user = await getUser(props.target) const user = await getUser(props.target)
@ -12,6 +13,9 @@
const externalcurrlist = await getExternalCurriculumByUser(user.regNo) const externalcurrlist = await getExternalCurriculumByUser(user.regNo)
const extercurrlist = ref(false) const extercurrlist = ref(false)
const courselist = await getUserActualCourses(user.regNo)
console.log(courselist)
const watchingUser = await getSelf() const watchingUser = await getSelf()
function getPP(){ function getPP(){
if(user.profilePictureUrl === null){ if(user.profilePictureUrl === null){

View File

@ -71,3 +71,11 @@ export async function getCourses(role){
export async function alterCourse(id, changes){ export async function alterCourse(id, changes){
return restPatch("/course/" + id, changes); return restPatch("/course/" + id, changes);
} }
/**
* Return a list containing all the actual courses of a user
*/
export async function getUserActualCourses(userId){
return restGet("/usercourses/"+userId)
}