package com.plannaplan.responses.models; import com.fasterxml.jackson.annotation.JsonInclude; import com.plannaplan.entities.Assignment; import com.plannaplan.entities.Groups; import com.plannaplan.types.GroupType; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; /** * Default api response for Groups entity */ @JsonInclude(JsonInclude.Include.NON_NULL) @ApiModel(description = "Response shows information about given group.", value = "GroupDefaultResponse") public class GroupDefaultResponse { @ApiModelProperty(value = "ID created by database.") private Long id; @ApiModelProperty(value = "Value shows what day when the course is. Example 0 is Monday.") private int day; @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; @ApiModelProperty(value = "Value shows room where the class takes.") private String room; @ApiModelProperty(value = "Value shows kind of group. The types are LECTURE or CLASS.") private GroupType type; @ApiModelProperty(value = "Value shows how many places is already taken by other students.") private Integer takenPlaces; @ApiModelProperty(value = "Used only in resposnes realted to user assignments. For example in /api/v1/users/schedule.") private Boolean isAccepted; private Integer grNr; /** * creat new entity * * @param group entity to map to api response */ public GroupDefaultResponse(Groups group) { 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 ? GroupType.isLectureOrClass(group.getType()) : null; this.grNr = group.getGrNr() != null ? group.getGrNr() : null; } /** * @return group number */ public Integer getGrNr() { return grNr; } /** * @return is group accepted if its related to assignmetn */ public Boolean getIsAccepted() { return isAccepted; } /** * * @param group entity to map to api response * @param takenPlaces ammount of taken places for group by other users */ public GroupDefaultResponse(Groups group, int takenPlaces) { this(group); this.takenPlaces = takenPlaces; } /** * creat new entity * * @param assignment entity to map to api response */ public GroupDefaultResponse(Assignment assignment) { this(assignment.getGroup()); } /** * * @param assignment entity to map to api response * @param takenPlaces map with ammounts of taken places */ public GroupDefaultResponse(Assignment assignment, int takenPlaces) { this(assignment.getGroup(), takenPlaces); this.isAccepted = assignment.isAccepted(); } /** * @return what typew of group is this (lecture or class) */ public GroupType getType() { return type; } /** * @return room where classes will take place */ public String getRoom() { return room; } /** * @return name of group lecturer */ public String getLecturer() { return lecturer; } /** * @return time when group is scheduled on */ public String getTime() { return time; } /** * @return time when class ends */ public String getEndTime() { return endTime; } /** * @return int what day is it. 0-6 (Monday - Sunday) */ public int getDay() { return day; } /** * @return db id */ public Long getId() { return id; } /** * @return ammount of taken places for group by other users */ public Integer getTakenPlaces() { return this.takenPlaces; } }