diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/GuestController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/GuestController.java index b0994a1..cfc0f36 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/GuestController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/GuestController.java @@ -4,8 +4,8 @@ import static ch.usi.inf.sa4.sanmarinoes.smarthut.utils.Utils.toList; 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.EagerUserRepository; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.User; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.UserRepository; import java.security.Principal; import java.util.List; import javax.validation.Valid; @@ -18,13 +18,19 @@ import org.springframework.web.bind.annotation.*; @RequestMapping("/user") public class GuestController { - @Autowired private UserRepository userRepository; + @Autowired private EagerUserRepository userRepository; @GetMapping public List findAll() { return toList(userRepository.findAll()); } + @GetMapping("/hosts") + public List findHosts(final Principal principal) { + final User u = userRepository.findByUsername(principal.getName()); + return toList(u.getHosts()); + } + @PostMapping("/guest") public User addUserAsGuest(@RequestParam("userId") long id, final Principal principal) throws NotFoundException {