File tree 5 files changed +122
-0
lines changed
5 files changed +122
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .bernd ;
2
+
3
+ import com .bernd .model .Chat ;
4
+ import com .bernd .model .ChatRequest ;
5
+ import org .springframework .beans .factory .annotation .Autowired ;
6
+ import org .springframework .http .ResponseEntity ;
7
+ import org .springframework .stereotype .Controller ;
8
+ import org .springframework .web .bind .annotation .GetMapping ;
9
+ import org .springframework .web .bind .annotation .PostMapping ;
10
+ import org .springframework .web .bind .annotation .RequestBody ;
11
+
12
+ @ Controller
13
+ public class ChatController {
14
+
15
+ @ Autowired
16
+ Chats chats ;
17
+
18
+ @ GetMapping ("/chat" )
19
+ public Chat getChat (@ RequestBody String id ) {
20
+ return chats .get (id );
21
+ }
22
+
23
+ @ PostMapping ("/sendChat" )
24
+ public ResponseEntity <?> sendChat (@ RequestBody ChatRequest chatRequest ) {
25
+ chats .put (chatRequest .chat ());
26
+ return ResponseEntity .ok ().build ();
27
+ }
28
+
29
+ }
Original file line number Diff line number Diff line change
1
+ package com .bernd ;
2
+
3
+ import com .bernd .model .Chat ;
4
+ import com .bernd .model .Game ;
5
+ import org .springframework .stereotype .Component ;
6
+
7
+ import java .util .LinkedHashMap ;
8
+ import java .util .List ;
9
+ import java .util .Map ;
10
+
11
+ @ Component
12
+ public class Chats {
13
+ private final Map <String , Chat > map = new LinkedHashMap <>();
14
+
15
+ Chat get (String id ) {
16
+ return map .get (id );
17
+ }
18
+
19
+ Chat put (Chat chat ) {
20
+ map .put (chat .getId (), chat );
21
+ return chat ;
22
+ }
23
+
24
+ List <Chat > chats () {
25
+ return List .copyOf (map .values ());
26
+ }
27
+ }
Original file line number Diff line number Diff line change
1
+ package com .bernd .model ;
2
+
3
+ import java .util .List ;
4
+
5
+ public class Chat {
6
+
7
+ private String id ;
8
+ private List <ChatMessage > chatMessages ;
9
+
10
+ public Chat (){
11
+ }
12
+
13
+ public Chat (String id , List <ChatMessage > chatMessages ){
14
+ this .id = id ;
15
+ this .chatMessages = chatMessages ;
16
+ }
17
+
18
+ public String getId () {
19
+ return id ;
20
+ }
21
+
22
+ public void setId (String id ) {
23
+ this .id = id ;
24
+ }
25
+
26
+ public List <ChatMessage > getChatMessages () {
27
+ return chatMessages ;
28
+ }
29
+
30
+ public void setChatMessages (List <ChatMessage > chatMessages ) {
31
+ this .chatMessages = chatMessages ;
32
+ }
33
+ }
Original file line number Diff line number Diff line change
1
+ package com .bernd .model ;
2
+
3
+ public class ChatMessage {
4
+
5
+ private String message ;
6
+ private String messageId ;
7
+
8
+ public ChatMessage (String message , String messageId ) {
9
+ this .message = message ;
10
+ this .messageId = messageId ;
11
+ }
12
+
13
+ public String getMessage () {
14
+ return message ;
15
+ }
16
+
17
+ public void setMessage (String message ) {
18
+ this .message = message ;
19
+ }
20
+
21
+ public String getMessageId () {
22
+ return messageId ;
23
+ }
24
+
25
+ public void setMessageId (String messageId ) {
26
+ this .messageId = messageId ;
27
+ }
28
+ }
Original file line number Diff line number Diff line change
1
+ package com .bernd .model ;
2
+
3
+ public record ChatRequest (
4
+ Chat chat ) {
5
+ }
You can’t perform that action at this time.
0 commit comments