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

다즐을 사칭한 누누 #14

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

be-student
Copy link

``

woo-chang and others added 21 commits April 15, 2023 23:07
* feat: 자동차 경주 코드 가져오기

Co-authored-by: aiaiaiai1 <[email protected]>

* docs: 개요 및 기능 목록 작성

Co-authored-by: aiaiaiai1 <[email protected]>

* docs: 개요 및 기능 목록 작성

Co-authored-by: aiaiaiai1 <[email protected]>

* feat: spring 어플리케이션 동작 구현

Co-authored-by: aiaiaiai1 <[email protected]>

* feat: 데이터 베이스 설정

Co-authored-by: aiaiaiai1 <[email protected]>

* refactor: 애플리케이션 패키지 생성

Co-authored-by: aiaiaiai1 <[email protected]>

* feat: 자동차 경주 게임 요청 형식 구현

Co-authored-by: aiaiaiai1 <[email protected]>

* feat: 자동차 경주 게임 응답 형식 구현

Co-authored-by: aiaiaiai1 <[email protected]>

* fix: 하위 컴포넌트 스캔 문제로 인한 패키지 수정

Co-authored-by: aiaiaiai1 <[email protected]>

* feat: 자동차 경주 게임 플레이 요청 및 우승자와 최종 위치 응답 기능 구현

Co-authored-by: aiaiaiai1 <[email protected]>

* refactor: 로직 리팩토링 및 서비스 레이어로 분리

Co-authored-by: aiaiaiai1 <[email protected]>

* test: 자동차 경주 비즈니스 로직 테스트

Co-authored-by: aiaiaiai1 <[email protected]>

* feat: 데이터베이스 테이블 생성

Co-authored-by: aiaiaiai1 <[email protected]>

* feat: 자동차 경주 게임 정보 저장 기능 구현

Co-authored-by: aiaiaiai1 <[email protected]>

* feat: 자동차 정보 저장 기능 구현

Co-authored-by: aiaiaiai1 <[email protected]>

* refactor: 메서드 분리 및 스프링 빈 등록

Co-authored-by: aiaiaiai1 <[email protected]>

* docs: 기능 목록 오타 수정

Co-authored-by: aiaiaiai1 <[email protected]>

* feat: 예외 처리 기능 구현

Co-authored-by: aiaiaiai1 <[email protected]>

* refactor: ResponseEntity 사용하도록 수정

Co-authored-by: aiaiaiai1 <[email protected]>

* feat: @transactional 어노테이션 추가

Co-authored-by: aiaiaiai1 <[email protected]>

* refactor: 요청과 응답에 사용되는 dto 네이밍 수정

* feat: 범용적으로 예외를 잡기 위한 핸들러 기능 구현

* refactor: JdbcTemplate -> SimpleJdbcInsert 사용하도록 수정

* test: 기존 테스트 코드 추가

* test: @SpringBootTest -> @jdbcTest 수정

* refactor: 단일 쿼리에서 벌크 쿼리를 날리도록 수정

---------

Co-authored-by: aiaiaiai1 <[email protected]>
Copy link
Author

@be-student be-student left a comment

Choose a reason for hiding this comment

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

굿굿 역시 다즐 고수네요

private String names;

@NotNull
@PositiveOrZero
Copy link
Author

Choose a reason for hiding this comment

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

0회도 허용했네?
신기하네 굿
직접 메시지 넣어줘도 좋을거 같아 다즐

Choose a reason for hiding this comment

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

사랑의 메시지 좋은데요

@PositiveOrZero
private Integer count;

public RacingCarRequest() {
Copy link
Author

Choose a reason for hiding this comment

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

기본 생성자 안 쓰면 private 쪽이 좋아보이는데?
안 써도 문제 없이 되기 때문에
없애도 좋아보여

Choose a reason for hiding this comment

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

빌드는 gradle로~

Comment on lines +24 to +36
jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
ps.setLong(1, racingCarEntities.get(i).getGameId());
ps.setString(2, racingCarEntities.get(i).getName());
ps.setInt(3, racingCarEntities.get(i).getPosition());
}

@Override
public int getBatchSize() {
return racingCarEntities.size();
}
});
Copy link
Author

Choose a reason for hiding this comment

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

simpleInsert 사용 해보면 어때?
코드 진짜 깔끔해지던데

Choose a reason for hiding this comment

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

써봤다가 Insert 쿼리 1개에 너무 의존적인 객체인 것 같아서 모든 쿼리에 범용적으로 사용할 수 있는 JdbcTemplate으로 돌아왔어

진짜 깔끔해지기는 하더라 좋은 의견 감사합니다 👍

Comment on lines +44 to +50
(rs, rowNum) -> RacingCarEntity.builder()
.id(rs.getLong(1))
.gameId(rs.getLong(2))
.name(rs.getString(3))
.position(rs.getInt(4))
.build(),
gameId
Copy link
Author

Choose a reason for hiding this comment

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

왜 빌더를 둔거야? 궁금스 궁금스
빌더의 장점이 뭐라고 생각해?

Copy link

@woo-chang woo-chang Apr 23, 2023

Choose a reason for hiding this comment

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

@Builder 어노테이션만 사용해오다가 직접 구현해보고 싶었고, 필드가 많아져서 동일한 타입의 파라미터가 많아졌을 때 이름을 통해 실수를 줄일 수 있다는 장점이 있는 것 같아

사실 필드가 적다면 생성자나 정적 팩터리 메서드 사용하는게 훨씬 좋을 것 같아 🥳

Comment on lines +55 to +66
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
RacingCarEntity that = (RacingCarEntity) o;
return Objects.equals(id, that.id);
}

@Override
public int hashCode() {
return Objects.hash(id);
}
Copy link
Author

Choose a reason for hiding this comment

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

엔티티에 equals and hashcode 가 있는 이유가 뭐야?
비교한다면 id 만을 통해 비교해야되지 않아?
entity 는 id 만 같으면 같은 객체잖아
이걸 처리하기 위해서 이렇게까지 해준건가?
노력이 멋있는데요

Choose a reason for hiding this comment

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

핵심만 콕콕 일타강사 누누

@PostMapping("/plays")
public ResponseEntity<RacingGameResponse> play(@Valid @RequestBody RacingCarRequest racingCarRequest) {
final RacingGameResponse result = racingCarService.play(racingCarRequest.getNames(), racingCarRequest.getCount());
return ResponseEntity.ok(result);
Copy link
Author

Choose a reason for hiding this comment

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

201이 더 좋은 코드같아보이는데? 어떻게 생각해

Choose a reason for hiding this comment

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

새로운 리소스가 생성되었다는 관점에서 동의합니다 누누 체고 👍

Choose a reason for hiding this comment

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

누누가 아니라 다즐이었어? ㅇㄴ


private List<RacingCarEntity> saveRacingCar(final RacingGame racingGame, final Long gameId) {
final List<RacingCarEntity> racingCarEntities = racingGame.getCurrentResult().stream()
.map(car -> RacingCarEntity.builder()
Copy link
Author

Choose a reason for hiding this comment

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

map 안에 함수가 살짝 복잡해보여...

Choose a reason for hiding this comment

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

빌더를 사용해서 발생한 문제 ,,

Copy link
Member

Choose a reason for hiding this comment

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

그냥 빌더 말고 정팩메 안되냐여 혹은 그냥 메서드

mockMvc.perform(get("/plays"))
.andExpect(status().isOk())
.andDo(print())
.andExpect(jsonPath("$", hasSize(2)))
Copy link
Author

Choose a reason for hiding this comment

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

$ 이거 굿

import static org.junit.jupiter.api.Assertions.assertAll;

@SpringBootTest
@Transactional
Copy link
Author

Choose a reason for hiding this comment

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

transactional 굿

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertAll;

@SpringBootTest
Copy link
Author

Choose a reason for hiding this comment

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

서비스 테스트는 왜 bootTest 야?

Choose a reason for hiding this comment

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

실제 비즈니스 로직이 담겨있는 레이어라 스프링 부트 환경에서 실제 사용되는 빈을 가져와서 테스트하고자 했어

서비스 계층에도 mock test하는거에 대해서는 어떻게 생각해?

Copy link
Member

@drunkenhw drunkenhw left a comment

Choose a reason for hiding this comment

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

다즐 굿~
사실 시간이 없어서 더 열심히 못했네 쏘리~


private Long id;
private Integer trialCount;
private LocalDateTime date;
Copy link
Member

Choose a reason for hiding this comment

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

date라는 변수명 맘에 안들어요

return new RacingGameBuilder();
}

public static class RacingGameBuilder {
Copy link
Member

Choose a reason for hiding this comment

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

ㄷㄷ 빌더도 만들었네요


private List<RacingCarEntity> saveRacingCar(final RacingGame racingGame, final Long gameId) {
final List<RacingCarEntity> racingCarEntities = racingGame.getCurrentResult().stream()
.map(car -> RacingCarEntity.builder()
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 +15 to +18
final RacingCarConsoleController racingCarConsoleController = new RacingCarConsoleController(
inputView(),
outputView(),
new RacingCarService(new RacingCarConsoleRepository(), new RandomNumberGenerator())
Copy link
Member

Choose a reason for hiding this comment

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

변수로 빼주면 가독성이 좋아질거 같아요

import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@WebMvcTest(RacingCarApiController.class)
class RacingCarApiControllerTest {
Copy link
Member

Choose a reason for hiding this comment

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

테스트 아주 꼼꼼 멋져요

Copy link

@gitchannn gitchannn left a comment

Choose a reason for hiding this comment

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

살포시..보고감

"names": "브리,토미,브라운",
"count": 10
}
```

Choose a reason for hiding this comment

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

꼼꼼하시네요!

- [x] RacingCar 테이블 생성한다.
- id, game_id, name, position
- [x] RacingWinner 테이블 생성한다.
- id, game_id, car_id

Choose a reason for hiding this comment

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

정갈하네 역시 누누!

@PostMapping("/plays")
public ResponseEntity<RacingGameResponse> play(@Valid @RequestBody RacingCarRequest racingCarRequest) {
final RacingGameResponse result = racingCarService.play(racingCarRequest.getNames(), racingCarRequest.getCount());
return ResponseEntity.ok(result);

Choose a reason for hiding this comment

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

누누가 아니라 다즐이었어? ㅇㄴ

public void saveAll(final List<RacingCarEntity> racingCarEntities) {
final String sql = "INSERT INTO RACING_CAR (game_id, name, position) VALUES (?, ?, ?)";

jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {

Choose a reason for hiding this comment

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

쩌는데?

batchUpdateNamedParameter 랑 같이 쓸 수는 없나요?

public RacingCarEntity build() {
return new RacingCarEntity(id, gameId, name, position);
}
}

Choose a reason for hiding this comment

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

옹...! 괜찮아 보이는걸?
근데 모든 필드를 다 설정 안하고 만들어버리면 어떡해?

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.

4 participants