schedule accepted
This commit is contained in:
parent
cf875889b9
commit
20f52746b5
@ -36,19 +36,19 @@ public class AssignmentResponseMappers {
|
|||||||
public static final List<AssignmentResponse> mapToResponse(List<Assignment> assignments,
|
public static final List<AssignmentResponse> mapToResponse(List<Assignment> assignments,
|
||||||
HashMap<Long, Integer> ammounts) {
|
HashMap<Long, Integer> ammounts) {
|
||||||
List<AssignmentResponse> response = new ArrayList<>();
|
List<AssignmentResponse> response = new ArrayList<>();
|
||||||
HashMap<Course, List<Groups>> courses = new HashMap<>();
|
HashMap<Course, List<Assignment>> courses = new HashMap<>();
|
||||||
assignments.stream().forEach((Assignment assignment) -> {
|
assignments.stream().forEach((Assignment assignment) -> {
|
||||||
final Groups group = assignment.getGroup();
|
final Groups group = assignment.getGroup();
|
||||||
final Course course = group.getCourseId();
|
final Course course = group.getCourseId();
|
||||||
if (courses.get(course) == null) {
|
if (courses.get(course) == null) {
|
||||||
courses.put(course, new ArrayList<>());
|
courses.put(course, new ArrayList<>());
|
||||||
}
|
}
|
||||||
courses.get(course).add(group);
|
courses.get(course).add(assignment);
|
||||||
});
|
});
|
||||||
|
|
||||||
for (Map.Entry<Course, List<Groups>> entry : courses.entrySet()) {
|
for (Map.Entry<Course, List<Assignment>> entry : courses.entrySet()) {
|
||||||
final Course course = entry.getKey();
|
final Course course = entry.getKey();
|
||||||
final List<Groups> courseGroups = entry.getValue();
|
final List<Assignment> courseGroups = entry.getValue();
|
||||||
if (courseGroups.size() == 1) {
|
if (courseGroups.size() == 1) {
|
||||||
if (ammounts != null) {
|
if (ammounts != null) {
|
||||||
response.add(new AssignmentResponse(course, courseGroups.get(0), ammounts));
|
response.add(new AssignmentResponse(course, courseGroups.get(0), ammounts));
|
||||||
@ -57,10 +57,12 @@ public class AssignmentResponseMappers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (courseGroups.size() == 2) {
|
if (courseGroups.size() == 2) {
|
||||||
final Groups lecture = courseGroups.stream()
|
final Assignment lecture = courseGroups.stream()
|
||||||
.filter(o -> GroupType.isLectureOrClass(o.getType()) == GroupType.LECTURE).findFirst().get();
|
.filter(o -> GroupType.isLectureOrClass(o.getGroup().getType()) == GroupType.LECTURE)
|
||||||
final Groups classes = courseGroups.stream()
|
.findFirst().get();
|
||||||
.filter(o -> GroupType.isLectureOrClass(o.getType()) == GroupType.CLASS).findFirst().get();
|
final Assignment classes = courseGroups.stream()
|
||||||
|
.filter(o -> GroupType.isLectureOrClass(o.getGroup().getType()) == GroupType.CLASS).findFirst()
|
||||||
|
.get();
|
||||||
|
|
||||||
if (ammounts != null) {
|
if (ammounts != null) {
|
||||||
response.add(new AssignmentResponse(course, lecture, classes, ammounts));
|
response.add(new AssignmentResponse(course, lecture, classes, ammounts));
|
||||||
|
@ -2,6 +2,7 @@ package com.plannaplan.responses.models;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import com.plannaplan.entities.Assignment;
|
||||||
import com.plannaplan.entities.Course;
|
import com.plannaplan.entities.Course;
|
||||||
import com.plannaplan.entities.Groups;
|
import com.plannaplan.entities.Groups;
|
||||||
import com.plannaplan.types.GroupType;
|
import com.plannaplan.types.GroupType;
|
||||||
@ -65,6 +66,51 @@ public class AssignmentResponse {
|
|||||||
GroupType.isLectureOrClass(group.getType()) == GroupType.CLASS ? group : null, ammounts);
|
GroupType.isLectureOrClass(group.getType()) == GroupType.CLASS ? group : null, ammounts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param course course entity
|
||||||
|
* @param group class/lecture entity
|
||||||
|
* @param ammounts map with ammounts key - group id, value - ammounts of taken
|
||||||
|
* places
|
||||||
|
*/
|
||||||
|
public AssignmentResponse(Course course, Assignment group, HashMap<Long, Integer> ammounts) {
|
||||||
|
this(course, GroupType.isLectureOrClass(group.getGroup().getType()) == GroupType.LECTURE ? group : null,
|
||||||
|
GroupType.isLectureOrClass(group.getGroup().getType()) == GroupType.CLASS ? group : null, ammounts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param course course entity
|
||||||
|
* @param group class/lecture entity
|
||||||
|
*/
|
||||||
|
public AssignmentResponse(Course course, Assignment group) {
|
||||||
|
this(course, GroupType.isLectureOrClass(group.getGroup().getType()) == GroupType.LECTURE ? group : null,
|
||||||
|
GroupType.isLectureOrClass(group.getGroup().getType()) == GroupType.CLASS ? group : null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param course course entity
|
||||||
|
* @param lecture lecture Groups entity
|
||||||
|
* @param classes class Groups entity
|
||||||
|
* @param ammounts map with ammounts key - group id, value - ammounts of taken
|
||||||
|
* places
|
||||||
|
*/
|
||||||
|
public AssignmentResponse(Course course, Assignment lecture, Assignment classes, HashMap<Long, Integer> ammounts) {
|
||||||
|
this.name = course.getName();
|
||||||
|
this.classes = new GroupWithCapacityResponse(classes, ammounts.get(classes.getGroup().getId()));
|
||||||
|
this.lecture = new GroupWithCapacityResponse(lecture, ammounts.get(lecture.getGroup().getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param course course entity
|
||||||
|
* @param lecture lecture Groups entity
|
||||||
|
* @param classes class Groups entity
|
||||||
|
*/
|
||||||
|
public AssignmentResponse(Course course, Assignment lecture, Assignment classes) {
|
||||||
|
this.name = course.getName();
|
||||||
|
this.classes = new GroupWithCapacityResponse(classes);
|
||||||
|
this.lecture = new GroupWithCapacityResponse(lecture);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Lecture in api response forms
|
* @return Lecture in api response forms
|
||||||
*/
|
*/
|
||||||
|
@ -39,6 +39,9 @@ public class GroupDefaultResponse {
|
|||||||
@ApiModelProperty(value = "Value shows how many places is already taken by other students.")
|
@ApiModelProperty(value = "Value shows how many places is already taken by other students.")
|
||||||
private Integer takenPlaces;
|
private Integer takenPlaces;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "Used only in resposnes realted to user assignments. For example in <code>/api/v1/users/schedule</code>.")
|
||||||
|
private Boolean isAccepted;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creat new entity
|
* creat new entity
|
||||||
*
|
*
|
||||||
@ -54,6 +57,13 @@ public class GroupDefaultResponse {
|
|||||||
this.type = group.getType() != null ? GroupType.isLectureOrClass(group.getType()) : null;
|
this.type = group.getType() != null ? GroupType.isLectureOrClass(group.getType()) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return is group accepted if its related to assignmetn
|
||||||
|
*/
|
||||||
|
public Boolean getIsAccepted() {
|
||||||
|
return isAccepted;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param group entity to map to api response
|
* @param group entity to map to api response
|
||||||
@ -73,6 +83,16 @@ public class GroupDefaultResponse {
|
|||||||
this(assignment.getGroup());
|
this(assignment.getGroup());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param assignment entity to map to api response
|
||||||
|
* @param takenPlaces map with ammounts of taken places
|
||||||
|
*/
|
||||||
|
public GroupDefaultResponse(Assignment assignment, int takenPlaces) {
|
||||||
|
this(assignment.getGroup(), takenPlaces);
|
||||||
|
this.isAccepted = assignment.isAccepted();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return what typew of group is this (lecture or class)
|
* @return what typew of group is this (lecture or class)
|
||||||
*/
|
*/
|
||||||
|
@ -49,7 +49,7 @@ public class GroupWithCapacityResponse extends GroupDefaultResponse {
|
|||||||
* @param takenPlaces group taken places
|
* @param takenPlaces group taken places
|
||||||
*/
|
*/
|
||||||
public GroupWithCapacityResponse(Assignment assignment, int takenPlaces) {
|
public GroupWithCapacityResponse(Assignment assignment, int takenPlaces) {
|
||||||
this(assignment.getGroup(), takenPlaces);
|
super(assignment, takenPlaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user