Added room icons in model as enum
This commit is contained in:
parent
23e3293e9c
commit
5683bbe3e3
3 changed files with 115 additions and 11 deletions
|
@ -39,7 +39,7 @@ public class RoomController {
|
||||||
final String username = principal.getName();
|
final String username = principal.getName();
|
||||||
final Long userId = userRepository.findByUsername(username).getId();
|
final Long userId = userRepository.findByUsername(username).getId();
|
||||||
final String img = r.getImage();
|
final String img = r.getImage();
|
||||||
final String icon = r.getIcon();
|
final Room.Icon icon = r.getIcon();
|
||||||
|
|
||||||
newRoom.setUserId(userId);
|
newRoom.setUserId(userId);
|
||||||
newRoom.setName(r.getName());
|
newRoom.setName(r.getName());
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
||||||
|
|
||||||
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Room;
|
||||||
import javax.persistence.Lob;
|
import javax.persistence.Lob;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
public class RoomSaveRequest {
|
public class RoomSaveRequest {
|
||||||
|
|
||||||
|
@NotNull private Room.Icon icon;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Icon and image are to be given as byte[]. In order to get an encoded string from it, the
|
* Image is to be given as byte[]. In order to get an encoded string from it, the
|
||||||
* Base64.getEncoder().encodeToString(byte[] content) should be used. For further information:
|
* Base64.getEncoder().encodeToString(byte[] content) should be used. For further information:
|
||||||
* https://www.baeldung.com/java-base64-image-string
|
* https://www.baeldung.com/java-base64-image-string
|
||||||
* https://docs.oracle.com/javase/8/docs/api/java/util/Base64.html
|
* https://docs.oracle.com/javase/8/docs/api/java/util/Base64.html
|
||||||
*/
|
*/
|
||||||
@Lob private String icon;
|
|
||||||
|
|
||||||
@Lob private String image;
|
@Lob private String image;
|
||||||
|
|
||||||
/** The user given name of this room (e.g. 'Master bedroom') */
|
/** The user given name of this room (e.g. 'Master bedroom') */
|
||||||
|
@ -25,11 +27,11 @@ public class RoomSaveRequest {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIcon() {
|
public Room.Icon getIcon() {
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIcon(String icon) {
|
public void setIcon(Room.Icon icon) {
|
||||||
this.icon = icon;
|
this.icon = icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
@ -8,20 +9,121 @@ import javax.validation.constraints.NotNull;
|
||||||
@Entity
|
@Entity
|
||||||
public class Room {
|
public class Room {
|
||||||
|
|
||||||
|
/** A collection of Semantic UI icons */
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public enum Icon {
|
||||||
|
@SerializedName("home")
|
||||||
|
HOME("home"),
|
||||||
|
@SerializedName("coffee")
|
||||||
|
COFFEE("coffee"),
|
||||||
|
@SerializedName("beer")
|
||||||
|
BEER("beer"),
|
||||||
|
@SerializedName("glass martini")
|
||||||
|
GLASS_MARTINI("glass martini"),
|
||||||
|
@SerializedName("film")
|
||||||
|
FILM("film"),
|
||||||
|
@SerializedName("video")
|
||||||
|
VIDEO("video"),
|
||||||
|
@SerializedName("music")
|
||||||
|
MUSIC("music"),
|
||||||
|
@SerializedName("headphones")
|
||||||
|
HEADPHONES("headphones"),
|
||||||
|
@SerializedName("fax")
|
||||||
|
FAX("fax"),
|
||||||
|
@SerializedName("phone")
|
||||||
|
PHONE("phone"),
|
||||||
|
@SerializedName("laptop")
|
||||||
|
LAPTOP("laptop"),
|
||||||
|
@SerializedName("bath")
|
||||||
|
BATH("bath"),
|
||||||
|
@SerializedName("shower")
|
||||||
|
SHOWER("shower"),
|
||||||
|
@SerializedName("bed")
|
||||||
|
BED("bed"),
|
||||||
|
@SerializedName("child")
|
||||||
|
CHILD("child"),
|
||||||
|
@SerializedName("warehouse")
|
||||||
|
WAREHOUSE("warehouse"),
|
||||||
|
@SerializedName("car")
|
||||||
|
CAR("car"),
|
||||||
|
@SerializedName("bicycle")
|
||||||
|
BICYCLE("bicycle"),
|
||||||
|
@SerializedName("motorcycle")
|
||||||
|
MOTORCYCLE("motorcycle"),
|
||||||
|
@SerializedName("archive")
|
||||||
|
ARCHIVE("archive"),
|
||||||
|
@SerializedName("boxes")
|
||||||
|
BOXES("boxes"),
|
||||||
|
@SerializedName("cubes")
|
||||||
|
CUBES("cubes"),
|
||||||
|
@SerializedName("chess")
|
||||||
|
CHESS("chess"),
|
||||||
|
@SerializedName("gamepad")
|
||||||
|
GAMEPAD("gamepad"),
|
||||||
|
@SerializedName("futbol")
|
||||||
|
FUTBOL("futbol"),
|
||||||
|
@SerializedName("table tennis")
|
||||||
|
TABLE_TENNIS("table tennis"),
|
||||||
|
@SerializedName("server")
|
||||||
|
SERVER("server"),
|
||||||
|
@SerializedName("tv")
|
||||||
|
TV("tv"),
|
||||||
|
@SerializedName("heart")
|
||||||
|
HEART("heart"),
|
||||||
|
@SerializedName("camera")
|
||||||
|
CAMERA("camera"),
|
||||||
|
@SerializedName("trophy")
|
||||||
|
TROPHY("trophy"),
|
||||||
|
@SerializedName("wrench")
|
||||||
|
WRENCH("wrench"),
|
||||||
|
@SerializedName("image")
|
||||||
|
IMAGE("image"),
|
||||||
|
@SerializedName("book")
|
||||||
|
BOOK("book"),
|
||||||
|
@SerializedName("university")
|
||||||
|
UNIVERSITY("university"),
|
||||||
|
@SerializedName("medkit")
|
||||||
|
MEDKIT("medkit"),
|
||||||
|
@SerializedName("paw")
|
||||||
|
PAW("paw"),
|
||||||
|
@SerializedName("tree")
|
||||||
|
TREE("tree"),
|
||||||
|
@SerializedName("utensils")
|
||||||
|
UTENSILS("utensils"),
|
||||||
|
@SerializedName("male")
|
||||||
|
MALE("male"),
|
||||||
|
@SerializedName("female")
|
||||||
|
FEMALE("female"),
|
||||||
|
@SerializedName("life ring outline")
|
||||||
|
LIFE_RING_OUTLINE("life ring outline");
|
||||||
|
|
||||||
|
private String iconName;
|
||||||
|
|
||||||
|
Icon(String s) {
|
||||||
|
this.iconName = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return iconName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
@Column(name = "id", updatable = false, nullable = false)
|
@Column(name = "id", updatable = false, nullable = false)
|
||||||
@ApiModelProperty(hidden = true)
|
@ApiModelProperty(hidden = true)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
/** The room icon, out of a set of Semantic UI icons */
|
||||||
|
@Column private Icon icon;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Icon and image are to be given as byte[]. In order to get an encoded string from it, the
|
* Image is to be given as byte[]. In order to get an encoded string from it, the
|
||||||
* Base64.getEncoder().encodeToString(byte[] content) should be used. For further information:
|
* Base64.getEncoder().encodeToString(byte[] content) should be used. For further information:
|
||||||
* https://www.baeldung.com/java-base64-image-string
|
* https://www.baeldung.com/java-base64-image-string
|
||||||
* https://docs.oracle.com/javase/8/docs/api/java/util/Base64.html
|
* https://docs.oracle.com/javase/8/docs/api/java/util/Base64.html
|
||||||
*/
|
*/
|
||||||
@Column private String icon;
|
|
||||||
|
|
||||||
@Lob
|
@Lob
|
||||||
@Column(name = "image", columnDefinition = "TEXT")
|
@Column(name = "image", columnDefinition = "TEXT")
|
||||||
private String image;
|
private String image;
|
||||||
|
@ -63,11 +165,11 @@ public class Room {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIcon() {
|
public Icon getIcon() {
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIcon(String icon) {
|
public void setIcon(Icon icon) {
|
||||||
this.icon = icon;
|
this.icon = icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue