-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentResponseResolver.java
More file actions
59 lines (44 loc) · 2.17 KB
/
StudentResponseResolver.java
File metadata and controls
59 lines (44 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.example.resolver;
import com.example.entity.Subject;
import com.example.enums.SubjectNameFilter;
import com.example.enums.SubjectNameFilterList;
import com.example.response.StudentResponse;
import com.example.response.SubjectResponse;
import graphql.kickstart.tools.GraphQLResolver;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
public class StudentResponseResolver implements GraphQLResolver<StudentResponse> {
// these are just for learning purpose not an efficient way to implement this functionality
public List<SubjectResponse> getLearningSubjects(StudentResponse studentResponse, SubjectNameFilter subjectNameFilter){
List<SubjectResponse> learningSubjects = new ArrayList<>();
if (studentResponse.getStudent().getLearningSubjects() != null) {
for (Subject subject: studentResponse.getStudent().getLearningSubjects()) {
if(subjectNameFilter.name().equalsIgnoreCase("All")) {
learningSubjects.add(new SubjectResponse(subject));
}
if(subjectNameFilter.name().equalsIgnoreCase(subject.getSubjectName())) {
learningSubjects.add(new SubjectResponse(subject));
}
}
}
return learningSubjects;
}
public List<SubjectResponse> getLearningSubjectsByList(StudentResponse studentResponse, SubjectNameFilterList subjectNameFilterList){
List<SubjectResponse> learningSubjects = new ArrayList<>();
if (studentResponse.getStudent().getLearningSubjects() != null) {
for (Subject subject: studentResponse.getStudent().getLearningSubjects()) {
for (String subjectListItem: subjectNameFilterList.getFilterList()) {
if (subjectListItem.equalsIgnoreCase(subject.getSubjectName())) {
learningSubjects.add(new SubjectResponse(subject));
}
}
}
}
return learningSubjects;
}
public String getFullName(StudentResponse studentResponse) {
return studentResponse.getFirstName() + " " + studentResponse.getLastName();
}
}