Skip to content

[๐Ÿš€ ์‚ฌ์ดํด2 - ๋ฏธ์…˜ (๊ธฐ๋ฌผ ํ™•์žฅ + DB ์ ์šฉ)] ๋กœ์น˜ ๋ฏธ์…˜ ์ œ์ถœํ•ฉ๋‹ˆ๋‹ค.#343

Open
bhoon716 wants to merge 40 commits intowoowacourse:bhoon716from
bhoon716:step2

Conversation

@bhoon716
Copy link
Copy Markdown

@bhoon716 bhoon716 commented Apr 9, 2026

์ฒดํฌ ๋ฆฌ์ŠคํŠธ

  • ๋ฏธ์…˜์˜ ํ•„์ˆ˜ ์š”๊ตฌ์‚ฌํ•ญ์„ ๋ชจ๋‘ ๊ตฌํ˜„ํ–ˆ๋‚˜์š”?
  • Gradle test๋ฅผ ์‹คํ–‰ํ–ˆ์„ ๋•Œ, ๋ชจ๋“  ํ…Œ์ŠคํŠธ๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ํ†ต๊ณผํ–ˆ๋‚˜์š”?
  • ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์ •์ƒ์ ์œผ๋กœ ์‹คํ–‰๋˜๋‚˜์š”?

์–ด๋–ค ๋ถ€๋ถ„์— ์ง‘์ค‘ํ•˜์—ฌ ๋ฆฌ๋ทฐํ•ด์•ผ ํ• ๊นŒ์š”?

DB์— ์žˆ๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ค์‹œ ๋„๋ฉ”์ธ์œผ๋กœ ์กฐ๋ฆฝ์„ ์–ด๋–ป๊ฒŒ ํ•˜๋Š”๊ฒŒ ์ข‹์„์ง€๊ฐ€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค.

์ง€๊ธˆ ๊ตฌํ˜„ํ•œ ๋ฐฉ์‹์€ ๋„๋ฉ”์ธ์ด ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ๋ชจ๋ฅด๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด์„œ, ๋ ˆํฌ์ง€ํ† ๋ฆฌ ๋‚ด์—์„œ ํ•˜๋‚˜ํ•˜๋‚˜ ์กฐ๋ฆฝํ•˜๊ณ  ์žˆ๋Š”๋ฐ,
์ด๋Ÿฐ ๋ฐฉ์‹์€ ์ฒ˜์Œ ์‚ฌ์šฉํ•ด๋ด์„œ ์ œ๋Œ€๋กœ ํ–ˆ๋Š”์ง€ ๋ชจ๋ฅด๊ฒ ๋„ค์š”.. ํ•ด๋‹น ๋ถ€๋ถ„ ์ง‘์ค‘์ ์œผ๋กœ ๋ด์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!

bhoon716 added 19 commits April 6, 2026 22:43
Copy link
Copy Markdown

@Gomding Gomding left a comment

Choose a reason for hiding this comment

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

์•ˆ๋…•ํ•˜์„ธ์š” ๋กœ์น˜!
์‚ฌ์ดํด2 ๊ตฌํ˜„ํ•˜๋А๋ผ ๊ณ ์ƒํ•˜์…จ์–ด์š” ๐Ÿ‘
์ „์ฒด์ ์œผ๋กœ ์ž˜ ๊ตฌํ˜„ํ•ด์ฃผ์…จ๋„ค์š”
์ฝ”๋ฉ˜ํŠธ ๋‚จ๊ฒผ์œผ๋‹ˆ ์˜๊ฒฌ ๋‚˜๋ˆ ๋ณด๋ฉด ์ข‹๊ฒ ์–ด์š”~

๊ถ๊ธˆํ•˜์‹  ๋ถ€๋ถ„ ์žˆ์œผ๋ฉด ์–ธ์ œ๋“  DM์ด๋‚˜ ์ฝ”๋ฉ˜ํŠธ ๋‚จ๊ฒจ์ฃผ์„ธ์š”~

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

DB์— ์žˆ๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ค์‹œ ๋„๋ฉ”์ธ์œผ๋กœ ์กฐ๋ฆฝ์„ ์–ด๋–ป๊ฒŒ ํ•˜๋Š”๊ฒŒ ์ข‹์„์ง€๊ฐ€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค.

์ง€๊ธˆ ๊ตฌํ˜„ํ•œ ๋ฐฉ์‹์€ ๋„๋ฉ”์ธ์ด ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ๋ชจ๋ฅด๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด์„œ, ๋ ˆํฌ์ง€ํ† ๋ฆฌ ๋‚ด์—์„œ ํ•˜๋‚˜ํ•˜๋‚˜ ์กฐ๋ฆฝํ•˜๊ณ  ์žˆ๋Š”๋ฐ,
์ด๋Ÿฐ ๋ฐฉ์‹์€ ์ฒ˜์Œ ์‚ฌ์šฉํ•ด๋ด์„œ ์ œ๋Œ€๋กœ ํ–ˆ๋Š”์ง€ ๋ชจ๋ฅด๊ฒ ๋„ค์š”.. ํ•ด๋‹น ๋ถ€๋ถ„ ์ง‘์ค‘์ ์œผ๋กœ ๋ด์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!

๋จผ์ € ๋กœ์น˜๋Š” ์–ด๋–ค ์˜๋„๋กœ ๊ตฌํ˜„ํ•˜์…จ๋Š”์ง€ ๊ถ๊ธˆํ•ด์š”!

  • ๋„๋ฉ”์ธ์ด ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ๋ชฐ๋ผ์•ผํ•˜๋Š” ์ด์œ ๋Š” ๋ฌด์—‡์ผ๊นŒ์š”? ์–ด๋–ค ์žฅ์ ์ด ์žˆ๋‚˜์š”?
    • ๋„๋ฉ”์ธ์ด ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ์•Œ๋ฉด ์–ด๋–ค ๋‹จ์ ์ด ์žˆ์„๊นŒ์š”!
  • ๋ ˆํฌ์ง€ํ† ๋ฆฌ ๋‚ด์—์„œ ํ•˜๋‚˜ํ•˜๋‚˜ ์กฐ๋ฆฝํ•˜๊ณ  ์žˆ๋Š” ๋ฐฉ์‹๋ง๊ณ  ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•๋„ ๊ณ ๋ฏผํ•ด๋ณด์…จ์„๊นŒ์š”?
    • ํ•ด๋‹น ๋ฐฉ์‹์„ ์„ ํƒํ•˜์‹  ์ด์œ ๋„ ๊ถ๊ธˆํ•ด์š”!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

  1. ๋„๋ฉ”์ธ์ด ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ์•Œ๊ฒŒ ๋˜๋ฉด ๋„๋ฉ”์ธ ์™ธ๋ถ€์˜ ๋ณ€๊ฒฝ์ด ๋„๋ฉ”์ธ๊นŒ์ง€ ์˜ํ–ฅ์„ ๋ผ์นœ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค. ๋งŒ์•ฝ ํ…Œ์ด๋ธ” ๊ตฌ์กฐ๊ฐ€ ๋ณ€๊ฒฝ๋˜๊ฑฐ๋‚˜, Jdbc์—์„œ ๋‹ค๋ฅธ ๋ฐฉ์‹์œผ๋กœ ๋ณ€๊ฒฝ๋˜๋Š” ์ผ์ด ๋ฐœ์ƒํ–ˆ์„ ๋•Œ, ๋„๋ฉ”์ธ์—๋„ ์˜ํ–ฅ์„ ๋ผ์น  ์ˆ˜ ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค.
    ๋งŒ์•ฝ ๋ชจ๋ฅธ๋‹ค๋ฉด ์œ„์™€ ๊ฐ™์€ ๋ณ€๊ฒฝ์—๋„ ๋„๋ฉ”์ธ์ด ์ˆ˜์ •๋˜์ง€ ์•Š์•„์„œ ์œ ์—ฐํ•œ ์ฝ”๋“œ๋กœ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  2. ๋‹ค๋ฅธ ๋ฐฉ์‹์ด ์ž˜ ๋– ์˜ค๋ฅด์ง€ ์•Š์•„์„œ ์ผ๋‹จ Repository์—์„œ ResultSet์„ ๊บผ๋‚ด์˜ค๊ณ , ํ•„์š”ํ•œ ํƒ€์ž…์œผ๋กœ ๋งคํ•‘ํ•˜๊ณ , ๋‹ค์‹œ ๊ฐ์ฒด๋กœ ์กฐ๋ฆฝํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ์ง„ํ–‰ํ–ˆ์Šต๋‹ˆ๋‹ค. ์ง€๊ธˆ ๋– ์˜ค๋ฅด๋Š” ์ƒ๊ฐ์œผ๋กœ๋Š” Mapper ํด๋ž˜์Šค๋ฅผ ๋”ฐ๋กœ ๋‘๋ฉด ์–ด๋А์ •๋„๋Š” ๋ถ„๋ฆฌ๊ฐ€ ๊ฐ€๋Šฅํ•  ๊ฒƒ ๊ฐ™๊ธด ํ•ฉ๋‹ˆ๋‹ค.


import java.util.List;

public record Direction(int column, int row) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

enum ์œผ๋กœ ํ‘œํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์žˆ๊ฒ ๋„ค์š”! ๐Ÿ˜ƒ

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

enum์œผ๋กœ ๋ฐ”๊พธ๋ฉด Direction.of(col, row)๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ๋ชปํ•ด์„œ, ๋งŒ์•ฝ์— ์ •์˜ํ•˜์ง€ ์•Š์€ Direction์ด ํ•„์š”ํ•ด์ง€๋ฉด ์ƒˆ๋กœ์šด enum ํ•„๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ด์•ผํ•ด์„œ ์˜คํžˆ๋ ค ๋” ๋ถˆํŽธํ•  ๊ฒƒ ๊ฐ™๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“ญ๋‹ˆ๋‹ค!
์ง€๊ธˆ๋„ '์ƒ'์ด๋ž‘ '๋งˆ'์—์„œ (2, 3), (1, 2) ๋“ฑ๋“ฑ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š”๋ฐ, ๋ชจ๋‘ enum์œผ๋กœ ๊ด€๋ฆฌํ•˜๊ธฐ์—” ์กฐ๊ธˆ ๋ฒˆ๊ฑฐ๋กญ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

enum์œผ๋กœ ๋ฐ”๊พธ๋ฉด Direction.of(col, row)๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ๋ชปํ•ด์„œ, ๋งŒ์•ฝ์— ์ •์˜ํ•˜์ง€ ์•Š์€ Direction์ด ํ•„์š”ํ•ด์ง€๋ฉด ์ƒˆ๋กœ์šด enum ํ•„๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ด์•ผํ•ด์„œ ์˜คํžˆ๋ ค ๋” ๋ถˆํŽธํ•  ๊ฒƒ ๊ฐ™๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“ญ๋‹ˆ๋‹ค!

Direction ์— enum ์š”์†Œ ์ถ”๊ฐ€ํ•˜๋Š”๊ฒƒ VS ์ƒˆ๋กœ์šด Piece ๊ฐ์ฒด ๋˜๋Š” ๊ธฐ์กด๊ฒƒ์— ์ƒˆ๋กœ์šด ๋ฐฉํ–ฅ ์ง์ ‘ ์„ ์–ธํ•˜๊ธฐ
๋‘˜ ๋‹ค ๋น„์Šทํ•œ ์ฝ”๋“œ๊ฐ€ ๋ฐœ์ƒํ•  ๊ฒƒ ๊ฐ™์€๋ฐ enum ์— ์š”์†Œ ์ถ”๊ฐ€ํ•˜๋Š”๊ฒƒ๋งŒ ๋ถˆํŽธํ•œ ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”?
๋กœ์น˜๊ฐ€ ๋ถˆํŽธํ•จ์„ ๋А๋ผ๋Š” ์ด์œ ๊ฐ€ ๋‹จ์ˆœํžˆ ํ•„๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ด์„œ๊ฐ€ ๋งž์„๊นŒ? ๋ผ๋Š” ์˜๋ฌธ์ด ๋“ค์–ด์„œ์š”~

(enum ๋ณ€๊ฒฝ์€ ๋ฐ˜์˜ํ•˜์ง€ ์•Š์œผ์…”๋„ ์ข‹์•„์š”! ์˜๊ฒฌ๋งŒ ๊ณต์œ ํ•ด์ฃผ์„ธ์š” ใ…Žใ…Ž)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

์žฅ๊ธฐ ๋ฏธ์…˜์—์„œ๋Š” ๊ทธ๋Ÿด ์ผ์ด ์—†์ง€๋งŒ, ๋งŒ์•ฝ์— ํ”„๋กœ๊ทธ๋žจ์—์„œ ๋™์ ์œผ๋กœ ๋ณ€ํ•˜๋Š” Direction์ด ํ•„์š”ํ•ด์ง€๋ฉด enum์œผ๋กœ๋Š” ํ•ด๋‹น Direction์œผ๋กœ ๊ด€๋ฆฌํ•  ์ˆ˜ ์—†๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.
๋˜ํ•œ, ํ•„์š”ํ•œ Direction์ด ๋” ์ถ”๊ฐ€๊ฐ€ ๋œ๋‹ค๋ฉด, ์ œ๊ฐ€ ์‚ฌ์šฉํ•œ ๋ฐฉ์‹์—์„œ๋Š” ํ•„์š”ํ•œ ๋ถ€๋ถ„์— Direction.of(col, row)๋งŒ ์ž‘์„ฑ๋งŒ ํ•ด์ฃผ๋ฉด ๋˜๋Š”๋ฐ, enum ๋ฐฉ์‹์€ ํ•ด๋‹น Direction์„ ์˜๋ฏธํ•˜๋Š” enum ์š”์†Œ๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ , ํ•„์š”ํ•œ ๋ถ€๋ถ„์• ์„œ ํ•ด๋‹น ์š”์†Œ๋ฅผ ๊ฐ€์ ธ์™€์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋” ๋ถˆํŽธํ•˜๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค!

๊ธฐ์กด ๋ฐฉ์‹

// ํ˜ธ์ถœ์ž
Positon next = now.move(Direction.of(2, 2));

enum ๋ฐฉ์‹

// enum
public enum Direction {
  // ์ƒ๋žต..
  RIGHT_TWO_DOWN_TWO(2, 2);
}
// ํ˜ธ์ถœ์ž
Position next = now.move(Direction.RIGHT_TWO_DOWN_TWO);

import domain.piece.Team;
import java.util.List;

public interface GameState {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

์ƒํƒœ ํŒจํ„ด์„ ์‚ฌ์šฉํ•˜์‹ ๊ฒƒ ๊ฐ™๋„ค์š”!
์ƒํƒœ ํŒจํ„ด์ด ํ•„์š”ํ•˜๋‹ค๊ณ  ํŒ๋‹จํ•˜์‹  ์ด์œ ๊ฐ€ ๊ถ๊ธˆํ•ด์š”~

์ƒํƒœ ํŒจํ„ด์„ ์‚ฌ์šฉํ•˜์ง€์•Š๊ณ  ๊ตฌํ˜„ํ•˜๋Š”๊ฒƒ๊ณผ ์–ด๋–ค ์ฐจ์ด๊ฐ€ ์žˆ์—ˆ๋‚˜์š”?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

์ƒํƒœํŒจํ„ด์„ ์‚ฌ์šฉํ•œ ๊ฐ€์žฅ ํฐ ์ด์œ ๋Š” ์‚ฌ์‹ค ์ƒํƒœํŒจํ„ด์„ ์‚ฌ์šฉํ•ด๋ณด๊ณ  ์‹ถ์–ด์„œ ์˜€์Šต๋‹ˆ๋‹ค.
์‹ค์ œ๋กœ ์‚ฌ์ดํด 1์—์„œ๋Š” ์ƒํƒœํŒจํ„ด ์—†์ด ๊ตฌํ˜„ํ•˜๊ณ  ์žˆ์—ˆ๋Š”๋ฐ, ์‚ฌ์ดํด 2์—์„œ ์Šน๋ฆฌ ์กฐ๊ฑด์„ ๊ตฌํ˜„ํ•˜๋ฉด์„œ ์ƒํƒœํŒจํ„ด์„ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.

์‚ฌ์‹ค ์ƒํƒœํŒจํ„ด์„ ์ด์šฉํ•ด๋„ ์•„์ง๊นŒ์ง€๋Š” ํฐ ์ฐจ์ด๋Š” ๋ชป ๋А๊ผˆ์Šต๋‹ˆ๋‹ค.
๋ฌผ๋ก  ๋‹ค๋ฅธ ์ƒํƒœ๊ฐ€ ์ถ”๊ฐ€๋˜๋ฉด ์ž์—ฐ์Šค๋Ÿฝ๊ณ  ์‰ฝ๊ฒŒ ์ถ”๊ฐ€๋ฅผ ํ•  ์ˆœ ์žˆ๊ฒ ์ง€๋งŒ, ํ˜„์žฌ๋Š” ๊ทธ๋Ÿด ์ผ์ด ์—†์–ด์„œ ๊ตณ์ด ์•ˆ ๋„ฃ์–ด๋„ ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

์ƒํƒœํŒจํ„ด์„ ์‚ฌ์šฉํ•œ ๊ฐ€์žฅ ํฐ ์ด์œ ๋Š” ์‚ฌ์‹ค ์ƒํƒœํŒจํ„ด์„ ์‚ฌ์šฉํ•ด๋ณด๊ณ  ์‹ถ์–ด์„œ ์˜€์Šต๋‹ˆ๋‹ค.

ํ•™์Šต์„ ์œ„ํ•œ ๋„์ž… ๐Ÿ’ฏ ๐Ÿ’ฏ ๐Ÿ’ฏ

์ƒํƒœํŒจํ„ด ๋„์ž… ํ›„ ๋ณต์žก๋„๊ฐ€ ์˜ฌ๋ผ๊ฐ”๋‹ค๊ณ  ๋А๋‚€์ ์€ ์—†์—ˆ์„๊นŒ์š”?
๊ธฐ์กด ์ฝ”๋“œ๊ฐ€ ๋” ๊ฐ€๋…์„ฑ์ด ์ข‹์•˜๋‹ค๋˜์ง€..

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

์žฅ๊ธฐ์—์„œ๋Š” ๊ธฐ์กด ์ฝ”๋“œ๊ฐ€ ์˜คํžˆ๋ ค ๋” ์ฝ๊ธฐ ์‰ฌ์› ๊ณ , ์ƒํƒœ ํŒจํ„ด์„ ๋„์ž…ํ–ˆ์„ ๋•Œ ์–ป์„ ์ˆ˜ ์žˆ๋Š” ์ด์ ๋„ ํฌ์ง€ ์•Š์•˜๋˜ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
์˜คํžˆ๋ ค State๋ฅผ ๋ณ„๋„๋กœ ๊ด€๋ฆฌํ•ด์•ผ ํ•ด์„œ ์ „์ฒด์ ์ธ ๋ณต์žก๋„๋งŒ ์กฐ๊ธˆ ๋†’์•„์ง„ ๋А๋‚Œ์ด์—ˆ์Šต๋‹ˆ๋‹ค.
๊ทธ๋‚˜๋งˆ ๊ธ์ •์ ์ด์—ˆ๋˜ ์ ์€ Controller๊ฐ€ Team์„ ์ง์ ‘ ๊ด€๋ฆฌํ•˜์ง€ ์•Š๊ฒŒ ๋˜๋ฉด์„œ, ๊ทธ ๋ถ€๋ถ„์ด ์•ฝ๊ฐ„ ๋” ๊ฐ„๊ฒฐํ•ด์กŒ๋‹ค๋Š” ์ •๋„์˜€์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ์— ์ƒํƒœ ํŒจํ„ด ๋„์ž…์„ ๋‹ค์‹œ ๊ณ ๋ คํ•˜๊ฒŒ ๋œ๋‹ค๋ฉด, ์ƒํƒœ์˜ ์ˆ˜๊ฐ€ ์ถฉ๋ถ„ํžˆ ๋งŽ์€์ง€, ์ถ”ํ›„์— ์ƒํƒœ์˜ ์ถ”๊ฐ€๋‚˜ ๋ณ€๊ฒฝ์ด ์ž์ฃผ ๋ฐœ์ƒํ•  ๊ฐ€๋Šฅ์„ฑ์ด ์žˆ๋Š”์ง€ ๋“ฑ์„ ๋จผ์ € ๋”ฐ์ ธ๋ณธ ๋’ค ์ ์šฉํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

import java.util.Optional;
import javax.sql.DataSource;

public class JdbcJanggiGameRepository implements JanggiGameRepository {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

์ด๋ฆ„์ด Repository ์ธ ์ด์œ ๋Š” ๋ฌด์—‡์ผ๊นŒ์š”?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

๋„ค์ด๋ฐ์— ํฌ๊ฒŒ ์˜๋ฏธ๋ฅผ ๋‘์ง„ ์•Š์•˜์Šต๋‹ˆ๋‹ค..
DAO, Repository ์ค‘์—์„œ Repository๊ฐ€ ๋” ์นœ์ˆ™ํ•ด์„œ ์‚ฌ์šฉํ•˜๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

์ข€ ๋” ์ฐพ์•„๋ณด๋‹ˆ๊นŒ, ๋‘˜ ๋‹ค ๋น„์Šทํ•˜์ง€๋งŒ DAO๋Š” ์ €์žฅ์†Œ์— ์ ‘๊ทผํ•˜๋Š” ๊ธฐ์ˆ  ์ค‘์ ์ด๊ณ , Repository๋Š” ๋„๋ฉ”์ธ ๊ด€์ ์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ค๋ฃจ๋Š” ์ถ”์ƒํ™” ๊ณ„์ธต์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค.
ํ•ด๋‹น ๊ด€์ ์œผ๋กœ ๋ณด๋ฉด ์ œ๊ฐ€ ๋งŒ๋“  ๊ฑด Repository๋ณด๋‹จ DAO๊ฐ€ ์ข€ ๋” ๋งž๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค!

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

์˜ค.. ์ ์ ˆํ•˜๊ฒŒ ํ•™์Šตํ•ด์ฃผ์…จ๋„ค์š”~
์ง€๊ธˆ ๋‹จ๊ณ„์—์„œ๋Š” ๊ตณ์ด DAO ์™€ Repository ๋ฅผ ๊ตฌ๋ถ„ํ•˜์ง€ ์•Š์•„๋„ ๋œ๋‹ค๊ณ  ์ƒ๊ฐํ•˜์ง€๋งŒ
๋ง์”€ํ•ด์ฃผ์‹ ๋Œ€๋กœ ๋ถ„๋ฆฌํ•ด์„œ ๋ณผ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค :)

Copy link
Copy Markdown
Author

@bhoon716 bhoon716 left a comment

Choose a reason for hiding this comment

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

์•ˆ๋…•ํ•˜์„ธ์š”, ์ฐฐ๋ฆฌ!

์‚ฌ์ดํด 2๋Š” ๊ธˆ๋ฐฉ ๋๋‚ผ ์ˆ˜ ์žˆ์„ ๊ฑฐ๋ผ๊ณ  ์ƒ๊ฐํ–ˆ๋Š”๋ฐ, ๋ง‰์ƒ ์ง„ํ–‰ํ•ด๋ณด๋‹ˆ ์ƒ๊ฐ๋ณด๋‹ค ํ›จ์”ฌ ์–ด๋ ต๊ณ  ๊นŠ๊ฒŒ ๊ณ ๋ฏผํ•  ๋ถ€๋ถ„์ด ๋งŽ๋‹ค๋Š” ๊ฑธ ๋งŽ์ด ๋А๋ผ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ํŠนํžˆ Repository์— ๋Œ€ํ•ด ๊ณ„์† ๊ณ ๋ฏผ๋˜๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

ํ•ญ์ƒ ์ œ๊ฐ€ ์ƒ๊ฐํ•˜์ง€ ๋ชปํ•œ ์ง€์ ์„ ๊ตฌ์ฒด์ ์œผ๋กœ ์งš์–ด์ฃผ์‹œ๊ณ , ๋‹จ์ˆœํžˆ ์ •๋‹ต์„ ์ฃผ๊ธฐ๋ณด๋‹ค ์Šค์Šค๋กœ ๋” ๊ณ ๋ฏผํ•ด๋ณผ ์ˆ˜ ์žˆ๊ฒŒ ์งˆ๋ฌธ ํ˜•ํƒœ๋กœ ์ด๋Œ์–ด์ฃผ์…”์„œ ์ •๋ง ๋งŽ์ด ๋ฐฐ์šฐ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

ํ•ญ์ƒ ๊ผผ๊ผผํ•œ ํ”ผ๋“œ๋ฐฑ ์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!!! ๐Ÿ™‡โ€โ™‚๏ธ


import java.util.List;

public record Direction(int column, int row) {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

enum์œผ๋กœ ๋ฐ”๊พธ๋ฉด Direction.of(col, row)๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ๋ชปํ•ด์„œ, ๋งŒ์•ฝ์— ์ •์˜ํ•˜์ง€ ์•Š์€ Direction์ด ํ•„์š”ํ•ด์ง€๋ฉด ์ƒˆ๋กœ์šด enum ํ•„๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ด์•ผํ•ด์„œ ์˜คํžˆ๋ ค ๋” ๋ถˆํŽธํ•  ๊ฒƒ ๊ฐ™๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“ญ๋‹ˆ๋‹ค!
์ง€๊ธˆ๋„ '์ƒ'์ด๋ž‘ '๋งˆ'์—์„œ (2, 3), (1, 2) ๋“ฑ๋“ฑ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š”๋ฐ, ๋ชจ๋‘ enum์œผ๋กœ ๊ด€๋ฆฌํ•˜๊ธฐ์—” ์กฐ๊ธˆ ๋ฒˆ๊ฑฐ๋กญ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

์ง€๊ธˆ ์žฅ๊ธฐํŒ์˜ ์ตœ๋Œ€/์ตœ์†Œ row, column๋„ ์•Œ๊ณ  ์žˆ์–ด์„œ ๊ถ์„ฑ ์ •๋ณด๋„ ์•Œ๊ณ  ์žˆ์–ด์„œ ๊ดœ์ฐฎ์„ ๊ฒƒ ๊ฐ™๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค.
๋‹ค๋ฅธ ๋ฐฉ์‹์—๋Š” ๋ญ๊ฐ€ ์žˆ์„๊นŒ ์ƒ๊ฐํ•ด๋ณด๊ณ  ๋‹ค๋ฅธ ํฌ๋ฃจ์™€ ์–˜๊ธฐํ•ด๋ดค์Šต๋‹ˆ๋‹ค.

  1. Palace ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ ๋‹ค.
  2. PalaceMoveStrategy ์ถ”์ƒ ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ ๋‹ค.
  3. ๊ธฐ๋ฌผ๋ณ„ PalaceMoveStrategy๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.

1๋ฒˆ ๊ฐ™์€ ๊ฒฝ์šฐ๋Š” Palace ํด๋ž˜์Šค๊ฐ€ Positon์— ๋Œ€ํ•œ ์œ ํ‹ธ ํด๋ž˜์Šค๊ฐ€ ๋˜๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ๋А๊ปด์กŒ๊ณ ,
2, 3๋ฒˆ ๊ฐ™์€ ๊ฒฝ์šฐ๋Š” TDA ์›์น™์— ์œ„๋ฐฐ๋œ๋‹ค๊ณ  ํŒ๋‹จํ–ˆ์Šต๋‹ˆ๋‹ค.

์ง€๊ธˆ Position์ด ์ฑ…์ž„์ด ์ ์ง„ ์•Š์ง€๋งŒ, ๊ฐ์ฒด์ง€ํ–ฅ์ ์œผ๋กœ ๋” ๋‚˜์€ ๋ฐฉํ–ฅ์ด ๋– ์˜ค๋ฅด์ง€ ์•Š์•„์„œ ์ด๋Œ€๋กœ๊ฐ€ ์ตœ์„ ์ด๋ผ๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

  1. ๋„๋ฉ”์ธ์ด ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ์•Œ๊ฒŒ ๋˜๋ฉด ๋„๋ฉ”์ธ ์™ธ๋ถ€์˜ ๋ณ€๊ฒฝ์ด ๋„๋ฉ”์ธ๊นŒ์ง€ ์˜ํ–ฅ์„ ๋ผ์นœ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค. ๋งŒ์•ฝ ํ…Œ์ด๋ธ” ๊ตฌ์กฐ๊ฐ€ ๋ณ€๊ฒฝ๋˜๊ฑฐ๋‚˜, Jdbc์—์„œ ๋‹ค๋ฅธ ๋ฐฉ์‹์œผ๋กœ ๋ณ€๊ฒฝ๋˜๋Š” ์ผ์ด ๋ฐœ์ƒํ–ˆ์„ ๋•Œ, ๋„๋ฉ”์ธ์—๋„ ์˜ํ–ฅ์„ ๋ผ์น  ์ˆ˜ ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค.
    ๋งŒ์•ฝ ๋ชจ๋ฅธ๋‹ค๋ฉด ์œ„์™€ ๊ฐ™์€ ๋ณ€๊ฒฝ์—๋„ ๋„๋ฉ”์ธ์ด ์ˆ˜์ •๋˜์ง€ ์•Š์•„์„œ ์œ ์—ฐํ•œ ์ฝ”๋“œ๋กœ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  2. ๋‹ค๋ฅธ ๋ฐฉ์‹์ด ์ž˜ ๋– ์˜ค๋ฅด์ง€ ์•Š์•„์„œ ์ผ๋‹จ Repository์—์„œ ResultSet์„ ๊บผ๋‚ด์˜ค๊ณ , ํ•„์š”ํ•œ ํƒ€์ž…์œผ๋กœ ๋งคํ•‘ํ•˜๊ณ , ๋‹ค์‹œ ๊ฐ์ฒด๋กœ ์กฐ๋ฆฝํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ์ง„ํ–‰ํ–ˆ์Šต๋‹ˆ๋‹ค. ์ง€๊ธˆ ๋– ์˜ค๋ฅด๋Š” ์ƒ๊ฐ์œผ๋กœ๋Š” Mapper ํด๋ž˜์Šค๋ฅผ ๋”ฐ๋กœ ๋‘๋ฉด ์–ด๋А์ •๋„๋Š” ๋ถ„๋ฆฌ๊ฐ€ ๊ฐ€๋Šฅํ•  ๊ฒƒ ๊ฐ™๊ธด ํ•ฉ๋‹ˆ๋‹ค.

import java.util.Optional;
import javax.sql.DataSource;

public class JdbcJanggiGameRepository implements JanggiGameRepository {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

๋„ค์ด๋ฐ์— ํฌ๊ฒŒ ์˜๋ฏธ๋ฅผ ๋‘์ง„ ์•Š์•˜์Šต๋‹ˆ๋‹ค..
DAO, Repository ์ค‘์—์„œ Repository๊ฐ€ ๋” ์นœ์ˆ™ํ•ด์„œ ์‚ฌ์šฉํ•˜๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

์ข€ ๋” ์ฐพ์•„๋ณด๋‹ˆ๊นŒ, ๋‘˜ ๋‹ค ๋น„์Šทํ•˜์ง€๋งŒ DAO๋Š” ์ €์žฅ์†Œ์— ์ ‘๊ทผํ•˜๋Š” ๊ธฐ์ˆ  ์ค‘์ ์ด๊ณ , Repository๋Š” ๋„๋ฉ”์ธ ๊ด€์ ์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ค๋ฃจ๋Š” ์ถ”์ƒํ™” ๊ณ„์ธต์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค.
ํ•ด๋‹น ๊ด€์ ์œผ๋กœ ๋ณด๋ฉด ์ œ๊ฐ€ ๋งŒ๋“  ๊ฑด Repository๋ณด๋‹จ DAO๊ฐ€ ์ข€ ๋” ๋งž๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค!

Copy link
Copy Markdown

@Gomding Gomding left a comment

Choose a reason for hiding this comment

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

์•ˆ๋…•ํ•˜์„ธ์š” ๋กœ์น˜!
๊ณ ๋ฏผ๊ณผ ํ•จ๊ป˜ ์ž˜ ์ˆ˜์ •ํ•ด์ฃผ์…จ๋„ค์š” ๐Ÿ‘
์ถ”๊ฐ€๋กœ ์ฝ”๋ฉ˜ํŠธ ๋‚จ๊ฒผ์œผ๋‹ˆ ํ™•์ธํ•ด์ฃผ์„ธ์š”!

๊ถ๊ธˆํ•œ ์  ์žˆ์œผ๋ฉด ์–ธ์ œ๋“  DM ์ด๋‚˜ ์ฝ”๋ฉ˜ํŠธ ๋‚จ๊ฒจ์ฃผ์„ธ์š”~

import domain.piece.Team;
import java.util.List;

public interface GameState {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

์ƒํƒœํŒจํ„ด์„ ์‚ฌ์šฉํ•œ ๊ฐ€์žฅ ํฐ ์ด์œ ๋Š” ์‚ฌ์‹ค ์ƒํƒœํŒจํ„ด์„ ์‚ฌ์šฉํ•ด๋ณด๊ณ  ์‹ถ์–ด์„œ ์˜€์Šต๋‹ˆ๋‹ค.

ํ•™์Šต์„ ์œ„ํ•œ ๋„์ž… ๐Ÿ’ฏ ๐Ÿ’ฏ ๐Ÿ’ฏ

์ƒํƒœํŒจํ„ด ๋„์ž… ํ›„ ๋ณต์žก๋„๊ฐ€ ์˜ฌ๋ผ๊ฐ”๋‹ค๊ณ  ๋А๋‚€์ ์€ ์—†์—ˆ์„๊นŒ์š”?
๊ธฐ์กด ์ฝ”๋“œ๊ฐ€ ๋” ๊ฐ€๋…์„ฑ์ด ์ข‹์•˜๋‹ค๋˜์ง€..


import java.util.List;

public record Direction(int column, int row) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

enum์œผ๋กœ ๋ฐ”๊พธ๋ฉด Direction.of(col, row)๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ๋ชปํ•ด์„œ, ๋งŒ์•ฝ์— ์ •์˜ํ•˜์ง€ ์•Š์€ Direction์ด ํ•„์š”ํ•ด์ง€๋ฉด ์ƒˆ๋กœ์šด enum ํ•„๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ด์•ผํ•ด์„œ ์˜คํžˆ๋ ค ๋” ๋ถˆํŽธํ•  ๊ฒƒ ๊ฐ™๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“ญ๋‹ˆ๋‹ค!

Direction ์— enum ์š”์†Œ ์ถ”๊ฐ€ํ•˜๋Š”๊ฒƒ VS ์ƒˆ๋กœ์šด Piece ๊ฐ์ฒด ๋˜๋Š” ๊ธฐ์กด๊ฒƒ์— ์ƒˆ๋กœ์šด ๋ฐฉํ–ฅ ์ง์ ‘ ์„ ์–ธํ•˜๊ธฐ
๋‘˜ ๋‹ค ๋น„์Šทํ•œ ์ฝ”๋“œ๊ฐ€ ๋ฐœ์ƒํ•  ๊ฒƒ ๊ฐ™์€๋ฐ enum ์— ์š”์†Œ ์ถ”๊ฐ€ํ•˜๋Š”๊ฒƒ๋งŒ ๋ถˆํŽธํ•œ ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”?
๋กœ์น˜๊ฐ€ ๋ถˆํŽธํ•จ์„ ๋А๋ผ๋Š” ์ด์œ ๊ฐ€ ๋‹จ์ˆœํžˆ ํ•„๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ด์„œ๊ฐ€ ๋งž์„๊นŒ? ๋ผ๋Š” ์˜๋ฌธ์ด ๋“ค์–ด์„œ์š”~

(enum ๋ณ€๊ฒฝ์€ ๋ฐ˜์˜ํ•˜์ง€ ์•Š์œผ์…”๋„ ์ข‹์•„์š”! ์˜๊ฒฌ๋งŒ ๊ณต์œ ํ•ด์ฃผ์„ธ์š” ใ…Žใ…Ž)

import java.util.Optional;
import javax.sql.DataSource;

public class JdbcJanggiGameRepository implements JanggiGameRepository {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

์˜ค.. ์ ์ ˆํ•˜๊ฒŒ ํ•™์Šตํ•ด์ฃผ์…จ๋„ค์š”~
์ง€๊ธˆ ๋‹จ๊ณ„์—์„œ๋Š” ๊ตณ์ด DAO ์™€ Repository ๋ฅผ ๊ตฌ๋ถ„ํ•˜์ง€ ์•Š์•„๋„ ๋œ๋‹ค๊ณ  ์ƒ๊ฐํ•˜์ง€๋งŒ
๋ง์”€ํ•ด์ฃผ์‹ ๋Œ€๋กœ ๋ถ„๋ฆฌํ•ด์„œ ๋ณผ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค :)

Comment on lines +213 to +216
if ("CHO".equals(currentTeam)) {
return new ChoPlayingState();
}
return new HanPlayingState();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

enum ๊ฐ™์€๊ฒƒ์„ ๋‹ค๋ฃฐ๋•Œ๋Š” else ๋ฅผ ์ฃผ์˜ํ•ด์„œ ์‚ฌ์šฉํ•ด์•ผํ•œ๋‹ค๋Š” ๊ฒƒ์„ ๋ช…์‹ฌํ•ด์ฃผ์„ธ์š”! ใ…Žใ…Ž
else ๋กœ ๋ฐ˜ํ™˜๋˜๋Š” ๊ธฐ๋ณธ๊ฐ’์€ ํŽธ๋ฆฌํ•˜์ง€๋งŒ ๋…์ด ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค~


@Override
public List<Position> getPiecePositions(Board board) {
throw new IllegalStateException("๊ฒŒ์ž„์ด ์ข…๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

์ž˜๋ชป๋œ ์ƒํƒœ๋ผ๋Š”๊ฒŒ ๋งž๋Š”๊ฒƒ ๊ฐ™์ง€๋งŒ UnsupportedOperationException ์„ ๋˜์ง€๋Š”๊ฒŒ ๋” ๋ช…ํ™•ํ•  ์ˆ˜ ์žˆ์–ด์š”~
์ง€์›ํ•˜์ง€ ์•Š๋Š” ๊ธฐ๋Šฅ์ด๋ผ๋Š”๊ฒƒ์„ ์•Œ๋ ค์•ผํ•˜๋Š” ์ƒํ™ฉ์ด๋‹ˆ๊นŒ์š”

Comment on lines +80 to +81
pieces.put(from, Piece.choPieceOf(PieceType.GENERAL));
pieces.put(Position.of(10, 1), Piece.choPieceOf(PieceType.GENERAL));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

cho ์žฅ๊ตฐ์ด ๋‘๊ฐœ์ง€์š”..? ๐Ÿ˜ณ

Image

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Image

import java.sql.Statement;
import javax.sql.DataSource;

public final class DatabaseInitializer {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

์ด๊ฒƒ๋„ ์œ ํ‹ธํด๋ž˜์Šค์ด๋‹ˆ DataSourceFactory ์ฒ˜๋Ÿผ ์ƒ์„ฑ์ž๋ฅผ private ์œผ๋กœ ๋‹ซ์•„๋‘์ฃ !

Comment on lines +80 to +83
gameDao.update(connection, gameId, janggiGame);
pieceDao.deleteByGameId(connection, gameId);
pieceDao.saveAll(connection, gameId, janggiGame.getPieces());
connection.commit();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

piece ๋ถ€๋ถ„ ์—…๋ฐ์ดํŠธ ํ•˜๋Š” ๋ฐฉ์‹์ด ์•„๋‹Œ
์ „์ฒด๋ฅผ ์‚ญ์ œํ•˜๊ณ  ์ „์ฒด๋ฅผ ์žฌ์ €์žฅํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ํ•˜์…จ๊ตฐ์š”!

๋กœ์น˜๋Š” ์–ด๋–ค ์ด์œ ๋กœ ์ด๋Ÿฐ ๋ฐฉ์‹์„ ์„ ํƒํ•˜์…จ๋Š”์ง€ ๊ถ๊ธˆํ•ด์š” :)

+) ์ด๋ฒคํŠธ ์†Œ์‹ฑ ๋ฐฉ์‹๋„ ๊ณ ๋ฏผํ•ด๋ณด์…จ์„๊นŒ์š”?
์•„๋ž˜ ๊ธ€์„ ๊ฐ€๋ณ๊ฒŒ ์ฝ๊ณ  ์ด๋ฒคํŠธ ์†Œ์‹ฑ์— ๋Œ€ํ•ด์„œ ๋ง›๋งŒ ๋ณด์…”๋„ ์ข‹๊ฒ ์–ด์š”!
(CQRS ๊ฐ™์ด ํ˜„์žฌ ๋‹จ๊ณ„์—์„œ ๋„ˆ๋ฌด ๋ฌด๊ฑฐ์šด ์ง€์‹๋“ค์€ ํŒจ์Šคํ•˜์‹œ๊ณ  ์ด๋ฒคํŠธ ์†Œ์‹ฑ์ด ๋ญ์ง€? ๋ผ๋Š”๊ฒƒ๋งŒ ์ง‘์ค‘ํ•ด์„œ ์ฝ์–ด๋ณด์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค! ใ…Žใ…Ž)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ JanggiGame์ด๋‹ค๋ณด๋‹ˆ, ์—…๋ฐ์ดํŠธ ๋œ ํ”ผ์Šค๋งŒ ์ฐพ์•„์„œ ๋ณ€๊ฒฝํ•ด์ฃผ๋Š” ๊ฒƒ๋ณด๋‹ค ์ „์ฒด๋ฅผ ์‚ญ์ œํ•˜๊ณ  ๋‹ค์‹œ ์ €์žฅํ•˜๋Š” ๋กœ์ง์ด ์ข€ ๋” ๊ฐ„ํŽธํ•  ๊ฒƒ ๊ฐ™์•„์„œ ํ•ด๋‹น ๋ฐฉ์‹์„ ์ฑ„ํƒํ–ˆ์Šต๋‹ˆ๋‹ค!

+) ์ด๋ฒคํŠธ ์†Œ์‹ฑ ๊ธ€ ์ž˜ ๋ดค์Šต๋‹ˆ๋‹ค! ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!
์ฒ˜์Œ ๋“ฃ๋Š” ํ‚ค์›Œ๋“œ์˜€๋Š”๋ฐ DB ๋„์ž… ์ดˆ๊ธฐ์— ๊ณ ๋ฏผํ–ˆ๋˜ ๋ถ€๋ถ„๊ณผ ๋น„์Šทํ•ด์„œ ์ดํ•ดํ•˜๋Š”๋ฐ ์–ด๋ ต์ง„ ์•Š์•˜์Šต๋‹ˆ๋‹ค.
์ดˆ๊ธฐ์—๋Š” ๋งจ ์ฒ˜์Œ ์žฅ๊ธฐํŒ ์ดˆ๊ธฐํ™” ์ƒํƒœ๋ž‘ move_history๋ฅผ ์ €์žฅํ•˜๋ ค๊ณ  ํ–ˆ์—ˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฌ๋ฉด ๋‚˜์ค‘์— ๋ฌด๋ฅด๊ธฐ ๊ธฐ๋Šฅ๋„ ์ถ”๊ฐ€ํ•˜๊ธฐ ์‰ฝ๊ณ , ๋งค ๋ผ์šด๋“œ๋ฅผ ์ €์žฅํ•˜๋Š” ๋ฐฉ์‹๋ณด๋‹ค ์ €์žฅ๊ณต๊ฐ„๋„ ๋œ ์ฐจ์ง€ํ•  ์ˆ˜ ์žˆ์–ด์„œ ์ข‹์•˜์Šต๋‹ˆ๋‹ค.
ํ•˜์ง€๋งŒ ๊ฒŒ์ž„์„ ๋ถˆ๋Ÿฌ์˜ฌ ๋•Œ๋งˆ๋‹ค ๋ชจ๋“  move_history๋ฅผ ์žฌ์—ฐํ•ด์•ผ ํ•ด์„œ ํฌ๊ธฐํ–ˆ์—ˆ์Šต๋‹ˆ๋‹ค๐Ÿฅฒ

Comment on lines +45 to +47
} catch (SQLException exception) {
throw new IllegalStateException("๊ฒŒ์ž„์„ ์ €์žฅํ•˜๋Š” ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.");
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

์ด์ „์—๋Š” IllegalStateException ์˜ˆ์™ธ ์ƒ์„ฑ์‹œ cause ์— SQLException ์„ ์ฃผ์ž…ํ•ด์ฃผ์…จ๋Š”๋ฐ
์ด๋ฒˆ์— ์ˆ˜์ •ํ•˜๋ฉด์„œ ์—†์–ด์กŒ๊ตฐ์š” ๐Ÿ˜ณ
์–ด๋–ค ์ด์œ ์—์„œ ์ˆ˜์ •ํ•˜์…จ์„๊นŒ์š”?

๋ฌธ์ œ๊ฐ€ ์žˆ์–ด์„œ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ์„ ๋•Œ SQLException ์˜ ๋‚ด์šฉ์—†์ด ๋””๋ฒ„๊น…์„ ๋น ๋ฅด๊ฒŒ ํ•  ์ˆ˜ ์žˆ์„๊นŒ์š”!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

์ˆ˜์ •ํ•˜๋ฉด์„œ cause๋ฅผ ํ•จ๊ป˜ ๋„˜๊ธฐ๋˜ ๋ถ€๋ถ„์ด ๋น ์กŒ๋„ค์š”.
๋ณ„๋„ ์˜๋„๊ฐ€ ์žˆ์—ˆ๋‹ค๊ธฐ๋ณด๋‹ค๋Š” ๋ฆฌํŒฉํ† ๋ง ๊ณผ์ •์—์„œ ๋†“์ณค์Šต๋‹ˆ๋‹ค...

Long savedId = janggiGameRepository.save(janggiGame);

// then
assertThat(savedId).isEqualTo(1L);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

id ๊ฐ€ 1์ธ์ง€ ๊ฒ€์ฆํ•˜๋Š”๊ฒƒ์€ ์กฐ๊ธˆ ์œ„ํ—˜ํ•  ์ˆ˜ ์žˆ์–ด์š”!
๋‹น์žฅ์€ ์„ฑ๊ณตํ•˜์ง€๋งŒ ํ…Œ์ŠคํŠธ ํ™˜๊ฒฝ, ์ˆœ์„œ์— ๋”ฐ๋ผ ์‹คํŒจํ•  ์ˆ˜๋„ ์žˆ๋Š” ๊ฒ€์ฆ์ž…๋‹ˆ๋‹ค :)

์–ด๋–ป๊ฒŒ ๊ฒ€์ฆํ•˜๋ฉด ์ข‹์„๊นŒ์š”~

+) id ๋งŒ ๊ฒ€์ฆํ•˜๋ฉด ์ •์ƒ์ ์œผ๋กœ ์ €์žฅ๋๋Š”์ง€ ์ถฉ๋ถ„ํžˆ ๊ฒ€์ฆํ•˜๋Š”๊ฒƒ์ผ๊นŒ์š”?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

์ผ๋‹จ savedId != null ์ธ์ง€ ํ™•์ธํ•˜๊ณ , savedId๋กœ ๋‹ค์‹œ findById๋ฅผ ํ–ˆ์„ ๋•Œ ๋™์ผํ•œ ๋ฐ์ดํ„ฐ๊ฐ€ ๋‚˜์˜ค๋Š”์ง€ ํ™•์ธํ•˜๋Š”๊ฒŒ ๋” ์ข‹์„ ๊ฒƒ ๊ฐ™๋„ค์š”!

๋งŒ์•ฝ Mockito๋ฅผ ์“ฐ๋ฉด verify()๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ๋„ ๊ดœ์ฐฎ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

bhoon716 added 11 commits April 12, 2026 18:24
Copy link
Copy Markdown
Author

@bhoon716 bhoon716 left a comment

Choose a reason for hiding this comment

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

๋ฆฌ๋ทฐ ๊ฐ์‚ฌํ•ด์š” ์ฐฐ๋ฆฌ!
์ด๋ฒˆ์—๋„ ๋งŽ์€ ๊นจ๋‹ฌ์Œ๊ณผ ์ƒˆ๋กœ์šด ์ง€์‹๋“ค์„ ๋ฐฐ์šด ๊ฒƒ ๊ฐ™์•„์š”!!
์•„์ง๋„ ๋งŽ์ด ๋ถ€์กฑํ•˜์ง€๋งŒ ๊ณ„์† ๋…ธ๋ ฅํ•ด๋ณผ๊ฒŒ์š”!!


import java.util.List;

public record Direction(int column, int row) {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

์žฅ๊ธฐ ๋ฏธ์…˜์—์„œ๋Š” ๊ทธ๋Ÿด ์ผ์ด ์—†์ง€๋งŒ, ๋งŒ์•ฝ์— ํ”„๋กœ๊ทธ๋žจ์—์„œ ๋™์ ์œผ๋กœ ๋ณ€ํ•˜๋Š” Direction์ด ํ•„์š”ํ•ด์ง€๋ฉด enum์œผ๋กœ๋Š” ํ•ด๋‹น Direction์œผ๋กœ ๊ด€๋ฆฌํ•  ์ˆ˜ ์—†๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.
๋˜ํ•œ, ํ•„์š”ํ•œ Direction์ด ๋” ์ถ”๊ฐ€๊ฐ€ ๋œ๋‹ค๋ฉด, ์ œ๊ฐ€ ์‚ฌ์šฉํ•œ ๋ฐฉ์‹์—์„œ๋Š” ํ•„์š”ํ•œ ๋ถ€๋ถ„์— Direction.of(col, row)๋งŒ ์ž‘์„ฑ๋งŒ ํ•ด์ฃผ๋ฉด ๋˜๋Š”๋ฐ, enum ๋ฐฉ์‹์€ ํ•ด๋‹น Direction์„ ์˜๋ฏธํ•˜๋Š” enum ์š”์†Œ๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ , ํ•„์š”ํ•œ ๋ถ€๋ถ„์• ์„œ ํ•ด๋‹น ์š”์†Œ๋ฅผ ๊ฐ€์ ธ์™€์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋” ๋ถˆํŽธํ•˜๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค!

๊ธฐ์กด ๋ฐฉ์‹

// ํ˜ธ์ถœ์ž
Positon next = now.move(Direction.of(2, 2));

enum ๋ฐฉ์‹

// enum
public enum Direction {
  // ์ƒ๋žต..
  RIGHT_TWO_DOWN_TWO(2, 2);
}
// ํ˜ธ์ถœ์ž
Position next = now.move(Direction.RIGHT_TWO_DOWN_TWO);

import domain.piece.Team;
import java.util.List;

public interface GameState {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

์žฅ๊ธฐ์—์„œ๋Š” ๊ธฐ์กด ์ฝ”๋“œ๊ฐ€ ์˜คํžˆ๋ ค ๋” ์ฝ๊ธฐ ์‰ฌ์› ๊ณ , ์ƒํƒœ ํŒจํ„ด์„ ๋„์ž…ํ–ˆ์„ ๋•Œ ์–ป์„ ์ˆ˜ ์žˆ๋Š” ์ด์ ๋„ ํฌ์ง€ ์•Š์•˜๋˜ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
์˜คํžˆ๋ ค State๋ฅผ ๋ณ„๋„๋กœ ๊ด€๋ฆฌํ•ด์•ผ ํ•ด์„œ ์ „์ฒด์ ์ธ ๋ณต์žก๋„๋งŒ ์กฐ๊ธˆ ๋†’์•„์ง„ ๋А๋‚Œ์ด์—ˆ์Šต๋‹ˆ๋‹ค.
๊ทธ๋‚˜๋งˆ ๊ธ์ •์ ์ด์—ˆ๋˜ ์ ์€ Controller๊ฐ€ Team์„ ์ง์ ‘ ๊ด€๋ฆฌํ•˜์ง€ ์•Š๊ฒŒ ๋˜๋ฉด์„œ, ๊ทธ ๋ถ€๋ถ„์ด ์•ฝ๊ฐ„ ๋” ๊ฐ„๊ฒฐํ•ด์กŒ๋‹ค๋Š” ์ •๋„์˜€์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ์— ์ƒํƒœ ํŒจํ„ด ๋„์ž…์„ ๋‹ค์‹œ ๊ณ ๋ คํ•˜๊ฒŒ ๋œ๋‹ค๋ฉด, ์ƒํƒœ์˜ ์ˆ˜๊ฐ€ ์ถฉ๋ถ„ํžˆ ๋งŽ์€์ง€, ์ถ”ํ›„์— ์ƒํƒœ์˜ ์ถ”๊ฐ€๋‚˜ ๋ณ€๊ฒฝ์ด ์ž์ฃผ ๋ฐœ์ƒํ•  ๊ฐ€๋Šฅ์„ฑ์ด ์žˆ๋Š”์ง€ ๋“ฑ์„ ๋จผ์ € ๋”ฐ์ ธ๋ณธ ๋’ค ์ ์šฉํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

}

String currentTeam = resultSet.getString("current_team");
if (CHO_TEAM_NAME.equals(currentTeam)) {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

์ €๋„ ์ด ๋ฐฉ์‹์ด ๋” ์•ˆ์ „ํ•ด์„œ ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!

Comment on lines +45 to +47
} catch (SQLException exception) {
throw new IllegalStateException("๊ฒŒ์ž„์„ ์ €์žฅํ•˜๋Š” ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.");
}
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

์ˆ˜์ •ํ•˜๋ฉด์„œ cause๋ฅผ ํ•จ๊ป˜ ๋„˜๊ธฐ๋˜ ๋ถ€๋ถ„์ด ๋น ์กŒ๋„ค์š”.
๋ณ„๋„ ์˜๋„๊ฐ€ ์žˆ์—ˆ๋‹ค๊ธฐ๋ณด๋‹ค๋Š” ๋ฆฌํŒฉํ† ๋ง ๊ณผ์ •์—์„œ ๋†“์ณค์Šต๋‹ˆ๋‹ค...

Comment on lines +80 to +81
pieces.put(from, Piece.choPieceOf(PieceType.GENERAL));
pieces.put(Position.of(10, 1), Piece.choPieceOf(PieceType.GENERAL));
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Image

Long savedId = janggiGameRepository.save(janggiGame);

// then
assertThat(savedId).isEqualTo(1L);
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

์ผ๋‹จ savedId != null ์ธ์ง€ ํ™•์ธํ•˜๊ณ , savedId๋กœ ๋‹ค์‹œ findById๋ฅผ ํ–ˆ์„ ๋•Œ ๋™์ผํ•œ ๋ฐ์ดํ„ฐ๊ฐ€ ๋‚˜์˜ค๋Š”์ง€ ํ™•์ธํ•˜๋Š”๊ฒŒ ๋” ์ข‹์„ ๊ฒƒ ๊ฐ™๋„ค์š”!

๋งŒ์•ฝ Mockito๋ฅผ ์“ฐ๋ฉด verify()๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ๋„ ๊ดœ์ฐฎ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

Comment on lines +80 to +83
gameDao.update(connection, gameId, janggiGame);
pieceDao.deleteByGameId(connection, gameId);
pieceDao.saveAll(connection, gameId, janggiGame.getPieces());
connection.commit();
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ JanggiGame์ด๋‹ค๋ณด๋‹ˆ, ์—…๋ฐ์ดํŠธ ๋œ ํ”ผ์Šค๋งŒ ์ฐพ์•„์„œ ๋ณ€๊ฒฝํ•ด์ฃผ๋Š” ๊ฒƒ๋ณด๋‹ค ์ „์ฒด๋ฅผ ์‚ญ์ œํ•˜๊ณ  ๋‹ค์‹œ ์ €์žฅํ•˜๋Š” ๋กœ์ง์ด ์ข€ ๋” ๊ฐ„ํŽธํ•  ๊ฒƒ ๊ฐ™์•„์„œ ํ•ด๋‹น ๋ฐฉ์‹์„ ์ฑ„ํƒํ–ˆ์Šต๋‹ˆ๋‹ค!

+) ์ด๋ฒคํŠธ ์†Œ์‹ฑ ๊ธ€ ์ž˜ ๋ดค์Šต๋‹ˆ๋‹ค! ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!
์ฒ˜์Œ ๋“ฃ๋Š” ํ‚ค์›Œ๋“œ์˜€๋Š”๋ฐ DB ๋„์ž… ์ดˆ๊ธฐ์— ๊ณ ๋ฏผํ–ˆ๋˜ ๋ถ€๋ถ„๊ณผ ๋น„์Šทํ•ด์„œ ์ดํ•ดํ•˜๋Š”๋ฐ ์–ด๋ ต์ง„ ์•Š์•˜์Šต๋‹ˆ๋‹ค.
์ดˆ๊ธฐ์—๋Š” ๋งจ ์ฒ˜์Œ ์žฅ๊ธฐํŒ ์ดˆ๊ธฐํ™” ์ƒํƒœ๋ž‘ move_history๋ฅผ ์ €์žฅํ•˜๋ ค๊ณ  ํ–ˆ์—ˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฌ๋ฉด ๋‚˜์ค‘์— ๋ฌด๋ฅด๊ธฐ ๊ธฐ๋Šฅ๋„ ์ถ”๊ฐ€ํ•˜๊ธฐ ์‰ฝ๊ณ , ๋งค ๋ผ์šด๋“œ๋ฅผ ์ €์žฅํ•˜๋Š” ๋ฐฉ์‹๋ณด๋‹ค ์ €์žฅ๊ณต๊ฐ„๋„ ๋œ ์ฐจ์ง€ํ•  ์ˆ˜ ์žˆ์–ด์„œ ์ข‹์•˜์Šต๋‹ˆ๋‹ค.
ํ•˜์ง€๋งŒ ๊ฒŒ์ž„์„ ๋ถˆ๋Ÿฌ์˜ฌ ๋•Œ๋งˆ๋‹ค ๋ชจ๋“  move_history๋ฅผ ์žฌ์—ฐํ•ด์•ผ ํ•ด์„œ ํฌ๊ธฐํ–ˆ์—ˆ์Šต๋‹ˆ๋‹ค๐Ÿฅฒ

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