diff --git a/src/main/java/application/controllers/UserController.java b/src/main/java/application/controllers/UserController.java index f471f3f..1cfec58 100644 --- a/src/main/java/application/controllers/UserController.java +++ b/src/main/java/application/controllers/UserController.java @@ -15,7 +15,6 @@ import org.json.JSONException; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.*; import javax.persistence.EntityManager; @@ -197,36 +196,8 @@ public class UserController { @RequestMapping public @ResponseBody - String listUsersJson(ModelMap model) throws JSONException { - - JSONArray userArray = new JSONArray(); - for (User user : userRepository.findAll()) { - JSONObject userJSON = new JSONObject(); - userJSON.put("id", user.getUserId()); - userJSON.put("firstname", user.getFirstName()); - userJSON.put("lastname", user.getLastName()); - userJSON.put("email", user.getEmail()); - JSONArray roleArray = new JSONArray(); - for(Role r:user.getRoles()){ - JSONObject roleJSON = new JSONObject(); - roleJSON.put("id", r.getRoleId()); - roleJSON.put("name", r.getRoleName()); - roleJSON.put("password", r.getPassword()); - roleArray.put(roleJSON); - } - JSONArray messageArray = new JSONArray(); - for(Message m:user.getMessages()){ - JSONObject messJSON = new JSONObject(); - messJSON.put("dataTime", m.getDateTime()); - messJSON.put("message", m.getMessage()); - messJSON.put("isRead", m.isRead()); - messageArray.put(messJSON); - } - userJSON.put("messages", messageArray); - userArray.put(userJSON); - } - return userArray.toString(); - + Iterable listUsersJson() throws JSONException { + return userRepository.findAll(); } @RequestMapping("/remove/{userId}") diff --git a/src/main/java/application/utils/Initializer.java b/src/main/java/application/utils/Initializer.java index bb9c2ec..8d481f5 100644 --- a/src/main/java/application/utils/Initializer.java +++ b/src/main/java/application/utils/Initializer.java @@ -45,6 +45,15 @@ public class Initializer { marcin.addMessage(new Message("You're fired")); userRepository.save(marcin); + User lukasz = new User("Lukasz", "Golinski", "l", "p"); + Set roles2 = new HashSet(); + roles2.add(new Role("NERD", "greatJob")); + roles2.add(new Role("BOSS", "fuckYea")); + lukasz.setRoles(roles2); + lukasz.addMessage(new Message("hello2")); + lukasz.addMessage(new Message("You're fired")); + userRepository.save(lukasz); + DoorMessage message=new DoorMessage("Be Careful"); doorRepository.save(new Door(message)); }