diff --git a/src/main/java/getaguitar/site/demo/Controller/APIController.java b/src/main/java/getaguitar/site/demo/Controller/APIController.java index 009b9e7..dbc2534 100644 --- a/src/main/java/getaguitar/site/demo/Controller/APIController.java +++ b/src/main/java/getaguitar/site/demo/Controller/APIController.java @@ -18,7 +18,6 @@ public class APIController { @GetMapping("/user") @CrossOrigin(origins = "*", allowedHeaders = "*") public ResUserNameDto getUser() throws JsonProcessingException { - ResUserNameDto userDto = apiService.getUser(); - return userDto; + return apiService.getUser(); } } diff --git a/src/main/java/getaguitar/site/demo/Controller/ChatController.java b/src/main/java/getaguitar/site/demo/Controller/ChatController.java index 821955e..cfefc62 100644 --- a/src/main/java/getaguitar/site/demo/Controller/ChatController.java +++ b/src/main/java/getaguitar/site/demo/Controller/ChatController.java @@ -16,7 +16,6 @@ public class ChatController { @MessageMapping("/message") @SendTo("/topic/chat/message") public ResChatMessageDto sendMessage(@Payload ReqChatMessageDto message) { - ResChatMessageDto resChatMessageDto = new ResChatMessageDto(message.getText(), message.getUsername()); - return resChatMessageDto; + return new ResChatMessageDto(message.getText(), message.getUsername()); } } diff --git a/src/main/java/getaguitar/site/demo/Controller/MapController.java b/src/main/java/getaguitar/site/demo/Controller/MapController.java index e3d2574..502562f 100644 --- a/src/main/java/getaguitar/site/demo/Controller/MapController.java +++ b/src/main/java/getaguitar/site/demo/Controller/MapController.java @@ -26,15 +26,13 @@ public class MapController { @MessageMapping("/move") @SendTo("/topic/map/move") public MoveUserDto moveUser(MoveUserDto position) { - MoveUserDto moveUserDto = mapService.moveUser(position); - return moveUserDto; + return mapService.moveUser(position); } @MessageMapping("/new") @SendTo("/topic/map/new") public ResNewUserDto newUser(@Payload ReqNewUserDto newUser) { - ResNewUserDto resNewUserDto = mapService.createUser(newUser); - return resNewUserDto; + return mapService.createUser(newUser); } @MessageMapping("/all") @@ -46,7 +44,6 @@ public List allUser(){ @MessageMapping("/stop") @SendTo("/topic/map/stop") public ResStopUserDto stopUser(ReqStopUserDto stopUser) { - ResStopUserDto resStopUserDto= mapService.stopUser(stopUser); - return resStopUserDto; + return mapService.stopUser(stopUser); } } diff --git a/src/main/java/getaguitar/site/demo/Entity/UserEntity.java b/src/main/java/getaguitar/site/demo/Entity/UserEntity.java index 2f64d45..f067922 100644 --- a/src/main/java/getaguitar/site/demo/Entity/UserEntity.java +++ b/src/main/java/getaguitar/site/demo/Entity/UserEntity.java @@ -6,6 +6,7 @@ @ToString @Getter +@Setter @Builder @AllArgsConstructor @NoArgsConstructor @@ -19,10 +20,8 @@ public class UserEntity { @Column(length = 45) private String username; - @NotNull private Integer x; - @NotNull private Integer y; private String direction; diff --git a/src/main/java/getaguitar/site/demo/Service/APIServiceImpl.java b/src/main/java/getaguitar/site/demo/Service/APIServiceImpl.java index 21d5d7c..dba9bfd 100644 --- a/src/main/java/getaguitar/site/demo/Service/APIServiceImpl.java +++ b/src/main/java/getaguitar/site/demo/Service/APIServiceImpl.java @@ -8,7 +8,6 @@ public class APIServiceImpl implements APIService{ @Override public ResUserNameDto getUser(){ String username = RandomStringUtils.randomAlphanumeric(5); - ResUserNameDto userDto = new ResUserNameDto(username); - return userDto; + return new ResUserNameDto(username); } } diff --git a/src/main/java/getaguitar/site/demo/Service/MapServiceImpl.java b/src/main/java/getaguitar/site/demo/Service/MapServiceImpl.java index 2915cb3..749cba0 100644 --- a/src/main/java/getaguitar/site/demo/Service/MapServiceImpl.java +++ b/src/main/java/getaguitar/site/demo/Service/MapServiceImpl.java @@ -7,6 +7,7 @@ import getaguitar.site.demo.Entity.UserEntity; import getaguitar.site.demo.Repository.UserRepository; +import jakarta.transaction.Transactional; import org.springframework.stereotype.Service; import java.util.List; @@ -28,8 +29,7 @@ public ResNewUserDto createUser(ReqNewUserDto newUser){ .y(300) .direction("down") .build()).getUsername(); - ResNewUserDto resNewUserDto = new ResNewUserDto(username,400,300,"down"); - return resNewUserDto; + return new ResNewUserDto(username,400,300,"down"); } @Override @@ -38,6 +38,7 @@ public List getAllUser(){ } @Override + @Transactional public MoveUserDto moveUser(MoveUserDto position) { String username = position.getUsername(); UserEntity user = userRepository.findByUsername(username); @@ -46,21 +47,12 @@ public MoveUserDto moveUser(MoveUserDto position) { int y = position.getY(); String direction = position.getDirection(); - if(direction.equals("up")) y-=2; - else if(direction.equals("down")) y+=2; - else if(direction.equals("left")) x-=2; - else if(direction.equals("right")) x+=2; + if(direction.equals("up")) { y-=2; user.setY(y); } + else if(direction.equals("down")) { y+=2; user.setY(y); } + else if(direction.equals("left")) { x-=2; user.setX(x); } + else if(direction.equals("right")) { x+=2; user.setX(x); } - userRepository.save(UserEntity.builder() - .id(user.getId()) - .username(username) - .x(x) - .y(y) - .direction(direction) - .build()); - - MoveUserDto moveUserDto = new MoveUserDto(username, x, y, direction); - return moveUserDto; + return new MoveUserDto(username, x, y, direction); } @Override