Skip to content

Commit

Permalink
feat: 이동 기능 완성!
Browse files Browse the repository at this point in the history
  • Loading branch information
yunuo46 committed May 9, 2024
1 parent 65aef17 commit a4218bb
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package getaguitar.site.demo.Controller;


import getaguitar.site.demo.Dto.ResMoveUserDto;
import getaguitar.site.demo.Dto.ResStopUserDto;
import getaguitar.site.demo.Dto.ReqStopUserDto;
import getaguitar.site.demo.Dto.MoveUser.ResMoveUserDto;
import getaguitar.site.demo.Dto.StopUser.ResStopUserDto;
import getaguitar.site.demo.Dto.StopUser.ReqStopUserDto;
import getaguitar.site.demo.Dto.Player;
import getaguitar.site.demo.Dto.NewUser.ReqNewUserDto;
import getaguitar.site.demo.Dto.NewUser.ResNewUserDto;
Expand Down Expand Up @@ -40,7 +39,7 @@ public ResNewUserDto newUser(@Payload ReqNewUserDto newUser) {
@SendTo("/topic/map/all")
public Player[] allUser(){
Player[] players = new Player[1];
players[0] = new Player("TestId", 0, 0, "down");
players[0] = new Player("TestName", 0, 0, "down");
return players;
}

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.MoveUser;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand All @@ -10,7 +10,7 @@
@Getter
@Setter
public class ResMoveUserDto {
private Object id;
private String username;
private int x;
private int y;
private String direction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@Getter
@Setter
public class ResNewUserDto {
private String id;
private String username;
private int x;
private int y;
private String direction;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/getaguitar/site/demo/Dto/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@Getter
@Setter
public class Player {
private String id;
private String username;
private int x;
private int y;
private String direction;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/getaguitar/site/demo/Dto/ResUserNameDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
@Getter
@Setter
public class ResUserNameDto {
private String name;
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.StopUser;

import lombok.AllArgsConstructor;
import lombok.Getter;
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.StopUser;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand All @@ -10,7 +10,7 @@
@Getter
@Setter
public class ResStopUserDto {
private String id;
private String username;
private int x;
private int y;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,27 @@
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.*;
import org.antlr.v4.runtime.misc.NotNull;

@ToString
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "tbl_test_entity")
@Table(name = "user")
@Entity
public class TestEntity {
public class UserEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Integer id;

@Column(length = 45)
private String username;

@NotNull
private Integer x;

@Column(length = 200, nullable = false)
private String name;
@NotNull
private Integer y;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package getaguitar.site.demo.Repository;

import getaguitar.site.demo.Entity.UserEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface UserRepository extends JpaRepository<UserEntity, Integer> {
}
6 changes: 3 additions & 3 deletions src/main/java/getaguitar/site/demo/Service/MapService.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package getaguitar.site.demo.Service;

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

Expand Down
38 changes: 33 additions & 5 deletions src/main/java/getaguitar/site/demo/Service/MapServiceImpl.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,56 @@
package getaguitar.site.demo.Service;
import getaguitar.site.demo.Dto.ReqStopUserDto;
import getaguitar.site.demo.Dto.ResStopUserDto;
import getaguitar.site.demo.Dto.MoveUser.ResMoveUserDto;
import getaguitar.site.demo.Dto.StopUser.ReqStopUserDto;
import getaguitar.site.demo.Dto.StopUser.ResStopUserDto;
import getaguitar.site.demo.Dto.NewUser.ReqNewUserDto;
import getaguitar.site.demo.Dto.NewUser.ResNewUserDto;

import getaguitar.site.demo.Entity.UserEntity;
import getaguitar.site.demo.Repository.UserRepository;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class MapServiceImpl implements MapService {
private final UserRepository userRepository;

public MapServiceImpl(UserRepository userRepository) {
this.userRepository = userRepository;
}

@Override
public ResNewUserDto createUser(ReqNewUserDto newUser){
ResNewUserDto resNewUserDto = new ResNewUserDto("testId",0,0,"down");
String username = userRepository.save(UserEntity.builder().username("TestName").x(0).y(0).build()).getUsername();
ResNewUserDto resNewUserDto = new ResNewUserDto(username,0,0,"down");
return resNewUserDto;
}

@Override
public ResMoveUserDto moveUser(String direction) {
ResMoveUserDto moveUserDto = new ResMoveUserDto("testId", 1, 1, direction);
Optional<UserEntity> user = Optional.of(userRepository.findById(1).get());
UserEntity userEntity = user.get();

int x = userEntity.getX();
int y = userEntity.getY();
if(direction.equals("up")) y++;
else if(direction.equals("down")) y--;
else if(direction.equals("left")) x--;
else if(direction.equals("right")) x++;

UserEntity storedUser = userRepository.save(UserEntity.builder()
.id(userEntity.getId())
.x(x)
.y(y)
.build());

ResMoveUserDto moveUserDto = new ResMoveUserDto(userEntity.getUsername(), storedUser.getX(), storedUser.getY(), direction);
return moveUserDto;
}

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

0 comments on commit a4218bb

Please sign in to comment.