Checkpoint - group controller needs to be fixed
This commit is contained in:
@ -1,12 +1,12 @@
|
||||
package com.plannaplan.controllers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Dictionary;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
|
||||
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,6 +18,8 @@ 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")
|
||||
@ -26,26 +28,12 @@ public class GroupController {
|
||||
private GroupService groupService;
|
||||
|
||||
@GetMapping("/getCourseGroups")
|
||||
public ResponseEntity<List<Dictionary<String, Object>>> getCourses(@RequestParam("id") Long id,
|
||||
@RequestParam(name = "capacity", defaultValue = "true") Boolean capacity) {
|
||||
public ResponseEntity<Either<List<WithCapacityGroupResponse>, List<DefaultGroupResponse>>> getCourses(
|
||||
@RequestParam("id") Long id, @RequestParam(name = "capacity", defaultValue = "true") Boolean capacity) {
|
||||
List<Groups> groups = this.groupService.getGroupsByCourse(id);
|
||||
List<Dictionary<String, Object>> response = new ArrayList<>();
|
||||
|
||||
for (Groups g : groups) {
|
||||
Dictionary<String, Object> group = new Hashtable<>();
|
||||
group.put("id", g.getId());
|
||||
group.put("day", g.getDay().label);
|
||||
group.put("time", g.getTimeString());
|
||||
group.put("lecturer", g.getLecturer().toString());
|
||||
group.put("room", g.getRoom());
|
||||
if (capacity) {
|
||||
group.put("capacity", g.getCapacity());
|
||||
}
|
||||
group.put("type", g.getType());
|
||||
|
||||
response.add(group);
|
||||
if (capacity) {
|
||||
return new ResponseEntity<>(Either.left(GroupsMappers.mapToCapacityResponse(groups)), HttpStatus.OK);
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
return new ResponseEntity<>(Either.right(GroupsMappers.mapToDefaultResponse(groups)), HttpStatus.OK);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user