Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Paysafe Interns Valentin-Martin
Student Managment
maya-metodieva-student-management-2023
Commits
64b5fd21
Commit
64b5fd21
authored
1 year ago
by
Maya Metodieva
Browse files
Options
Download
Email Patches
Plain Diff
Add user info endpoind and small fixes
parent
3444ce6a
main
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
BusinessLayer/src/main/java/com/mayametodieva/studentmanagement/services/ReportingService.java
+13
-4
...etodieva/studentmanagement/services/ReportingService.java
BusinessLayer/src/main/java/com/mayametodieva/studentmanagement/services/UserManagementService.java
+10
-1
...eva/studentmanagement/services/UserManagementService.java
REST/src/main/java/com/mayametodieva/studentmanagement/rest/controllers/ReportingRestController.java
+3
-2
...tmanagement/rest/controllers/ReportingRestController.java
REST/src/main/java/com/mayametodieva/studentmanagement/rest/controllers/UserManagementController.java
+8
-0
...management/rest/controllers/UserManagementController.java
REST/src/main/java/com/mayametodieva/studentmanagement/rest/dto/UserInfoDto.java
+33
-0
...mayametodieva/studentmanagement/rest/dto/UserInfoDto.java
with
67 additions
and
7 deletions
+67
-7
BusinessLayer/src/main/java/com/mayametodieva/studentmanagement/services/ReportingService.java
+
13
-
4
View file @
64b5fd21
...
...
@@ -22,6 +22,7 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.TreeMap
;
import
java.util.stream.Collectors
;
@Service
public
class
ReportingService
{
...
...
@@ -119,7 +120,11 @@ public class ReportingService {
public
Double
showAverageGradeForCourse
(
int
courseId
)
{
ReportCardDTO
reportCard
=
this
.
showTotalAverageGradeForAll
(
courseId
);
return
reportCard
.
getStudentGrades
().
values
().
stream
().
mapToDouble
(
value
->
value
).
summaryStatistics
()
return
reportCard
.
getStudentGrades
()
.
values
()
.
stream
()
.
filter
(
grade
->
grade
!=
0.0
)
.
mapToDouble
(
value
->
value
).
summaryStatistics
()
.
getAverage
();
}
...
...
@@ -134,7 +139,7 @@ public class ReportingService {
return
entity
.
getName
()
+
"#"
+
entity
.
getId
();
}
public
CourseInfoWithGradesDTO
showCourseInfo
(
Integer
id
)
{
public
CourseInfoWithGradesDTO
showCourseInfo
(
Integer
id
,
String
filter
)
{
Optional
<
Course
>
courseInfo
=
courseService
.
getIfPresent
(
id
);
if
(
courseInfo
.
isEmpty
())
{
throw
new
CourseNotFoundException
(
"There is no such course."
);
...
...
@@ -143,7 +148,11 @@ public class ReportingService {
return
new
CourseInfoWithGradesDTO
(
courseInfo
.
get
().
getName
(),
courseInfo
.
get
().
getTeacher
()
==
null
?
"No teacher"
:
courseInfo
.
get
().
getTeacher
().
getName
(),
grades
.
getStudentGrades
());
:
this
.
getNameWithId
(
courseInfo
.
get
().
getTeacher
()),
grades
.
getStudentGrades
()
.
entrySet
()
.
stream
()
.
filter
(
student
->
student
.
getKey
().
toLowerCase
().
contains
(
filter
==
null
?
""
:
filter
.
toLowerCase
()))
.
collect
(
Collectors
.
toMap
(
Map
.
Entry
::
getKey
,
Map
.
Entry
::
getValue
)));
}
}
This diff is collapsed.
Click to expand it.
BusinessLayer/src/main/java/com/mayametodieva/studentmanagement/services/UserManagementService.java
+
10
-
1
View file @
64b5fd21
...
...
@@ -38,6 +38,16 @@ public class UserManagementService {
this
.
assignmentService
=
assignmentService
;
}
public
Optional
<
UserDetails
>
getUserByRoleAndId
(
String
role
,
int
id
)
{
if
(
role
.
equals
(
Student
.
class
.
getSimpleName
().
toLowerCase
()))
{
return
Optional
.
ofNullable
(
this
.
studentService
.
getIfPresent
(
id
).
orElse
(
null
));
}
if
(
role
.
equals
(
Teacher
.
class
.
getSimpleName
().
toLowerCase
()))
{
return
Optional
.
ofNullable
(
this
.
teacherService
.
getIfPresent
(
id
).
orElse
(
null
));
}
return
Optional
.
ofNullable
(
this
.
administratorService
.
getIfPresent
(
id
).
orElse
(
null
));
}
public
Optional
<
UserDetails
>
getUserByUsername
(
String
username
)
{
Student
student
=
studentService
.
findByUsername
(
username
)
...
...
@@ -148,5 +158,4 @@ public class UserManagementService {
}
teacherService
.
deleteTeacher
(
teacher
);
}
}
This diff is collapsed.
Click to expand it.
REST/src/main/java/com/mayametodieva/studentmanagement/rest/controllers/ReportingRestController.java
+
3
-
2
View file @
64b5fd21
...
...
@@ -9,6 +9,7 @@ import org.springframework.http.HttpStatus;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
...
...
@@ -44,8 +45,8 @@ public class ReportingRestController {
}
@GetMapping
(
path
=
"/courses/{id}/info"
)
public
ResponseEntity
<
CourseInfoWithGradesDTO
>
showCourseInfo
(
@PathVariable
Integer
id
)
{
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
this
.
reportingService
.
showCourseInfo
(
id
));
public
ResponseEntity
<
CourseInfoWithGradesDTO
>
showCourseInfo
(
@PathVariable
Integer
id
,
@RequestParam
(
required
=
false
)
String
filter
)
{
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
this
.
reportingService
.
showCourseInfo
(
id
,
filter
));
}
@GetMapping
(
path
=
"/students/{id}"
)
...
...
This diff is collapsed.
Click to expand it.
REST/src/main/java/com/mayametodieva/studentmanagement/rest/controllers/UserManagementController.java
+
8
-
0
View file @
64b5fd21
...
...
@@ -3,15 +3,18 @@ package com.mayametodieva.studentmanagement.rest.controllers;
import
com.mayametodieva.studentmanagement.domain.SchoolUser
;
import
com.mayametodieva.studentmanagement.rest.dto.AuthenticationResponseDto
;
import
com.mayametodieva.studentmanagement.rest.dto.ChangeRoleDto
;
import
com.mayametodieva.studentmanagement.rest.dto.UserInfoDto
;
import
com.mayametodieva.studentmanagement.rest.exceptions.AuthenticationFailedException
;
import
com.mayametodieva.studentmanagement.rest.util.JwtUtil
;
import
com.mayametodieva.studentmanagement.services.UserManagementService
;
import
com.mayametodieva.studentmanagement.services.exceptions.ObjectAlreadyExistsException
;
import
com.mayametodieva.studentmanagement.services.exceptions.UserNotFoundException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.crypto.password.PasswordEncoder
;
import
org.springframework.web.bind.annotation.CrossOrigin
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PatchMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PostMapping
;
...
...
@@ -59,4 +62,9 @@ public class UserManagementController {
userManagementService
.
changeRole
(
username
,
changeRoleDto
.
getNewRole
(),
changeRoleDto
.
getDegree
());
return
ResponseEntity
.
ok
().
build
();
}
@GetMapping
(
path
=
"/{role}/{id}"
)
public
ResponseEntity
<
UserInfoDto
>
getUserInfo
(
@PathVariable
String
role
,
@PathVariable
int
id
)
{
return
ResponseEntity
.
ok
(
new
UserInfoDto
((
SchoolUser
)
userManagementService
.
getUserByRoleAndId
(
role
,
id
).
orElseThrow
(()
->
new
UserNotFoundException
(
"Missing user"
))));
}
}
This diff is collapsed.
Click to expand it.
REST/src/main/java/com/mayametodieva/studentmanagement/rest/dto/UserInfoDto.java
0 → 100644
+
33
-
0
View file @
64b5fd21
package
com.mayametodieva.studentmanagement.rest.dto
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
com.mayametodieva.studentmanagement.domain.SchoolUser
;
import
com.mayametodieva.studentmanagement.domain.teacher.Teacher
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public
class
UserInfoDto
{
private
String
username
;
private
String
name
;
private
int
age
;
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
private
String
degree
;
private
String
role
;
public
UserInfoDto
(
SchoolUser
schoolUser
)
{
this
.
username
=
schoolUser
.
getUsername
();
this
.
name
=
schoolUser
.
getName
();
this
.
age
=
schoolUser
.
getAge
();
this
.
role
=
schoolUser
.
getClass
().
getSimpleName
();
if
(
schoolUser
instanceof
Teacher
)
{
this
.
degree
=
((
Teacher
)
schoolUser
).
getDegree
().
name
();
}
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
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
Menu
Projects
Groups
Snippets
Help