Skip to content

Commit

Permalink
Change Method Name in app/repositories/RoomRepository.java
Browse files Browse the repository at this point in the history
  • Loading branch information
chiashengchen committed Aug 15, 2023
1 parent 5ce62bf commit b01abd4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
import java.util.Optional;

public interface RoomRepository {
Optional<Room> save(Room room);
Optional<Room> findById(String gameId);
Optional<Room> createRoom(Room room);
Optional<Room> findRoomById(String gameId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public void execute(Request request, Presenter presenter) {
Room room = findRoomById(request.getRoomId());
User user = new User(request.getUserName(), request.getUserImage());
room.joinUser(user);
roomRepository.save(room);
roomRepository.createRoom(room);
presenter.present(room);
}

private Room findRoomById(String roomId) {
Optional<Room> room = roomRepository.findById(roomId);
Optional<Room> room = roomRepository.findRoomById(roomId);
return room.orElseThrow(() -> new NullPointerException("CAN NOT FIND GAME, ID=" + roomId));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public class RoomRepositoryImpl implements RoomRepository {
private final RoomDAO roomDAO;

@Override
public Optional<Room> save(Room room) {
public Optional<Room> createRoom(Room room) {
RoomData data = RoomData.toData(room);
return Optional.ofNullable(roomDAO.save(data).toDomain());
}

@Override
public Optional<Room> findById(String gameId) {
public Optional<Room> findRoomById(String gameId) {
return roomDAO.findById(gameId).map(RoomData::toDomain);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public abstract class CitadelsApplicationTest {
private RoomRepository roomRepository;

protected Room givenGameStarted(String name, User holder, User... users) {
return roomRepository.save(new Room(name, holder, asList(users))).orElseThrow();
return roomRepository.createRoom(new Room(name, holder, asList(users))).orElseThrow();
}

protected Room findRoomById(String roomId) {
return roomRepository.findById(roomId).orElseThrow(() -> new JoinRoomException("CAN NOT FIND ROOM ID=" + roomId));
return roomRepository.findRoomById(roomId).orElseThrow(() -> new JoinRoomException("CAN NOT FIND ROOM ID=" + roomId));
}

protected User findUserByName(String roomId, String name) {
Expand Down

0 comments on commit b01abd4

Please sign in to comment.