backend/restservice/src/main/java/com/plannaplan/controllers/GroupController.java

39 lines
1.6 KiB
Java
Raw Normal View History

2020-08-08 14:14:42 +02:00
package com.plannaplan.controllers;
import java.util.List;
2020-09-15 11:31:30 +02:00
import com.plannaplan.App;
2020-08-08 14:14:42 +02:00
import com.plannaplan.entities.Groups;
import com.plannaplan.responses.mappers.GroupsMappers;
import com.plannaplan.responses.models.DefaultGroupResponse;
import com.plannaplan.responses.models.WithCapacityGroupResponse;
2020-08-08 14:14:42 +02:00
import com.plannaplan.services.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
2020-09-15 11:31:30 +02:00
import org.springframework.web.bind.annotation.RequestMapping;
2020-08-08 14:14:42 +02:00
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.vavr.control.Either;
2020-08-08 14:14:42 +02:00
@RestController
@CrossOrigin
2020-09-15 11:31:30 +02:00
@RequestMapping("/api/" + App.API_VERSION + "/groups")
2020-08-08 14:14:42 +02:00
public class GroupController {
@Autowired
private GroupService groupService;
@GetMapping("/getCourseGroups")
public ResponseEntity<Either<List<WithCapacityGroupResponse>, List<DefaultGroupResponse>>> getCourses(
@RequestParam("id") Long id, @RequestParam(name = "capacity", defaultValue = "true") Boolean capacity) {
2020-08-11 17:36:58 +02:00
List<Groups> groups = this.groupService.getGroupsByCourse(id);
if (capacity) {
return new ResponseEntity<>(Either.left(GroupsMappers.mapToCapacityResponse(groups)), HttpStatus.OK);
2020-08-11 17:36:58 +02:00
}
return new ResponseEntity<>(Either.right(GroupsMappers.mapToDefaultResponse(groups)), HttpStatus.OK);
2020-08-08 14:14:42 +02:00
}
}