From c62674b9d80601db443fc5cea92513bb1e725cfc Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Sun, 20 Dec 2020 12:14:12 +0100 Subject: [PATCH] Added time to in group resonse --- .../java/com/plannaplan/entities/Groups.java | 72 +++++++++++++++++-- .../models/GroupDefaultResponse.java | 8 +++ 2 files changed, 74 insertions(+), 6 deletions(-) diff --git a/buisnesslogic/src/main/java/com/plannaplan/entities/Groups.java b/buisnesslogic/src/main/java/com/plannaplan/entities/Groups.java index 36aaa84..3aecce0 100755 --- a/buisnesslogic/src/main/java/com/plannaplan/entities/Groups.java +++ b/buisnesslogic/src/main/java/com/plannaplan/entities/Groups.java @@ -11,11 +11,14 @@ import com.plannaplan.types.GroupType; import com.plannaplan.types.WeekDay; /** - * Entity of Groups grouping of state ssociated about course,time,room,capacity,type,day + * Entity of Groups grouping of state ssociated about + * course,time,room,capacity,type,day */ @Entity public class Groups { + private static final int DEFAULT_CLASS_TIME = 90; + @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @@ -23,6 +26,7 @@ public class Groups { @JoinColumn(name = "course_id") private Course course; private int time; + private int endTime; private String room; private int capacity; private GroupType type; @@ -38,24 +42,50 @@ public class Groups { * Groups * * @param capacity capacity given to the groups - * @param room room given to the groups - * @param course course given to the groups - * @param time time given to the groups - * @param day day given to the groups + * @param room room given to the groups + * @param course course given to the groups + * @param time time given to the groups + * @param endTime end time of class in minutes + * @param day day given to the groups * @param lecturer lecturer given to the groups */ - public Groups(int capacity, String room, Course course, int time, WeekDay day, Lecturer lecturer) { + public Groups(int capacity, String room, Course course, int time, int endTime, WeekDay day, Lecturer lecturer) { this.capacity = capacity; this.room = room; this.course = course; this.time = time; + this.endTime = endTime; this.day = day; this.lecturer = lecturer; this.type = capacity >= 50 ? GroupType.LECTURE : GroupType.CLASS; } + /** + * Create groups with default class duration + * + * @param capacity capacity given to the groups + * @param room room given to the groups + * @param course course given to the groups + * @param time time given to the groups + * @param day day given to the groups + * @param lecturer lecturer given to the groups + */ + public Groups(int capacity, String room, Course course, int time, WeekDay day, Lecturer lecturer) { + this(capacity, room, course, time, time + DEFAULT_CLASS_TIME, day, lecturer); + } + + /** + * get time of class end + * + * @return hour of class finish time in minutes + */ + public int getEndTime() { + return endTime; + } + /** * getId + * * @return id */ public Long getId() { @@ -64,6 +94,7 @@ public class Groups { /** * getLecturer + * * @return lecturer */ public Lecturer getLecturer() { @@ -72,6 +103,7 @@ public class Groups { /** * setLecturer + * * @param lecturer set lecturer into groups */ public void setLecturer(Lecturer lecturer) { @@ -80,6 +112,7 @@ public class Groups { /** * WeekDay + * * @return day */ public WeekDay getDay() { @@ -88,6 +121,7 @@ public class Groups { /** * setLecturer + * * @param day set day into groups */ public void setDay(WeekDay day) { @@ -96,6 +130,7 @@ public class Groups { /** * GroupType + * * @return type */ public GroupType getType() { @@ -104,6 +139,7 @@ public class Groups { /** * setType + * * @param type set type into groups */ public void setType(GroupType type) { @@ -112,6 +148,7 @@ public class Groups { /** * getCapacity + * * @return capacity */ public int getCapacity() { @@ -120,6 +157,7 @@ public class Groups { /** * setCapacity + * * @param capacity set capacity into groups */ public void setCapacity(int capacity) { @@ -128,6 +166,7 @@ public class Groups { /** * getRoom + * * @return room */ public String getRoom() { @@ -136,6 +175,7 @@ public class Groups { /** * setRoom + * * @param room set room into groups */ public void setRoom(String room) { @@ -144,6 +184,7 @@ public class Groups { /** * getTime + * * @return time */ public int getTime() { @@ -152,6 +193,7 @@ public class Groups { /** * setTime + * * @param time set time into groups */ public void setTime(int time) { @@ -160,6 +202,7 @@ public class Groups { /** * getCourseId + * * @return course */ public Course getCourseId() { @@ -168,6 +211,7 @@ public class Groups { /** * setCourseId + * * @param courseId set courseId into groups */ public void setCourseId(Course courseId) { @@ -176,6 +220,7 @@ public class Groups { /** * getTimeString + * * @return time as formated String */ public String getTimeString() { @@ -187,4 +232,19 @@ public class Groups { } return String.format("%s.%s", hoursString, minutesString); } + + /** + * gets end time formated strins + * + * @return end time as formated String + */ + public String getEndTimeString() { + int minutes = this.getEndTime() % 60; + String hoursString = Integer.toString(this.getEndTime() / 60); + String minutesString = Integer.toString(minutes); + if (minutes < 10) { + minutesString = "0" + minutesString; + } + return String.format("%s.%s", hoursString, minutesString); + } } diff --git a/restservice/src/main/java/com/plannaplan/responses/models/GroupDefaultResponse.java b/restservice/src/main/java/com/plannaplan/responses/models/GroupDefaultResponse.java index c182343..2a16b91 100755 --- a/restservice/src/main/java/com/plannaplan/responses/models/GroupDefaultResponse.java +++ b/restservice/src/main/java/com/plannaplan/responses/models/GroupDefaultResponse.java @@ -21,6 +21,9 @@ public class GroupDefaultResponse { @ApiModelProperty(value = "Value shows time when the course takes.") private String time; + @ApiModelProperty(value = "Value shows time when the course ends.") + private String endTime; + @ApiModelProperty(value = "Value shows degree, name and surname.") private String lecturer; @@ -37,6 +40,7 @@ public class GroupDefaultResponse { this.id = group.getId() != null ? group.getId() : null; this.day = group.getDay() != null ? group.getDay().label : -1; this.time = group.getTimeString() != null ? group.getTimeString() : ""; + this.endTime = group.getEndTimeString() != null ? group.getEndTimeString() : ""; this.lecturer = group.getLecturer() != null ? group.getLecturer().toString() : ""; this.room = group.getRoom() != null ? group.getRoom() : ""; this.type = group.getType() != null ? group.getType() : null; @@ -67,6 +71,10 @@ public class GroupDefaultResponse { return time; } + public String getEndTime() { + return endTime; + } + public int getDay() { return day; }