-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/#1538 아티클 좋아요 기능 추가
- Loading branch information
Showing
17 changed files
with
462 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
backend/src/main/java/wooteco/prolog/article/domain/ArticleLike.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package wooteco.prolog.article.domain; | ||
|
||
import java.util.Objects; | ||
import javax.persistence.Entity; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Table(name = "article_like") | ||
public class ArticleLike { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "article_id") | ||
private Article article; | ||
|
||
private Long memberId; | ||
|
||
private ArticleLike(final Long id, final Article article, final Long memberId) { | ||
this.id = id; | ||
this.article = article; | ||
this.memberId = memberId; | ||
} | ||
|
||
public ArticleLike(final Article article, final Long memberId) { | ||
this(null, article, memberId); | ||
} | ||
|
||
public boolean isOwner(final Long memberId) { | ||
return Objects.equals(this.memberId, memberId); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
backend/src/main/java/wooteco/prolog/article/domain/ArticleLikes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package wooteco.prolog.article.domain; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import javax.persistence.Embeddable; | ||
import javax.persistence.OneToMany; | ||
import org.hibernate.annotations.Cascade; | ||
import org.hibernate.annotations.CascadeType; | ||
|
||
@Embeddable | ||
public class ArticleLikes { | ||
|
||
@OneToMany(mappedBy = "article") | ||
@Cascade(value = {CascadeType.PERSIST, CascadeType.DELETE}) | ||
private List<ArticleLike> articleLikes; | ||
|
||
public ArticleLikes() { | ||
this.articleLikes = new ArrayList<>(); | ||
} | ||
|
||
public void addLike(final ArticleLike articleLike) { | ||
articleLikes.add(articleLike); | ||
} | ||
|
||
public void removeLike(final Long memberId) { | ||
articleLikes.stream() | ||
.filter(like -> like.isOwner(memberId)) | ||
.findAny() | ||
.ifPresent(like -> articleLikes.remove(like)); | ||
} | ||
|
||
public boolean isAlreadyLike(final Long memberId) { | ||
return articleLikes.stream() | ||
.anyMatch(like -> like.isOwner(memberId)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
backend/src/main/java/wooteco/prolog/article/ui/ArticleLikesRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package wooteco.prolog.article.ui; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public class ArticleLikesRequest { | ||
|
||
private final Boolean like; | ||
|
||
public ArticleLikesRequest() { | ||
this(null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
backend/src/main/resources/db/migration/prod/V7__create_table_article_like.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
create table if not exists prolog.article_like | ||
( | ||
id bigint auto_increment primary key, | ||
article_id bigint not null, | ||
member_id bigint not null, | ||
foreign key (member_id) references prolog.member (id), | ||
foreign key (article_id) references prolog.article (id) | ||
) ENGINE = InnoDB | ||
DEFAULT CHARSET = utf8mb4 | ||
COLLATE = utf8mb4_0900_ai_ci; |
Oops, something went wrong.