Skip to content

Commit

Permalink
feat : NewsLetter 도메인 클래스를 생성한다
Browse files Browse the repository at this point in the history
  • Loading branch information
packdev937 committed May 7, 2024
1 parent 9c72207 commit 09a9649
Show file tree
Hide file tree
Showing 10 changed files with 234 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public enum Category {

public static Category from(String description) {
return Arrays.stream(Category.values())
.filter(c -> c.name().equalsIgnoreCase(description))
.filter(d -> d.description.equals(description))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("지원하지 않는 OAuth 제공자입니다."));
.orElseThrow(() -> new IllegalArgumentException("올바르지 않은 카테고리입니다."));
}
}
30 changes: 30 additions & 0 deletions domain/src/main/java/kusitms/duduk/domain/global/Count.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package kusitms.duduk.domain.global;

import lombok.Getter;

@Getter
public class Count {

private static final int ZERO = 0;
private int Count;

private Count(int Count) {
this.Count = Count;
}

public static Count initial() {
return new Count(ZERO);
}

public static Count from(int Count) {
return new Count(Count);
}

public void increase() {
this.Count++;
}

public void decrease() {
this.Count--;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package kusitms.duduk.domain.newsletter;

import java.util.List;
import kusitms.duduk.domain.global.Category;
import kusitms.duduk.domain.global.Count;
import kusitms.duduk.domain.global.Id;
import kusitms.duduk.domain.newsletter.vo.Content;
import kusitms.duduk.domain.newsletter.vo.Keywords;
import kusitms.duduk.domain.newsletter.vo.Summary;
import kusitms.duduk.domain.newsletter.vo.Thumbnail;
import kusitms.duduk.domain.newsletter.vo.Title;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Builder(toBuilder = true)
public class NewsLetter {

private Id newsLetterId;
private Id editorId;
private Thumbnail thumbnail;
private Title title;
private Content content;
private Keywords keywords;
private Category category;
private Summary summary;
private Count viewCount;
private Count scrapCount;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package kusitms.duduk.domain.newsletter.vo;

import lombok.Getter;

@Getter
public class Content {

private String content;

private Content(String content) {
this.content = content;
}

public static Content from(String content) {
return new Content(content);
}

public void revise(String content) {
this.content = content;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package kusitms.duduk.domain.newsletter.vo;

import java.util.ArrayList;
import java.util.List;
import lombok.Getter;

@Getter
public class Keywords {

List<String> words;

private Keywords(List<String> words) {
this.words = words;
}

public static Keywords from(String sentence) {
List<String> list = new ArrayList<>();
for (String keyword : sentence.split(",")) {
list.add(keyword);
}
return new Keywords(list);
}

public void add(String keyword) {
words.add(keyword);
}

public void remove(String keyword) {
words.remove(keyword);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package kusitms.duduk.domain.newsletter.vo;

import java.util.ArrayList;
import java.util.List;
import lombok.Getter;

@Getter
public class Summary {

private List<String> sentences;

private Summary(List<String> sentences) {
this.sentences = sentences;
}

public static Summary from(String summary) {
List<String> list = new ArrayList<>();
for (String sentence : summary.split("\n")) {
list.add(sentence);
}
return new Summary(list);
}

public void revise(int index, String sentence) {
// todo : 이렇게 하면 덮어쓰나?
sentences.set(index, sentence);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package kusitms.duduk.domain.newsletter.vo;

import lombok.Getter;

@Getter
public class Thumbnail {

private String url;

private Thumbnail(String url) {
this.url = url;
}

public static Thumbnail from(String url) {
return new Thumbnail(url);
}
}
21 changes: 21 additions & 0 deletions domain/src/main/java/kusitms/duduk/domain/newsletter/vo/Title.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package kusitms.duduk.domain.newsletter.vo;

import lombok.Getter;

@Getter
public class Title {

private String title;

private Title(String title) {
this.title = title;
}

public static Title from(String title) {
return new Title(title);
}

public void revise(String title) {
this.title = title;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package kusitms.duduk.domain.newsletter;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

import kusitms.duduk.domain.global.Category;
import kusitms.duduk.domain.global.Count;
import kusitms.duduk.domain.newsletter.vo.Content;
import kusitms.duduk.domain.newsletter.vo.Keywords;
import kusitms.duduk.domain.newsletter.vo.Summary;
import kusitms.duduk.domain.newsletter.vo.Thumbnail;
import kusitms.duduk.domain.newsletter.vo.Title;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

@DisplayName("NewsLetter 테스트")
class NewsLetterTest {

@Test
void 뉴스_레터_객체를_생성한다() {
// given
String title = "title";
String content = "content";
String thumbnail = "thumbnail";
String keywords = "keyword1,keyword2,keyword3";
String stock = "주식";
String summary = "summary\nsummary\nsummary";

// when
NewsLetter newsLetter = NewsLetter.builder()
.title(Title.from(title))
.content(Content.from(content))
.thumbnail(Thumbnail.from(thumbnail))
.keywords(Keywords.from(keywords))
.category(Category.from(stock))
.summary(Summary.from(summary))
.viewCount(Count.initial())
.scrapCount(Count.from(6))
.build();

// then
assertThat(newsLetter.getTitle().getTitle()).isEqualTo(title);
assertThat(newsLetter.getContent().getContent()).isEqualTo(content);
assertThat(newsLetter.getThumbnail().getUrl()).isEqualTo(thumbnail);
assertThat(newsLetter.getKeywords().getWords().size()).isEqualTo(3);
assertThat(newsLetter.getCategory().getDescription()).isEqualTo(stock);
assertThat(newsLetter.getSummary().getSentences().size()).isEqualTo(3);
assertThat(newsLetter.getViewCount().getCount()).isEqualTo(0);
assertThat(newsLetter.getScrapCount().getCount()).isEqualTo(6);
}
}
2 changes: 2 additions & 0 deletions domain/src/test/java/kusitms/duduk/domain/user/UserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import kusitms.duduk.domain.user.vo.Gender;
import kusitms.duduk.domain.user.vo.Nickname;
import kusitms.duduk.domain.user.vo.RefreshToken;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

@DisplayName("User 테스트")
public class UserTest {

@Test
Expand Down

0 comments on commit 09a9649

Please sign in to comment.