Courses Controller getCourses Mapping

This commit is contained in:
Filip Izydorczyk
2020-10-09 14:53:54 +02:00
parent f97e22fa5f
commit 29851dac0d
5 changed files with 91 additions and 9 deletions

View File

@ -8,6 +8,8 @@ import java.util.List;
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.services.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
@ -26,16 +28,9 @@ public class CoursesController {
private CourseService courseService;
@GetMapping("/getCourses")
public ResponseEntity<List<Dictionary<String, Object>>> getMethodName() {
public ResponseEntity<List<CoursesResponse>> getMethodName() {
List<Course> courses = this.courseService.getAllCourses();
List<Dictionary<String, Object>> response = new ArrayList<>();
for (Course c : courses) {
Dictionary<String, Object> element = new Hashtable<>();
element.put("id", c.getId());
element.put("name", c.getName());
response.add(element);
}
List<CoursesResponse> response = CoursesResponseMappers.mapCoursesListToCoursesResponseList(courses);
return new ResponseEntity<>(response, HttpStatus.OK);
}