From cf875889b9fda5871e32b8f8fdc00648cc27d48f Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Wed, 20 Jan 2021 14:36:09 +0100 Subject: [PATCH] exchanges fixes + accepted in deanery response --- .../controllers/CommisionController.java | 13 ++++-- .../controllers/ExchangeController.java | 6 ++- .../mappers/CommisionResponseMappers.java | 11 +++++ .../models/AssignmentDetailedResponse.java | 7 +-- .../models/AssignmentsSingleResponse.java | 34 +++++++++++++++ .../CommisionWithAcceptedGroupsResponse.java | 43 +++++++++++++++++++ 6 files changed, 105 insertions(+), 9 deletions(-) create mode 100755 restservice/src/main/java/com/plannaplan/responses/models/AssignmentsSingleResponse.java create mode 100755 restservice/src/main/java/com/plannaplan/responses/models/CommisionWithAcceptedGroupsResponse.java diff --git a/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java b/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java index 1d9a7cd..b96da7b 100755 --- a/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java +++ b/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java @@ -160,17 +160,22 @@ public class CommisionController extends TokenBasedController { @GetMapping("/user") @ApiOperation("Return list of user all commisions (history of schedules)") public ResponseEntity> getAlCommisions( - @RequestParam(name = "groups", defaultValue = "false") @ApiParam(value = "Boolean if we want to display wiht commision's group ids") Boolean groups) + @RequestParam(name = "groups", defaultValue = "false") @ApiParam(value = "Boolean if we want to display wiht commision's group ids") Boolean groups, + @RequestParam(name = "extraInfo", defaultValue = "false") @ApiParam(value = "Boolean if we want to display extra info about listed groups. Works only if we have groups set top true") Boolean extraInfo) throws UserNotFoundException { User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException()); List result; + final List commisions = this.commisionService.getUsersCommisions(user); if (!groups) { - result = CommisionResponseMappers.mapToResponse(this.commisionService.getUsersCommisions(user)); + result = CommisionResponseMappers.mapToResponse(commisions); } else { - result = CommisionResponseMappers - .mapToResponseWithGroups(this.commisionService.getUsersCommisions(user)); + if (extraInfo) { + result = CommisionResponseMappers.mapToResponseWithExtraInforGroups(commisions); + } else { + result = CommisionResponseMappers.mapToResponseWithGroups(commisions); + } } return new ResponseEntity<>(result, HttpStatus.OK); diff --git a/restservice/src/main/java/com/plannaplan/controllers/ExchangeController.java b/restservice/src/main/java/com/plannaplan/controllers/ExchangeController.java index d063e0b..9b2edce 100755 --- a/restservice/src/main/java/com/plannaplan/controllers/ExchangeController.java +++ b/restservice/src/main/java/com/plannaplan/controllers/ExchangeController.java @@ -16,6 +16,7 @@ import com.plannaplan.responses.models.ExchangeResponse; import com.plannaplan.services.AssignmentService; import com.plannaplan.services.ExchangeService; import com.plannaplan.services.GroupService; +import com.plannaplan.types.GroupType; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -89,13 +90,14 @@ public class ExchangeController extends TokenBasedController { final Groups groupInstance = group.get(); if (assignmentInstance.getGroup().getCourseId() != null - && ! assignmentInstance.getGroup().getCourseId().getId().equals(groupInstance.getCourseId().getId())) { + && !assignmentInstance.getGroup().getCourseId().getId().equals(groupInstance.getCourseId().getId())) { System.out.println(assignmentInstance.getGroup().getCourseId().getId()); System.out.println(groupInstance.getCourseId().getId()); return new ResponseEntity<>("You can performe exchange only within one course.", HttpStatus.BAD_REQUEST); } - if (assignmentInstance.getGroup().getType() != groupInstance.getType()) { + if (GroupType.isLectureOrClass(assignmentInstance.getGroup().getType()) != GroupType + .isLectureOrClass(groupInstance.getType())) { return new ResponseEntity<>("You can't exchange lecture to class and otherwise.", HttpStatus.BAD_REQUEST); } diff --git a/restservice/src/main/java/com/plannaplan/responses/mappers/CommisionResponseMappers.java b/restservice/src/main/java/com/plannaplan/responses/mappers/CommisionResponseMappers.java index 1962a4f..9c8ce6e 100755 --- a/restservice/src/main/java/com/plannaplan/responses/mappers/CommisionResponseMappers.java +++ b/restservice/src/main/java/com/plannaplan/responses/mappers/CommisionResponseMappers.java @@ -6,6 +6,7 @@ import java.util.stream.Collectors; import com.plannaplan.entities.Commision; import com.plannaplan.responses.models.CommisionResponse; +import com.plannaplan.responses.models.CommisionWithAcceptedGroupsResponse; import com.plannaplan.responses.models.CommisionWithGroupsResponse; /** @@ -28,4 +29,14 @@ public class CommisionResponseMappers { return commisions.stream().filter(Objects::nonNull).map(CommisionWithGroupsResponse::new) .collect(Collectors.toList()); } + + /** + * @param commisions list of commisions to be mapped + * @return list of api responses + */ + public static final List mapToResponseWithExtraInforGroups( + List commisions) { + return commisions.stream().filter(Objects::nonNull).map(CommisionWithAcceptedGroupsResponse::new) + .collect(Collectors.toList()); + } } diff --git a/restservice/src/main/java/com/plannaplan/responses/models/AssignmentDetailedResponse.java b/restservice/src/main/java/com/plannaplan/responses/models/AssignmentDetailedResponse.java index bbb2490..7328495 100755 --- a/restservice/src/main/java/com/plannaplan/responses/models/AssignmentDetailedResponse.java +++ b/restservice/src/main/java/com/plannaplan/responses/models/AssignmentDetailedResponse.java @@ -2,6 +2,7 @@ package com.plannaplan.responses.models; import com.plannaplan.entities.Assignment; import com.plannaplan.entities.Groups; +import com.plannaplan.types.GroupType; /** * Assignment detailed response for api @@ -25,15 +26,15 @@ public class AssignmentDetailedResponse { this.day = group.getDay().label; this.time = group.getTimeString(); this.endTime = group.getEndTimeString(); - this.lecturer = group.getLecturer().toString(); - this.type = group.getType().toString(); + this.lecturer = group.getLecturer().toString(); + this.type = GroupType.isLectureOrClass(group.getType()).toString(); } /** * @return type of the lecture */ public String getType() { - return type; + return type; } /** diff --git a/restservice/src/main/java/com/plannaplan/responses/models/AssignmentsSingleResponse.java b/restservice/src/main/java/com/plannaplan/responses/models/AssignmentsSingleResponse.java new file mode 100755 index 0000000..1699f05 --- /dev/null +++ b/restservice/src/main/java/com/plannaplan/responses/models/AssignmentsSingleResponse.java @@ -0,0 +1,34 @@ +package com.plannaplan.responses.models; + +import com.plannaplan.entities.Assignment; + +/** + * Repsonse for single assignment to use in commision repsonse + */ +public class AssignmentsSingleResponse { + private Long id; + private boolean isAccepted; + + /** + * @param assignment to map to response + */ + public AssignmentsSingleResponse(Assignment assignment) { + this.id = assignment.getGroup().getId(); + this.isAccepted = assignment.isAccepted(); + } + + /** + * @return id of assigned group + */ + public Long getId() { + return id; + } + + /** + * @return is group already accepted or not + */ + public boolean isAccepted() { + return isAccepted; + } + +} diff --git a/restservice/src/main/java/com/plannaplan/responses/models/CommisionWithAcceptedGroupsResponse.java b/restservice/src/main/java/com/plannaplan/responses/models/CommisionWithAcceptedGroupsResponse.java new file mode 100755 index 0000000..f0450a1 --- /dev/null +++ b/restservice/src/main/java/com/plannaplan/responses/models/CommisionWithAcceptedGroupsResponse.java @@ -0,0 +1,43 @@ +package com.plannaplan.responses.models; + +import java.util.List; +import java.util.Objects; +import java.util.function.Function; +import java.util.stream.Collectors; + +import com.plannaplan.entities.Assignment; +import com.plannaplan.entities.Commision; + +import io.swagger.annotations.ApiModel; + +/** + * Commision With Groups api Response. It extends CommisionResponse repsone + */ +@ApiModel(description = "Response shows information about commision and its groups. It also has info about group state (is accepted or not)", value = "CommisionWithGroupsResponse") +public class CommisionWithAcceptedGroupsResponse extends CommisionResponse { + + private List groups; + + /** + * @param commision commision to map to api response + */ + public CommisionWithAcceptedGroupsResponse(Commision commision) { + super(commision); + this.groups = commision.getAssignments().stream().filter(Objects::nonNull) + .map(new Function() { + + @Override + public AssignmentsSingleResponse apply(Assignment arg0) { + return new AssignmentsSingleResponse(arg0); + } + }).collect(Collectors.toList()); + } + + /** + * @return lsit of fetured groups informations + */ + public List getGroups() { + return groups; + } + +}