From 7073e3b1d8f6f176e7066210523f7dca1bc8127f Mon Sep 17 00:00:00 2001 From: BuildTools Date: Wed, 28 Oct 2020 13:44:13 +0100 Subject: [PATCH] Chenged newest plan response --- __pycache__/token.cpython-38.pyc | Bin 0 -> 1467 bytes .../src/main/java/com/plannaplan/App.java | 2 +- .../mappers/AssignmentResponseMappers.java | 37 ++++++++++++-- .../models/GetCurrentAssignmentsResponse.java | 38 ++++++++++++-- .../src/main/resources/application.properties | 1 + .../AssignmentResponseMappersTest.java | 14 ++++-- .../GetCurrentAssignmentsResponseTest.java | 47 +++++++++++++----- 7 files changed, 114 insertions(+), 25 deletions(-) create mode 100755 __pycache__/token.cpython-38.pyc diff --git a/__pycache__/token.cpython-38.pyc b/__pycache__/token.cpython-38.pyc new file mode 100755 index 0000000000000000000000000000000000000000..48e8f04444cca8f51ba6e4916758cda2c1f1b087 GIT binary patch literal 1467 zcmZuwPj4$V5VyU%>1MNOi-f9Igha&wX%8=3i3@t-!4nVEo+3nwgnU_T)-Kt0|J8N~ ziPBSg;3IHMj(h_?0-s^8oZeU90yEyW%9F6<@r-9Y9{=X&ABV$$!1(Q_-;+;VLjFc$ zf50Aj15>X+2qI`fIIgUqCF87gxKp~^rJc_!d;GxaPT`e4_aFEByl>A2Jh&jj72X38 zo@5(`52Pap*G%-p!2{)?@cB@Z?V%j*C?zu75Xe9$Bo19gPzElm9>h&9ZY!={zmBz;i#&}RRo}>4ljPNES>;mc+dNjXsdYR}vs*|Tn;Mo; zvuuZnmgc#D0luyWg3y45bagZtz2|=q5(mOOm=+QaiUCLrU6UKO0buT_p~hL$8+Stm zJq1Rck`29Q##@7*64Tortl1-gK7s}(``bV`+rf@(L*ec$ycSAt-1bZkwHt+zW$QI6uT0x- zpe+g$v@RrEDnx;M3jkNP-a_R@w!Q0Gm8ofavdU^9BS-ld)U)}83c;|A=>-0`wkPW3 z;=8M3&^7uAJ*Fqr2Vi}=@+YItJ&wHAPm(GvWsv(1RVb-NHlyda)*Jwx%0)@2s6I*&%7!IAXkC)LB~0 zYHjjA0gZ_A!JrcDS8<%BdX$#)kreY$Q=l0a_0M_rHC~oy@-+rR+;j1- zK0iM{|IC{5byGw~JXpx-RMiVO!3P*V>Izi|l|pwk%PLWSX9e+H#s3E$MKKK&5>S_ri8-Qy!h*}uVo H%L4izD8q3` literal 0 HcmV?d00001 diff --git a/restservice/src/main/java/com/plannaplan/App.java b/restservice/src/main/java/com/plannaplan/App.java index d63eba5..6e91104 100755 --- a/restservice/src/main/java/com/plannaplan/App.java +++ b/restservice/src/main/java/com/plannaplan/App.java @@ -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(); diff --git a/restservice/src/main/java/com/plannaplan/responses/mappers/AssignmentResponseMappers.java b/restservice/src/main/java/com/plannaplan/responses/mappers/AssignmentResponseMappers.java index abc7ddc..b82bd7a 100755 --- a/restservice/src/main/java/com/plannaplan/responses/mappers/AssignmentResponseMappers.java +++ b/restservice/src/main/java/com/plannaplan/responses/mappers/AssignmentResponseMappers.java @@ -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 mapToResponse(List assignments) { - return assignments.stream().filter(Objects::nonNull).map(GetCurrentAssignmentsResponse::new) - .collect(Collectors.toList()); + List response = new ArrayList<>(); + HashMap> 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> entry : courses.entrySet()) { + final Course course = entry.getKey(); + final List 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; } } diff --git a/restservice/src/main/java/com/plannaplan/responses/models/GetCurrentAssignmentsResponse.java b/restservice/src/main/java/com/plannaplan/responses/models/GetCurrentAssignmentsResponse.java index b307a61..6296a87 100755 --- a/restservice/src/main/java/com/plannaplan/responses/models/GetCurrentAssignmentsResponse.java +++ b/restservice/src/main/java/com/plannaplan/responses/models/GetCurrentAssignmentsResponse.java @@ -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; } } diff --git a/restservice/src/main/resources/application.properties b/restservice/src/main/resources/application.properties index 0477c97..55e1449 100755 --- a/restservice/src/main/resources/application.properties +++ b/restservice/src/main/resources/application.properties @@ -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 \ No newline at end of file diff --git a/restservice/src/test/java/com/plannaplan/responses/mappers/AssignmentResponseMappersTest.java b/restservice/src/test/java/com/plannaplan/responses/mappers/AssignmentResponseMappersTest.java index 27eb13d..431211c 100755 --- a/restservice/src/test/java/com/plannaplan/responses/mappers/AssignmentResponseMappersTest.java +++ b/restservice/src/test/java/com/plannaplan/responses/mappers/AssignmentResponseMappersTest.java @@ -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 groups = Arrays.asList(new Assignment(new Groups(), com), - new Assignment(new Groups(), com)); + final Course course = new Course("Kurs", "TES-T"); + final List 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 response = AssignmentResponseMappers.mapToResponse(groups); - assertTrue(response.size() == 2); - assertTrue(response instanceof List); + assertTrue(response.size() == 1); assertTrue(response.get(0) instanceof GetCurrentAssignmentsResponse); } } diff --git a/restservice/src/test/java/com/plannaplan/responses/models/GetCurrentAssignmentsResponseTest.java b/restservice/src/test/java/com/plannaplan/responses/models/GetCurrentAssignmentsResponseTest.java index 0ff4e1a..8a2aa17 100755 --- a/restservice/src/test/java/com/plannaplan/responses/models/GetCurrentAssignmentsResponseTest.java +++ b/restservice/src/test/java/com/plannaplan/responses/models/GetCurrentAssignmentsResponseTest.java @@ -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); } }