This commit is contained in:
Claudio Maggioni (maggicl) 2020-05-02 16:41:11 +02:00
parent 7ae7522359
commit 92e93c80e8

View file

@ -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<User> findAll() {
return toList(userRepository.findAll());
}
@GetMapping("/hosts")
public List<User> 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 {