-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
There was a problem hiding this 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}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GetMapping("/{boardId}")
가 맞지 않을까요..?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
맞지 {/boardId}
는 좀 너무했다
private Long createdUser; | ||
private Long updatedUser; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
혹시 likeCount 업데이트는 어떻게 진행되나요?
좋아요 누르면 이 값이 업데이트 되어야 할텐데요
List<Board> boardList = boardRepository.findAll(); | ||
List<BoardDto> boardDtoList = new ArrayList<>(); | ||
// boardDtoList = boardList.stream().map().toList(); | ||
return boardDtoList; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
우선 빈 리스트만 리턴하도록 해놓은 것 맞나요
// 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(); | ||
} |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
마찬가지로 mappedBy
를 사용해보세요
There was a problem hiding this 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}") |
There was a problem hiding this comment.
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.*; |
There was a problem hiding this comment.
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.*; |
There was a problem hiding this comment.
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.*; |
There was a problem hiding this comment.
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.*; |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
필요없음.
There was a problem hiding this 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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
제거하시기 바랍니다.
|
||
@Slf4j | ||
@RestController | ||
@RequestMapping("/articles") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이게 좀 더 어울리지 않을까요?
@RequestMapping("/articles") | |
@RequestMapping("/article") |
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; |
There was a problem hiding this comment.
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.*; | |
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; | |
BoardType language = BoardType.valueOf(request.getHeader("language")); | ||
return articleService.getArticleList(boardId, language); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이게 낫지 않을까요?, "language"는 따로 상수화 시키는게 좋을 것 같네요.
BoardType language = BoardType.valueOf(request.getHeader("language")); | |
return articleService.getArticleList(boardId, language); | |
return articleService.getArticleList(boardId, BoardType.valueOf(request.getHeader("language"))); |
articleContentService.updateContent( | ||
requestDto, articleService.updateArticle(articleId, requestDto) | ||
); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
해당 메소드가 실행이 되는지 확인하시기 바랍니다.
또한 파라미터도 정상적으로 기입하였는지 확인바랍니다.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ArticleController에서 했던 말처럼 articleService에서 기록했던 것처럼 한개의 메소드에서 처리가 필요할 것 같습니다.
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); | ||
} |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rollback
진석 + 정훈 기능 join
…pleController로 분리
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 고생하셨습니다
게시판 entity, repo 작성 완료했습니다.