From c62674b9d80601db443fc5cea92513bb1e725cfc Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Sun, 20 Dec 2020 12:14:12 +0100 Subject: [PATCH 1/2] 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; } From dfae6d7c782c4386d3270875e321dc79ef60afdd Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Sun, 20 Dec 2020 13:04:25 +0100 Subject: [PATCH 2/2] Added info about commiter to comision entity --- .../com/plannaplan/entities/Commision.java | 42 +++++++++++++++---- .../controllers/CommisionController.java | 2 +- .../responses/models/CommisionResponse.java | 17 ++++++++ 3 files changed, 53 insertions(+), 8 deletions(-) diff --git a/buisnesslogic/src/main/java/com/plannaplan/entities/Commision.java b/buisnesslogic/src/main/java/com/plannaplan/entities/Commision.java index 36e3585..7ebf890 100755 --- a/buisnesslogic/src/main/java/com/plannaplan/entities/Commision.java +++ b/buisnesslogic/src/main/java/com/plannaplan/entities/Commision.java @@ -13,7 +13,7 @@ import javax.persistence.OneToMany; import javax.persistence.OneToOne; /** - * Entity of Commision grouping of state associated about commison and owner_id + * Entity of Commision grouping of state associated about commison and owner_id */ @Entity @@ -24,6 +24,9 @@ public class Commision { @OneToOne @JoinColumn(name = "owner_id") private User commisionOwner; + @OneToOne + @JoinColumn(name = "commiter_id") + private User commisionCommiter; private Timestamp commisionDate; @OneToMany(mappedBy = "commision", fetch = FetchType.EAGER) @@ -37,37 +40,62 @@ public class Commision { public Commision(User user) { this.commisionDate = new Timestamp(System.currentTimeMillis()); this.commisionOwner = user; + this.commisionCommiter = user; + } + + /** + * + * @param user user whose shedule is being commited + * @param commiter user that commited new schedule + */ + public Commision(User user, User commiter) { + this(user); + this.commisionCommiter = commiter; } public Commision() { } /** - * Id getter - * @return id id of commision + * Id getter + * + * @return id id of commision */ public Long getId() { return this.id; } /** - * CommisionDate getter - * @return commisionDate + * CommisionDate getter + * + * @return commisionDate */ public Timestamp getCommisionDate() { return commisionDate; } /** - * User of given commision getter - * @return User commisionOwner + * User of given commision getter + * + * @return User commisionOwner */ public User getCommisionOwner() { return commisionOwner; } + /** + * @return User entity that created commision (can be owner or deanery user) + */ + public User getCommisionCommiter() { + if (commisionCommiter == null) { + return commisionOwner; + } + return commisionCommiter; + } + /** * Assigments getter + * * @return List of assignments */ public List getAssignments() { diff --git a/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java b/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java index 2388f12..2f1053a 100755 --- a/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java +++ b/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java @@ -82,7 +82,7 @@ public class CommisionController extends TokenBasedController { Assert.isTrue(!notExistingGroup.isPresent(), "Group " + notExistingGroup.orElse(Long.MIN_VALUE).toString() + "doesn't exist"); - final Commision com = new Commision(user); + final Commision com = new Commision(user, asker); this.commisionService.save(com); groups.stream().forEach((groupId) -> { diff --git a/restservice/src/main/java/com/plannaplan/responses/models/CommisionResponse.java b/restservice/src/main/java/com/plannaplan/responses/models/CommisionResponse.java index e995e27..9c91e1e 100755 --- a/restservice/src/main/java/com/plannaplan/responses/models/CommisionResponse.java +++ b/restservice/src/main/java/com/plannaplan/responses/models/CommisionResponse.java @@ -10,12 +10,29 @@ public class CommisionResponse { @ApiModelProperty(value = "ID created by database") private Long id; + @ApiModelProperty(value = "ID of user that commision belongs to") + private UserResponse owner; + + @ApiModelProperty(value = "ID of user that created commision") + private UserResponse commiter; + @ApiModelProperty(value = "Timestamp where the user commit the commision") private String commisionDate; public CommisionResponse(Commision commision) { this.id = commision.getId(); this.commisionDate = commision.getCommisionDate().toString(); + this.owner = commision.getCommisionOwner() != null ? new UserResponse(commision.getCommisionOwner()) : null; + this.commiter = commision.getCommisionCommiter() != null ? new UserResponse(commision.getCommisionCommiter()) + : null; + } + + public UserResponse getCommiter() { + return commiter; + } + + public UserResponse getOwner() { + return owner; } public String getCommisionDate() {