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

Feat/10 board - 게시판 entity , repo 작성 #20

Merged
merged 18 commits into from
Oct 13, 2023
Merged

Conversation

lgsok00
Copy link
Collaborator

@lgsok00 lgsok00 commented Oct 10, 2023

게시판 entity, repo 작성 완료했습니다.

@lgsok00 lgsok00 added the enhancement New feature or request label Oct 10, 2023
@lgsok00 lgsok00 self-assigned this Oct 10, 2023
Copy link
Member

@bongsh0112 bongsh0112 left a comment

Choose a reason for hiding this comment

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

고생하셨습니다
수정사항 확인해주세요


private final ArticleService articleService;

@GetMapping("{/boardId}")
Copy link
Member

Choose a reason for hiding this comment

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

@GetMapping("/{boardId}")
가 맞지 않을까요..?

Copy link
Member

Choose a reason for hiding this comment

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

맞지 {/boardId}는 좀 너무했다

Comment on lines 48 to 49
private Long createdUser;
private Long updatedUser;
Copy link
Member

Choose a reason for hiding this comment

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

create 혹은 update한 User의 Id를 쓰는거면
createdUserId와 같은 방식으로 쓰는게 좋겠네요

private String orgArticleLanguage;
private String articleType;
private String status;
private int likeCount;
Copy link
Member

Choose a reason for hiding this comment

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

혹시 likeCount 업데이트는 어떻게 진행되나요?
좋아요 누르면 이 값이 업데이트 되어야 할텐데요

Comment on lines 21 to 24
List<Board> boardList = boardRepository.findAll();
List<BoardDto> boardDtoList = new ArrayList<>();
// boardDtoList = boardList.stream().map().toList();
return boardDtoList;
Copy link
Member

Choose a reason for hiding this comment

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

우선 빈 리스트만 리턴하도록 해놓은 것 맞나요

Comment on lines 22 to 29
// boardId로 board에 해당하는 Article들을 모두 뽑아온다
// Article들 하나하나마다에 해당하는 ArticleContent랑 같이 DTO로 변환한다
// 변환된 DTO들을 모아놓은 list를 리턴한다
return articleRepository
.findAllByBoard(boardRepository.findById(boardId).orElseThrow(() -> ExampleException.EXCEPTION))
.stream().map(article -> ArticleDto.of(article, articleContentRepository.findByArticleAndLanguage(article, language).orElseThrow(() -> ExampleException.EXCEPTION)))
.toList();
}
Copy link
Member

Choose a reason for hiding this comment

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

주석에 따라 혼자서 다시 작성해보세요

@JoinColumn(name="board_id")
private Board board;

@OneToMany
Copy link
Member

Choose a reason for hiding this comment

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

@OneToMany(mappedBy = ~~~)에 대해
공부해보시고 수정 바랍니다

@OneToMany
private List<ArticleLike> ArticleLike;

@OneToMany
Copy link
Member

Choose a reason for hiding this comment

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

@OneToMany(mappedBy = ~~~)에 대해
공부해보시고 수정 바랍니다

@OneToMany
private List<ArticleContent> articleContent;

@OneToMany
Copy link
Member

Choose a reason for hiding this comment

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

@OneToMany(mappedBy = ~~~)에 대해
공부해보시고 수정 바랍니다

@JoinColumn(name="article_id")
private Article article;

private String language;
Copy link
Member

Choose a reason for hiding this comment

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

LanguageType이라는 이넘을 만드신 걸로 아는데
혹시 이건 어떤 필드인가요

@JoinColumn(name="article_id")
private Article article;

@OneToMany
Copy link
Member

Choose a reason for hiding this comment

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

마찬가지로 mappedBy를 사용해보세요

Copy link
Member

@donsonioc2010 donsonioc2010 left a comment

Choose a reason for hiding this comment

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

일단 바꿔오세욧


private final ArticleService articleService;

@GetMapping("{/boardId}")
Copy link
Member

Choose a reason for hiding this comment

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

맞지 {/boardId}는 좀 너무했다

import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
Copy link
Member

Choose a reason for hiding this comment

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

import org.springframework.web.bind.annotation.*;
는 실제 참조하는 메소드로 변경해주세요.

package HookKiller.server.board.entity;

import HookKiller.server.common.AbstractTimeStamp;
import jakarta.persistence.*;
Copy link
Member

Choose a reason for hiding this comment

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

import jakarta.persistence.*를 참조하는 메소드로 수정바람

package HookKiller.server.board.entity;


import jakarta.persistence.*;
Copy link
Member

Choose a reason for hiding this comment

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

import jakarta.persistence.*를 참조하는 메소드로 수정바람



import HookKiller.server.common.AbstractTimeStamp;
import jakarta.persistence.*;
Copy link
Member

Choose a reason for hiding this comment

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

import jakarta.persistence.*를 참조하는 메소드로 수정바람


@Getter
@AllArgsConstructor
public enum GlobalException implements BaseErrorCode {
Copy link
Member

Choose a reason for hiding this comment

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

BoardExceptions로 따로 뺴기 바람. GlobalException은 이미 사용중이니..


import java.util.List;

@Repository
Copy link
Member

Choose a reason for hiding this comment

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

필요없음.

* Spring Data JPA를 사용하여 기본 CRUD 작업을 자동으로 처리합니다.
*/

@Repository
Copy link
Member

Choose a reason for hiding this comment

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

필요없음.

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

@Repository
Copy link
Member

Choose a reason for hiding this comment

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

필요없음.

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

@Repository
Copy link
Member

Choose a reason for hiding this comment

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

필요없음.

Copy link
Member

@donsonioc2010 donsonioc2010 left a comment

Choose a reason for hiding this comment

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

build.gradle Outdated
@@ -72,6 +72,9 @@ dependencies {
// IAMPORT
implementation 'com.github.iamport:iamport-rest-client-java:0.2.23'

// WebClient
implementation "org.springframework.boot:spring-boot-starter-webflux"
Copy link
Member

Choose a reason for hiding this comment

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

제거하시기 바랍니다.


@Slf4j
@RestController
@RequestMapping("/articles")
Copy link
Member

Choose a reason for hiding this comment

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

이게 좀 더 어울리지 않을까요?

Suggested change
@RequestMapping("/articles")
@RequestMapping("/article")

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

Comment on lines 30 to 31
BoardType language = BoardType.valueOf(request.getHeader("language"));
return articleService.getArticleList(boardId, language);
Copy link
Member

Choose a reason for hiding this comment

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

이게 낫지 않을까요?, "language"는 따로 상수화 시키는게 좋을 것 같네요.

Suggested change
BoardType language = BoardType.valueOf(request.getHeader("language"));
return articleService.getArticleList(boardId, language);
return articleService.getArticleList(boardId, BoardType.valueOf(request.getHeader("language")));

Comment on lines 51 to 53
articleContentService.updateContent(
requestDto, articleService.updateArticle(articleId, requestDto)
);
Copy link
Member

Choose a reason for hiding this comment

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

여기는 깊게 생각해봤는데 두개를 한개의 메소드에서 작업하고 Transactional 처리를 해야 할 것 같습니다.

번역에 실패하면 롤백해야 하기 떄문입니다.


public interface ArticleRepository extends JpaRepository<Article, Long> {

public List<Article> findAllByBoard(Board board);
Copy link
Member

Choose a reason for hiding this comment

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

public이라면 접근제어자가 굳이 필요하지 않습니다.


public List<Article> findAllByBoard(Board board);

List<Article> findAllByBoardAndStatus(Board board, String status);
Copy link
Member

Choose a reason for hiding this comment

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

해당 메소드가 실행이 되는지 확인하시기 바랍니다.

또한 파라미터도 정상적으로 기입하였는지 확인바랍니다.

Comment on lines 25 to 47
List<LanguageType> targetLanguageList = Arrays.stream(LanguageType.values())
.filter(languageType -> !languageType.equals(requestDto.getOrgArticleLanguage()))
.toList();

List<ArticleContent> articleContentList = new ArrayList<>(
targetLanguageList.stream().map(
languageType -> ArticleContent.builder()
.article(article)
.language(languageType)
.title(getTranslatePapagoTextArticleContent(requestDto.getOrgArticleLanguage().getLanguageCode(), languageType.getLanguageCode(), requestDto.getTitle()))
.content(getTranslatePapagoHTMLArticleContent(requestDto.getOrgArticleLanguage().getLanguageCode(), languageType.getLanguageCode(), requestDto.getContent()))
.build()
).toList()
);
articleContentList.add(
ArticleContent.builder()
.article(article)
.language(requestDto.getOrgArticleLanguage())
.title(requestDto.getTitle())
.content(requestDto.getContent())
.build()
);
articleContentRepository.saveAll(articleContentList);
Copy link
Member

Choose a reason for hiding this comment

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

ArticleController에서 했던 말처럼 articleService에서 기록했던 것처럼 한개의 메소드에서 처리가 필요할 것 같습니다.

Comment on lines 50 to 74
public void updateContent(PostArticleRequestDto requestDto, Article article) {
// 게시물의 모든 내용을 찾습니다.
List<ArticleContent> existingContents = articleContentRepository.findAllByArticle(article);

// 원본 언어의 내용을 업데이트합니다.
existingContents.stream()
.filter(content -> content.getLanguage().equals(requestDto.getOrgArticleLanguage()))
.forEach(content -> {
content.articleUpdate(requestDto.getTitle(), requestDto.getContent());
});

// 다른 언어로 번역된 내용들을 업데이트합니다.
for (LanguageType languageType : LanguageType.values()) {
if (!languageType.equals(requestDto.getOrgArticleLanguage())) {
existingContents.stream()
.filter(content -> content.getLanguage().equals(languageType))
.forEach(content -> {
content.articleUpdate(getTranslatePapagoTextArticleContent(requestDto.getOrgArticleLanguage().getLanguageCode(), languageType.getLanguageCode(), requestDto.getTitle()),
getTranslatePapagoHTMLArticleContent(requestDto.getOrgArticleLanguage().getLanguageCode(), languageType.getLanguageCode(), requestDto.getContent()));
});
}
}

articleContentRepository.saveAll(existingContents);
}
Copy link
Member

Choose a reason for hiding this comment

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

ArticleController에서 했던 말처럼 articleService에서 기록했던 것처럼 한개의 메소드에서 처리가 필요할 것 같습니다.

@@ -2,7 +2,7 @@
hook:
db:
url: db-it7f7-kr.vpc-pub-cdb.ntruss.com
database: jw
database: js
Copy link
Member

Choose a reason for hiding this comment

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

Rollback

@donsonioc2010 donsonioc2010 self-requested a review October 13, 2023 00:27
Copy link
Member

@donsonioc2010 donsonioc2010 left a comment

Choose a reason for hiding this comment

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

LGTM

@donsonioc2010 donsonioc2010 requested review from bongsh0112 and removed request for bongsh0112 October 13, 2023 00:30
Copy link
Member

@bongsh0112 bongsh0112 left a comment

Choose a reason for hiding this comment

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

LGTM 고생하셨습니다

@bongsh0112 bongsh0112 merged commit 031b0e5 into dev Oct 13, 2023
1 check passed
@bongsh0112 bongsh0112 deleted the feat/10-board branch October 13, 2023 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants