From 9d97306e5c441a504d1aaec0ef63a92593b6fb54 Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Thu, 8 Oct 2020 15:57:42 +0200 Subject: [PATCH] Added Assignment Response Model --- .../controllers/TokenController.java | 2 +- .../responses/models/AssignmentResponse.java | 54 +++++++++++++++++++ .../models/AssignmentResponseTest.java | 28 ++++++++++ 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100755 restservice/src/main/java/com/plannaplan/responses/models/AssignmentResponse.java create mode 100755 restservice/src/test/java/com/plannaplan/responses/models/AssignmentResponseTest.java diff --git a/restservice/src/main/java/com/plannaplan/controllers/TokenController.java b/restservice/src/main/java/com/plannaplan/controllers/TokenController.java index fc3fdd9..5093783 100755 --- a/restservice/src/main/java/com/plannaplan/controllers/TokenController.java +++ b/restservice/src/main/java/com/plannaplan/controllers/TokenController.java @@ -17,7 +17,7 @@ import org.springframework.web.bind.annotation.RestController; @CrossOrigin public class TokenController { - public static String SERVICE_URL = "http://localhost:3000"; + private final static String SERVICE_URL = "http://localhost:3000"; @Autowired private UserService userService; diff --git a/restservice/src/main/java/com/plannaplan/responses/models/AssignmentResponse.java b/restservice/src/main/java/com/plannaplan/responses/models/AssignmentResponse.java new file mode 100755 index 0000000..82dee10 --- /dev/null +++ b/restservice/src/main/java/com/plannaplan/responses/models/AssignmentResponse.java @@ -0,0 +1,54 @@ +package com.plannaplan.responses.models; + +import com.plannaplan.entities.Groups; +import com.plannaplan.types.GroupType; + +public class AssignmentResponse { + + private Long id; + private int day; + private String time; + private String lecturer; + private String room; + private int capacity; + private GroupType type; + + public AssignmentResponse(Groups group) { + this.id = group.getId(); + this.day = group.getDay().label; + this.time = group.getTimeString(); + this.lecturer = group.getLecturer().toString(); + this.room = group.getRoom(); + this.capacity = group.getCapacity(); + this.type = group.getType(); + } + + public GroupType getType() { + return type; + } + + public int getCapacity() { + return capacity; + } + + public String getRoom() { + return room; + } + + public String getLecturer() { + return lecturer; + } + + public String getTime() { + return time; + } + + public int getDay() { + return day; + } + + public Long getId() { + return id; + } + +} diff --git a/restservice/src/test/java/com/plannaplan/responses/models/AssignmentResponseTest.java b/restservice/src/test/java/com/plannaplan/responses/models/AssignmentResponseTest.java new file mode 100755 index 0000000..c69311b --- /dev/null +++ b/restservice/src/test/java/com/plannaplan/responses/models/AssignmentResponseTest.java @@ -0,0 +1,28 @@ +package com.plannaplan.responses.models; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.plannaplan.entities.Groups; +import com.plannaplan.entities.Lecturer; +import com.plannaplan.types.GroupType; +import com.plannaplan.types.WeekDay; + +import org.junit.Test; + +public class AssignmentResponseTest { + + @Test + public void shouldMapGroupClassToResponse() { + final Groups group = new Groups(42, "A4-1", null, 520, WeekDay.MONDAY, + new Lecturer("krul.", "Wladyslaw", "Potocki")); + + final AssignmentResponse response = new AssignmentResponse(group); + assertTrue(response.getCapacity() == 42); + assertTrue(response.getDay() == 0); + assertTrue(response.getLecturer().equals("krul. Wladyslaw Potocki")); + assertTrue(response.getRoom().equals("A4-1")); + assertTrue(response.getTime().equals("8.40")); + assertTrue(response.getType() == GroupType.CLASS); + } + +}