Responses up[dated
This commit is contained in:
@ -12,7 +12,7 @@ import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.responses.mappers.AssignmentResponseMappers;
|
||||
import com.plannaplan.responses.models.AssignmentResponse;
|
||||
import com.plannaplan.responses.models.GetCurrentAssignmentsResponse;
|
||||
import com.plannaplan.services.AssignmentService;
|
||||
import com.plannaplan.services.CommisionService;
|
||||
|
||||
@ -33,7 +33,7 @@ public class AssignmentsController extends TokenBasedController {
|
||||
private AssignmentService assignmentService;
|
||||
|
||||
@GetMapping("/getCurrentAssignments")
|
||||
public ResponseEntity<List<AssignmentResponse>> getCurrentAssignments() throws Exception {
|
||||
public ResponseEntity<List<GetCurrentAssignmentsResponse>> getCurrentAssignments() throws Exception {
|
||||
User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException("User not found"));
|
||||
Optional<Commision> com = this.commisionService.getNewestCommision(user);
|
||||
|
||||
|
@ -1,15 +1,12 @@
|
||||
package com.plannaplan.controllers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Dictionary;
|
||||
import java.util.Hashtable;
|
||||
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.GetCoursesResponse;
|
||||
import com.plannaplan.responses.models.GetCoursesWithGroupsResponse;
|
||||
import com.plannaplan.services.CourseService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -35,30 +32,33 @@ public class CoursesController {
|
||||
}
|
||||
|
||||
@GetMapping("/getCoursesWithGroups")
|
||||
public ResponseEntity<List<Dictionary<String, Object>>> getCoursesWithGroups() {
|
||||
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());
|
||||
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);
|
||||
}
|
||||
|
||||
public ResponseEntity<List<GetCoursesWithGroupsResponse>> getCoursesWithGroups() {
|
||||
final List<Course> courses = this.courseService.getAllCourses();
|
||||
final List<GetCoursesWithGroupsResponse> response = CoursesResponseMappers
|
||||
.mapCoursesWithGrtoupsListToCoursesResponseList(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);
|
||||
}
|
||||
|
||||
}
|
@ -5,16 +5,13 @@ import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.responses.models.AssignmentResponse;
|
||||
import com.plannaplan.responses.models.GetCurrentAssignmentsResponse;
|
||||
|
||||
public class AssignmentResponseMappers {
|
||||
public static final List<AssignmentResponse> mapGroupsListToAssignmentResponseList(List<Groups> groups) {
|
||||
return groups.stream().filter(Objects::nonNull).map(AssignmentResponse::new).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static final List<AssignmentResponse> mapAssignmentsListToAssignmentResponseList(
|
||||
public static final List<GetCurrentAssignmentsResponse> mapAssignmentsListToAssignmentResponseList(
|
||||
List<Assignment> assignments) {
|
||||
return assignments.stream().filter(Objects::nonNull).map(AssignmentResponse::new).collect(Collectors.toList());
|
||||
return assignments.stream().filter(Objects::nonNull).map(GetCurrentAssignmentsResponse::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -6,9 +6,16 @@ import java.util.stream.Collectors;
|
||||
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.responses.models.GetCoursesResponse;
|
||||
import com.plannaplan.responses.models.GetCoursesWithGroupsResponse;
|
||||
|
||||
public class CoursesResponseMappers {
|
||||
public static final List<GetCoursesResponse> mapCoursesListToCoursesResponseList(List<Course> courses) {
|
||||
return courses.stream().filter(Objects::nonNull).map(GetCoursesResponse::new).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static final List<GetCoursesWithGroupsResponse> mapCoursesWithGrtoupsListToCoursesResponseList(
|
||||
List<Course> courses) {
|
||||
return courses.stream().filter(Objects::nonNull).map(GetCoursesWithGroupsResponse::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.types.GroupType;
|
||||
|
||||
public class AssignmentResponse {
|
||||
public class DefaultGroupResponse {
|
||||
|
||||
private Long id;
|
||||
private int day;
|
||||
@ -14,7 +14,7 @@ public class AssignmentResponse {
|
||||
private int capacity;
|
||||
private GroupType type;
|
||||
|
||||
public AssignmentResponse(Groups group) {
|
||||
public DefaultGroupResponse(Groups group) {
|
||||
this.id = group.getId() != null ? group.getId() : null;
|
||||
this.day = group.getDay() != null ? group.getDay().label : -1;
|
||||
this.time = group.getTimeString() != null ? group.getTimeString() : "";
|
||||
@ -24,7 +24,7 @@ public class AssignmentResponse {
|
||||
this.type = group.getType() != null ? group.getType() : null;
|
||||
}
|
||||
|
||||
public AssignmentResponse(Assignment assignment) {
|
||||
public DefaultGroupResponse(Assignment assignment) {
|
||||
this(assignment.getGroup());
|
||||
}
|
||||
|
@ -0,0 +1,33 @@
|
||||
package com.plannaplan.responses.models;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.types.GroupType;
|
||||
|
||||
public class GetCoursesWithGroupsResponse extends CoursesResponse {
|
||||
|
||||
private List<DefaultGroupResponse> lectures = new ArrayList<>();
|
||||
private List<DefaultGroupResponse> classes = new ArrayList<>();
|
||||
|
||||
public GetCoursesWithGroupsResponse(Course course) {
|
||||
super(course);
|
||||
course.getGroups().stream().forEach(group -> {
|
||||
if (group.getType() == GroupType.CLASS) {
|
||||
this.classes.add(new DefaultGroupResponse(group));
|
||||
} else {
|
||||
this.lectures.add(new DefaultGroupResponse(group));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public List<DefaultGroupResponse> getClasses() {
|
||||
return this.classes;
|
||||
}
|
||||
|
||||
public List<DefaultGroupResponse> getLectures() {
|
||||
return this.lectures;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.plannaplan.responses.models;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
|
||||
public class GetCurrentAssignmentsResponse extends DefaultGroupResponse {
|
||||
|
||||
public GetCurrentAssignmentsResponse(Assignment assignment) {
|
||||
super(assignment);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user