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

스크랩 엔티티 구현 (issue #489) #496

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
39 changes: 39 additions & 0 deletions backend/src/main/java/develup/domain/scrap/Scrap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package develup.domain.scrap;

import develup.domain.IdentifiableEntity;
import develup.domain.member.Member;
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;

@Entity
public class Scrap extends IdentifiableEntity {

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(nullable = false)
private Member member;

@Embedded
private ScrapedItem item;
Copy link
Contributor

Choose a reason for hiding this comment

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

[Request Changed]

오타 발견! 💡 scrapped 😊

Copy link
Member Author

Choose a reason for hiding this comment

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

변경했습니다. 감사합니다. 👍


@Column(nullable = false)
private boolean isScrapped;
Comment on lines +22 to +23
Copy link
Member Author

Choose a reason for hiding this comment

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

해당 컬럼이 존재하는 이유는 사용자가 스크랩 버튼을 반복해서 클릭하는 경우 insert와 delete를 반복해서 수행하는 것보다 update 비용이 더욱 저렴하다고 생각했기 때문입니다.

  1. 사용자가 스크랩한 적이 없다. = scrap 없음
  2. 사용자가 스크랩한다. scrap.isScrapped == true
  3. 사용자가 스크랩을 취소한다. scrap.isScrapped = false

다른 분들의 의견을 들어보고 싶습니다! 👀

Copy link
Contributor

Choose a reason for hiding this comment

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

[Comment]

비용이 적을것이라는 것에는 동감합니다. 하지만 그 비용을 아끼는 대가로 나중에 구현될 스크랩 API의 명세가 복잡해지거나 내부 구현이 복잡해질 것 같네요.
물론, 코드가 얼마나 복잡해질지 모르고, 비용차이에 따른 서버의 성능이 얼마나 향상될지도 모르는 거긴 합니다. 이런 상황에서 어떤 방향의 시도가 먼저 되어야 할까요? 코드의 복잡도는 수치로 측정하기가 힘든데, 성능 향상은 비교적 명확하게 측정할 수 있을 것 같아요. 그러니 저는 복잡도를 먼저 감수하는 것 보단, 단순함을 먼저 선택하고 후에 필요에 의해 개선하는 방향이 좋을 것 같아요.
그런데, 한편으론 이런식이면 아무것도 못하고 매 기능마다 똑같은 수준으로 작성하니 성장이나 학습 관점에선 별로 좋지 않을 수 있을 것 같네요.


protected Scrap() {
}

public Scrap(Member member, ScrapedItem item) {
this(null, member, item, true);
}

public Scrap(Long id, Member member, ScrapedItem item, boolean isScrapped) {
super(id);
this.id = id;
this.member = member;
this.item = item;
this.isScrapped = isScrapped;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package develup.domain.scrap;

import org.springframework.data.jpa.repository.JpaRepository;

public interface ScrapRepository extends JpaRepository<Scrap, Long> {
}
25 changes: 25 additions & 0 deletions backend/src/main/java/develup/domain/scrap/ScrapedItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package develup.domain.scrap;

import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;

@Embeddable
public class ScrapedItem {

@Column(name = "item_id", nullable = false)
private Long id;

@Column(nullable = false)
@Enumerated(EnumType.STRING)
private ScrapedItemType itemType;

protected ScrapedItem() {
}

public ScrapedItem(Long id, ScrapedItemType itemType) {
this.id = id;
this.itemType = itemType;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package develup.domain.scrap;

public enum ScrapedItemType {

DISCUSSION,
SOLUTION,
;
}
Loading