Przesylanie i zapisywanie wiadomosci
This commit is contained in:
1 parent
cf372020e7
commit
835a26d627
3 files changed
+101
-6
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package application.controllers;
|
||||
|
||||
import application.model.Message;
|
||||
import application.model.Role;
|
||||
import application.model.User;
|
||||
import application.repositories.RoleRepository;
|
||||
@@ -14,7 +15,8 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import java.util.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by lukasgol on 21.04.14.
|
||||
@@ -65,12 +67,20 @@ public class UserController {
|
||||
accessCodes.put(returnedRole);
|
||||
}
|
||||
|
||||
|
||||
//message
|
||||
JSONObject message = new JSONObject();
|
||||
JSONArray messages = new JSONArray();
|
||||
for( Message message : user.getMessages()){
|
||||
JSONObject returnedMessage = new JSONObject();
|
||||
returnedMessage.put("dateTime", message.getDateTime());
|
||||
returnedMessage.put("isRead", message.isRead());
|
||||
returnedMessage.put("message", message.getMessage());
|
||||
|
||||
messages.put(returnedMessage);
|
||||
}
|
||||
|
||||
loginResponse.put("accessCodes", accessCodes);
|
||||
loginResponse.put("message", message);
|
||||
loginResponse.put("messages", messages);
|
||||
|
||||
}
|
||||
|
||||
if(login.equals(user.getEmail()) && !password.equals(user.getPassword())){
|
||||
@@ -87,17 +97,20 @@ public class UserController {
|
||||
loginResponse.put("error_message", "NO_SUCH_USER");
|
||||
}
|
||||
|
||||
System.out.println(loginResponse.toString());
|
||||
return loginResponse.toString();
|
||||
}
|
||||
|
||||
@RequestMapping("/addMe")
|
||||
@ResponseBody
|
||||
public String addMe() {
|
||||
User marcin = new User("Marcin", "Michalek", "marcin.marcim@gmail.com", "pass");
|
||||
User marcin = new User("Marcin", "Michalek", "m", "p");
|
||||
Set<Role> roles = new HashSet<Role>();
|
||||
roles.add(new Role("CLEANER", "shityJob"));
|
||||
roles.add(new Role("BOSS", "fuckYea"));
|
||||
marcin.setRoles(roles);
|
||||
marcin.addMessage(new Message("hello"));
|
||||
marcin.addMessage(new Message("You're fired"));
|
||||
|
||||
userRepository.save(marcin);
|
||||
|
||||
@@ -137,7 +150,15 @@ public class UserController {
|
||||
roleJSON.put("password", r.getPassword());
|
||||
roleArray.put(roleJSON);
|
||||
}
|
||||
userJSON.put("roles", roleArray);
|
||||
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();
|
||||
|
||||
Reference in new issue
Block a user