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

♻️ Refactor: Briefing-Article 관계 1:N으로 변경 #195

Merged
merged 3 commits into from
Mar 10, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.servers.Server;
import lombok.RequiredArgsConstructor;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public static BriefingResponseDTO.BriefingDetailDTO toBriefingDetailDTO(
Briefing briefing, Boolean isScrap, Boolean isBriefingOpen, Boolean isWarning) {

List<BriefingResponseDTO.ArticleResponseDTO> articleResponseDTOList =
briefing.getBriefingArticles().stream()
.map(article -> toArticleResponseDTO(article.getArticle()))
briefing.getArticles().stream()
.map(BriefingConverter::toArticleResponseDTO)
.toList();

return BriefingResponseDTO.BriefingDetailDTO.builder()
Expand All @@ -101,8 +101,8 @@ public static BriefingResponseDTO.BriefingDetailDTOV2 toBriefingDetailDTOV2(
Briefing briefing, Boolean isScrap, Boolean isBriefingOpen, Boolean isWarning) {

List<BriefingResponseDTO.ArticleResponseDTO> articleResponseDTOList =
briefing.getBriefingArticles().stream()
.map(article -> toArticleResponseDTO(article.getArticle()))
briefing.getArticles().stream()
.map(BriefingConverter::toArticleResponseDTO)
.toList();

return BriefingResponseDTO.BriefingDetailDTOV2.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.Optional;

import com.example.briefingapi.briefing.implement.service.ArticleCommandService;
import com.example.briefingapi.briefing.implement.service.BriefingArticleCommandService;
import com.example.briefingapi.briefing.implement.service.BriefingCommandService;
import com.example.briefingapi.briefing.implement.service.BriefingQueryService;
import com.example.briefingapi.briefing.presentation.dto.BriefingRequestDTO;
Expand All @@ -13,7 +12,6 @@
import com.example.briefingapi.scrap.implement.ScrapQueryService;
import com.example.briefingcommon.entity.Article;
import com.example.briefingcommon.entity.Briefing;
import com.example.briefingcommon.entity.BriefingArticle;
import com.example.briefingcommon.entity.Member;
import com.example.briefingcommon.entity.enums.APIVersion;
import org.springframework.stereotype.Component;
Expand All @@ -29,7 +27,6 @@ public class BriefingFacade {
private final BriefingQueryService briefingQueryService;
private final BriefingCommandService briefingCommandService;
private final ArticleCommandService articleCommandService;
private final BriefingArticleCommandService briefingArticleCommandService;
private static final APIVersion version = APIVersion.V1;

@Transactional(readOnly = true)
Expand All @@ -55,19 +52,19 @@ public BriefingResponseDTO.BriefingDetailDTO findBriefing(final Long id, Member

@Transactional
public void createBriefing(final BriefingRequestDTO.BriefingCreate request) {
final List<Article> articles =
request.getArticles().stream().map(BriefingConverter::toArticle).toList();

Briefing createdBriefing =
briefingCommandService.create(BriefingConverter.toBriefing(request));
List<Article> createdArticles = articleCommandService.createAll(articles);

final List<BriefingArticle> briefingArticles =
createdArticles.stream()
.map(article -> new BriefingArticle(createdBriefing, article))
.toList();
final List<Article> articles =
request.getArticles().stream()
.map(articleCreateDto -> {
Article article = BriefingConverter.toArticle(articleCreateDto);
article.setBriefing(createdBriefing);
return article;
}).toList();

briefingArticleCommandService.createAll(briefingArticles);
List<Article> createdArticles = articleCommandService.createAll(articles);
createdBriefing.setArticles(createdArticles);
}

@Transactional
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.querydsl.core.types.PathMetadata;
import javax.annotation.processing.Generated;
import com.querydsl.core.types.Path;
import com.querydsl.core.types.dsl.PathInits;


/**
Expand All @@ -17,10 +18,14 @@ public class QArticle extends EntityPathBase<Article> {

private static final long serialVersionUID = 426734549L;

private static final PathInits INITS = PathInits.DIRECT2;

public static final QArticle article = new QArticle("article");

public final QBaseDateTimeEntity _super = new QBaseDateTimeEntity(this);

public final QBriefing briefing;

//inherited
public final DateTimePath<java.time.LocalDateTime> createdAt = _super.createdAt;

Expand All @@ -36,15 +41,24 @@ public class QArticle extends EntityPathBase<Article> {
public final StringPath url = createString("url");

public QArticle(String variable) {
super(Article.class, forVariable(variable));
this(Article.class, forVariable(variable), INITS);
}

public QArticle(Path<? extends Article> path) {
super(path.getType(), path.getMetadata());
this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS));
}

public QArticle(PathMetadata metadata) {
super(Article.class, metadata);
this(metadata, PathInits.getFor(metadata, INITS));
}

public QArticle(PathMetadata metadata, PathInits inits) {
this(Article.class, metadata, inits);
}

public QArticle(Class<? extends Article> type, PathMetadata metadata, PathInits inits) {
super(type, metadata, inits);
this.briefing = inits.isInitialized("briefing") ? new QBriefing(forProperty("briefing")) : null;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class QBriefing extends EntityPathBase<Briefing> {

public final QBaseDateTimeEntity _super = new QBaseDateTimeEntity(this);

public final ListPath<BriefingArticle, QBriefingArticle> briefingArticles = this.<BriefingArticle, QBriefingArticle>createList("briefingArticles", BriefingArticle.class, QBriefingArticle.class, PathInits.DIRECT2);
public final ListPath<Article, QArticle> articles = this.<Article, QArticle>createList("articles", Article.class, QArticle.class, PathInits.DIRECT2);

public final StringPath content = createString("content");

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.briefingcommon;

import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package com.example.briefingcommon;

import com.querydsl.jpa.impl.JPAQueryFactory;
import jakarta.persistence.EntityManager;

import org.springframework.boot.autoconfigure.domain.EntityScan;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.querydsl.jpa.impl.JPAQueryFactory;

import lombok.RequiredArgsConstructor;

@Configuration
@RequiredArgsConstructor
public class QueryDslConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import com.example.briefingcommon.entity.FcmToken;
import com.example.briefingcommon.entity.Member;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

public interface FcmTokenRepository extends JpaRepository<FcmToken, Long> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.example.briefingcommon.entity.Article;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;



Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.example.briefingcommon.domain.repository.article;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import com.example.briefingcommon.entity.Briefing;
import com.example.briefingcommon.entity.enums.BriefingType;
import com.example.briefingcommon.entity.enums.TimeOfDay;
import org.springframework.stereotype.Repository;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;


public interface BriefingCustomRepository {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.example.briefingcommon.domain.repository.article;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

import com.example.briefingcommon.entity.Briefing;
import com.example.briefingcommon.entity.enums.BriefingType;
import java.time.LocalDateTime;
import java.util.List;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@


import com.example.briefingcommon.entity.Scrap;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

public interface ScrapRepository extends JpaRepository<Scrap, Long>, ScrapCustomRepository {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;


import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.*;

@Entity
Expand All @@ -29,6 +32,14 @@ public class Article extends BaseDateTimeEntity {
@Column(nullable = false, length = 1024)
private String url;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(nullable = false)
private Briefing briefing;

public void setBriefing(Briefing briefing) {
this.briefing = briefing;
}

// public Article(final String press, final String title, final String url) {
// this.press = press;
// this.title = title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class Briefing extends BaseDateTimeEntity {

@Builder.Default
@OneToMany(mappedBy = "briefing", fetch = FetchType.LAZY)
private List<BriefingArticle> briefingArticles = new ArrayList<>();
private List<Article> articles = new ArrayList<>();

@Builder.Default @Transient private Integer scrapCount = 0;

Expand Down Expand Up @@ -69,6 +69,10 @@ public void setContent(String content) {
this.content = content;
}

public void setArticles(List<Article> articles) {
this.articles = articles;
}

public void updateBriefing(String title, String subtitle, String content) {
Optional.ofNullable(title).ifPresent(this::setTitle);
Optional.ofNullable(subtitle).ifPresent(this::setSubtitle);
Expand Down
Loading
Loading