-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Christopher Strauss
committed
Aug 2, 2024
1 parent
267b0de
commit d35f01b
Showing
5 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.bernd; | ||
|
||
import com.bernd.model.Chat; | ||
import com.bernd.model.ChatRequest; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
|
||
@Controller | ||
public class ChatController { | ||
|
||
@Autowired | ||
Chats chats; | ||
|
||
@GetMapping("/chat") | ||
public Chat getChat(@RequestBody String id) { | ||
return chats.get(id); | ||
} | ||
|
||
@PostMapping("/sendChat") | ||
public ResponseEntity<?> sendChat(@RequestBody ChatRequest chatRequest) { | ||
chats.put(chatRequest.chat()); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.bernd; | ||
|
||
import com.bernd.model.Chat; | ||
import com.bernd.model.Game; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Component | ||
public class Chats { | ||
private final Map<String, Chat> map = new LinkedHashMap<>(); | ||
|
||
Chat get(String id) { | ||
return map.get(id); | ||
} | ||
|
||
Chat put(Chat chat) { | ||
map.put(chat.getId(), chat); | ||
return chat; | ||
} | ||
|
||
List<Chat> chats() { | ||
return List.copyOf(map.values()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.bernd.model; | ||
|
||
import java.util.List; | ||
|
||
public class Chat { | ||
|
||
private String id; | ||
private List<ChatMessage> chatMessages; | ||
|
||
public Chat(){ | ||
} | ||
|
||
public Chat(String id, List<ChatMessage> chatMessages){ | ||
this.id = id; | ||
this.chatMessages = chatMessages; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public List<ChatMessage> getChatMessages() { | ||
return chatMessages; | ||
} | ||
|
||
public void setChatMessages(List<ChatMessage> chatMessages) { | ||
this.chatMessages = chatMessages; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.bernd.model; | ||
|
||
public class ChatMessage { | ||
|
||
private String message; | ||
private String messageId; | ||
|
||
public ChatMessage(String message, String messageId) { | ||
this.message = message; | ||
this.messageId = messageId; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public void setMessage(String message) { | ||
this.message = message; | ||
} | ||
|
||
public String getMessageId() { | ||
return messageId; | ||
} | ||
|
||
public void setMessageId(String messageId) { | ||
this.messageId = messageId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.bernd.model; | ||
|
||
public record ChatRequest( | ||
Chat chat) { | ||
} |