package com.plannaplan.controllers; import java.util.ArrayList; import java.util.Dictionary; import java.util.Hashtable; 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") public ResponseEntity>> getCourses(@RequestParam("id") Long id, @RequestParam(name="capacity", defaultValue="true") Boolean capacity){ List groups = this.groupService.getGroupsByCourse(id); List> response = new ArrayList<>(); for (Groups g : groups) { Dictionary group = new Hashtable<>(); group.put("id", g.getId()); group.put("day", g.getDay().label + 1); 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); } return new ResponseEntity<>(response, HttpStatus.OK); } }