-
Notifications
You must be signed in to change notification settings - Fork 46
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
[댓글 기능] 베디 미션 제출합니다. #105
Merged
Merged
[댓글 기능] 베디 미션 제출합니다. #105
Changes from all commits
Commits
Show all changes
119 commits
Select commit
Hold shift + click to select a range
21df515
remove : 기존 로직 삭제
vsh123 52f4012
feat : MainController 구현
vsh123 2159261
feat: Article 구현
vsh123 2fb0c09
feat: ArticleReposiory 구현
vsh123 95fd8d0
feat: ArticleController.write()
vsh123 1cad0c7
feat: ArticleController.show()
vsh123 44dc298
feat: ArticleController.editForm()
vsh123 a9fda55
ArticleController.edit()
vsh123 0386658
feat: ArticleController.delete()
vsh123 0b5b1bd
feat: ArticleController.writeForm()
vsh123 cd21f32
rename: ArticleControllerTests
vsh123 821ecce
feat: MainController Aritcles 조회
vsh123 908ed88
refactor: @transactional 추가
vsh123 7d3a682
rename: template 이름 변경
vsh123 49bf7b7
feat: UserController.signupForm()
vsh123 c0ee6a0
feat: 회원가입 유효성 검사
vsh123 38a5156
feat: 회원가입 이메일 중복, 패스워드 중복 검사
vsh123 946b966
feat: 회원가입 프론트 구현
vsh123 85d66f2
feat: 로그인 구현
vsh123 24d9d5f
feat: login 구현
vsh123 eff17e5
feat: 로그아웃
vsh123 8e92b91
feat: 회원 목록 조회
vsh123 5924c54
feat: 마이페이지, 수정폼 구현
vsh123 c5f9692
feat: 회원정보 수정
vsh123 d98f66c
feat: 회원탈퇴
vsh123 a7d29a4
refactor: UserDto
vsh123 724fc14
refactor: 테스트코드 중복제거
vsh123 39d11f7
feat: interceptor
vsh123 9fafd01
feat: logger 추가
dpudpu 07aa7d2
test: LoginInterceptor 세션 테스트 추가
dpudpu da27b3f
feat: jupiter-params 추가
dpudpu f8eaf0f
refactor: html 중복 제거
dpudpu 0d41c3c
feat: Articles Paging 구현
dpudpu 64c43a4
test: UserControllerTest 세션 테스트 추가
dpudpu de6c1c0
refactor: uri 상수 처리
dpudpu ee00f77
test: UserServiceTest
dpudpu f5d62fa
style: 포맷팅
dpudpu 81b5335
refactor: 샘플데이터 수정
dpudpu 8ff0ca3
refactor: user session 상수 처리
dpudpu 39ae181
rename: ValidSignupException -> ValidUserException
dpudpu 5502bff
refactor: LoginInterceptor 매직넘버 상수처리
dpudpu 80d6306
fix: logout AuthInterceptor에서 튕기는 문제 해결
dpudpu 654fd03
style: build.gradle 정리
dpudpu 1fc5673
refactor: errorAttributes() 를 ErrorConfig.class 로 분리
dpudpu 296c66f
refactor: uri 상수 제거
dpudpu fe563ad
refactor: Article.update() 수정
dpudpu 8db3f71
refactor: test 코드 필요 없는 어노테이션 제거
dpudpu 28a1191
refactor: 인터셉터 클래스 commons 패키지에서 interceptor 로 변경
dpudpu 86143aa
refactor: BeanUtils 제거, User setter 제거
dpudpu 1a9bcb1
refactor: MainController.index Pageable 파라미터로 변경
dpudpu ff6f559
feat: User.authenticate 추가
dpudpu 95d4f77
refactor: ControllerTests 에서 service 빈 제거하고 api를 직접 호출하는 방식으로 변경
dpudpu c5c801e
refactor: user session 처리용 UserSession 생성
dpudpu 5c27961
style: 포맷팅
dpudpu fbf4518
feat: User 유효성검사 추가
dpudpu edf822e
refactor: Article @Builder 방식 변경
dpudpu 864ba07
fix: LoginInterceptor 적용 패스 및 테스트코드 추가
dpudpu 53bf60c
fix: UserDto.Update.toUser()
dpudpu 9e31983
fix: test코드 session 추가
dpudpu bbe330e
docs: application.properties spring.jpa.show-sql=true 제거
dpudpu 56e0055
refactor: UserDto.Update.toUser() 방식 수정
dpudpu 09a288b
refactor: UserDto.Update에 id 필드 추가
dpudpu dde12ec
refactor: User unique 설정 방식 변경
dpudpu 945cb29
refactor: SessionId 상수 UserSession 으로 이동
dpudpu 3c6c1ba
refactor: UserService.login() UserSession 반환 하는 부분 수정
dpudpu 13c0e9e
feat: UserSessionArgumentResolver
dpudpu 3fd3101
refactor: Entity 기본생성자 private으로 변경
dpudpu a931277
Merge remote-tracking branch 'upstream/dpudpu' into dpudpu
dpudpu 41598ee
remove : 모두 삭제하고 처음부터 시작
dpudpu cdf240c
feat: User 유효성 검사
dpudpu 8230130
Revert "feat: User 유효성 검사"
dpudpu 5896d72
Revert "remove : 모두 삭제하고 처음부터 시작"
dpudpu c42eb49
feat: UserValidator
dpudpu 80f8fae
refactor: User.authenticate() 에서 로그인 검증하게 변경
dpudpu 65419e3
refactor: LoginInterceptor 역할 분리
dpudpu 3bec3d9
feat: Article -> User 단방향 관계 추가 + @Column 설정 추가
dpudpu 61907a5
feat: BaseControllerTests 공통 기능(회원가입, getJSession) 추상클래스 추가
dpudpu 5b18c28
feat: Article 글쓴이 추가
dpudpu 07784bd
feat: app-head.html 프론트 디자인 변경
dpudpu 5bfb005
feat: Article 수정시 작성자 아닌 경우 예외처리
dpudpu 7010806
feat: ArticleController Delete 작성자 검증 추가
dpudpu 6884a33
refactor: MainController 패키지 수정
dpudpu 98d5376
rename: NotLoginInterceptor -> GuestInterceptor
dpudpu 1a628db
refactor: Article.User nullable = false 로 변경
dpudpu 281146e
feat: AuthExceptionAdvice 작성자 예외처리 해주는
dpudpu 4c06a15
fix: @ExceptionHandler(AuthException.class) Illigal인거 수정
dpudpu c4873bb
rename: AuthExceptionAdvice -> ExceptionAdvice
dpudpu b4b1911
style: ArticleService 메소드 순서 변경
dpudpu fc61a82
feat: Comment entity
dpudpu dfbc68f
rename: Article.updateDate -> modifiedDate
dpudpu a4ff613
feat: CommentRepository
dpudpu d1ed186
feat: Comment 작성
dpudpu c9d3f49
refactor: Comment 구조 Article 하위로 변경
dpudpu ce61d44
test: CommentControllerTests 수정, 작성 테스트코드 추가
dpudpu 20f29ce
feat: Comment 수정, 삭제 다른 작성자 접근 금지 추가
dpudpu 72fddc8
feat: ArticleController.show() 댓글 목록 보여주기 프론트까지 완료
dpudpu f36cad4
feat: article.html 댓글 수정 구현
dpudpu 69522d9
refactor: Comment 엔티티 어노테이션 수정
dpudpu ee0cadd
feat: error.html 에러페이지 추가
dpudpu da5c8c1
refactor: ExceptionAdvice.handleAuthException() 수정
dpudpu 04d6f7f
feat: ExceptionAdvice.handleRuntimeException()
dpudpu fadad5b
refactor: CommentService 중복 제거
dpudpu 51d4718
style: 포맷팅
dpudpu 2be369e
refactor: ExceptionAdvice RuntimeException -> IllegalArgumentExceptio…
dpudpu e72d96c
feat: Article, Comment 양방향 관계 추가
dpudpu 8b0bea5
feat: CommentDto.Update 추가
dpudpu 6e23087
test: CommentServiceTest
dpudpu 1832271
Revert "feat: CommentDto.Update 추가"
dpudpu eb21053
refactor: ExceptionAdvice.class log.info -> log.error
dpudpu a5f4bf3
refactor: 작성자 확인 후 예외처리 Comment, Article 에게 위임
dpudpu 72d7366
refactor: Comment, Article @ManyToOne(fetch = FetchType.LAZY) 추가
dpudpu a35234b
refactor: 예외처리 메시지 영어에서 한글로 수정
dpudpu e0481ea
test: User.authenticate() 테스트 추가
dpudpu 0e18a79
refactor: Comment.User FetchType.LAZY 제거
dpudpu 26035ce
refactor: ValidUserException log.debug -> log.error 로 변경
dpudpu fc3a565
feat: BaseEntity (@MappedSuperclass) 구현
dpudpu 3d47ce1
feat: ArticleDto 추가
dpudpu 9c27bb1
refactor: 작성자 확인 isWrittenBy() 엔티티가 아닌 @Id로 확인
dpudpu 1715714
refactor: Article.getComments() Collections.unmodifiableList() 추가
dpudpu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/techcourse/myblog/advice/ExceptionAdvice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package techcourse.myblog.advice; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import techcourse.myblog.exception.AuthException; | ||
|
||
@ControllerAdvice | ||
public class ExceptionAdvice { | ||
private static final Logger log = LoggerFactory.getLogger(ExceptionAdvice.class); | ||
|
||
@ResponseStatus(HttpStatus.FORBIDDEN) | ||
@ExceptionHandler(AuthException.class) | ||
public String handleAuthException(Exception e, Model model) { | ||
|
||
log.error(e.toString()); | ||
|
||
model.addAttribute("errorMessage", e.getMessage()); | ||
model.addAttribute("path", "/"); | ||
return "error"; | ||
} | ||
|
||
@ResponseStatus(HttpStatus.BAD_REQUEST) | ||
@ExceptionHandler(IllegalArgumentException.class) | ||
public String handleRuntimeException(Exception e, Model model) { | ||
|
||
log.error(e.toString()); | ||
|
||
model.addAttribute("errorMessage", e.getMessage()); | ||
model.addAttribute("path", "/"); | ||
return "error"; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,64 @@ | ||
package techcourse.myblog.articles; | ||
|
||
import lombok.*; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import techcourse.myblog.articles.comments.Comment; | ||
import techcourse.myblog.exception.AuthException; | ||
import techcourse.myblog.users.User; | ||
|
||
import javax.persistence.*; | ||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
@Entity | ||
@Getter | ||
@Setter | ||
@ToString | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
@EqualsAndHashCode(of = "id") | ||
public class Article { | ||
@NoArgsConstructor | ||
public class Article extends BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column | ||
@Column(nullable = false, length = 100) | ||
private String title; | ||
|
||
@Column | ||
@Lob | ||
private String contents; | ||
|
||
@Column | ||
@Column(nullable = false) | ||
private String coverUrl; | ||
|
||
@CreatedDate | ||
@Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", updatable = false) | ||
private LocalDateTime regDate; | ||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "user_id", foreignKey = @ForeignKey(name = "fk_article_to_user"), nullable = false) | ||
private User author; | ||
|
||
@LastModifiedDate | ||
@Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP") | ||
private LocalDateTime updateDate; | ||
@OneToMany(mappedBy = "article", orphanRemoval = true) | ||
private List<Comment> comments = new ArrayList<>(); | ||
|
||
@Builder | ||
private Article(final String title, final String contents, final String coverUrl) { | ||
public Article(final String title, final String contents, final String coverUrl, final User author) { | ||
this.title = title; | ||
this.contents = contents; | ||
this.coverUrl = coverUrl; | ||
this.author = author; | ||
} | ||
|
||
public List<Comment> getComments() { | ||
return Collections.unmodifiableList(comments); | ||
} | ||
|
||
public void update(Article other) { | ||
this.updateDate = LocalDateTime.now(); | ||
void update(Article other) { | ||
this.title = other.title; | ||
this.coverUrl = other.coverUrl; | ||
this.contents = other.contents; | ||
} | ||
|
||
boolean isWrittenBy(final Long other) { | ||
if (author.getId().equals(other)) { | ||
return true; | ||
} | ||
throw new AuthException("작성자가 아닙니다."); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package techcourse.myblog.articles; | ||
|
||
|
||
import lombok.*; | ||
import techcourse.myblog.articles.comments.Comment; | ||
import techcourse.myblog.users.User; | ||
|
||
import java.util.List; | ||
|
||
public class ArticleDto { | ||
|
||
@Setter | ||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class Request { | ||
private Long id; | ||
private String contents; | ||
private String title; | ||
private String coverUrl; | ||
|
||
public Article toArticle(final User author) { | ||
return Article.builder() | ||
.contents(contents) | ||
.coverUrl(coverUrl) | ||
.title(title) | ||
.author(author) | ||
.build(); | ||
} | ||
|
||
public Article toArticle() { | ||
return Article.builder() | ||
.contents(contents) | ||
.coverUrl(coverUrl) | ||
.title(title) | ||
.build(); | ||
} | ||
} | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public static class Response { | ||
private Long id; | ||
private String contents; | ||
private String title; | ||
private String coverUrl; | ||
private List<Comment> comments; | ||
|
||
Response(Article article) { | ||
id = article.getId(); | ||
contents = article.getContents(); | ||
title = article.getTitle(); | ||
coverUrl = article.getCoverUrl(); | ||
} | ||
|
||
public static Response createBy(Article article) { | ||
return new ArticleDto.Response(article); | ||
} | ||
|
||
public void setComments(List<Comment> comments) { | ||
this.comments = comments; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package techcourse.myblog.articles; | ||
|
||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import org.hibernate.annotations.CreationTimestamp; | ||
import org.hibernate.annotations.UpdateTimestamp; | ||
|
||
import javax.persistence.*; | ||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@MappedSuperclass | ||
@EqualsAndHashCode(of = "id") | ||
public abstract class BaseEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@CreationTimestamp | ||
@Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", updatable = false) | ||
private LocalDateTime regDate; | ||
|
||
@UpdateTimestamp | ||
@Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP") | ||
private LocalDateTime modifiedDate; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
fetch type 에 대해 찾아볼까요?
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.
@manytoone(fetch = FetchType.LAZY)
반영했습니다. 감사합니다
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.
차이점에 대해서도 찾아보았죠 !? 👍