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

feat: 쪽지 기능 뼈대코드 설계 및 구현 #389

Merged
merged 8 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions backend/src/main/java/com/now/naaga/letter/domain/Letter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.now.naaga.letter.domain;

import com.now.naaga.common.domain.BaseEntity;
import com.now.naaga.place.domain.Position;
import com.now.naaga.player.domain.Player;
import jakarta.persistence.*;

import java.util.Objects;

@Entity
public class Letter extends BaseEntity {
Copy link
Collaborator

Choose a reason for hiding this comment

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

P5:

저희가 게임 같은 경우에는
BaseEntity는 DB관리 차원에서 등록일 수정일을 관리하는 것이고,
따로 게임 시작 시간을 기록하기 위해서 startTime 이라는 컬럼을 두었는데요.
해당 쪽지에서도 등록일이 유의미한 데이터인 것 같아서, 혹시 등록일을 따로 컬럼으로 하나 더 넣을 필요는 없겠쬬?

Copy link
Collaborator

Choose a reason for hiding this comment

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

게임에서는 db 관리 차원에서의 시간과 게임 시작시간이 따로 있어야 하는 것이 맞는데 쪽지는..제 의견으로는 굳이 없어도 될것같아요! 쪽지 생성시간이 곧 쪽지 등록시간이라서..!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

쪽지를] 조회할 때 항상 등록시간을 보내줄 예정인데요. 하지만 저도 startTime이라는 컬럼을 따로 만들어야할 이유는 잘 모르겠습니다.
game 객체에서는 endTime이라는 필드가 있기 때문에 그에 상응하는 startTime이라는 필드가 있다고 생각했는데, 쪽지의 경우 굳이 컬럼을 추가할 필요가 있을까? 하는 생각이 듭니다

Copy link
Collaborator

Choose a reason for hiding this comment

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

네넵!! 저도 동의합니다!!


@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "player_id")
private Player registeredPlayer;

@Embedded
private Position position;

private String message;

public Letter() {
}

public Letter(final Player registeredPlayer,
final Position position,
final String message) {
this(null, registeredPlayer, position, message);
}

public Letter(final Long id,
final Player registeredPlayer,
final Position position,
final String message) {
this.id = id;
this.registeredPlayer = registeredPlayer;
this.position = position;
this.message = message;
}

public Long getId() {
return id;
}

public Player getRegisteredPlayer() {
return registeredPlayer;
}

public Position getPosition() {
return position;
}
Comment on lines +53 to +55
Copy link
Collaborator

Choose a reason for hiding this comment

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

(해당 PR의 변경 요구사항 아님)

저희 포지션이 정말 이곳저곳에서 많이 쓰이네요.
그렇다면 저희 포지션을 이제는 place 패키지 안에 두기는 힘들것 같아요!!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

특히 포지션 관련 dto가 여기저기서 쓰이는 것을 보고 저도 그런 생각을 했는데, 이유가 명확하지 않아서요. place 패키지가 아니라면 개별적인 패키지로 분리를 생각하시는 건가여>?

Copy link
Collaborator

Choose a reason for hiding this comment

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

네!
Position이 개별적인 도메인 패키지로 존재해도 될 것 같습니다!!


public String getMessage() {
return message;
}

@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Letter letter = (Letter) o;
return Objects.equals(id, letter.id);
}

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

@Override
public String toString() {
return "Letter{" +
"id=" + id +
", playerId=" + registeredPlayer.getId() +
", position=" + position +
", message='" + message +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.now.naaga.letter.presentation;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/letters")
@RestController
public class LetterController {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.now.naaga.letter.repository;

import com.now.naaga.letter.domain.Letter;
import org.springframework.data.jpa.repository.JpaRepository;

public interface LetterRepository extends JpaRepository<Letter, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.now.naaga.common.builder;

import com.now.naaga.letter.domain.Letter;
import com.now.naaga.letter.repository.LetterRepository;
import com.now.naaga.place.domain.Position;
import com.now.naaga.player.domain.Player;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Optional;

import static com.now.naaga.common.fixture.LetterFixture.MESSAGE;
import static com.now.naaga.common.fixture.PositionFixture.잠실역_교보문고_좌표;

@Component
public class LetterBuilder {

@Autowired
private LetterRepository letterRepository;

@Autowired
private PlayerBuilder playerBuilder;

private Optional<Player> registeredPlayer;

private Position position;

private String message;

public LetterBuilder init() {
this.registeredPlayer = Optional.empty();
this.position = 잠실역_교보문고_좌표;
this.message = MESSAGE;
return this;
}

public LetterBuilder registeredPlayer(final Player persistedPlayer) {
this.registeredPlayer = Optional.ofNullable(persistedPlayer);
return this;
}

public LetterBuilder position(final Position position) {
this.position = position;
return this;
}

public LetterBuilder message(final String message) {
this.message = message;
return this;
}

public Letter build() {
final Player persistedPlayer = registeredPlayer.orElseGet(this::getPersistedPlayer);
final Letter letter = new Letter(persistedPlayer, position, message);
return letterRepository.save(letter);
}

private Player getPersistedPlayer() {
return playerBuilder.init()
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.now.naaga.common.fixture;

import com.now.naaga.letter.domain.Letter;

import static com.now.naaga.common.fixture.PlayerFixture.PLAYER;
import static com.now.naaga.common.fixture.PositionFixture.잠실_루터회관_정문_좌표;

public class LetterFixture {

public static final String MESSAGE = "안녕하세요. 나아가 개발자들 입니다.";

public static Letter LETTER() {
return new Letter(PLAYER(), 잠실_루터회관_정문_좌표, MESSAGE);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.now.naaga.common.fixture;

import com.now.naaga.place.domain.Position;

import java.math.BigDecimal;

public class PositionFixture {
Expand Down
Loading