Little refactor

This commit is contained in:
Filip Izydorczyk 2020-10-13 17:13:43 +02:00
parent 148d7a31c6
commit 932e1a8830
9 changed files with 12 additions and 35 deletions

View File

@ -39,8 +39,7 @@ public class AssignmentsController extends TokenBasedController {
if (com.isPresent()) {
List<Assignment> respone = this.assignmentService.getCommisionAssignments(com.get());
return new ResponseEntity<>(AssignmentResponseMappers.mapAssignmentsListToAssignmentResponseList(respone),
HttpStatus.OK);
return new ResponseEntity<>(AssignmentResponseMappers.mapToResponse(respone), HttpStatus.OK);
}
return new ResponseEntity<>(null, HttpStatus.OK);

View File

@ -27,7 +27,7 @@ public class CoursesController {
@GetMapping("/getCourses")
public ResponseEntity<List<GetCoursesResponse>> getMethodName() {
List<Course> courses = this.courseService.getAllCourses();
List<GetCoursesResponse> response = CoursesResponseMappers.mapCoursesListToCoursesResponseList(courses);
List<GetCoursesResponse> response = CoursesResponseMappers.mapToGetCoursesResponse(courses);
return new ResponseEntity<>(response, HttpStatus.OK);
}
@ -35,30 +35,9 @@ public class CoursesController {
public ResponseEntity<List<GetCoursesWithGroupsResponse>> getCoursesWithGroups() {
final List<Course> courses = this.courseService.getAllCourses();
final List<GetCoursesWithGroupsResponse> response = CoursesResponseMappers
.mapCoursesWithGrtoupsListToCoursesResponseList(courses);
.mapToGetCoursesWithGroupsResponse(courses);
return new ResponseEntity<>(response, HttpStatus.OK);
// for (Course c : courses) {
// Dictionary<String, Object> element = new Hashtable<>();
// element.put("id", c.getId());
// element.put("name", c.getName());
// List<Dictionary<String, Object>> groups = new ArrayList<>();
// for (Groups g : c.getGroups()) {
// Dictionary<String, Object> group = new Hashtable<>();
// group.put("id", g.getId());
// group.put("day", g.getDay().label);
// group.put("time", g.getTimeString());
// group.put("lecturer", g.getLecturer().toString());
// group.put("room", g.getRoom());
// group.put("type", g.getType());
// groups.add(group);
// }
// element.put("groups", groups);
// response.add(element);
// }
// return new ResponseEntity<>(response, HttpStatus.OK);
}
}

View File

@ -9,8 +9,7 @@ import com.plannaplan.responses.models.GetCurrentAssignmentsResponse;
public class AssignmentResponseMappers {
public static final List<GetCurrentAssignmentsResponse> mapAssignmentsListToAssignmentResponseList(
List<Assignment> assignments) {
public static final List<GetCurrentAssignmentsResponse> mapToResponse(List<Assignment> assignments) {
return assignments.stream().filter(Objects::nonNull).map(GetCurrentAssignmentsResponse::new)
.collect(Collectors.toList());
}

View File

@ -9,12 +9,11 @@ import com.plannaplan.responses.models.GetCoursesResponse;
import com.plannaplan.responses.models.GetCoursesWithGroupsResponse;
public class CoursesResponseMappers {
public static final List<GetCoursesResponse> mapCoursesListToCoursesResponseList(List<Course> courses) {
public static final List<GetCoursesResponse> mapToGetCoursesResponse(List<Course> courses) {
return courses.stream().filter(Objects::nonNull).map(GetCoursesResponse::new).collect(Collectors.toList());
}
public static final List<GetCoursesWithGroupsResponse> mapCoursesWithGrtoupsListToCoursesResponseList(
List<Course> courses) {
public static final List<GetCoursesWithGroupsResponse> mapToGetCoursesWithGroupsResponse(List<Course> courses) {
return courses.stream().filter(Objects::nonNull).map(GetCoursesWithGroupsResponse::new)
.collect(Collectors.toList());
}

View File

@ -1,6 +1,7 @@
package com.plannaplan.responses.models;
import com.plannaplan.entities.Course;
import com.plannaplan.responses.models.abstracts.CoursesResponse;
public class GetCoursesResponse extends CoursesResponse {

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import com.plannaplan.entities.Course;
import com.plannaplan.responses.models.abstracts.CoursesResponse;
import com.plannaplan.types.GroupType;
public class GetCoursesWithGroupsResponse extends CoursesResponse {

View File

@ -1,4 +1,4 @@
package com.plannaplan.responses.models;
package com.plannaplan.responses.models.abstracts;
import com.plannaplan.entities.Course;

View File

@ -18,8 +18,7 @@ public class AssignmentResponseMappersTest {
final Commision com = new Commision();
final List<Assignment> groups = Arrays.asList(new Assignment(new Groups(), com),
new Assignment(new Groups(), com));
final List<GetCurrentAssignmentsResponse> response = AssignmentResponseMappers
.mapAssignmentsListToAssignmentResponseList(groups);
final List<GetCurrentAssignmentsResponse> response = AssignmentResponseMappers.mapToResponse(groups);
assertTrue(response.size() == 2);
assertTrue(response instanceof List);

View File

@ -15,7 +15,7 @@ public class CoursesResponseMappersTest {
@Test
public void shouldMapListCoursesToResponseList() {
final List<Course> courses = Arrays.asList(new Course(), new Course());
final List<GetCoursesResponse> response = CoursesResponseMappers.mapCoursesListToCoursesResponseList(courses);
final List<GetCoursesResponse> response = CoursesResponseMappers.mapToGetCoursesResponse(courses);
assertTrue(response.size() == 2);
assertTrue(response.get(0) instanceof GetCoursesResponse);
@ -26,7 +26,7 @@ public class CoursesResponseMappersTest {
public void shouldMapListCoursesToResponseWithGroupsList() {
final List<Course> courses = Arrays.asList(new Course(), new Course());
final List<GetCoursesWithGroupsResponse> response = CoursesResponseMappers
.mapCoursesWithGrtoupsListToCoursesResponseList(courses);
.mapToGetCoursesWithGroupsResponse(courses);
assertTrue(response.size() == 2);
assertTrue(response.get(0) instanceof GetCoursesWithGroupsResponse);