Translation of the student inscription extension and profile #166
@ -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);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -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);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -49,5 +49,7 @@ public class UserCurriculumService {
 | 
				
			|||||||
        return toReturn;
 | 
					        return toReturn;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public ArrayList<UserCurriculum> findByStudentAndActual(User u, boolean actual){
 | 
				
			||||||
 | 
					        return userCurriculumRepository.findByUserAndActual(u, actual);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -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){
 | 
				
			||||||
 | 
				
			|||||||
@ -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)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user