Added api endpoiunt mapper needs to be rewriteen

This commit is contained in:
BuildTools 2020-11-20 16:20:38 +01:00
parent b4bb13f2dd
commit 9d3500c1fb
3 changed files with 19 additions and 1 deletions

View File

@ -37,7 +37,8 @@ public class GroupController {
@ApiOperation(value = "Return list of lectures and classes (if present) given course") @ApiOperation(value = "Return list of lectures and classes (if present) given course")
public ResponseEntity<CourseWithGroupsResponse<? extends GroupDefaultResponse>> getCourses( public ResponseEntity<CourseWithGroupsResponse<? extends GroupDefaultResponse>> getCourses(
@PathVariable(name = "id") Long id, @PathVariable(name = "id") Long id,
@RequestParam(name = "capacity", defaultValue = "true") @ApiParam(value = "Boolean if we want to have capacity field in response") Boolean capacity) { @RequestParam(name = "capacity", defaultValue = "true") @ApiParam(value = "Boolean if we want to have capacity field in response") Boolean capacity,
@RequestParam(name = "takenPlaces", defaultValue = "false") @ApiParam(value = "Boolean if we want to have respoonse with information about taken places by other students") Boolean takenPlaces) {
List<Groups> groups = this.groupService.getGroupsByCourse(id); List<Groups> groups = this.groupService.getGroupsByCourse(id);
if (capacity) { if (capacity) {
return new ResponseEntity<>(GroupsMappers.mapToGetCourseGroupsWithCapacityResponse(groups), HttpStatus.OK); return new ResponseEntity<>(GroupsMappers.mapToGetCourseGroupsWithCapacityResponse(groups), HttpStatus.OK);

View File

@ -28,6 +28,9 @@ public class GroupDefaultResponse {
@ApiModelProperty(value = "Value shows kind of group. The types are LECTURE or CLASS.") @ApiModelProperty(value = "Value shows kind of group. The types are LECTURE or CLASS.")
private GroupType type; private GroupType type;
@ApiModelProperty(value = "Value shows how many places is already taken by other students.")
private int takenPlaces;
public GroupDefaultResponse(Groups group) { public GroupDefaultResponse(Groups group) {
this.id = group.getId() != null ? group.getId() : null; this.id = group.getId() != null ? group.getId() : null;
this.day = group.getDay() != null ? group.getDay().label : -1; this.day = group.getDay() != null ? group.getDay().label : -1;
@ -37,6 +40,11 @@ public class GroupDefaultResponse {
this.type = group.getType() != null ? group.getType() : null; this.type = group.getType() != null ? group.getType() : null;
} }
public GroupDefaultResponse(Groups group, int takenPlaces) {
this(group);
this.takenPlaces = takenPlaces;
}
public GroupDefaultResponse(Assignment assignment) { public GroupDefaultResponse(Assignment assignment) {
this(assignment.getGroup()); this(assignment.getGroup());
} }
@ -65,4 +73,8 @@ public class GroupDefaultResponse {
return id; return id;
} }
public int getTakenPlaces() {
return this.takenPlaces;
}
} }

View File

@ -14,6 +14,11 @@ public class GroupWithCapacityResponse extends GroupDefaultResponse {
this.capacity = group.getCapacity(); this.capacity = group.getCapacity();
} }
public GroupWithCapacityResponse(Groups group, int takenPlaces) {
super(group, takenPlaces);
this.capacity = group.getCapacity();
}
public GroupWithCapacityResponse(Assignment assignment) { public GroupWithCapacityResponse(Assignment assignment) {
this(assignment.getGroup()); this(assignment.getGroup());
} }