Part 2 has been ended. The Part 3: chanaged test

This commit is contained in:
Marcin Woźniak 2020-11-08 17:20:00 +01:00
parent a30c3af09c
commit 035de011f2
Signed by: y0rune
GPG Key ID: F204C385F57EB348
16 changed files with 82 additions and 82 deletions

View File

@ -16,7 +16,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.GetCurrentAssignmentsResponse;
import com.plannaplan.responses.models.AssignmentResponse;
import com.plannaplan.services.AssignmentService;
import com.plannaplan.services.CommisionService;
@ -40,7 +40,7 @@ public class AssignmentsController extends TokenBasedController {
@GetMapping("/user")
@ApiOperation(value = "Return user current assignemts (from newest commision). STUDENT Token needs to be provided.")
public ResponseEntity<List<GetCurrentAssignmentsResponse>> getCurrentAssignments() throws Exception {
public ResponseEntity<List<AssignmentResponse>> getCurrentAssignments() throws Exception {
User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException("User not found"));
Optional<Commision> com = this.commisionService.getNewestCommision(user);

View File

@ -5,8 +5,8 @@ import java.util.List;
import com.plannaplan.App;
import com.plannaplan.entities.Course;
import com.plannaplan.responses.mappers.CoursesResponseMappers;
import com.plannaplan.responses.models.GetCoursesResponse;
import com.plannaplan.responses.models.GetCoursesWithGroupsResponse;
import com.plannaplan.responses.models.CoursesDefaultResponse;
import com.plannaplan.responses.models.CoursesWithGroupsResponse;
import com.plannaplan.services.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
@ -39,11 +39,11 @@ public class CoursesController {
@RequestParam(name = "groups", defaultValue = "false") @ApiParam(value = "Boolean if you want to have resopnse with associated groups or without") Boolean groups) {
List<Course> courses = this.courseService.getAllCourses();
if (groups) {
final List<GetCoursesWithGroupsResponse> response = CoursesResponseMappers
final List<CoursesWithGroupsResponse> response = CoursesResponseMappers
.mapToGetCoursesWithGroupsResponse(courses);
return new ResponseEntity<>(response, HttpStatus.OK);
}
final List<GetCoursesResponse> response = CoursesResponseMappers.mapToGetCoursesResponse(courses);
final List<CoursesDefaultResponse> response = CoursesResponseMappers.mapToGetCoursesResponse(courses);
return new ResponseEntity<>(response, HttpStatus.OK);
}
}

View File

@ -5,8 +5,8 @@ import java.util.List;
import com.plannaplan.App;
import com.plannaplan.entities.Groups;
import com.plannaplan.responses.mappers.GroupsMappers;
import com.plannaplan.responses.models.DefaultGroupResponse;
import com.plannaplan.responses.models.GetCourseGroupsResponse;
import com.plannaplan.responses.models.GroupDefaultResponse;
import com.plannaplan.responses.models.CourseWithGroupsResponse;
import com.plannaplan.services.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
@ -35,7 +35,7 @@ public class GroupController {
@GetMapping("/course/{id}")
@ApiOperation(value = "Return list of lectures and classes (if present) given course")
public ResponseEntity<GetCourseGroupsResponse<? extends DefaultGroupResponse>> getCourses(
public ResponseEntity<CourseWithGroupsResponse<? extends GroupDefaultResponse>> getCourses(
@PathVariable(name = "id") Long id,
@RequestParam(name = "capacity", defaultValue = "true") @ApiParam(value = "Boolean if we want to have capacity field in response") Boolean capacity) {
List<Groups> groups = this.groupService.getGroupsByCourse(id);

View File

@ -5,7 +5,7 @@ import java.util.List;
import com.plannaplan.App;
import com.plannaplan.entities.User;
import com.plannaplan.responses.mappers.UserResponseMappers;
import com.plannaplan.responses.models.SearchForStudentsResponse;
import com.plannaplan.responses.models.UserResponse;
import com.plannaplan.services.UserService;
import org.springframework.beans.factory.annotation.Autowired;
@ -36,10 +36,10 @@ public class UsersController {
@GetMapping("/student/search")
@PreAuthorize("hasRole('ROLE_DEANERY')")
@ApiOperation(value = "Serch for user by providing query. If query is empty it will return all students. You need token with DEANERY role to call this")
public ResponseEntity<List<SearchForStudentsResponse>> configApp(
public ResponseEntity<List<UserResponse>> configApp(
@RequestParam("query") @ApiParam(value = "Query to filter all students. If empty will match everyone") String query) {
final List<User> searches = this.userService.searchForStudents(query);
final List<SearchForStudentsResponse> response = UserResponseMappers.mapToDefaultResponse(searches);
final List<UserResponse> response = UserResponseMappers.mapToDefaultResponse(searches);
return new ResponseEntity<>(response, HttpStatus.OK);
}
}

View File

@ -8,13 +8,13 @@ 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.responses.models.AssignmentResponse;
import com.plannaplan.types.GroupType;
public class AssignmentResponseMappers {
public static final List<GetCurrentAssignmentsResponse> mapToResponse(List<Assignment> assignments) {
List<GetCurrentAssignmentsResponse> response = new ArrayList<>();
public static final List<AssignmentResponse> mapToResponse(List<Assignment> assignments) {
List<AssignmentResponse> response = new ArrayList<>();
HashMap<Course, List<Groups>> courses = new HashMap<>();
assignments.stream().forEach((Assignment assignment) -> {
final Groups group = assignment.getGroup();
@ -29,14 +29,14 @@ public class AssignmentResponseMappers {
final Course course = entry.getKey();
final List<Groups> courseGroups = entry.getValue();
if (courseGroups.size() == 1) {
response.add(new GetCurrentAssignmentsResponse(course, courseGroups.get(0)));
response.add(new AssignmentResponse(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));
response.add(new AssignmentResponse(course, lecture, classes));
}
}

View File

@ -5,16 +5,16 @@ import java.util.Objects;
import java.util.stream.Collectors;
import com.plannaplan.entities.Course;
import com.plannaplan.responses.models.GetCoursesResponse;
import com.plannaplan.responses.models.GetCoursesWithGroupsResponse;
import com.plannaplan.responses.models.CoursesDefaultResponse;
import com.plannaplan.responses.models.CoursesWithGroupsResponse;
public class CoursesResponseMappers {
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<CoursesDefaultResponse> mapToGetCoursesResponse(List<Course> courses) {
return courses.stream().filter(Objects::nonNull).map(CoursesDefaultResponse::new).collect(Collectors.toList());
}
public static final List<GetCoursesWithGroupsResponse> mapToGetCoursesWithGroupsResponse(List<Course> courses) {
return courses.stream().filter(Objects::nonNull).map(GetCoursesWithGroupsResponse::new)
public static final List<CoursesWithGroupsResponse> mapToGetCoursesWithGroupsResponse(List<Course> courses) {
return courses.stream().filter(Objects::nonNull).map(CoursesWithGroupsResponse::new)
.collect(Collectors.toList());
}
}

View File

@ -6,53 +6,53 @@ import java.util.Objects;
import java.util.stream.Collectors;
import com.plannaplan.entities.Groups;
import com.plannaplan.responses.models.DefaultGroupResponse;
import com.plannaplan.responses.models.GetCourseGroupsResponse;
import com.plannaplan.responses.models.WithCapacityGroupResponse;
import com.plannaplan.responses.models.GroupDefaultResponse;
import com.plannaplan.responses.models.CourseWithGroupsResponse;
import com.plannaplan.responses.models.GroupWithCapacityResponse;
import com.plannaplan.types.GroupType;
public class GroupsMappers {
public static List<DefaultGroupResponse> mapToDefaultResponse(List<Groups> groups) {
return groups.stream().filter(Objects::nonNull).map(DefaultGroupResponse::new).collect(Collectors.toList());
public static List<GroupDefaultResponse> mapToDefaultResponse(List<Groups> groups) {
return groups.stream().filter(Objects::nonNull).map(GroupDefaultResponse::new).collect(Collectors.toList());
}
public static List<WithCapacityGroupResponse> mapToCapacityResponse(List<Groups> groups) {
return groups.stream().filter(Objects::nonNull).map(WithCapacityGroupResponse::new)
public static List<GroupWithCapacityResponse> mapToCapacityResponse(List<Groups> groups) {
return groups.stream().filter(Objects::nonNull).map(GroupWithCapacityResponse::new)
.collect(Collectors.toList());
}
public static GetCourseGroupsResponse<DefaultGroupResponse> mapToGetCourseGroupsDefaultResponse (List<Groups> groups){
public static CourseWithGroupsResponse<GroupDefaultResponse> mapToGetCourseGroupsDefaultResponse (List<Groups> groups){
List<DefaultGroupResponse> lectures = new ArrayList<>();
List<DefaultGroupResponse> classes = new ArrayList<>();
List<GroupDefaultResponse> lectures = new ArrayList<>();
List<GroupDefaultResponse> classes = new ArrayList<>();
groups.stream().forEach(group -> {
if (group.getType() == GroupType.CLASS) {
classes.add(new DefaultGroupResponse(group));
classes.add(new GroupDefaultResponse(group));
} else {
lectures.add(new DefaultGroupResponse(group));
lectures.add(new GroupDefaultResponse(group));
}
});
return new GetCourseGroupsResponse<>(classes, lectures);
return new CourseWithGroupsResponse<>(classes, lectures);
}
public static GetCourseGroupsResponse<WithCapacityGroupResponse> mapToGetCourseGroupsWithCapacityResponse (List<Groups> groups){
public static CourseWithGroupsResponse<GroupWithCapacityResponse> mapToGetCourseGroupsWithCapacityResponse (List<Groups> groups){
List<WithCapacityGroupResponse> lectures = new ArrayList<>();
List<WithCapacityGroupResponse> classes = new ArrayList<>();
List<GroupWithCapacityResponse> lectures = new ArrayList<>();
List<GroupWithCapacityResponse> classes = new ArrayList<>();
groups.stream().forEach(group -> {
if (group.getType() == GroupType.CLASS) {
classes.add(new WithCapacityGroupResponse(group));
classes.add(new GroupWithCapacityResponse(group));
} else {
lectures.add(new WithCapacityGroupResponse(group));
lectures.add(new GroupWithCapacityResponse(group));
}
});
return new GetCourseGroupsResponse<>(classes, lectures);
return new CourseWithGroupsResponse<>(classes, lectures);
}
}

View File

@ -5,11 +5,11 @@ import java.util.Objects;
import java.util.stream.Collectors;
import com.plannaplan.entities.User;
import com.plannaplan.responses.models.SearchForStudentsResponse;
import com.plannaplan.responses.models.UserResponse;
public class UserResponseMappers {
public static List<SearchForStudentsResponse> mapToDefaultResponse(List<User> groups) {
return groups.stream().filter(Objects::nonNull).map(SearchForStudentsResponse::new)
public static List<UserResponse> mapToDefaultResponse(List<User> groups) {
return groups.stream().filter(Objects::nonNull).map(UserResponse::new)
.collect(Collectors.toList());
}
}

View File

@ -6,30 +6,30 @@ import com.plannaplan.types.GroupType;
import io.swagger.annotations.ApiModel;
@ApiModel(description = "Response shows information about given assigment to course.", value = "GetCurrentAssignmentsResponse")
public class GetCurrentAssignmentsResponse {
@ApiModel(description = "Response shows information about given assigment to course.", value = "AssignmentResponse")
public class AssignmentResponse {
private Long id;
private String name;
private WithCapacityGroupResponse classes;
private WithCapacityGroupResponse lecture;
private GroupWithCapacityResponse classes;
private GroupWithCapacityResponse lecture;
public GetCurrentAssignmentsResponse(Course course, Groups lecture, Groups classes) {
public AssignmentResponse(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);
this.lecture = lecture == null ? null : new GroupWithCapacityResponse(lecture);
this.classes = classes == null ? null : new GroupWithCapacityResponse(classes);
}
public GetCurrentAssignmentsResponse(Course course, Groups group) {
public AssignmentResponse(Course course, Groups group) {
this(course, group.getType() == GroupType.LECTURE ? group : null,
group.getType() == GroupType.CLASS ? group : null);
}
public WithCapacityGroupResponse getLecture() {
public GroupWithCapacityResponse getLecture() {
return this.lecture;
}
public WithCapacityGroupResponse getClasses() {
public GroupWithCapacityResponse getClasses() {
return this.classes;
}

View File

@ -7,7 +7,7 @@ import com.plannaplan.entities.Commision;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@ApiModel(description = "Response shows information about commision", value = "CommisionResponse")
@ApiModel(description = "Response shows information about commision.", value = "CommisionResponse")
public class CommisionResponse {
@ApiModelProperty(value = "ID created by database")
private Long id;

View File

@ -5,13 +5,13 @@ import java.util.List;
import io.swagger.annotations.ApiModel;
@ApiModel(description = "Response shows information about groups to given course.", value = "DefaultGroupResponse")
public class GetCourseGroupsResponse <T> {
@ApiModel(description = "Response shows information about groups to given course.", value = "CourseWithGroupsResponse")
public class CourseWithGroupsResponse <T> {
private List<T> lectures = new ArrayList<>();
private List<T> classes = new ArrayList<>();
public GetCourseGroupsResponse(List<T> classes, List<T> lectures ){
public CourseWithGroupsResponse(List<T> classes, List<T> lectures ){
this.lectures = lectures;
this.classes = classes;
}

View File

@ -5,10 +5,10 @@ import com.plannaplan.responses.models.abstracts.CoursesResponse;
import io.swagger.annotations.ApiModel;
@ApiModel(description = "Response shows information about course.", value = "DefaultGroupResponse")
public class GetCoursesResponse extends CoursesResponse {
@ApiModel(description = "Response shows information about course.", value = "CoursesDefaultResponse")
public class CoursesDefaultResponse extends CoursesResponse {
public GetCoursesResponse(Course course) {
public CoursesDefaultResponse(Course course) {
super(course);
}

View File

@ -9,28 +9,28 @@ import com.plannaplan.types.GroupType;
import io.swagger.annotations.ApiModel;
@ApiModel(description = "Response shows information about groups to given course.", value = "GetCoursesWithGroupsResponse")
public class GetCoursesWithGroupsResponse extends CoursesResponse {
@ApiModel(description = "Response shows information about groups to given course.", value = "CoursesWithGroupsResponse")
public class CoursesWithGroupsResponse extends CoursesResponse {
private List<DefaultGroupResponse> lectures = new ArrayList<>();
private List<DefaultGroupResponse> classes = new ArrayList<>();
private List<GroupDefaultResponse> lectures = new ArrayList<>();
private List<GroupDefaultResponse> classes = new ArrayList<>();
public GetCoursesWithGroupsResponse(Course course) {
public CoursesWithGroupsResponse(Course course) {
super(course);
course.getGroups().stream().forEach(group -> {
if (group.getType() == GroupType.CLASS) {
this.classes.add(new DefaultGroupResponse(group));
this.classes.add(new GroupDefaultResponse(group));
} else {
this.lectures.add(new DefaultGroupResponse(group));
this.lectures.add(new GroupDefaultResponse(group));
}
});
}
public List<DefaultGroupResponse> getClasses() {
public List<GroupDefaultResponse> getClasses() {
return this.classes;
}
public List<DefaultGroupResponse> getLectures() {
public List<GroupDefaultResponse> getLectures() {
return this.lectures;
}

View File

@ -7,8 +7,8 @@ import com.plannaplan.types.GroupType;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@ApiModel(description = "Response shows information about given group", value = "DefaultGroupResponse")
public class DefaultGroupResponse {
@ApiModel(description = "Response shows information about given group.", value = "GroupDefaultResponse")
public class GroupDefaultResponse {
@ApiModelProperty(value = "ID created by database.")
private Long id;
@ -28,7 +28,7 @@ public class DefaultGroupResponse {
@ApiModelProperty(value = "Value shows kind of group. The types are LECTURE or CLASS.")
private GroupType type;
public DefaultGroupResponse(Groups group) {
public GroupDefaultResponse(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() : "";
@ -37,7 +37,7 @@ public class DefaultGroupResponse {
this.type = group.getType() != null ? group.getType() : null;
}
public DefaultGroupResponse(Assignment assignment) {
public GroupDefaultResponse(Assignment assignment) {
this(assignment.getGroup());
}

View File

@ -4,17 +4,17 @@ import com.plannaplan.entities.Assignment;
import com.plannaplan.entities.Groups;
import io.swagger.annotations.ApiModel;
@ApiModel(description = "Response shows information about group with included capacity.", value = "WithCapacityGroupResponse")
public class WithCapacityGroupResponse extends DefaultGroupResponse {
@ApiModel(description = "Response shows information about group with included capacity.", value = "GroupWithCapacityResponse")
public class GroupWithCapacityResponse extends GroupDefaultResponse {
private int capacity;
public WithCapacityGroupResponse(Groups group) {
public GroupWithCapacityResponse(Groups group) {
super(group);
this.capacity = group.getCapacity();
}
public WithCapacityGroupResponse(Assignment assignment) {
public GroupWithCapacityResponse(Assignment assignment) {
this(assignment.getGroup());
}

View File

@ -4,15 +4,15 @@ import com.plannaplan.entities.User;
import io.swagger.annotations.ApiModel;
@ApiModel(description = "Response shows information about user.", value = "SearchForStudentsResponse")
public class SearchForStudentsResponse {
@ApiModel(description = "Response shows information about user.", value = "UserResponse")
public class UserResponse {
private Long id;
private String name;
private String surname;
private String email;
public SearchForStudentsResponse(User user) {
public UserResponse(User user) {
this.id = user.getId();
this.name = user.getName();
this.surname = user.getSurname();