Code review
This commit is contained in:
parent
cfe3848d7e
commit
6317ac99e4
4 changed files with 28 additions and 104 deletions
|
@ -2,7 +2,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
|
|||
|
||||
import static ch.usi.inf.sa4.sanmarinoes.smarthut.utils.Utils.toList;
|
||||
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.GuestUserResponse;
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.GuestPermissionsRequest;
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException;
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.User;
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.UserRepository;
|
||||
|
@ -27,34 +27,21 @@ public class GuestController {
|
|||
User host = userRepository.findByUsername(principal.getName());
|
||||
|
||||
host.addGuest(guest);
|
||||
/** Not sure if this is useful. userRepository.save(guest); */
|
||||
guest.addHost(host);
|
||||
userRepository.save(guest);
|
||||
/* Not sure if this is useful. userRepository.save(guest); */
|
||||
return userRepository.save(host);
|
||||
}
|
||||
|
||||
public User save(GuestUserResponse g, User newGuest) {
|
||||
newGuest.setCameraEnabled(g.isCameraEnabled());
|
||||
newGuest.setEmail(g.getEmail());
|
||||
newGuest.setId(g.getId());
|
||||
newGuest.setName(g.getName());
|
||||
newGuest.setUsername(g.getUsername());
|
||||
newGuest.setPassword(g.getPassword());
|
||||
newGuest.setEnabled(g.getEnabled());
|
||||
|
||||
for (User guest : g.getGuests()) {
|
||||
newGuest.addGuest(guest);
|
||||
}
|
||||
|
||||
for (User host : g.getHosts()) {
|
||||
newGuest.addHost(host);
|
||||
}
|
||||
|
||||
return userRepository.save(newGuest);
|
||||
public User save(GuestPermissionsRequest g, User currentUser) {
|
||||
currentUser.setCameraEnabled(g.isCameraEnabled());
|
||||
return userRepository.save(currentUser);
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
public User updatePermissions(@Valid @RequestBody GuestUserResponse g)
|
||||
throws NotFoundException {
|
||||
return this.save(g, userRepository.findById(g.getId()).orElseThrow(NotFoundException::new));
|
||||
public User updatePermissions(
|
||||
@Valid @RequestBody GuestPermissionsRequest g, final Principal principal) {
|
||||
return this.save(g, userRepository.findByUsername(principal.getName()));
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
|
@ -63,7 +50,8 @@ public class GuestController {
|
|||
User host = userRepository.findByUsername(principal.getName());
|
||||
|
||||
host.removeGuest(guest);
|
||||
userRepository.deleteById(id);
|
||||
guest.getHosts().remove(host);
|
||||
userRepository.save(host);
|
||||
userRepository.save(guest);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,6 +56,8 @@ public class SceneController {
|
|||
newScene.setUserId(userId);
|
||||
newScene.setName(s.getName());
|
||||
|
||||
newScene.setGuestAccessEnabled(s.isGuestAccessEnabled());
|
||||
|
||||
return sceneService.save(newScene);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
||||
|
||||
|
||||
public class GuestPermissionsRequest {
|
||||
private boolean cameraEnabled;
|
||||
|
||||
public boolean isCameraEnabled() {
|
||||
return cameraEnabled;
|
||||
}
|
||||
|
||||
public void setCameraEnabled(boolean cameraEnabled) {
|
||||
this.cameraEnabled = cameraEnabled;
|
||||
}
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
||||
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.User;
|
||||
import java.util.Set;
|
||||
|
||||
public class GuestUserResponse {
|
||||
private boolean cameraEnabled;
|
||||
private long id;
|
||||
private String name;
|
||||
private String username;
|
||||
private String password;
|
||||
private String email;
|
||||
private Set<User> hosts;
|
||||
private Set<User> guests;
|
||||
private Boolean isEnabled = false;
|
||||
|
||||
public Boolean getEnabled() {
|
||||
return isEnabled;
|
||||
}
|
||||
|
||||
public void setEnabled(Boolean enabled) {
|
||||
isEnabled = enabled;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public Set<User> getHosts() {
|
||||
return hosts;
|
||||
}
|
||||
|
||||
public Set<User> getGuests() {
|
||||
return guests;
|
||||
}
|
||||
|
||||
public boolean isCameraEnabled() {
|
||||
return cameraEnabled;
|
||||
}
|
||||
|
||||
public void setCameraEnabled(boolean cameraEnabled) {
|
||||
this.cameraEnabled = cameraEnabled;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue