Chenged newest plan response
This commit is contained in:
parent
db0115280f
commit
7073e3b1d8
BIN
__pycache__/token.cpython-38.pyc
Executable file
BIN
__pycache__/token.cpython-38.pyc
Executable file
Binary file not shown.
@ -32,7 +32,7 @@ public class App {
|
||||
filip.setEmail("filizy@st.amu.edu.pl");
|
||||
filip.setName("Filip");
|
||||
filip.setSurname("Izydorczyk");
|
||||
filip.setRole(UserRoles.DEANERY);
|
||||
filip.setRole(UserRoles.ADMIN);
|
||||
this.userService.save(filip);
|
||||
|
||||
User hub = new User();
|
||||
|
@ -1,16 +1,45 @@
|
||||
package com.plannaplan.responses.mappers;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.responses.models.GetCurrentAssignmentsResponse;
|
||||
import com.plannaplan.types.GroupType;
|
||||
|
||||
public class AssignmentResponseMappers {
|
||||
|
||||
public static final List<GetCurrentAssignmentsResponse> mapToResponse(List<Assignment> assignments) {
|
||||
return assignments.stream().filter(Objects::nonNull).map(GetCurrentAssignmentsResponse::new)
|
||||
.collect(Collectors.toList());
|
||||
List<GetCurrentAssignmentsResponse> response = new ArrayList<>();
|
||||
HashMap<Course, List<Groups>> courses = new HashMap<>();
|
||||
assignments.stream().forEach((Assignment assignment) -> {
|
||||
final Groups group = assignment.getGroup();
|
||||
final Course course = group.getCourseId();
|
||||
if (courses.get(course) == null) {
|
||||
courses.put(course, new ArrayList<>());
|
||||
}
|
||||
courses.get(course).add(group);
|
||||
});
|
||||
|
||||
for (Map.Entry<Course, List<Groups>> entry : courses.entrySet()) {
|
||||
final Course course = entry.getKey();
|
||||
final List<Groups> courseGroups = entry.getValue();
|
||||
if (courseGroups.size() == 1) {
|
||||
response.add(new GetCurrentAssignmentsResponse(course, courseGroups.get(0)));
|
||||
}
|
||||
if (courseGroups.size() == 2) {
|
||||
final Groups lecture = courseGroups.stream().filter(o -> o.getType() == GroupType.LECTURE).findFirst()
|
||||
.get();
|
||||
final Groups classes = courseGroups.stream().filter(o -> o.getType() == GroupType.CLASS).findFirst()
|
||||
.get();
|
||||
response.add(new GetCurrentAssignmentsResponse(course, lecture, classes));
|
||||
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,41 @@
|
||||
package com.plannaplan.responses.models;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.types.GroupType;
|
||||
|
||||
public class GetCurrentAssignmentsResponse extends WithCapacityGroupResponse {
|
||||
public class GetCurrentAssignmentsResponse {
|
||||
private Long id;
|
||||
private String name;
|
||||
private WithCapacityGroupResponse classes;
|
||||
private WithCapacityGroupResponse lecture;
|
||||
|
||||
public GetCurrentAssignmentsResponse(Assignment assignment) {
|
||||
super(assignment);
|
||||
public GetCurrentAssignmentsResponse(Course course, Groups lecture, Groups classes) {
|
||||
this.id = course.getId();
|
||||
this.name = course.getName();
|
||||
this.lecture = lecture == null ? null : new WithCapacityGroupResponse(lecture);
|
||||
this.classes = classes == null ? null : new WithCapacityGroupResponse(classes);
|
||||
}
|
||||
|
||||
public GetCurrentAssignmentsResponse(Course course, Groups group) {
|
||||
this(course, group.getType() == GroupType.LECTURE ? group : null,
|
||||
group.getType() == GroupType.CLASS ? group : null);
|
||||
}
|
||||
|
||||
public WithCapacityGroupResponse getLecture() {
|
||||
return this.lecture;
|
||||
}
|
||||
|
||||
public WithCapacityGroupResponse getClasses() {
|
||||
return this.classes;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,5 +7,6 @@ spring.jpa.open-in-view=true
|
||||
spring.jpa.hibernate.ddl-auto=create-drop
|
||||
spring.jackson.serialization.fail-on-empty-beans=false
|
||||
spring.main.allow-bean-definition-overriding=true
|
||||
spring.jackson.default-property-inclusion = NON_NULL
|
||||
|
||||
server.port=1285
|
@ -7,8 +7,11 @@ import java.util.List;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.responses.models.GetCurrentAssignmentsResponse;
|
||||
import com.plannaplan.entities.Lecturer;
|
||||
import com.plannaplan.types.WeekDay;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@ -16,12 +19,15 @@ public class AssignmentResponseMappersTest {
|
||||
@Test
|
||||
public void shouldReturnNewList() {
|
||||
final Commision com = new Commision();
|
||||
final List<Assignment> groups = Arrays.asList(new Assignment(new Groups(), com),
|
||||
new Assignment(new Groups(), com));
|
||||
final Course course = new Course("Kurs", "TES-T");
|
||||
final List<Assignment> groups = Arrays.asList(
|
||||
new Assignment(new Groups(142, "A4-1", course, 520, WeekDay.MONDAY,
|
||||
new Lecturer("krul.", "Wladyslaw", "Potocki")), com),
|
||||
new Assignment(new Groups(32, "A4-1", course, 420, WeekDay.MONDAY,
|
||||
new Lecturer("krul.", "Wladyslaw", "Potocki")), com));
|
||||
final List<GetCurrentAssignmentsResponse> response = AssignmentResponseMappers.mapToResponse(groups);
|
||||
|
||||
assertTrue(response.size() == 2);
|
||||
assertTrue(response instanceof List);
|
||||
assertTrue(response.size() == 1);
|
||||
assertTrue(response.get(0) instanceof GetCurrentAssignmentsResponse);
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,9 @@ package com.plannaplan.responses.models;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.entities.Lecturer;
|
||||
import com.plannaplan.types.GroupType;
|
||||
import com.plannaplan.types.WeekDay;
|
||||
|
||||
import org.junit.Test;
|
||||
@ -13,17 +12,41 @@ import org.junit.Test;
|
||||
public class GetCurrentAssignmentsResponseTest {
|
||||
|
||||
@Test
|
||||
public void shouldMapAssignmentClassToResponse() {
|
||||
final Assignment assignment = new Assignment(
|
||||
new Groups(42, "A4-1", null, 520, WeekDay.MONDAY, new Lecturer("krul.", "Wladyslaw", "Potocki")), null);
|
||||
public void shouldMapGroupsToResponse() {
|
||||
final Course course = new Course("Kurs", "tst.");
|
||||
final Groups lecture = new Groups(142, "A4-1", null, 520, WeekDay.MONDAY,
|
||||
new Lecturer("krul.", "Wladyslaw", "Potocki"));
|
||||
final Groups classes = new Groups(22, "A4-2", null, 580, WeekDay.MONDAY,
|
||||
new Lecturer("krul.", "Wladyslaw", "Potocki"));
|
||||
|
||||
final GetCurrentAssignmentsResponse response = new GetCurrentAssignmentsResponse(assignment);
|
||||
assertTrue(response.getCapacity() == 42);
|
||||
assertTrue(response.getDay() == 0);
|
||||
assertTrue(response.getLecturer().equals("krul. Wladyslaw Potocki"));
|
||||
assertTrue(response.getRoom().equals("A4-1"));
|
||||
assertTrue(response.getTime().equals("8.40"));
|
||||
assertTrue(response.getType() == GroupType.CLASS);
|
||||
final GetCurrentAssignmentsResponse response = new GetCurrentAssignmentsResponse(course, lecture, classes);
|
||||
assertTrue(response.getName() == "Kurs");
|
||||
assertTrue(response.getLecture() instanceof WithCapacityGroupResponse);
|
||||
assertTrue(response.getClasses() instanceof WithCapacityGroupResponse);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMapLectureToResponse() {
|
||||
final Course course = new Course("Kurs", "tst.");
|
||||
final Groups lecture = new Groups(142, "A4-1", null, 520, WeekDay.MONDAY,
|
||||
new Lecturer("krul.", "Wladyslaw", "Potocki"));
|
||||
|
||||
final GetCurrentAssignmentsResponse response = new GetCurrentAssignmentsResponse(course, lecture);
|
||||
assertTrue(response.getName() == "Kurs");
|
||||
assertTrue(response.getLecture() instanceof WithCapacityGroupResponse);
|
||||
assertTrue(response.getClasses() == null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMapClassToResponse() {
|
||||
final Course course = new Course("Kurs", "tst.");
|
||||
final Groups classes = new Groups(22, "A4-2", null, 580, WeekDay.MONDAY,
|
||||
new Lecturer("krul.", "Wladyslaw", "Potocki"));
|
||||
|
||||
final GetCurrentAssignmentsResponse response = new GetCurrentAssignmentsResponse(course, classes);
|
||||
assertTrue(response.getName() == "Kurs");
|
||||
assertTrue(response.getLecture() == null);
|
||||
assertTrue(response.getClasses() instanceof WithCapacityGroupResponse);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user