Correction of groups endpoint

This commit is contained in:
Filip Izydorczyk 2020-08-11 17:36:58 +02:00
parent 2e40e33545
commit e8ebcd3517
3 changed files with 31 additions and 2 deletions

View File

@ -30,6 +30,10 @@ public class Groups {
public Groups() {
}
public Long getId() {
return this.id;
}
public Lecturer getLecturer() {
return lecturer;
}

View File

@ -47,4 +47,9 @@ public class Lecturer {
public Lecturer() {
}
@Override
public String toString() {
return String.format("%s %s %s", this.title, this.name, this.surname);
}
}

View File

@ -1,5 +1,9 @@
package com.plannaplan.controllers;
import java.security.acl.Group;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.List;
import com.plannaplan.entities.Groups;
@ -20,7 +24,23 @@ public class GroupController {
private GroupService groupService;
@GetMapping("/getCourseGroups")
public ResponseEntity<List<Groups>> getCourses(@RequestParam("id") Long id) {
return new ResponseEntity<>(this.groupService.getGroupsByCourse(id), HttpStatus.OK);
public ResponseEntity<List<Dictionary<String, Object>>> getCourses(@RequestParam("id") Long id) {
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 + 1);
group.put("time", String.format("%o.%o", g.getTime() / 60, g.getTime() % 60));
group.put("lecturer", g.getLecturer().toString());
group.put("room", g.getRoom());
group.put("capacity", g.getCapacity());
group.put("type", g.getType());
response.add(group);
}
return new ResponseEntity<>(response, HttpStatus.OK);
}
}