From b151204306908ff8b40f5a473022c9bdc7585a0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=A1=ED=98=84=EC=9A=B0?= <83938394+yunuo46@users.noreply.github.com> Date: Fri, 10 May 2024 19:51:12 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20inline=20variable=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../site/demo/Controller/APIController.java | 3 +-- .../site/demo/Controller/ChatController.java | 3 +-- .../site/demo/Controller/MapController.java | 9 +++---- .../site/demo/Entity/UserEntity.java | 3 +-- .../site/demo/Service/APIServiceImpl.java | 3 +-- .../site/demo/Service/MapServiceImpl.java | 24 +++++++------------ 6 files changed, 15 insertions(+), 30 deletions(-) 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