Chenged newest plan response

This commit is contained in:
BuildTools 2020-10-28 13:44:13 +01:00
parent db0115280f
commit 7073e3b1d8
7 changed files with 114 additions and 25 deletions

BIN
__pycache__/token.cpython-38.pyc Executable file

Binary file not shown.

View File

@ -32,7 +32,7 @@ public class App {
filip.setEmail("filizy@st.amu.edu.pl"); filip.setEmail("filizy@st.amu.edu.pl");
filip.setName("Filip"); filip.setName("Filip");
filip.setSurname("Izydorczyk"); filip.setSurname("Izydorczyk");
filip.setRole(UserRoles.DEANERY); filip.setRole(UserRoles.ADMIN);
this.userService.save(filip); this.userService.save(filip);
User hub = new User(); User hub = new User();

View File

@ -1,16 +1,45 @@
package com.plannaplan.responses.mappers; package com.plannaplan.responses.mappers;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.ArrayList;
import java.util.stream.Collectors; import java.util.HashMap;
import java.util.Map;
import com.plannaplan.entities.Assignment; import com.plannaplan.entities.Assignment;
import com.plannaplan.entities.Course;
import com.plannaplan.entities.Groups;
import com.plannaplan.responses.models.GetCurrentAssignmentsResponse; import com.plannaplan.responses.models.GetCurrentAssignmentsResponse;
import com.plannaplan.types.GroupType;
public class AssignmentResponseMappers { public class AssignmentResponseMappers {
public static final List<GetCurrentAssignmentsResponse> mapToResponse(List<Assignment> assignments) { public static final List<GetCurrentAssignmentsResponse> mapToResponse(List<Assignment> assignments) {
return assignments.stream().filter(Objects::nonNull).map(GetCurrentAssignmentsResponse::new) List<GetCurrentAssignmentsResponse> response = new ArrayList<>();
.collect(Collectors.toList()); 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;
} }
} }

View File

@ -1,11 +1,41 @@
package com.plannaplan.responses.models; 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) { public GetCurrentAssignmentsResponse(Course course, Groups lecture, Groups classes) {
super(assignment); 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;
} }
} }

View File

@ -7,5 +7,6 @@ spring.jpa.open-in-view=true
spring.jpa.hibernate.ddl-auto=create-drop spring.jpa.hibernate.ddl-auto=create-drop
spring.jackson.serialization.fail-on-empty-beans=false spring.jackson.serialization.fail-on-empty-beans=false
spring.main.allow-bean-definition-overriding=true spring.main.allow-bean-definition-overriding=true
spring.jackson.default-property-inclusion = NON_NULL
server.port=1285 server.port=1285

View File

@ -7,8 +7,11 @@ import java.util.List;
import com.plannaplan.entities.Assignment; import com.plannaplan.entities.Assignment;
import com.plannaplan.entities.Commision; import com.plannaplan.entities.Commision;
import com.plannaplan.entities.Course;
import com.plannaplan.entities.Groups; import com.plannaplan.entities.Groups;
import com.plannaplan.responses.models.GetCurrentAssignmentsResponse; import com.plannaplan.responses.models.GetCurrentAssignmentsResponse;
import com.plannaplan.entities.Lecturer;
import com.plannaplan.types.WeekDay;
import org.junit.Test; import org.junit.Test;
@ -16,12 +19,15 @@ public class AssignmentResponseMappersTest {
@Test @Test
public void shouldReturnNewList() { public void shouldReturnNewList() {
final Commision com = new Commision(); final Commision com = new Commision();
final List<Assignment> groups = Arrays.asList(new Assignment(new Groups(), com), final Course course = new Course("Kurs", "TES-T");
new Assignment(new Groups(), com)); 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); final List<GetCurrentAssignmentsResponse> response = AssignmentResponseMappers.mapToResponse(groups);
assertTrue(response.size() == 2); assertTrue(response.size() == 1);
assertTrue(response instanceof List);
assertTrue(response.get(0) instanceof GetCurrentAssignmentsResponse); assertTrue(response.get(0) instanceof GetCurrentAssignmentsResponse);
} }
} }

View File

@ -2,10 +2,9 @@ package com.plannaplan.responses.models;
import static org.junit.jupiter.api.Assertions.assertTrue; 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.Groups;
import com.plannaplan.entities.Lecturer; import com.plannaplan.entities.Lecturer;
import com.plannaplan.types.GroupType;
import com.plannaplan.types.WeekDay; import com.plannaplan.types.WeekDay;
import org.junit.Test; import org.junit.Test;
@ -13,17 +12,41 @@ import org.junit.Test;
public class GetCurrentAssignmentsResponseTest { public class GetCurrentAssignmentsResponseTest {
@Test @Test
public void shouldMapAssignmentClassToResponse() { public void shouldMapGroupsToResponse() {
final Assignment assignment = new Assignment( final Course course = new Course("Kurs", "tst.");
new Groups(42, "A4-1", null, 520, WeekDay.MONDAY, new Lecturer("krul.", "Wladyslaw", "Potocki")), null); 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); final GetCurrentAssignmentsResponse response = new GetCurrentAssignmentsResponse(course, lecture, classes);
assertTrue(response.getCapacity() == 42); assertTrue(response.getName() == "Kurs");
assertTrue(response.getDay() == 0); assertTrue(response.getLecture() instanceof WithCapacityGroupResponse);
assertTrue(response.getLecturer().equals("krul. Wladyslaw Potocki")); assertTrue(response.getClasses() instanceof WithCapacityGroupResponse);
assertTrue(response.getRoom().equals("A4-1")); }
assertTrue(response.getTime().equals("8.40"));
assertTrue(response.getType() == GroupType.CLASS); @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);
} }
} }