Moved CoursesResponse To Abstract
This commit is contained in:
parent
29851dac0d
commit
bdd0278880
@ -9,7 +9,7 @@ import com.plannaplan.App;
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.responses.mappers.CoursesResponseMappers;
|
||||
import com.plannaplan.responses.models.CoursesResponse;
|
||||
import com.plannaplan.responses.models.GetCoursesResponse;
|
||||
import com.plannaplan.services.CourseService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -28,9 +28,9 @@ public class CoursesController {
|
||||
private CourseService courseService;
|
||||
|
||||
@GetMapping("/getCourses")
|
||||
public ResponseEntity<List<CoursesResponse>> getMethodName() {
|
||||
public ResponseEntity<List<GetCoursesResponse>> getMethodName() {
|
||||
List<Course> courses = this.courseService.getAllCourses();
|
||||
List<CoursesResponse> response = CoursesResponseMappers.mapCoursesListToCoursesResponseList(courses);
|
||||
List<GetCoursesResponse> response = CoursesResponseMappers.mapCoursesListToCoursesResponseList(courses);
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
@ -5,10 +5,10 @@ import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.responses.models.CoursesResponse;
|
||||
import com.plannaplan.responses.models.GetCoursesResponse;
|
||||
|
||||
public class CoursesResponseMappers {
|
||||
public static final List<CoursesResponse> mapCoursesListToCoursesResponseList(List<Course> courses) {
|
||||
return courses.stream().filter(Objects::nonNull).map(CoursesResponse::new).collect(Collectors.toList());
|
||||
public static final List<GetCoursesResponse> mapCoursesListToCoursesResponseList(List<Course> courses) {
|
||||
return courses.stream().filter(Objects::nonNull).map(GetCoursesResponse::new).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package com.plannaplan.responses.models;
|
||||
|
||||
import com.plannaplan.entities.Course;
|
||||
|
||||
public class CoursesResponse {
|
||||
public abstract class CoursesResponse {
|
||||
|
||||
private Long id;
|
||||
private String name;
|
||||
|
@ -0,0 +1,11 @@
|
||||
package com.plannaplan.responses.models;
|
||||
|
||||
import com.plannaplan.entities.Course;
|
||||
|
||||
public class GetCoursesResponse extends CoursesResponse {
|
||||
|
||||
public GetCoursesResponse(Course course) {
|
||||
super(course);
|
||||
}
|
||||
|
||||
}
|
@ -6,7 +6,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.responses.models.CoursesResponse;
|
||||
import com.plannaplan.responses.models.GetCoursesResponse;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@ -14,10 +14,10 @@ public class CoursesResponseMappersTest {
|
||||
@Test
|
||||
public void shouldMapListCoursesToResponseList() {
|
||||
final List<Course> courses = Arrays.asList(new Course(), new Course());
|
||||
final List<CoursesResponse> response = CoursesResponseMappers.mapCoursesListToCoursesResponseList(courses);
|
||||
final List<GetCoursesResponse> response = CoursesResponseMappers.mapCoursesListToCoursesResponseList(courses);
|
||||
|
||||
assertTrue(response.size() == 2);
|
||||
assertTrue(response.get(0) instanceof CoursesResponse);
|
||||
assertTrue(response.get(0) instanceof GetCoursesResponse);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -6,11 +6,11 @@ import com.plannaplan.entities.Course;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class CoursesResponseTest {
|
||||
public class GetCoursesResponseTest {
|
||||
@Test
|
||||
public void shouldMapFilledCourse() {
|
||||
final Course course = new Course("Test", "XD");
|
||||
final CoursesResponse response = new CoursesResponse(course);
|
||||
final GetCoursesResponse response = new GetCoursesResponse(course);
|
||||
|
||||
assertTrue(response.getId() == null);
|
||||
assertTrue(response.getName().equals("Test"));
|
||||
@ -19,7 +19,7 @@ public class CoursesResponseTest {
|
||||
@Test
|
||||
public void shouldMapEmptyCourse() {
|
||||
final Course course = new Course();
|
||||
final CoursesResponse response = new CoursesResponse(course);
|
||||
final GetCoursesResponse response = new GetCoursesResponse(course);
|
||||
|
||||
assertTrue(response.getId() == null);
|
||||
assertTrue(response.getName().equals(""));
|
Loading…
Reference in New Issue
Block a user