Skip to content

[πŸš€ 사이클2 - λ―Έμ…˜ (κΈ°λ¬Ό ν™•μž₯ + DB 적용)] 벨둜 λ―Έμ…˜ μ œμΆœν•©λ‹ˆλ‹€.#270

Open
juntae6942 wants to merge 91 commits intowoowacourse:juntae6942from
juntae6942:step2
Open

[πŸš€ 사이클2 - λ―Έμ…˜ (κΈ°λ¬Ό ν™•μž₯ + DB 적용)] 벨둜 λ―Έμ…˜ μ œμΆœν•©λ‹ˆλ‹€.#270
juntae6942 wants to merge 91 commits intowoowacourse:juntae6942from
juntae6942:step2

Conversation

@juntae6942
Copy link
Copy Markdown

@juntae6942 juntae6942 commented Mar 31, 2026

체크 리슀트

  • λ―Έμ…˜μ˜ ν•„μˆ˜ μš”κ΅¬μ‚¬ν•­μ„ λͺ¨λ‘ κ΅¬ν˜„ν–ˆλ‚˜μš”?
  • Gradle testλ₯Ό μ‹€ν–‰ν–ˆμ„ λ•Œ, λͺ¨λ“  ν…ŒμŠ€νŠΈκ°€ μ •μƒμ μœΌλ‘œ ν†΅κ³Όν–ˆλ‚˜μš”?
  • μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ΄ μ •μƒμ μœΌλ‘œ μ‹€ν–‰λ˜λ‚˜μš”?

μ•„λž˜μ˜ ν™˜κ²½λ³€μˆ˜λ₯Ό μ‚¬μš©ν•˜μ—¬ h2 DB둜 μ—°λ™ν•˜μ˜€μŠ΅λ‹ˆλ‹€.

db.url=jdbc:h2:./janggi;AUTO_SERVER=TRUE;INIT=RUNSCRIPT FROM 'classpath:init.sql'
db.username=sa
db.password=

ν˜„μž¬ μƒˆλ‘œμš΄ μž₯기판으둜 κ²Œμž„μ„ ν•  것인지 μ•„λ‹ˆλ©΄ 기쑴의 κ²Œμž„νŒμ„ μ°Ύμ•„μ„œ ν•  것인지 μž…λ ₯λ°›λŠ” 둜직으둜 κ΅¬ν˜„ν•˜μ˜€μŠ΅λ‹ˆλ‹€.
λ‹€λ§Œ κΈ°μ‘΄ μž₯기판 리슀트 μ‘°νšŒλŠ” κ΅¬ν˜„ν•˜μ§€ λͺ»ν•˜μ˜€μŠ΅λ‹ˆλ‹€. 이점 μ°Έκ³ ν•΄μ£Όμ‹œλ©΄ κ°μ‚¬ν•˜κ² μŠ΅λ‹ˆλ‹€.

좜λ ₯ μ˜ˆμ‹œ

μƒˆλ‘œμš΄ μž₯κΈ° κ²Œμž„μ„ μ‹œμž‘ν•˜μ‹œκ² μŠ΅λ‹ˆκΉŒ?(y,n)
n
κΈ°μ‘΄ μž₯κΈ° κ²Œμž„λ°©IDλ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš”.
1
μž₯κΈ° κ²Œμž„μ„ μ‹œμž‘ν•©λ‹ˆλ‹€. μ΄ˆλ‚˜λΌλΆ€ν„° μ‹œμž‘ν•˜κ³ , μ™Όμͺ½ μ•„λž˜λ₯Ό (0,0)으둜 ν•©λ‹ˆλ‹€.
[+, 마, 상, 사, +, 사, 상, 마, μ°¨]
[+, +, +, +, μž₯, +, +, +, +]
[+, 포, +, +, +, +, +, 포, +]
[+, +, μ‘Έ, +, μ‘Έ, +, μ‘Έ, +, μ‘Έ]
[+, +, +, +, +, +, +, +, +]
[μ°¨, +, +, +, +, +, +, +, +]
[+, μ‘Έ, μ‘Έ, +, μ‘Έ, +, μ‘Έ, +, μ‘Έ]
[+, 포, +, +, +, +, +, 포, +]
[+, +, +, +, μž₯, +, +, +, +]
[+, 마, 상, 사, +, 사, 상, 마, μ°¨]
ν•œ : 71.5, 초 : 59.0
ν˜„μž¬ μ΄ˆλ‚˜λΌμ˜ μ°¨λ‘€μž…λ‹ˆλ‹€.
움직일 기물의 μΆœλ°œμ§€ μ’Œν‘œ μž…λ ₯ν•΄ μ£Όμ„Έμš”.(μ‰Όν‘œ κΈ°μ€€μœΌλ‘œ 뢄리, ex. 0,0) : 

μ–΄λ–€ 뢀뢄에 μ§‘μ€‘ν•˜μ—¬ 리뷰해야 ν• κΉŒμš”?

1μ°¨ ν”Όλ“œλ°±μ„ 기반으둜 μ½”λ“œλ₯Ό μˆ˜μ •ν•˜μ˜€μŠ΅λ‹ˆλ‹€. μ œμ•ˆ μ£Όμ…¨λ˜ λ‚΄μš©μ„ κ³ λ―Όν•΄μ„œ 좔상 골격 클래슀λ₯Ό ν™•μ‹€ν•˜κ²Œ μ‚¬μš©ν•˜λŠ” λ°©ν–₯을 λͺ¨μƒ‰ν•΄μ„œ μ μš©ν•΄λ³΄μ•˜μŠ΅λ‹ˆλ‹€.

  1. 사이클 2μ—μ„œλŠ” Domain에 Controller와 Serviceλ₯Ό μΆ”κ°€ν•˜μ˜€λŠ”λ°, 각각의 λ ˆμ΄μ–΄κ°€ μ˜¬λ°”λ₯Έ μ—­ν• κ³Ό μ±…μž„μ„ ν•˜κ³  μžˆλŠ”μ§€ κΆκΈˆν•©λ‹ˆλ‹€.
  2. Repositoryλ₯Ό κ΅¬ν˜„ν•˜λ©΄μ„œ DAOλ₯Ό μ‚¬μš©ν•˜μ—¬ JDBC 기반으둜 κ΅¬ν˜„ν•˜μ˜€λŠ”λ°, μ˜¬λ°”λ₯Έ 방식인지 κΆκΈˆν•©λ‹ˆλ‹€.
  3. DB에 μ €μž₯ν•˜λŠ” μ‹œμ μ΄ κ²Œμž„μ΄ μ’…λ£Œλ˜μ—ˆμ„ λ•Œ, 맀번 기물을 μ›€μ§μ˜€μ„ λ•Œ μ€‘μ—μ„œ μš”κ΅¬μ‚¬ν•­μ— 이전에 μ§„ν–‰ν•˜λ˜ κ²Œμž„μ„ μ΄μ–΄μ„œ μ§„ν–‰ ν•  수 μžˆμ–΄μ•Ό ν•œλ‹€κ³  ν•˜μ—¬ 정합성을 μœ„ν•΄μ„œ 맀번 기물을 μ›€μ§μ˜€μ„ λ•Œ μ €μž₯ν•˜λŠ” κ²ƒμœΌλ‘œ κ΅¬ν˜„ν•˜μ˜€λŠ”λ°, κ²Œμž„μ„ μ€‘μ§€ν•˜λŠ” μž…λ ₯을 μΆ”κ°€λ‘œ λ°›μ•„μ„œ κ·Έ 경우만 μ €μž₯ν•˜λŠ” 것과 ν˜„μž¬ κ΅¬ν˜„ν•œ 방법 μ€‘μ—μ„œ 각각의 νŠΈλ ˆμ΄λ“œ μ˜€ν”„(μ •ν•©μ„±κ³Ό DB μ—°κ²° μ΅œμ†Œν™” 쀑)κ°€ μžˆμ„ 것 같은데 아루라면 μ–΄λ–€ μ‹œμ μ— μ €μž₯ν•˜λŠ” λ°©μ‹μœΌλ‘œ ν•  것인지 κΆκΈˆν•©λ‹ˆλ‹€.

Copy link
Copy Markdown
Member

@donghoony donghoony left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

벨둜 μ•ˆλ…•ν•˜μ„Έμš”~ μ €λ²ˆ 사이클도 κ·Έλ ‡κ³  λŠ¦μ€ μ‹œκ°„μž„μ—λ„ λΉ λ₯΄κ²Œ 리뷰λ₯Ό λ°˜μ˜ν•΄μ£Όμ…¨λ„€μš”. νŠΈλžœμž­μ…˜μ΄λΌλŠ” κ°œλ…μ„ κ°€μ Έμ™€μ„œ κ΅¬ν˜„ν•΄μ£Όμ…”μ„œ 깜짝 λ†€λžμŠ΅λ‹ˆλ‹€. 그와 λ™μ‹œμ— νŠΈλžœμž­μ…˜μ˜ μ±…μž„μ€? 인프라 레벨의 μΆ”μƒν™”λŠ”? 와 같은 객체/κ³„μΈ΅μ˜ μ±…μž„ μ§ˆλ¬Έμ„ 더 λ¬Όμ–΄μ™”μ–΄μš”. 😈

λ‚¨κ²¨λ“œλ¦° 리뷰λ₯Ό 잘 ν™•μΈν•΄λ³΄μ‹œκ³  λ°˜μ˜ν•΄μ£Όμ„Έμš”. λ‹€μŒ μš”μ²­ λ•Œ λ‹€μ‹œ λ§Œλ‚˜μš”~!

}

@Override
public JanggiGame loadGame(Long gameRoomId) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gameRoomIdλ₯Ό primitiveλ₯Ό λ°›μœΌλ©΄ μ•„λž˜ 검증이 λΆˆν•„μš”ν•˜μ§€ μ•Šμ„κΉŒμš”? μœ„ updateμ—μ„œλŠ” 검증을 ν•˜μ§€ μ•Šκ³  μžˆμ–΄μ„œ, 이럴 λ•Œμ—λŠ” 였히렀 받을 λ•Œ μ œν•œμ„ λ‘λŠ” 게 μΈμ§€λΆ€ν•˜λ„ 쀄어듀 것 κ°™μŠ΅λ‹ˆλ‹€.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image

daoλ‚˜ repositoryλ₯Ό λ―Ώκ³  μ“Έ 수 μžˆμ„κΉŒμš”? 😒

connection.commit();
return result;
} catch (SQLException e) {
connection.rollback();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Dao의 μ˜ˆμ™Έκ°€ 둀백으둜 μ§„ν–‰λ κΉŒμš”? 😈
  • 이 ν•¨μˆ˜λŠ” SQLException을 λ˜μ§€λ‚˜μš”?
  • 이전 λ¦¬λ·°μ—μ„œλŠ” SQLException을 Daoμ—μ„œ λ˜μ§€λŠ” μ±…μž„μ— λŒ€ν•΄μ„œ μ—¬μ­€λ΄€μ—ˆμŠ΅λ‹ˆλ‹€. 상황이 바뀐 μ§€κΈˆμ€ SQLException을 μ™ΈλΆ€λ‘œ λ˜μ§€λ©΄, 이λ₯Ό λ°›μ•„ μ–΄λ–€ 역할을 ν•  수 μžˆμ–΄λ³΄μ΄λŠ” κ²ƒμ²˜λŸΌ λ³΄μ΄λ„€μš”. 이처럼 μ½”λ“œ λ§₯락은 ν˜„μž¬ μ½”λ“œκ°€ μ–΄λ–»κ²Œ μ§œμ—¬μ‘ŒλŠ”μ§€μ— 따라 μœ μ—°ν•˜κ²Œ λ³€ν•œλ‹΅λ‹ˆλ‹€!


import java.util.Arrays;

public enum GameCommand {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ‘πŸ» ν‘œν˜„ κ³„μΈ΅μ—μ„œμ˜ 객체λ₯Ό 잘 생성해주셨닀고 μƒκ°ν•©λ‹ˆλ‹€. μ μ ˆν•œ μ±…μž„λ„ κ°€μ Έκ°€κ³  μžˆλ„€μš”

Comment on lines +26 to +28
private final DataConnectionManager manager;
private final GameRoomDao roomDao = new GameRoomDao();
private final PiecesDao piecesDao = new PiecesDao();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(ꢁ금) managerλŠ” μ™ΈλΆ€μ—μ„œ λ°›μ•„λ‚΄λŠ”λ°, Dao듀은 λ‚΄λΆ€μ—μ„œ new둜 μƒμ„±ν•˜λŠ” μ΄μœ κ°€ μžˆλ‚˜μš”?

Console.close();
}

private void playGame(Long roomId) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private void playGame(Long roomId) {
private void playGame(long roomId) {

μ „μ²΄μ μœΌλ‘œ ν™•μΈν•΄μ£Όμ„Έμš”. ν•œ 번 ν—ˆμš©ν•˜κ²Œ λ˜λŠ” nullable은 λŒμ΄ν‚¬ 수 μ—†κ²Œ 되곀 ν•©λ‹ˆλ‹€.

moveStatement.executeUpdate();
}

public List<PieceData> findAllByRoomId(Long roomId, Connection connection) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 μΉœκ΅¬λŠ” μ˜ˆμ™Έλ₯Ό λž˜ν•‘ν•˜κ³  μžˆλŠ”λ° 톡일성 μ§€μΌœμ£Όμ„Έμš”~!


public class GameRoomDao {

public Long save(GameRoomData data, Connection connection) throws SQLException {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

νŠΈλžœμž­μ…˜μ΄ λ„μž…λ˜λ©΄μ„œ λ³€ν™˜μ˜ μ±…μž„μ„ λ°–μœΌλ‘œ λ„˜κΈ΄ μ΄μœ κ°€ 생긴 것 κ°™μŠ΅λ‹ˆλ‹€. πŸ‘πŸ»

OutputView.printWinner(game.getWinner());
Console.close();
public static void main(String[] args) throws SQLException {
Server server = Server.createTcpServer("-tcp", "-tcpAllowOthers", "-tcpPort", "9092").start();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(선택) μ‹œκ°„μ΄ 많이 λ‚¨μœΌμ‹œκ±°λ‚˜ μ‚¬μ΄ν΄μ˜ μ—°μž₯μ„ μœΌλ‘œ μƒκ°ν•˜μ‹ λ‹€λ©΄ 도전해보셔도 μ’‹κ² μŠ΅λ‹ˆλ‹€ γ…Žγ…Ž

JanggiGame game = repository.loadGame(roomId);
game.play(from, to);
repository.update(roomId, from, to, game);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR μ§ˆλ¬Έμ— λŒ€ν•œ 의견) playκ°€ 객체λ₯Ό λ³€ν˜•ν•˜κ³  μžˆμœΌλ‹ˆ, 이λ₯Ό λ°˜ν™˜ν•˜μ—¬ ν™œμš©ν•˜λ©΄ DB λΆ€ν•˜λ₯Ό 쀄일 수 μžˆμ§€ μ•Šμ„κΉŒμš”? λ™μ‹œμ„±κ³Ό DB λΆ€ν•˜ λͺ¨λ‘ μ±™κΈΈ 수 μžˆμ„ 것 κ°™μ•„μš”.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants