Merge branch '5-add-delete-or-modify-rooms' into 'dev'

Resolve "Add, Delete, or Modify rooms"

Closes #5

See merge request sa4-2020/the-sanmarinoes/backend!35
This commit is contained in:
Claudio Maggioni 2020-03-14 19:56:28 +01:00
commit 082c420d6c
3 changed files with 115 additions and 11 deletions

View file

@ -39,7 +39,7 @@ public class RoomController {
final String username = principal.getName();
final Long userId = userRepository.findByUsername(username).getId();
final String img = r.getImage();
final String icon = r.getIcon();
final Room.Icon icon = r.getIcon();
newRoom.setUserId(userId);
newRoom.setName(r.getName());

View file

@ -1,17 +1,19 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Room;
import javax.persistence.Lob;
import javax.validation.constraints.NotNull;
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:
* https://www.baeldung.com/java-base64-image-string
* https://docs.oracle.com/javase/8/docs/api/java/util/Base64.html
*/
@Lob private String icon;
@Lob private String image;
/** The user given name of this room (e.g. 'Master bedroom') */
@ -25,11 +27,11 @@ public class RoomSaveRequest {
this.name = name;
}
public String getIcon() {
public Room.Icon getIcon() {
return icon;
}
public void setIcon(String icon) {
public void setIcon(Room.Icon icon) {
this.icon = icon;
}

View file

@ -1,5 +1,6 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import com.google.gson.annotations.SerializedName;
import io.swagger.annotations.ApiModelProperty;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
@ -8,20 +9,121 @@ import javax.validation.constraints.NotNull;
@Entity
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
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", updatable = false, nullable = false)
@ApiModelProperty(hidden = true)
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:
* https://www.baeldung.com/java-base64-image-string
* https://docs.oracle.com/javase/8/docs/api/java/util/Base64.html
*/
@Column private String icon;
@Lob
@Column(name = "image", columnDefinition = "TEXT")
private String image;
@ -63,11 +165,11 @@ public class Room {
this.name = name;
}
public String getIcon() {
public Icon getIcon() {
return icon;
}
public void setIcon(String icon) {
public void setIcon(Icon icon) {
this.icon = icon;
}