Merge pull request 'timeto-owner' (#33) from timeto-owner into master

Reviewed-on: http://git.plannaplan.pl/filipizydorczyk/backend/pulls/33
This commit is contained in:
Marcin Woźniak 2020-12-20 15:15:03 +01:00
commit 0d6ad184bc
5 changed files with 127 additions and 14 deletions

View File

@ -13,7 +13,7 @@ import javax.persistence.OneToMany;
import javax.persistence.OneToOne; 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 @Entity
@ -24,6 +24,9 @@ public class Commision {
@OneToOne @OneToOne
@JoinColumn(name = "owner_id") @JoinColumn(name = "owner_id")
private User commisionOwner; private User commisionOwner;
@OneToOne
@JoinColumn(name = "commiter_id")
private User commisionCommiter;
private Timestamp commisionDate; private Timestamp commisionDate;
@OneToMany(mappedBy = "commision", fetch = FetchType.EAGER) @OneToMany(mappedBy = "commision", fetch = FetchType.EAGER)
@ -37,37 +40,62 @@ public class Commision {
public Commision(User user) { public Commision(User user) {
this.commisionDate = new Timestamp(System.currentTimeMillis()); this.commisionDate = new Timestamp(System.currentTimeMillis());
this.commisionOwner = user; 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() { public Commision() {
} }
/** /**
* Id getter * Id getter
* @return id id of commision *
* @return id id of commision
*/ */
public Long getId() { public Long getId() {
return this.id; return this.id;
} }
/** /**
* CommisionDate getter * CommisionDate getter
* @return commisionDate *
* @return commisionDate
*/ */
public Timestamp getCommisionDate() { public Timestamp getCommisionDate() {
return commisionDate; return commisionDate;
} }
/** /**
* User of given commision getter * User of given commision getter
* @return User commisionOwner *
* @return User commisionOwner
*/ */
public User getCommisionOwner() { public User getCommisionOwner() {
return commisionOwner; 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 * Assigments getter
*
* @return List of assignments * @return List of assignments
*/ */
public List<Assignment> getAssignments() { public List<Assignment> getAssignments() {

View File

@ -11,11 +11,14 @@ import com.plannaplan.types.GroupType;
import com.plannaplan.types.WeekDay; 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 @Entity
public class Groups { public class Groups {
private static final int DEFAULT_CLASS_TIME = 90;
@Id @Id
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO)
private Long id; private Long id;
@ -23,6 +26,7 @@ public class Groups {
@JoinColumn(name = "course_id") @JoinColumn(name = "course_id")
private Course course; private Course course;
private int time; private int time;
private int endTime;
private String room; private String room;
private int capacity; private int capacity;
private GroupType type; private GroupType type;
@ -38,24 +42,50 @@ public class Groups {
* Groups * Groups
* *
* @param capacity capacity given to the groups * @param capacity capacity given to the groups
* @param room room given to the groups * @param room room given to the groups
* @param course course given to the groups * @param course course given to the groups
* @param time time given to the groups * @param time time given to the groups
* @param day day 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 * @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.capacity = capacity;
this.room = room; this.room = room;
this.course = course; this.course = course;
this.time = time; this.time = time;
this.endTime = endTime;
this.day = day; this.day = day;
this.lecturer = lecturer; this.lecturer = lecturer;
this.type = capacity >= 50 ? GroupType.LECTURE : GroupType.CLASS; 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 * getId
*
* @return id * @return id
*/ */
public Long getId() { public Long getId() {
@ -64,6 +94,7 @@ public class Groups {
/** /**
* getLecturer * getLecturer
*
* @return lecturer * @return lecturer
*/ */
public Lecturer getLecturer() { public Lecturer getLecturer() {
@ -72,6 +103,7 @@ public class Groups {
/** /**
* setLecturer * setLecturer
*
* @param lecturer set lecturer into groups * @param lecturer set lecturer into groups
*/ */
public void setLecturer(Lecturer lecturer) { public void setLecturer(Lecturer lecturer) {
@ -80,6 +112,7 @@ public class Groups {
/** /**
* WeekDay * WeekDay
*
* @return day * @return day
*/ */
public WeekDay getDay() { public WeekDay getDay() {
@ -88,6 +121,7 @@ public class Groups {
/** /**
* setLecturer * setLecturer
*
* @param day set day into groups * @param day set day into groups
*/ */
public void setDay(WeekDay day) { public void setDay(WeekDay day) {
@ -96,6 +130,7 @@ public class Groups {
/** /**
* GroupType * GroupType
*
* @return type * @return type
*/ */
public GroupType getType() { public GroupType getType() {
@ -104,6 +139,7 @@ public class Groups {
/** /**
* setType * setType
*
* @param type set type into groups * @param type set type into groups
*/ */
public void setType(GroupType type) { public void setType(GroupType type) {
@ -112,6 +148,7 @@ public class Groups {
/** /**
* getCapacity * getCapacity
*
* @return capacity * @return capacity
*/ */
public int getCapacity() { public int getCapacity() {
@ -120,6 +157,7 @@ public class Groups {
/** /**
* setCapacity * setCapacity
*
* @param capacity set capacity into groups * @param capacity set capacity into groups
*/ */
public void setCapacity(int capacity) { public void setCapacity(int capacity) {
@ -128,6 +166,7 @@ public class Groups {
/** /**
* getRoom * getRoom
*
* @return room * @return room
*/ */
public String getRoom() { public String getRoom() {
@ -136,6 +175,7 @@ public class Groups {
/** /**
* setRoom * setRoom
*
* @param room set room into groups * @param room set room into groups
*/ */
public void setRoom(String room) { public void setRoom(String room) {
@ -144,6 +184,7 @@ public class Groups {
/** /**
* getTime * getTime
*
* @return time * @return time
*/ */
public int getTime() { public int getTime() {
@ -152,6 +193,7 @@ public class Groups {
/** /**
* setTime * setTime
*
* @param time set time into groups * @param time set time into groups
*/ */
public void setTime(int time) { public void setTime(int time) {
@ -160,6 +202,7 @@ public class Groups {
/** /**
* getCourseId * getCourseId
*
* @return course * @return course
*/ */
public Course getCourseId() { public Course getCourseId() {
@ -168,6 +211,7 @@ public class Groups {
/** /**
* setCourseId * setCourseId
*
* @param courseId set courseId into groups * @param courseId set courseId into groups
*/ */
public void setCourseId(Course courseId) { public void setCourseId(Course courseId) {
@ -176,6 +220,7 @@ public class Groups {
/** /**
* getTimeString * getTimeString
*
* @return time as formated String * @return time as formated String
*/ */
public String getTimeString() { public String getTimeString() {
@ -187,4 +232,19 @@ public class Groups {
} }
return String.format("%s.%s", hoursString, minutesString); 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);
}
} }

View File

@ -82,7 +82,7 @@ public class CommisionController extends TokenBasedController {
Assert.isTrue(!notExistingGroup.isPresent(), "Group " Assert.isTrue(!notExistingGroup.isPresent(), "Group "
+ notExistingGroup.orElse(Long.MIN_VALUE).toString() + "doesn't exist"); + 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); this.commisionService.save(com);
groups.stream().forEach((groupId) -> { groups.stream().forEach((groupId) -> {

View File

@ -10,12 +10,29 @@ public class CommisionResponse {
@ApiModelProperty(value = "ID created by database") @ApiModelProperty(value = "ID created by database")
private Long id; 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") @ApiModelProperty(value = "Timestamp where the user commit the commision")
private String commisionDate; private String commisionDate;
public CommisionResponse(Commision commision) { public CommisionResponse(Commision commision) {
this.id = commision.getId(); this.id = commision.getId();
this.commisionDate = commision.getCommisionDate().toString(); 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() { public String getCommisionDate() {

View File

@ -21,6 +21,9 @@ public class GroupDefaultResponse {
@ApiModelProperty(value = "Value shows time when the course takes.") @ApiModelProperty(value = "Value shows time when the course takes.")
private String time; private String time;
@ApiModelProperty(value = "Value shows time when the course ends.")
private String endTime;
@ApiModelProperty(value = "Value shows degree, name and surname.") @ApiModelProperty(value = "Value shows degree, name and surname.")
private String lecturer; private String lecturer;
@ -37,6 +40,7 @@ public class GroupDefaultResponse {
this.id = group.getId() != null ? group.getId() : null; this.id = group.getId() != null ? group.getId() : null;
this.day = group.getDay() != null ? group.getDay().label : -1; this.day = group.getDay() != null ? group.getDay().label : -1;
this.time = group.getTimeString() != null ? group.getTimeString() : ""; this.time = group.getTimeString() != null ? group.getTimeString() : "";
this.endTime = group.getEndTimeString() != null ? group.getEndTimeString() : "";
this.lecturer = group.getLecturer() != null ? group.getLecturer().toString() : ""; this.lecturer = group.getLecturer() != null ? group.getLecturer().toString() : "";
this.room = group.getRoom() != null ? group.getRoom() : ""; this.room = group.getRoom() != null ? group.getRoom() : "";
this.type = group.getType() != null ? group.getType() : null; this.type = group.getType() != null ? group.getType() : null;
@ -67,6 +71,10 @@ public class GroupDefaultResponse {
return time; return time;
} }
public String getEndTime() {
return endTime;
}
public int getDay() { public int getDay() {
return day; return day;
} }