groups by course fix

This commit is contained in:
Filip Izydorczyk 2020-10-15 16:56:31 +02:00
parent 3e8bfe85d6
commit cb60b17389

View File

@ -6,7 +6,6 @@ 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.WithCapacityGroupResponse;
import com.plannaplan.services.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
@ -18,8 +17,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.vavr.control.Either;
@RestController
@CrossOrigin
@RequestMapping("/api/" + App.API_VERSION + "/groups")
@ -28,12 +25,12 @@ public class GroupController {
private GroupService groupService;
@GetMapping("/getCourseGroups")
public ResponseEntity<Either<List<WithCapacityGroupResponse>, List<DefaultGroupResponse>>> getCourses(
@RequestParam("id") Long id, @RequestParam(name = "capacity", defaultValue = "true") Boolean capacity) {
public ResponseEntity<List<? extends DefaultGroupResponse>> getCourses(@RequestParam("id") Long id,
@RequestParam(name = "capacity", defaultValue = "true") Boolean capacity) {
List<Groups> groups = this.groupService.getGroupsByCourse(id);
if (capacity) {
return new ResponseEntity<>(Either.left(GroupsMappers.mapToCapacityResponse(groups)), HttpStatus.OK);
return new ResponseEntity<>(GroupsMappers.mapToCapacityResponse(groups), HttpStatus.OK);
}
return new ResponseEntity<>(Either.right(GroupsMappers.mapToDefaultResponse(groups)), HttpStatus.OK);
return new ResponseEntity<>(GroupsMappers.mapToDefaultResponse(groups), HttpStatus.OK);
}
}