コード例 #1
0
        public CourseStudentResponseDTO connectWithUser(CourseStudentResponseDTO response)
        {
            StudentResponseDTO student = this._httpClientService.SendRequest <StudentResponseDTO>(HttpMethod.Get, "http://localhost:40001/api/users/students/" + response.student.uuid, new UserPrincipal(_httpContextAccessor.HttpContext).token).Result;

            if (student == null)
            {
                throw new EntityNotFoundException($"Student with uuid: {student.uuid} does not exist!", GeneralConsts.MICROSERVICE_NAME);
            }

            response.student = student;
            return(response);
        }
コード例 #2
0
        //DELETE METHODS
        public CourseStudentResponseDTO DeleteStudentOnCourse(string courseUuid, string studentUuid)
        {
            //provera da li postojji student na kursu
            CourseStudent oldStudent = FindStudentOnCourseOrThrow(courseUuid, studentUuid);
            //ako student vrsi zahtev, moze da upise samo sebe
            UserPrincipal up = new UserPrincipal(_httpContextAccessor.HttpContext);

            if (up.role == RoleConsts.ROLE_STUDENT_ONLY)
            {
                checkStudent(studentUuid, up.uuid);
            }
            oldStudent.activeStudent = false;
            oldStudent = this._queryExecutor.Execute <CourseStudent>(DatabaseConsts.USER_SCHEMA, this._sqlCommands.UPDATE_STUDENT_ON_COURSE(oldStudent), this._modelMapper.MapToCourseStudent);
            CourseStudentResponseDTO response = this._autoMapper.Map <CourseStudentResponseDTO>(oldStudent);

            response.course = this._courseService.GetOneByUuid(response.course.uuid);
            return(connectWithUser(response));
        }
コード例 #3
0
        //PUT METHODS
        public CourseStudentResponseDTO UpdateStudentOnCourse(UpdateCourseStudentRequestDTO request)
        {
            //provera da li postojji student na kursu
            CourseStudent oldStudent = FindStudentOnCourseOrThrow(request.courseUUID, request.studentUUID);

            oldStudent.currentPoints = request.currentPoints;
            oldStudent.course        = new Course()
            {
                uuid = request.courseUUID
            };
            oldStudent.student = new Student()
            {
                uuid = request.studentUUID
            };
            oldStudent.finalMark = request.finalMark;
            oldStudent.beginDate = request.beginDate;
            oldStudent           = this._queryExecutor.Execute <CourseStudent>(DatabaseConsts.USER_SCHEMA, this._sqlCommands.UPDATE_STUDENT_ON_COURSE(oldStudent), this._modelMapper.MapToCourseStudent);
            CourseStudentResponseDTO response = this._autoMapper.Map <CourseStudentResponseDTO>(oldStudent);

            response.course = this._courseService.GetOneByUuid(response.course.uuid);
            return(connectWithUser(response));
        }
コード例 #4
0
        //POST METHODS
        public CourseStudentResponseDTO CreateStudentOnCourse(CreateCourseStudentRequestDTO request)
        {
            //provera da li postoji kurs
            CourseResponseDTO  course    = this._courseService.GetOneByUuid(request.courseUUID);
            String             courseDep = course.subject.department.uuid;
            StudentResponseDTO student;

            //provera da li postoji student
            try {
                student = this._httpClientService.SendRequest <StudentResponseDTO>(HttpMethod.Get, "http://localhost:40001/api/users/students/" + request.studentUUID, new UserPrincipal(_httpContextAccessor.HttpContext).token).Result;
            }
            catch
            {
                throw new EntityNotFoundException("Student with uuid " + request.studentUUID + " doesn't exist", GeneralConsts.MICROSERVICE_NAME);
            }
            String studentDep = student.departmentUUID;

            //provera da li su predmet i student na istom departmanu
            if (studentDep != courseDep)
            {
                throw new EntityNotFoundException("Student with uuid " + request.studentUUID + " and course with uuid: " + request.courseUUID + " are not on the same department", GeneralConsts.MICROSERVICE_NAME);
            }
            //ako student vrsi zahtev, moze da upise samo sebe
            UserPrincipal up = new UserPrincipal(_httpContextAccessor.HttpContext);

            if (up.role == RoleConsts.ROLE_STUDENT_ONLY)
            {
                checkStudent(student.uuid, up.uuid);
            }
            //provera da li vec postoji student na tom kursu
            CourseStudent existingCourseStudent = this.FindStudentOnCourse(request.courseUUID, request.studentUUID);

            if (existingCourseStudent != null)
            {
                if (existingCourseStudent.activeStudent == false)
                {
                    CourseStudent updatedStudent = this._autoMapper.Map <CourseStudent>(request);
                    updatedStudent.activeStudent = true;
                    updatedStudent.course        = new Course()
                    {
                        uuid = request.courseUUID
                    };
                    updatedStudent.student = new Student()
                    {
                        uuid = request.studentUUID
                    };
                    updatedStudent = this._queryExecutor.Execute <CourseStudent>(DatabaseConsts.USER_SCHEMA, this._sqlCommands.UPDATE_STUDENT_ON_COURSE(updatedStudent), this._modelMapper.MapToCourseStudent);
                    CourseStudentResponseDTO updatedResponse = this._autoMapper.Map <CourseStudentResponseDTO>(updatedStudent);
                    return(connectWithUser(updatedResponse));
                }
                else
                {
                    throw new EntityAlreadyExistsException("Student with uuid " + request.studentUUID + " already exists in course with uuid " + request.courseUUID, GeneralConsts.MICROSERVICE_NAME);
                }
            }
            CourseStudent newCourseStudent = this._autoMapper.Map <CourseStudent>(request);

            newCourseStudent.activeStudent = true;
            newCourseStudent.course        = new Course()
            {
                uuid = request.courseUUID
            };
            newCourseStudent.student = new Student()
            {
                uuid = request.studentUUID
            };
            newCourseStudent = this._queryExecutor.Execute <CourseStudent>(DatabaseConsts.USER_SCHEMA, this._sqlCommands.CREATE_STUDENT_ON_COURSE(newCourseStudent), this._modelMapper.MapToCourseStudent);
            CourseStudentResponseDTO response = this._autoMapper.Map <CourseStudentResponseDTO>(newCourseStudent);

            response.course = this._courseService.GetOneByUuid(response.course.uuid);
            return(connectWithUser(response));
        }