Get List Subject and Score by Student Id, Year and Month#24
Conversation
|
|
||
| List<RankDTO> getRankDTO(Map<String, String> params); | ||
|
|
||
| Map<String,Double> getListScoreByStudentIDYearMonth(Map<String, String> params); |
There was a problem hiding this comment.
Since parameter of method is a map , it is very flexible. So the method name should be more general.
You can consider method name like this : "listScore".
| MonthlyScoreFilter monthlyScoreFilter = new MonthlyScoreFilter(); | ||
|
|
||
| if(params.containsKey(MonthlyScorePropertyFilter.STUDENTID)) { | ||
| monthlyScoreFilter.setAStudentId(params.get(MonthlyScorePropertyFilter.STUDENTID).isBlank() ? 0 : Long.parseLong(params.get("studentId"))); |
There was a problem hiding this comment.
studentId is required, if not provided in query param, please throw exception as bad request (400).
| monthlyScoreFilter.setAStudentId(params.get(MonthlyScorePropertyFilter.STUDENTID).isBlank() ? 0 : Long.parseLong(params.get("studentId"))); | ||
| } | ||
| if(params.containsKey(YEAR)) { | ||
| monthlyScoreFilter.setYear(params.get(YEAR).isBlank() ? 0 : Short.parseShort(params.get(YEAR))); |
There was a problem hiding this comment.
year is required, if not provided in query param, please throw exception as bad request (400).
| monthlyScoreFilter.setYear(params.get(YEAR).isBlank() ? 0 : Short.parseShort(params.get(YEAR))); | ||
| } | ||
| if(params.containsKey(MONTH)) { | ||
| monthlyScoreFilter.setMonth(params.get(MONTH).isBlank() ? 0 : Short.parseShort(params.get(MONTH))); |
There was a problem hiding this comment.
month is required, if not provided in query param, please throw exception as bad request (400).
|
|
||
| private Map<String,Double> toListSubjectScore(List<MonthlyScore> monthlyScores) { | ||
| Map<String,Double> listSubjectscore = new HashMap<>(); | ||
| monthlyScores.forEach(l->listSubjectscore.put(l.getSubject().getName(),l.getScore())); |
There was a problem hiding this comment.
To convert from list to map, you can use stream().collect(Collectors.toMap(.......)).
Please google how to do it.
| public class MonthlyScoreFilter { | ||
| private List<Long> studentIds; | ||
| private List<Long> subjectIds; | ||
| private Long aStudentId; |
| Predicate gender = student.get("gender").in(studentFilter.getGender()); | ||
| predicates.add(gender); | ||
| } | ||
| predicates.stream().forEach(s->System.out.println(s.getAlias()+"\t"+s.isCompoundSelection())); |
There was a problem hiding this comment.
Please remove it.
For logging purpose, you use log instead.
| } | ||
|
|
||
| @Override | ||
| public Map<String,Double> getListScoreByStudentIDYearMonth(Map<String, String> params) { |
There was a problem hiding this comment.
Please develop a unit test for this service method.
Predicate studentIds = student.get("id").in(filter.getAStudentId());
predicates.add(studentIds);
}
}