2020-08-08 14:14:42 +02:00
|
|
|
package com.plannaplan.controllers;
|
|
|
|
|
2020-08-11 17:36:58 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Dictionary;
|
|
|
|
import java.util.Hashtable;
|
2020-08-08 14:14:42 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import com.plannaplan.entities.Groups;
|
|
|
|
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;
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@CrossOrigin
|
|
|
|
public class GroupController {
|
|
|
|
@Autowired
|
|
|
|
private GroupService groupService;
|
|
|
|
|
|
|
|
@GetMapping("/getCourseGroups")
|
2020-08-19 16:37:24 +02:00
|
|
|
public ResponseEntity<List<Dictionary<String, Object>>> 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);
|
|
|
|
List<Dictionary<String, Object>> response = new ArrayList<>();
|
|
|
|
|
2020-08-19 16:37:24 +02:00
|
|
|
|
2020-08-11 17:36:58 +02:00
|
|
|
for (Groups g : groups) {
|
|
|
|
Dictionary<String, Object> group = new Hashtable<>();
|
|
|
|
group.put("id", g.getId());
|
2020-08-19 16:38:25 +02:00
|
|
|
group.put("day", g.getDay().label);
|
2020-08-18 15:41:03 +02:00
|
|
|
group.put("time", g.getTimeString());
|
2020-08-11 17:36:58 +02:00
|
|
|
group.put("lecturer", g.getLecturer().toString());
|
|
|
|
group.put("room", g.getRoom());
|
2020-08-19 16:37:24 +02:00
|
|
|
if (capacity) {
|
|
|
|
group.put("capacity", g.getCapacity());
|
|
|
|
}
|
2020-08-11 17:36:58 +02:00
|
|
|
group.put("type", g.getType());
|
|
|
|
|
|
|
|
response.add(group);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new ResponseEntity<>(response, HttpStatus.OK);
|
2020-08-08 14:14:42 +02:00
|
|
|
}
|
|
|
|
}
|