Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
yunuo46 authored May 9, 2024
2 parents ccc5e0e + 4cad346 commit c507c94
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package getaguitar.site.demo.Controller;

import getaguitar.site.demo.Dto.ResChatMessageDto;
import getaguitar.site.demo.Dto.ChatMessage.ReqChatMessageDto;
import getaguitar.site.demo.Dto.ChatMessage.ResChatMessageDto;
import lombok.RequiredArgsConstructor;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.web.bind.annotation.RestController;

@RestController
@MessageMapping("/chat")
@RequiredArgsConstructor
@MessageMapping("/chat")
public class ChatController {

@MessageMapping("/message")
@SendTo("/topic/chat/message")
public ResChatMessageDto sendMessage(ResChatMessageDto message) {
return message;
public ResChatMessageDto sendMessage(@Payload ReqChatMessageDto message) {
ResChatMessageDto resChatMessageDto = new ResChatMessageDto(message.getText(), message.getUsername());
return resChatMessageDto;
}
}
21 changes: 18 additions & 3 deletions src/main/java/getaguitar/site/demo/Controller/MapController.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package getaguitar.site.demo.Controller;

import getaguitar.site.demo.Dto.ReqNewUserDto;

import getaguitar.site.demo.Dto.ResMoveUserDto;
import getaguitar.site.demo.Dto.ResNewUserDto;
import getaguitar.site.demo.Dto.ResStopUserDto;
import getaguitar.site.demo.Dto.ReqStopUserDto;
import getaguitar.site.demo.Dto.Player;
import getaguitar.site.demo.Dto.NewUser.ReqNewUserDto;
import getaguitar.site.demo.Dto.NewUser.ResNewUserDto;
import getaguitar.site.demo.Service.MapService;

import lombok.RequiredArgsConstructor;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.Payload;
Expand Down Expand Up @@ -31,8 +36,18 @@ public ResNewUserDto newUser(@Payload ReqNewUserDto newUser) {
return resNewUserDto;
}

@MessageMapping("/all")
@SendTo("/topic/map/all")
public Player[] allUser(){
Player[] players = new Player[1];
players[0] = new Player("TestId", 0, 0, "down");
return players;
}

@MessageMapping("/stop")
@SendTo("/topic/map/stop")
public void stopUser() {
public ResStopUserDto stopUser(ReqStopUserDto stopUser) {
ResStopUserDto resStopUserDto= mapService.stopUser(stopUser);
return resStopUserDto;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package getaguitar.site.demo.Dto.ChatMessage;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
public class ReqChatMessageDto {
private String room;
private String text;
private String username;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package getaguitar.site.demo.Dto;
package getaguitar.site.demo.Dto.ChatMessage;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package getaguitar.site.demo.Dto;
package getaguitar.site.demo.Dto.NewUser;

import getaguitar.site.demo.Dto.IPosition;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package getaguitar.site.demo.Dto;
package getaguitar.site.demo.Dto.NewUser;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/getaguitar/site/demo/Dto/Player.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package getaguitar.site.demo.Dto;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
public class Player {
private String id;
private int x;
private int y;
private String direction;
}
14 changes: 14 additions & 0 deletions src/main/java/getaguitar/site/demo/Dto/ReqStopUserDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package getaguitar.site.demo.Dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
public class ReqStopUserDto {
private String username;
}
16 changes: 16 additions & 0 deletions src/main/java/getaguitar/site/demo/Dto/ResStopUserDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package getaguitar.site.demo.Dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
public class ResStopUserDto {
private String id;
private int x;
private int y;
}
7 changes: 5 additions & 2 deletions src/main/java/getaguitar/site/demo/Service/MapService.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package getaguitar.site.demo.Service;

import getaguitar.site.demo.Dto.ReqNewUserDto;
import getaguitar.site.demo.Dto.ResMoveUserDto;
import getaguitar.site.demo.Dto.ResNewUserDto;
import getaguitar.site.demo.Dto.ReqStopUserDto;
import getaguitar.site.demo.Dto.ResStopUserDto;
import getaguitar.site.demo.Dto.NewUser.ReqNewUserDto;
import getaguitar.site.demo.Dto.NewUser.ResNewUserDto;

public interface MapService {
ResNewUserDto createUser(ReqNewUserDto newUser);
ResStopUserDto stopUser(ReqStopUserDto stopUser);
ResMoveUserDto moveUser(String direction);
}
13 changes: 10 additions & 3 deletions src/main/java/getaguitar/site/demo/Service/MapServiceImpl.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package getaguitar.site.demo.Service;
import getaguitar.site.demo.Dto.ReqNewUserDto;
import getaguitar.site.demo.Dto.ResMoveUserDto;
import getaguitar.site.demo.Dto.ResNewUserDto;
import getaguitar.site.demo.Dto.ReqStopUserDto;
import getaguitar.site.demo.Dto.ResStopUserDto;
import getaguitar.site.demo.Dto.NewUser.ReqNewUserDto;
import getaguitar.site.demo.Dto.NewUser.ResNewUserDto;

import org.springframework.stereotype.Service;

@Service
Expand All @@ -18,4 +20,9 @@ public ResMoveUserDto moveUser(String direction) {
return moveUserDto;
}

@Override
public ResStopUserDto stopUser(ReqStopUserDto stopUser){
ResStopUserDto resStopUserDto = new ResStopUserDto("testId", 0, 0);
return resStopUserDto;
}
}

0 comments on commit c507c94

Please sign in to comment.