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
Show file tree
Hide file tree
Changes from 8 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
@@ -0,0 +1,26 @@
package HookKiller.server.board.controller;

import HookKiller.server.board.dto.ArticleDto;
import HookKiller.server.board.entity.Article;
import HookKiller.server.board.service.ArticleService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@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")

@RequiredArgsConstructor
public class ArticleController {

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}는 좀 너무했다

public List<ArticleDto> getArticleList(@PathVariable Long boardId) {
String language = "KOR";
return articleService.getArticleList(boardId, language);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package HookKiller.server.board.controller;

import HookKiller.server.board.dto.BoardDto;
import HookKiller.server.board.entity.Board;
import HookKiller.server.board.service.BoardService;
import lombok.Getter;
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.*;
는 실제 참조하는 메소드로 변경해주세요.


import java.util.List;
import java.util.Optional;

@RestController
@RequiredArgsConstructor
@RequestMapping("/board")
public class BoardController {

private final BoardService boardService;

@GetMapping
public List<BoardDto> getBoardList() {
List<BoardDto> dto = boardService.getBoardList();
return dto;
}
}
31 changes: 31 additions & 0 deletions src/main/java/HookKiller/server/board/dto/ArticleDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package HookKiller.server.board.dto;

import HookKiller.server.board.entity.Article;
import HookKiller.server.board.entity.ArticleContent;
import lombok.Builder;
import lombok.Getter;
import org.joda.time.DateTime;

import java.sql.Timestamp;

@Getter
@Builder
public class ArticleDto {

private Long articleId;
private String title;
private Timestamp createdAt;
private Long createdUser;
private int likeCount;

public static ArticleDto of(Article article, ArticleContent articleContent) {
return ArticleDto.builder()
.articleId(article.getId())
.title(articleContent.getTitle())
.createdAt(article.getCreateAt())
.createdUser(article.getCreatedUser())
.likeCount(article.getLikeCount())
.build();
}

}
29 changes: 29 additions & 0 deletions src/main/java/HookKiller/server/board/dto/BoardDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package HookKiller.server.board.dto;

import HookKiller.server.board.entity.Board;
import HookKiller.server.board.repository.BoardRepository;
import jakarta.persistence.Enumerated;
import lombok.Builder;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.springframework.stereotype.Service;

@Getter
@Builder
public class BoardDto {

private Long id;
private String name;
private String boardType;
private String description;

public static BoardDto from(Board board) {
return BoardDto.builder()
.id(board.getId())
.name(board.getName())
.description(board.getDescription())
.build();
}

}
51 changes: 51 additions & 0 deletions src/main/java/HookKiller/server/board/entity/Article.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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.*를 참조하는 메소드로 수정바람

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 jakarta.persistence.*;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
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 jakarta.persistence.OneToMany;
import jakarta.persistence.Table;

import lombok.*;
import org.joda.time.DateTime;

import java.util.List;

/**
* orgArticleLanguage : 원본으로 작성된 언어 타입. KOR:한국어, ENG:영어, CHI:중국어, JPN:일본어
* articleType : 게시물 종류. NOTI:공지사항, NORMAL:일반적인 게시물
* status : 게시물 상태. WRITING:작성중, PUBLIC:공개상태, HIDING:숨김처리, DELETE:삭제처리
* likeCount : 좋아요 갯수.
* isDeleted : 게시글 삭제 여부
* createdAt : 게시글 생성일
* createdUser : 게시글 작성 사용자 ID입력
* updatedAt : 게시글 정보 업데이트 일자
* updatedUser : 마지막에 수정한 사용자 ID입력
*/
Copy link
Member

Choose a reason for hiding this comment

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

아래의 컬럼과 동일한 정보인가요?


@Entity
@Getter
@RequiredArgsConstructor
public class Article extends AbstractTimeStamp {
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
@Entity
@Getter
@RequiredArgsConstructor
public class Article extends AbstractTimeStamp {
@Entity
@Getter
@Table(name = "tbl_article")
@RequiredArgsConstructor
public class Article extends AbstractTimeStamp {


@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@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 = ~~~)에 대해
공부해보시고 수정 바랍니다

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 = ~~~)에 대해
공부해보시고 수정 바랍니다

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 = ~~~)에 대해
공부해보시고 수정 바랍니다

private List<Reply> reply;

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 업데이트는 어떻게 진행되나요?
좋아요 누르면 이 값이 업데이트 되어야 할텐데요

private boolean isDeleted;
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와 같은 방식으로 쓰는게 좋겠네요


}
37 changes: 37 additions & 0 deletions src/main/java/HookKiller/server/board/entity/ArticleContent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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 lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
* id : PK
* article : 게시글 정보
* language : 적용된 언어 타입
* title : 게시글 제목
* content : 게시글 내용
*/

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
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
@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@Getter
@Table(name = "tbl_article_content")
@NoArgsConstructor(access = AccessLevel.PROTECTED)

public class ArticleContent {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@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이라는 이넘을 만드신 걸로 아는데
혹시 이건 어떤 필드인가요

private String title;

@Column
@Lob
private String content;

}
32 changes: 32 additions & 0 deletions src/main/java/HookKiller/server/board/entity/ArticleLike.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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.*를 참조하는 메소드로 수정바람

import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.joda.time.DateTime;

/**
* id : PK
* article : 게시물 정보
* userId : 좋아요를 누른 사용자의 userId
* createdAt : 게시물 좋아요를 클릭한 일자
*/

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ArticleLike extends AbstractTimeStamp {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="article_id")
private Article article;

private Long userId;
}
41 changes: 41 additions & 0 deletions src/main/java/HookKiller/server/board/entity/Board.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package HookKiller.server.board.entity;

import HookKiller.server.board.type.BoardType;
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.*를 참조하는 메소드로 수정바람

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 jakarta.persistence.*;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;

import jakarta.validation.constraints.NotNull;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;

import java.util.List;

/**
* id : PK
* name :게시판 명
* boardType : 게시판 종류
* description : 게시판 사용 용도
*/

@Entity
@Getter
@Table(name = "Board")
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
@Table(name = "Board")
@Table(name = "tbl_board")

@RequiredArgsConstructor
public class Board {

@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@OneToMany
private List<Article> article;

@NotNull
private String name;

@Enumerated(EnumType.STRING)
private BoardType boardType;

@NotNull
private String description;

}
43 changes: 43 additions & 0 deletions src/main/java/HookKiller/server/board/entity/Reply.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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.*를 참조하는 메소드로 수정바람

import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.joda.time.DateTime;

import java.util.List;

/**
* id : PK
* article : 게시글 정보
* replyContent : 댓글 내용
* orgReplyLanguage : 원본으로 작성된 언어 타입
* isDeleted : 댓글 삭제 여부
* createdAt : 댓글 생성일
* createdUser : 댓글 작성 사용자 ID
* updatedAt : 댓글 정보 업데이트
* updatedUser : 마지막에 수정한 사용자 ID
*/

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Reply extends AbstractTimeStamp {
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
@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Reply extends AbstractTimeStamp {
@Entity
@Getter
@Table(name = "tbl_reply")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Reply extends AbstractTimeStamp {


@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="article_id")
private Article article;
Comment on lines +40 to +42
Copy link
Member

Choose a reason for hiding this comment

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

@ManyToOne 좋습니다


@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를 사용해보세요

private List<ReplyContent> replyContent;

private String orgReplyLanguage;
private boolean isDeleted;
private Long createdUser;
private Long updatedUser;
}
33 changes: 33 additions & 0 deletions src/main/java/HookKiller/server/board/entity/ReplyContent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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.*를 참조하는 메소드로 수정바람

import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
* language : content가 적용된 언어 타입.
* content : 댓글 내용.
*/

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ReplyContent {
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
@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ReplyContent {
@Entity
@Getter
@Table(name = "tbl_reply_content")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ReplyContent {


@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="reply_id")
private Reply reply;
Comment on lines +33 to +35
Copy link
Member

Choose a reason for hiding this comment

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

@ManyToOne 좋습니다


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 Enum으로 해야하지 않을까?


@Column
@Lob
private String content;


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package HookKiller.server.board.exception;

import HookKiller.server.common.dto.ErrorDetail;

public interface BaseErrorCode {

ErrorDetail getErrorDetail();
}

Copy link
Member

Choose a reason for hiding this comment

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

해당 클래스는 Common에 구현된 클래스 같이 쓰기바람.

17 changes: 17 additions & 0 deletions src/main/java/HookKiller/server/board/exception/BaseException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package HookKiller.server.board.exception;


import HookKiller.server.common.dto.ErrorDetail;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class BaseException extends RuntimeException {

private BaseErrorCode errorCode;

public ErrorDetail getErrorDetail() {
return this.errorCode.getErrorDetail();
}
}
Copy link
Member

Choose a reason for hiding this comment

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

해당 클래스는 Common에 구현된 클래스 같이 쓰기바람.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package HookKiller.server.board.exception;

public class ExampleException extends BaseException {

public static final BaseException EXCEPTION = new ExampleException();

private ExampleException() {
super(GlobalException.EXAMPLE_ERROR);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

이친구는 왜만든거야?

Loading
Loading