Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
school-portal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Muhammad Suleman
school-portal
Commits
0c70dc0c
Commit
0c70dc0c
authored
Jul 13, 2022
by
Muhammad Suleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Assign Course Service
parent
3e163747
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
271 additions
and
29 deletions
+271
-29
AdminController.java
...n/java/com/school/project/controller/AdminController.java
+24
-0
StudentController.java
...java/com/school/project/controller/StudentController.java
+3
-6
TeacherController.java
...java/com/school/project/controller/TeacherController.java
+31
-0
UserController.java
...in/java/com/school/project/controller/UserController.java
+2
-16
TeacherCourseAssignDTO.java
...om/school/project/dto/teacher/TeacherCourseAssignDTO.java
+17
-0
TeacherViewCoursesDTO.java
...com/school/project/dto/teacher/TeacherViewCoursesDTO.java
+18
-0
TeacherViewDataDTO.java
...va/com/school/project/dto/teacher/TeacherViewDataDTO.java
+15
-0
TeacherViewCoursesMapper.java
...a/com/school/project/mapper/TeacherViewCoursesMapper.java
+19
-0
TeacherViewDataMapper.java
...java/com/school/project/mapper/TeacherViewDataMapper.java
+21
-0
Student.java
src/main/java/com/school/project/model/Student.java
+0
-3
Teacher.java
src/main/java/com/school/project/model/Teacher.java
+1
-1
TeacherRepository.java
...project/repository/modelRepositery/TeacherRepository.java
+4
-0
TeacherFunctionsForAdminService.java
...roject/service/admin/TeacherFunctionsForAdminService.java
+11
-0
TeacherFunctionsForAdminServiceImpl.java
...ct/service/admin/TeacherFunctionsForAdminServiceImpl.java
+49
-0
CourseRegistrationService.java
...ol/project/service/student/CourseRegistrationService.java
+1
-1
CourseRegistrationServiceImpl.java
...roject/service/student/CourseRegistrationServiceImpl.java
+1
-2
TeacherService.java
...va/com/school/project/service/teacher/TeacherService.java
+10
-0
TeacherServiceImpl.java
...om/school/project/service/teacher/TeacherServiceImpl.java
+44
-0
No files found.
src/main/java/com/school/project/controller/AdminController.java
0 → 100644
View file @
0c70dc0c
package
com
.
school
.
project
.
controller
;
import
com.school.project.dto.teacher.TeacherCourseAssignDTO
;
import
com.school.project.service.admin.TeacherFunctionsForAdminService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.Set
;
@RestController
@RequestMapping
(
"/admin"
)
public
class
AdminController
{
@Autowired
TeacherFunctionsForAdminService
teacher
;
@PostMapping
(
"/assignCourses"
)
public
void
assignCourseToTeacher
(
@RequestBody
TeacherCourseAssignDTO
assignCourses
)
{
teacher
.
assignCourseToTeachers
(
assignCourses
);
}
}
src/main/java/com/school/project/controller/StudentController.java
View file @
0c70dc0c
...
@@ -4,15 +4,12 @@ package com.school.project.controller;
...
@@ -4,15 +4,12 @@ package com.school.project.controller;
import
com.school.project.dto.student.StudentCourseRegistrationDTO
;
import
com.school.project.dto.student.StudentCourseRegistrationDTO
;
import
com.school.project.dto.student.StudentCoursesDTO
;
import
com.school.project.dto.student.StudentCoursesDTO
;
import
com.school.project.dto.student.StudentViewDataDTO
;
import
com.school.project.dto.student.StudentViewDataDTO
;
import
com.school.project.service.
courseRegistration
.CourseRegistrationService
;
import
com.school.project.service.
student
.CourseRegistrationService
;
import
com.school.project.service.student.StudentServiceImpl
;
import
com.school.project.service.student.StudentServiceImpl
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.core.annotation.CurrentSecurityContext
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
java.security.Principal
;
import
java.security.Principal
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.Set
;
@RestController
@RestController
...
@@ -26,9 +23,9 @@ public class StudentController {
...
@@ -26,9 +23,9 @@ public class StudentController {
private
CourseRegistrationService
courseRegistrationService
;
private
CourseRegistrationService
courseRegistrationService
;
@GetMapping
(
""
)
@GetMapping
(
""
)
public
StudentViewDataDTO
getUserDetails
(
@CurrentSecurityContext
(
expression
=
"authentication"
)
Authentication
authentication
)
{
public
StudentViewDataDTO
getUserDetails
(
Principal
principal
)
{
return
studentService
.
viewData
(
authentication
.
getName
());
return
studentService
.
viewData
(
principal
.
getName
());
}
}
...
...
src/main/java/com/school/project/controller/TeacherController.java
0 → 100644
View file @
0c70dc0c
package
com
.
school
.
project
.
controller
;
import
com.school.project.dto.teacher.TeacherViewCoursesDTO
;
import
com.school.project.dto.teacher.TeacherViewDataDTO
;
import
com.school.project.service.teacher.TeacherServiceImpl
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.security.Principal
;
@RestController
@RequestMapping
(
"/teacher"
)
public
class
TeacherController
{
@Autowired
TeacherServiceImpl
teacherService
;
@GetMapping
(
""
)
public
TeacherViewDataDTO
getTeacherData
(
Principal
principal
)
{
return
teacherService
.
getTeacherData
(
principal
.
getName
());
}
@GetMapping
(
"/course"
)
public
TeacherViewCoursesDTO
getTeacherCourses
(
Principal
principal
)
{
return
teacherService
.
getTeacherCourses
(
principal
.
getName
());
}
}
src/main/java/com/school/project/controller/UserController.java
View file @
0c70dc0c
...
@@ -15,21 +15,7 @@ import java.util.List;
...
@@ -15,21 +15,7 @@ import java.util.List;
public
class
UserController
{
public
class
UserController
{
@GetMapping
(
"/user"
)
@GetMapping
(
"/user"
)
public
List
<
String
>
currentUserName
(
@CurrentSecurityContext
(
expression
=
"authentication"
)
public
String
currentUserName
(
Principal
principal
)
{
Authentication
authentication
,
Principal
principal
)
{
return
principal
.
getName
();
List
<
String
>
data
=
new
ArrayList
<>();
data
.
add
(
authentication
.
getName
());
data
.
add
(
String
.
valueOf
(
authentication
.
getAuthorities
()));
data
.
add
(
String
.
valueOf
(
authentication
.
getCredentials
()));
data
.
add
(
String
.
valueOf
(
authentication
.
getDetails
()));
data
.
add
(
String
.
valueOf
(
authentication
.
getPrincipal
()));
data
.
add
(
"\nNow Here Is Principal Details\n"
);
data
.
add
(
principal
.
getName
());
return
data
;
}
}
}
}
src/main/java/com/school/project/dto/teacher/TeacherCourseAssignDTO.java
0 → 100644
View file @
0c70dc0c
package
com
.
school
.
project
.
dto
.
teacher
;
import
com.school.project.model.Course
;
import
lombok.Getter
;
import
lombok.RequiredArgsConstructor
;
import
lombok.Setter
;
import
java.util.Set
;
@Getter
@Setter
@RequiredArgsConstructor
public
class
TeacherCourseAssignDTO
{
private
String
teacherNumber
;
private
Set
<
String
>
courseList
;
}
src/main/java/com/school/project/dto/teacher/TeacherViewCoursesDTO.java
0 → 100644
View file @
0c70dc0c
package
com
.
school
.
project
.
dto
.
teacher
;
import
com.school.project.model.Course
;
import
lombok.Getter
;
import
lombok.RequiredArgsConstructor
;
import
lombok.Setter
;
import
org.springframework.stereotype.Component
;
import
java.util.Set
;
@Getter
@Setter
@RequiredArgsConstructor
public
class
TeacherViewCoursesDTO
{
private
String
name
;
private
String
teacherNumber
;
private
Set
<
Course
>
courseList
;
}
src/main/java/com/school/project/dto/teacher/TeacherViewDataDTO.java
0 → 100644
View file @
0c70dc0c
package
com
.
school
.
project
.
dto
.
teacher
;
import
com.school.project.model.Department
;
import
lombok.*
;
@Getter
@Setter
@RequiredArgsConstructor
public
class
TeacherViewDataDTO
{
private
String
name
;
private
String
teacherNumber
;
private
String
degree
;
private
Department
department
;
}
src/main/java/com/school/project/mapper/TeacherViewCoursesMapper.java
0 → 100644
View file @
0c70dc0c
package
com
.
school
.
project
.
mapper
;
import
com.school.project.dto.teacher.TeacherViewCoursesDTO
;
import
com.school.project.model.Teacher
;
import
org.springframework.stereotype.Component
;
@Component
public
class
TeacherViewCoursesMapper
{
public
TeacherViewCoursesDTO
modelToDTO
(
Teacher
teacher
)
{
TeacherViewCoursesDTO
teacherViewCoursesDTO
=
new
TeacherViewCoursesDTO
();
teacherViewCoursesDTO
.
setName
(
teacher
.
getName
());
teacherViewCoursesDTO
.
setTeacherNumber
(
teacher
.
getTeacherNumber
());
teacherViewCoursesDTO
.
setCourseList
(
teacher
.
getCourseList
());
return
teacherViewCoursesDTO
;
}
}
src/main/java/com/school/project/mapper/TeacherViewDataMapper.java
0 → 100644
View file @
0c70dc0c
package
com
.
school
.
project
.
mapper
;
import
com.school.project.dto.teacher.TeacherViewDataDTO
;
import
com.school.project.model.Teacher
;
import
org.springframework.stereotype.Component
;
@Component
public
class
TeacherViewDataMapper
{
public
TeacherViewDataDTO
modelToDto
(
Teacher
teacher
)
{
TeacherViewDataDTO
teacherViewDataDTO
=
new
TeacherViewDataDTO
();
teacherViewDataDTO
.
setName
(
teacher
.
getName
());
teacherViewDataDTO
.
setTeacherNumber
(
teacher
.
getTeacherNumber
());
teacherViewDataDTO
.
setDegree
(
teacher
.
getDegree
());
teacherViewDataDTO
.
setDepartment
(
teacher
.
getDepartment
());
return
teacherViewDataDTO
;
}
}
src/main/java/com/school/project/model/Student.java
View file @
0c70dc0c
package
com
.
school
.
project
.
model
;
package
com
.
school
.
project
.
model
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.school.project.model.Course
;
import
com.school.project.model.userRegistration.User
;
import
com.school.project.model.userRegistration.User
;
import
com.sun.istack.NotNull
;
import
com.sun.istack.NotNull
;
import
lombok.Data
;
import
lombok.Data
;
...
@@ -10,10 +9,8 @@ import lombok.NoArgsConstructor;
...
@@ -10,10 +9,8 @@ import lombok.NoArgsConstructor;
import
lombok.ToString
;
import
lombok.ToString
;
import
org.hibernate.annotations.Fetch
;
import
org.hibernate.annotations.Fetch
;
import
org.hibernate.annotations.FetchMode
;
import
org.hibernate.annotations.FetchMode
;
import
org.springframework.context.annotation.Lazy
;
import
javax.persistence.*
;
import
javax.persistence.*
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.Set
;
@Data
@Data
...
...
src/main/java/com/school/project/model/Teacher.java
View file @
0c70dc0c
...
@@ -30,7 +30,7 @@ public class Teacher {
...
@@ -30,7 +30,7 @@ public class Teacher {
private
String
name
;
private
String
name
;
@NotNull
@NotNull
@Column
(
name
=
"teacher_num"
)
@Column
(
name
=
"teacher_num"
,
unique
=
true
)
private
String
teacherNumber
;
private
String
teacherNumber
;
@NotNull
@NotNull
...
...
src/main/java/com/school/project/repository/modelRepositery/TeacherRepository.java
View file @
0c70dc0c
...
@@ -2,10 +2,14 @@ package com.school.project.repository.modelRepositery;
...
@@ -2,10 +2,14 @@ package com.school.project.repository.modelRepositery;
import
com.school.project.model.Teacher
;
import
com.school.project.model.Teacher
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.stereotype.Repository
;
import
org.springframework.stereotype.Repository
;
@Repository
@Repository
public
interface
TeacherRepository
extends
JpaRepository
<
Teacher
,
Long
>
{
public
interface
TeacherRepository
extends
JpaRepository
<
Teacher
,
Long
>
{
Teacher
findOneByTeacherId
(
Long
id
);
Teacher
findOneByTeacherId
(
Long
id
);
@Query
(
value
=
"SELECT * FROM teacher WHERE teacher_num= ?1"
,
nativeQuery
=
true
)
Teacher
findByTeacherNumber
(
String
number
);
}
}
src/main/java/com/school/project/service/admin/TeacherFunctionsForAdminService.java
0 → 100644
View file @
0c70dc0c
package
com
.
school
.
project
.
service
.
admin
;
import
com.school.project.dto.teacher.TeacherCourseAssignDTO
;
import
java.util.Set
;
public
interface
TeacherFunctionsForAdminService
{
public
Long
getUserId
(
String
username
);
void
assignCourseToTeachers
(
TeacherCourseAssignDTO
assignCourses
);
}
src/main/java/com/school/project/service/admin/TeacherFunctionsForAdminServiceImpl.java
0 → 100644
View file @
0c70dc0c
package
com
.
school
.
project
.
service
.
admin
;
import
com.school.project.dto.teacher.TeacherCourseAssignDTO
;
import
com.school.project.model.Course
;
import
com.school.project.model.Teacher
;
import
com.school.project.model.userRegistration.User
;
import
com.school.project.repository.modelRepositery.CourseRepository
;
import
com.school.project.repository.modelRepositery.TeacherRepository
;
import
com.school.project.repository.userRegistration.UserRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.jpa.repository.Modifying
;
import
org.springframework.stereotype.Service
;
import
javax.transaction.Transactional
;
import
java.util.Set
;
@Service
public
class
TeacherFunctionsForAdminServiceImpl
implements
TeacherFunctionsForAdminService
{
@Autowired
TeacherRepository
teacherRepository
;
@Autowired
UserRepository
userRepository
;
@Autowired
CourseRepository
courseRepository
;
@Override
public
Long
getUserId
(
String
username
)
{
User
user
=
userRepository
.
findUserByEmail
(
username
).
get
();
return
user
.
getUserId
();
}
@Override
@Transactional
@Modifying
public
void
assignCourseToTeachers
(
TeacherCourseAssignDTO
assignCourses
)
{
Teacher
teacher
=
teacherRepository
.
findByTeacherNumber
(
assignCourses
.
getTeacherNumber
());
Set
<
Course
>
teacherCourses
=
teacher
.
getCourseList
();
Set
<
String
>
newCourses
=
assignCourses
.
getCourseList
();
newCourses
.
forEach
(
course
->
teacherCourses
.
add
(
courseRepository
.
findByCourseName
(
course
)));
teacher
.
setCourseList
(
teacherCourses
);
}
}
src/main/java/com/school/project/service/
courseRegistration
/CourseRegistrationService.java
→
src/main/java/com/school/project/service/
student
/CourseRegistrationService.java
View file @
0c70dc0c
package
com
.
school
.
project
.
service
.
courseRegistration
;
package
com
.
school
.
project
.
service
.
student
;
import
com.school.project.dto.student.StudentCourseRegistrationDTO
;
import
com.school.project.dto.student.StudentCourseRegistrationDTO
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
...
src/main/java/com/school/project/service/
courseRegistration
/CourseRegistrationServiceImpl.java
→
src/main/java/com/school/project/service/
student
/CourseRegistrationServiceImpl.java
View file @
0c70dc0c
package
com
.
school
.
project
.
service
.
courseRegistration
;
package
com
.
school
.
project
.
service
.
student
;
import
com.school.project.dto.student.StudentCourseRegistrationDTO
;
import
com.school.project.dto.student.StudentCourseRegistrationDTO
;
import
com.school.project.model.Course
;
import
com.school.project.model.Course
;
...
@@ -35,7 +35,6 @@ public class CourseRegistrationServiceImpl implements CourseRegistrationService
...
@@ -35,7 +35,6 @@ public class CourseRegistrationServiceImpl implements CourseRegistrationService
student
.
setCourseLists
(
studentCourses
);
student
.
setCourseLists
(
studentCourses
);
studentRepository
.
save
(
student
);
}
}
}
}
src/main/java/com/school/project/service/teacher/TeacherService.java
0 → 100644
View file @
0c70dc0c
package
com
.
school
.
project
.
service
.
teacher
;
import
com.school.project.dto.teacher.TeacherViewCoursesDTO
;
import
com.school.project.dto.teacher.TeacherViewDataDTO
;
public
interface
TeacherService
{
TeacherViewDataDTO
getTeacherData
(
String
username
);
TeacherViewCoursesDTO
getTeacherCourses
(
String
username
);
}
src/main/java/com/school/project/service/teacher/TeacherServiceImpl.java
0 → 100644
View file @
0c70dc0c
package
com
.
school
.
project
.
service
.
teacher
;
import
com.school.project.dto.teacher.TeacherViewCoursesDTO
;
import
com.school.project.dto.teacher.TeacherViewDataDTO
;
import
com.school.project.mapper.TeacherViewCoursesMapper
;
import
com.school.project.mapper.TeacherViewDataMapper
;
import
com.school.project.model.userRegistration.User
;
import
com.school.project.repository.modelRepositery.TeacherRepository
;
import
com.school.project.repository.userRegistration.UserRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
@Service
public
class
TeacherServiceImpl
implements
TeacherService
{
@Autowired
TeacherRepository
teacherRepository
;
@Autowired
UserRepository
userRepository
;
@Autowired
TeacherViewDataMapper
teacherViewDataMapper
;
@Autowired
TeacherViewCoursesMapper
teacherViewCoursesMapper
;
@Override
public
TeacherViewDataDTO
getTeacherData
(
String
username
)
{
User
user
=
userRepository
.
findUserByEmail
(
username
).
get
();
return
teacherViewDataMapper
.
modelToDto
(
teacherRepository
.
findOneByTeacherId
(
user
.
getUserId
()));
}
@Override
public
TeacherViewCoursesDTO
getTeacherCourses
(
String
username
)
{
User
user
=
userRepository
.
findUserByEmail
(
username
).
get
();
return
teacherViewCoursesMapper
.
modelToDTO
(
teacherRepository
.
findOneByTeacherId
(
user
.
getUserId
()));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment