-
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.
- Loading branch information
Showing
3 changed files
with
75 additions
and
8 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
62 changes: 62 additions & 0 deletions
62
backend/src/main/java/wooteco/prolog/roadmap/domain/RecommendedPost.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,62 @@ | ||
package wooteco.prolog.roadmap.domain; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
import java.util.Objects; | ||
|
||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
@Getter | ||
public class RecommendedPost { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private String url; | ||
|
||
@ManyToOne | ||
@JoinColumn(nullable = false) | ||
private Keyword keyword; | ||
|
||
public RecommendedPost(final String url) { | ||
this(null, url, null); | ||
} | ||
|
||
public void updateUrl(final String url) { | ||
this.url = url; | ||
} | ||
|
||
public void remove() { | ||
if (this.keyword == null) { | ||
return; | ||
} | ||
|
||
keyword.getRecommendedPosts().remove(this); | ||
this.keyword = null; | ||
} | ||
|
||
public void addKeyword(final Keyword keyword) { | ||
this.keyword = keyword; | ||
keyword.getRecommendedPosts().add(this); | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof RecommendedPost)) return false; | ||
final RecommendedPost post = (RecommendedPost) o; | ||
return Objects.equals(id, post.id); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
backend/src/main/resources/db/migration/prod/V4__alter_table_keyword_reference.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 @@ | ||
drop table prolog.keyword_reference; | ||
|
||
create table if not exists prolog.recommended_post | ||
( | ||
id bigint auto_increment primary key, | ||
url varchar(255) not null, | ||
keyword_id bigint not null, | ||
constraint FK_KEYWORD_ID | ||
foreign key (keyword_id) references prolog.keyword (id) | ||
); |