exchanges fixes + accepted in deanery response
This commit is contained in:
parent
08a4bdde06
commit
cf875889b9
@ -160,17 +160,22 @@ public class CommisionController extends TokenBasedController {
|
||||
@GetMapping("/user")
|
||||
@ApiOperation("Return list of user all commisions (history of schedules)")
|
||||
public ResponseEntity<List<? extends CommisionResponse>> 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<? extends CommisionResponse> result;
|
||||
|
||||
final List<Commision> 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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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<CommisionWithAcceptedGroupsResponse> mapToResponseWithExtraInforGroups(
|
||||
List<Commision> commisions) {
|
||||
return commisions.stream().filter(Objects::nonNull).map(CommisionWithAcceptedGroupsResponse::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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<AssignmentsSingleResponse> 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<Assignment, AssignmentsSingleResponse>() {
|
||||
|
||||
@Override
|
||||
public AssignmentsSingleResponse apply(Assignment arg0) {
|
||||
return new AssignmentsSingleResponse(arg0);
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return lsit of fetured groups informations
|
||||
*/
|
||||
public List<AssignmentsSingleResponse> getGroups() {
|
||||
return groups;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user