Skip to content

Get List Subject and Score by Student Id, Year and Month#24

Open
kimhakSeang wants to merge 1 commit into
mainfrom
ListScoreOfStudent
Open

Get List Subject and Score by Student Id, Year and Month#24
kimhakSeang wants to merge 1 commit into
mainfrom
ListScoreOfStudent

Conversation

@kimhakSeang

Copy link
Copy Markdown
Collaborator
                            Monthly Score

  • Add Contoller ==> getListScoreByStudentIDYearMonth
  • Add Service and ServiceImpl ==> getListScoreByStudentIDYearMonth
  • MonthlyScoreFilter ==> add a field Long aStudentId
  • MonthlyScorePropertyFilter ==> add a field String STUDENTID="studentId"
  • MonthlyScoreSpec ==> if(filter.getAStudentId()!=null ) {
    Predicate studentIds = student.get("id").in(filter.getAStudentId());
    predicates.add(studentIds);
    }
    }


List<RankDTO> getRankDTO(Map<String, String> params);

Map<String,Double> getListScoreByStudentIDYearMonth(Map<String, String> params);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")));

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)));

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)));

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()));

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just name it as studentId

Predicate gender = student.get("gender").in(studentFilter.getGender());
predicates.add(gender);
}
predicates.stream().forEach(s->System.out.println(s.getAlias()+"\t"+s.isCompoundSelection()));

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove it.
For logging purpose, you use log instead.

}

@Override
public Map<String,Double> getListScoreByStudentIDYearMonth(Map<String, String> params) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please develop a unit test for this service method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants