funkcja przeczytania wiadomosci
This commit is contained in:
1 parent
835a26d627
commit
75f1e6b1ab
2 files changed
+32
No files matched your search
@@ -57,6 +57,7 @@ public class UserController {
|
||||
if(login.equals(user.getEmail()) && password.equals(user.getPassword())){
|
||||
userFound = true;
|
||||
loginResponse.put("success", true);
|
||||
loginResponse.put("userId", user.getUserId());
|
||||
|
||||
//access codes
|
||||
JSONArray accessCodes = new JSONArray();
|
||||
@@ -71,6 +72,7 @@ public class UserController {
|
||||
JSONArray messages = new JSONArray();
|
||||
for( Message message : user.getMessages()){
|
||||
JSONObject returnedMessage = new JSONObject();
|
||||
returnedMessage.put("messageId", message.getMessageId());
|
||||
returnedMessage.put("dateTime", message.getDateTime());
|
||||
returnedMessage.put("isRead", message.isRead());
|
||||
returnedMessage.put("message", message.getMessage());
|
||||
@@ -117,7 +119,19 @@ public class UserController {
|
||||
return "User created" + marcin.getUserId();
|
||||
}
|
||||
|
||||
@RequestMapping("/change")
|
||||
@ResponseBody
|
||||
public String change() {
|
||||
User marcin = userRepository.findOne((long) 1);
|
||||
Set set =marcin.getMessages();
|
||||
set.add(new Message("lala"));
|
||||
userRepository.save(marcin);
|
||||
|
||||
return "User changed" + marcin.getUserId();
|
||||
}
|
||||
|
||||
@RequestMapping("/{userId}")
|
||||
@ResponseBody
|
||||
public String getUser(@PathVariable("userId") Long userId) throws JSONException{
|
||||
User user = userRepository.findOne(userId);
|
||||
JSONObject userJSON = new JSONObject();
|
||||
@@ -130,6 +144,20 @@ public class UserController {
|
||||
return userArray.toString();
|
||||
}
|
||||
|
||||
@RequestMapping("/markRead/{userId}/{messageId}")
|
||||
@ResponseBody
|
||||
public String getUser(@PathVariable("userId") Long userId,@PathVariable("messageId") Long messageId) throws JSONException{
|
||||
User user = userRepository.findOne(userId);
|
||||
Set<Message> messages= user.getMessages();
|
||||
for(Message m:messages){
|
||||
if(m.getMessageId()==messageId) m.setRead(true);
|
||||
}
|
||||
JSONObject loginResponse = new JSONObject();
|
||||
loginResponse.put("success", true);
|
||||
userRepository.save(user);
|
||||
return loginResponse.toString();
|
||||
}
|
||||
|
||||
@RequestMapping
|
||||
public
|
||||
@ResponseBody
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.util.Date;
|
||||
@Entity (name = "messsage")
|
||||
public class Message {
|
||||
|
||||
|
||||
@Id
|
||||
@Column(name = "ID")
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
@@ -56,4 +57,7 @@ public class Message {
|
||||
this.isRead = read;
|
||||
}
|
||||
|
||||
public Long getMessageId() {
|
||||
return messageId;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user