Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸš€ 1단계 - μ˜ˆμ•½ κΈ°λŠ₯ κ΅¬ν˜„ #91

Open
wants to merge 5 commits into
base: yhheo96
Choose a base branch
from

Conversation

yhheo96
Copy link

@yhheo96 yhheo96 commented Jun 18, 2024

μ•ˆλ…•ν•˜μ„Έμš”!

1단계가 많이 λŠ¦μ–΄μ‘Œλ„€μš” γ… γ…  😒

이번 λ―Έμ…˜μ„ κ΅¬ν˜„ν•˜λ©΄μ„œ κ°€μž₯ 고민이 됐던 ν¬μΈνŠΈλŠ” 두 가지 μž…λ‹ˆλ‹€.

  • ν…ŒμŠ€νŠΈ μ½”λ“œλ₯Ό μ–΄λŠ λ ˆλ²¨κΉŒμ§€ μž‘μ„±μ„ ν•΄μ•Όν•˜λŠ”μ§€( 아직 λ‹¨μœ„ ν…ŒμŠ€νŠΈμ™€ 같은 ν…ŒμŠ€νŠΈ μ½”λ“œλŠ” μž‘μ„±ν•˜μ§€ λͺ»ν•˜μ˜€μŠ΅λ‹ˆλ‹€ 😒 )

    • λ‹¨μœ„ ν…ŒμŠ€νŠΈλ₯Ό 각 μ„œλΉ„μŠ€λ‚˜ repository ν…ŒμŠ€νŠΈκΉŒμ§€ κ΅¬ν˜„μ„ ν•˜λŠ”μ§€
    • ν•΄λ‹Ή 리뷰λ₯Ό λ°›κ³  TDDλŠ” μ•„λ‹ˆμ§€λ§Œ ν…ŒμŠ€νŠΈλ₯Ό μž‘μ„±ν•˜λ©΄μ„œ μ§„ν–‰ν•˜λ„λ‘ ν•˜κ² μŠ΅λ‹ˆλ‹€.
  • DTOλ₯Ό μ–΄λŠ λ ˆλ²¨κΉŒμ§€ μž‘μ„±μ„ ν•΄μ•Όν•˜λŠ”μ§€

    • request와 response와 λ³„κ°œλ‘œ requestμ—μ„œ service둜 λ„˜κΈΈ λ•Œμ™€ serviceμ—μ„œ response둜 λ„˜κΈΈ λ•Œ 각각의 μš”κ΅¬μ‚¬ν•­λ“€μ΄ λ‹¬λΌμ§ˆ 수 μžˆλ‹€κ³  μƒκ°ν•΄μ„œ api layerμ—μ„œλŠ” request, response application layerμ—μ„œ result, command dtoλ₯Ό λͺ…λͺ…ν•΄μ„œ μž‘μ„±ν•˜μ˜€μŠ΅λ‹ˆλ‹€.
    • λ¬Όλ‘  ν˜„μž¬λŠ” μš”κ΅¬μ‚¬ν•­μ΄ λ‹¨μˆœν•΄ λ‹¨μˆœ λ°˜λ³΅λ˜λŠ” λ³΄μΌλŸ¬ν”Œλ ˆμ΄νŠΈ μ½”λ“œκ°€ λ§Žμ•„μ§ˆ 수 μžˆλŠ” 단점이 있고 각각의 λ³€ν™˜ λ‘œμ§λ“€μ΄ λ§Žμ•„μ§„λ‹€λŠ” 단점이 μžˆμ§€λ§Œ 보톡 μ–΄λ–»κ²Œ κ΅¬ν˜„μ„ 많이 ν•˜μ‹œλŠ”μ§€ κΆκΈˆν•©λ‹ˆλ‹€ πŸ˜„

Copy link
Member

@Hyeon9mak Hyeon9mak left a comment

Choose a reason for hiding this comment

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

μ•ˆλ…•ν•˜μ„Έμš” μœ€ν–‰λ‹˜, μ˜ˆμ•½ κΈ°λŠ₯ κ΅¬ν˜„ λ―Έμ…˜μ„ ν•¨κ»˜ν•  μ΅œν˜„κ΅¬μž…λ‹ˆλ‹€. πŸ™‡β€β™‚οΈ
λͺ‡ 가지 μ½”λ©˜νŠΈ λ‚¨κ²ΌμŠ΅λ‹ˆλ‹€! ν™•μΈν•΄μ£Όμ„Έμš”~

ν…ŒμŠ€νŠΈ μ½”λ“œλ₯Ό μ–΄λŠ λ ˆλ²¨κΉŒμ§€ μž‘μ„±μ„ ν•΄μ•Όν•˜λŠ”μ§€

ν…ŒμŠ€νŠΈ μ½”λ“œλŠ” κ²°κ΅­ 'λ‚΄κ°€ ν”„λ‘œκ·Έλž¨μ„ 직접 μ‹€ν–‰μ‹œμΌœλ³΄μ§€ μ•Šλ”λΌλ„, 잘 λ™μž‘ν•˜λŠ”μ§€ μ•Œκ³  μ‹Άμ–΄.' λΌλŠ” μš•κ΅¬λ₯Ό ν•΄μ†Œν•˜κΈ° μœ„ν•΄ μž‘μ„±ν• κ±°μ—μš”.
μœ€ν–‰λ‹˜μ΄ 직접 κ΅¬ν˜„ν•˜μ‹  controller, serivce, repository 에 λŒ€ν•΄ λΆˆμ•ˆν•œ μš”μ†Œκ°€ μžˆμœΌμ‹ κ°€μš”? πŸ˜„
이번 λ―Έμ…˜μ„ μ§„ν–‰ν•˜λŠ” λ™μ•ˆμ€ ν•™μŠ΅μ„ μœ„ν•΄μ„œ, 각 계측별 ν…ŒμŠ€νŠΈλ₯Ό ν•˜λ‚˜μ”© μž‘μ„±ν•΄λ³΄λŠ” 것도 쒋을거 κ°™μ•„μš”.

λ‹€λ§Œ μ‹€μ œ ν”„λ‘œκ·Έλž¨μ„ λ§Œλ“œμ‹€ 땐 정말 μ€‘μš”ν•œ ν…ŒμŠ€νŠΈλ§Œ μ λ‹Ήνžˆ μž‘μ„±ν•˜λŠ”κ²Œ μ€‘μš”ν•˜κ² λ„€μš”.
λ„ˆλ¬΄ ν…ŒμŠ€νŠΈ μ½”λ“œλ₯Ό μž‘μ„±ν•˜μ§€ μ•ŠλŠ”λ‹€λ©΄ ν”„λ‘œκ·Έλž¨ μ•ˆμ •μ„±μ΄ λ–¨μ–΄μ§€κ² μ§€λ§Œ,
λΆˆν•„μš”ν•œ ν…ŒμŠ€νŠΈκ°€ λ„ˆλ¬΄ λ§Žμ•„μ§€λ©΄ 정말 μ€‘μš”ν•œ ν…ŒμŠ€νŠΈκ°€ λˆˆμ— 잘 띄지 μ•Šμ„ μˆ˜λ„ μžˆμœΌλ‹ˆκΉŒμš”!

DTOλ₯Ό μ–΄λŠ λ ˆλ²¨κΉŒμ§€ μž‘μ„±μ„ ν•΄μ•Όν•˜λŠ”μ§€

μ›λ‘ μ μœΌλ‘œλŠ” controller - service - repository λ₯Ό κ±°μΉ˜λŠ” layered architecture λ₯Ό μ„ νƒν•΄μ£Όμ…¨μœΌλ―€λ‘œ,
ν˜„μž¬μ™€ 같이 각 κ²½κ³„μ—μ„œ μ‚¬μš©λ˜λŠ” dto(data transfer object)λ₯Ό μ‚¬μš©ν•˜λŠ”κ²Œ μ˜³λ‹€κ³  μƒκ°λ©λ‹ˆλ‹€.
"layer λ₯Ό λ‚˜λˆ„κ³  μ‹Άλ‹€." -> "layer κ°„ μœ μ§€λ³΄μˆ˜μ— μ„œλ‘œ 영ν–₯을 λ°›κ³  싢지 μ•Šλ‹€."
ν•˜λ‚˜μ˜ object 둜 μ—¬λŸ¬ layer κ°€ μ†Œν†΅μ„ μ£Όκ³  λ°›λŠ” μˆœκ°„ μœ μ§€λ³΄μˆ˜κ°€ μ–΄λ €μ›Œμ§ˆκ±°μ—μš”.

μš”μ¦˜μ€ intellij 와 같은 IDE 의 λ‹¨μΆ•μ–΄λ‚˜ github copilot 의 도움이 κ°•λ ₯ν•΄μ„œ
큰 어렀움 없이 dto ν΄λž˜μŠ€λ“€μ„ μˆœμ‹κ°„μ— μ°μ–΄λ‚΄λŠ” 것 κ°™μ•„μš”.

κΆκΈˆν•˜μ‹  점 νŽΈν•˜κ²Œ 질문 λ‚¨κ²¨μ£Όμ„Έμš”~

Comment on lines +7 to +14
@Builder
@Getter
@Setter
public class CreateReservationCommand {
private String name;
private String date;
private String timeId;
}
Copy link
Member

Choose a reason for hiding this comment

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

setter κ°€ ν•„μš”ν•œ μ΄μœ κ°€ μžˆμ—ˆμ„κΉŒμš”?

Comment on lines 19 to 22
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.projectlombok:lombok'
annotationProcessor('org.projectlombok:lombok')
runtimeOnly 'com.h2database:h2'
Copy link
Member

Choose a reason for hiding this comment

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

둬볡을 μ μš©ν•˜μ‹  μ΄μœ κ°€ κΆκΈˆν•΄μš”!

Comment on lines +7 to +21
@Getter
@Setter
public class Reservation {

private Long id;
private String name;
private String date;
private ReservationTime time;

public Reservation(Long id, String name, String date, ReservationTime time
) {
this.id = id;
this.name = name;
this.date = date;
this.time = time;
Copy link
Member

Choose a reason for hiding this comment

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

entity = id + vo 라고 μƒκ°ν•˜λŠ”λ°μš”, id λ₯Ό ν†΅ν•΄μ„œ μ„œλ‘œ 같은 데이터라고 μ‹λ³„ν•˜κΈ° λ•Œλ¬Έμ΄μ—μš”.

κ°€λ Ή id = 1, name = "μœ€ν–‰" κ³Ό id = 1, name = "ν–‰μœ€" 은 μ„œλ‘œ 같은 λ°μ΄ν„°λ‘œ,
id = 1, name = "μœ€ν–‰" κ³Ό id = 9, name = "μœ€ν–‰" 은 μ„œλ‘œ λ‹€λ₯Έ λ°μ΄ν„°λ‘œ λ³Ό 수 μžˆκ² λ„€μš”.

이λ₯Ό ν‘œν˜„ν•΄μ£ΌκΈ° μœ„ν•΄ id 에 λŒ€ν•΄μ„œλ§Œ equals & hashcode override λ₯Ό ν•΄μ£ΌλŠ” 것은 μ–΄λ–¨κΉŒμš”?

Comment on lines +9 to +14

@Repository
public interface ReservationRepository {
public List<Reservation> findAllReservations();

public Reservation createReservation(Reservation reservation, ReservationTime reservationTime);
Copy link
Member

Choose a reason for hiding this comment

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

μΈν„°νŽ˜μ΄μŠ€μ— @Repository μ–΄λ…Έν…Œμ΄μ…˜μ΄ ν•„μš”ν•œ μ΄μœ κ°€ μžˆμ—ˆμ„κΉŒμš”?!

Comment on lines +23 to +35
public final RowMapper<Reservation> rowMapper = (rs, rowNum) -> {
ReservationTime reservationTime = new ReservationTime(
rs.getLong("time_id"),
rs.getString("time_start_at")
);

return new Reservation(
rs.getLong("reservation_id"),
rs.getString("reservation_name"),
rs.getString("reservation_date"),
reservationTime
);
};
Copy link
Member

Choose a reason for hiding this comment

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

private 으둜 선언해쀄 수 μžˆκ² λ„€μš”! πŸ˜‰

Comment on lines +34 to +37
@Override
public ReservationTime findByTimeId(String timeId) {
return jdbcTemplate.queryForObject("SELECT * FROM reservation_time where id = ?", rowMapper, timeId);
}
Copy link
Member

Choose a reason for hiding this comment

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

λ§Œμ•½ 단건 μ‘°νšŒμ— μ‹€νŒ¨ν•  경우 (μ‹œκ°„μ΄ μ—†λŠ” 경우) μ˜ˆμ™Έμ²˜λ¦¬λŠ” μ–΄λ–»κ²Œ λ κΉŒμš”?
μ‹œκ°„ 정보가 μ—†λŠ” 것은 persistence 의 μ±…μž„μΌκΉŒμš”, business 의 μ±…μž„μΌκΉŒμš”?

Comment on lines +52 to +72

@Override
public Reservation createReservation(Reservation reservation, ReservationTime reservationTime) {
KeyHolder keyHolder = new GeneratedKeyHolder();

String sql = "insert into reservation(name, date, time_id) values(?, ?, ?)";

jdbcTemplate.update(connection -> {
PreparedStatement pstmt = connection.prepareStatement(sql, new String[]{"id"});
pstmt.setString(1, reservation.getName());
pstmt.setString(2, reservation.getDate());
pstmt.setLong(3, reservationTime.getId());
return pstmt;
}, keyHolder);

long key = keyHolder.getKey().longValue();
reservation.setId(key);
reservation.setTime(reservationTime);

return reservation;
}
Copy link
Member

Choose a reason for hiding this comment

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

key holder ν™œμš© πŸ‘
simple jdbc insert λ₯Ό ν™œμš©ν•΄λ³΄λŠ” 것도 μ’‹κ² λ„€μš” πŸ˜„

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