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

[비동기 댓글 기능] 베디 미션 제출합니다 #166

Merged
merged 29 commits into from
Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d5c497e
refactor: 패키지 구조 mvc로 변경
dpudpu Aug 3, 2019
f8f2b08
refactor: controller 패키지 구조 변경
dpudpu Aug 3, 2019
5d80a86
feat: 작성글 갯수 확인 api 구현
dpudpu Aug 4, 2019
0b9c209
feat: 댓글 작성 api 구현
dpudpu Aug 4, 2019
219b125
refactor: service layer, 다른 service 의존하게 변경
dpudpu Aug 4, 2019
5b8ff08
refactor: ArticleServiceTest Mockito 로 구현
dpudpu Aug 4, 2019
b59cfb8
feat: RollingFileAppender 추가
dpudpu Aug 5, 2019
adafd65
refactor: CommentApiTest ObjectMapper 적용
dpudpu Aug 5, 2019
3671a77
test: CommentServiceTest slicesTest 로 구현
dpudpu Aug 5, 2019
a7c3c42
feat: CommentApi CRUD 추가
dpudpu Aug 6, 2019
5941524
feat: comments.js crud ajax 구현
dpudpu Aug 6, 2019
cff3431
refactor: error.html 에러처리 방식 수정
dpudpu Aug 6, 2019
32fa41d
feat: logback-spring RollingFileAppender 추가
dpudpu Aug 6, 2019
f99fa93
feat: deploy.sh 쉘스크립트 추가
dpudpu Aug 6, 2019
0aa25d1
feat: Logging 컬러 추가
dpudpu Aug 6, 2019
bfe4ece
style: 포맷팅
dpudpu Aug 6, 2019
b1f8d93
rename: ArticleApi, CommentApi -> ArticleRestController, CommentRestC…
dpudpu Aug 8, 2019
3e71a64
refactor: ArticleRestController.getCount() 응답 HttpStatus 변경
dpudpu Aug 8, 2019
5cd1db8
refactor: interceptor 패스 추가
dpudpu Aug 8, 2019
2e64f35
test: Mockito 학습테스트 추가
dpudpu Aug 8, 2019
bcf7779
refactor: UserController 본인 확인 AuthInterceptor 가 아닌 Controller에서 하게 변경
dpudpu Aug 8, 2019
d0e0410
style: 필요없는 주석 제거
dpudpu Aug 8, 2019
2cea2b7
refactor: deploy.sh
dpudpu Aug 8, 2019
29eba69
feat: CommentDto @JsonFormat(pattern = "yyyy-mm-dd HH:mm") 추가
dpudpu Aug 9, 2019
6b28f03
refactor: SpringExtension -> MockitoExtension 로 변경
dpudpu Aug 9, 2019
fbd4ab7
feat: 테스트용 샘플 데이터 추가
dpudpu Aug 9, 2019
31a1bfb
refactor: CommentRestController Hateoas 일부 기능 적용, 리턴 방식 변경
dpudpu Aug 9, 2019
9cc1ea3
refactor: 패키지 구조 변경
dpudpu Aug 9, 2019
a953ac5
refactor: ArticleDto.Response 의존 변경 List<Comment> -> List<CommentDto.…
dpudpu Aug 9, 2019
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
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ repositories {

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-hateoas'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'com.h2database:h2'
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'
implementation 'org.projectlombok:lombok:1.18.8'
implementation 'com.h2database:h2'

annotationProcessor 'org.projectlombok:lombok:1.18.8'

runtimeOnly 'net.rakugakibox.spring.boot:logback-access-spring-boot-starter:2.7.1'
runtimeOnly 'org.springframework.boot:spring-boot-devtools'

testImplementation 'org.mockito:mockito-junit-jupiter'
testImplementation "org.junit.jupiter:junit-jupiter-params:5.4.2"
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
Expand Down
26 changes: 26 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
REPOSITORY="/home/ubuntu/"
cd $REPOSITORY/jwp-blog

BRANCH="step4"
echo ">>> GIT PULL ..."
git pull origin $BRANCH

echo ">>> BUILD START ..."
./gradlew clean build
echo ">>> BUILD COMPLETE"

echo ">>> 현재 구동중인 애플리케이션 pid 확인"
CURRENT_PID=$(pgrep -f myblog)
echo "$CURRENT_PID"

if [ -z $CURRENT_PID ]; then
echo ">>> 현재 구동중인 애플리케이션이 없으므로 종료하지 않습니다."
else
echo ">>> KILL PROCESS $CURRENT_PID"
kill -9 $CURRENT_PID
fi

echo ">>> START NEW APPLICATION..."
JAR_NAME=$(ls $REPOSITORY/jwp-blog/build/libs/ | grep 'myblog' | tail -n 1)
echo ">>> JAR NAME: $JAR_NAME"
nohup java -jar build/libs/$JAR_NAME &

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package techcourse.myblog.articles;
package techcourse.myblog.domain;

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 techcourse.myblog.service.exception.AuthException;

import javax.persistence.*;
import java.util.ArrayList;
Expand Down Expand Up @@ -47,13 +45,13 @@ public List<Comment> getComments() {
return Collections.unmodifiableList(comments);
}

void update(Article other) {
public void update(Article other) {
this.title = other.title;
this.coverUrl = other.coverUrl;
this.contents = other.contents;
}

boolean isWrittenBy(final Long other) {
public boolean isWrittenBy(final Long other) {
if (author.getId().equals(other)) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package techcourse.myblog.articles;
package techcourse.myblog.domain;

import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package techcourse.myblog.articles.comments;
package techcourse.myblog.domain;

import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import techcourse.myblog.articles.Article;
import techcourse.myblog.articles.BaseEntity;
import techcourse.myblog.exception.AuthException;
import techcourse.myblog.users.User;
import techcourse.myblog.service.exception.AuthException;

import javax.persistence.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package techcourse.myblog.users;
package techcourse.myblog.domain;

import lombok.*;
import techcourse.myblog.articles.BaseEntity;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;

Expand All @@ -24,7 +25,7 @@ public class User extends BaseEntity {
private String password;

@Builder
private User(final Long id, final String email, final String name, final String password) {
public User(final Long id, final String email, final String name, final String password) {
if (id == null) {
UserValidator.validateEmail(email);
UserValidator.validatePassword(password);
Expand All @@ -36,11 +37,11 @@ private User(final Long id, final String email, final String name, final String
this.password = password;
}

boolean authenticate(final String password) {
public boolean authenticate(final String password) {
return this.password.equals(password);
}

void update(final User other) {
public void update(final User other) {
this.name = other.name;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package techcourse.myblog.users;
package techcourse.myblog.domain;

import java.util.regex.Pattern;

public class UserValidator {
static final String EMAIL_REGEX = "^[_a-z0-9-]+(.[_a-z0-9-]+)*@(?:\\w+\\.)+\\w+$";
static final String PASSWORD_REGEX = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[$@$!%*?&])[A-Za-z\\d$@$!%*?&]{8,}";
static final String NAME_REGEX = "[가-힣ㄱ-ㅎㅏ-ㅣa-zA-Z]{2,10}";
public static final String PASSWORD_REGEX = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[$@$!%*?&])[A-Za-z\\d$@$!%*?&]{8,}";
public static final String NAME_REGEX = "[가-힣ㄱ-ㅎㅏ-ㅣa-zA-Z]{2,10}";

static final String EMAIL_NOT_MATCH_MESSAGE = "메일의 양식을 지켜주세요.";
static final String NAME_NOT_MATCH_MESSAGE = "이름은 2자이상 10자이하이며, 숫자나 특수문자가 포함될 수 없습니다.";
static final String PASSWORD_NOT_MATCH_MESSAGE = "비밀번호는 8자 이상의 소문자,대문자,숫자,특수문자의 조합이여야 합니다.";
public static final String EMAIL_NOT_MATCH_MESSAGE = "메일의 양식을 지켜주세요.";
public static final String NAME_NOT_MATCH_MESSAGE = "이름은 2자이상 10자이하이며, 숫자나 특수문자가 포함될 수 없습니다.";
public static final String PASSWORD_NOT_MATCH_MESSAGE = "비밀번호는 8자 이상의 소문자,대문자,숫자,특수문자의 조합이여야 합니다.";

private static final Pattern EMAIL_PATTERN = Pattern.compile(EMAIL_REGEX);
private static final Pattern PASSWORD_PATTERN = Pattern.compile(PASSWORD_REGEX);
Expand Down
29 changes: 0 additions & 29 deletions src/main/java/techcourse/myblog/interceptor/AuthInterceptor.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package techcourse.myblog.articles;
package techcourse.myblog.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import techcourse.myblog.domain.Article;
import techcourse.myblog.domain.User;

import java.util.List;

@Repository
public interface ArticleRepository extends JpaRepository<Article, Long> {

List<Article> findAllByAuthor(User user);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package techcourse.myblog.articles.comments;
package techcourse.myblog.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import techcourse.myblog.articles.Article;
import techcourse.myblog.domain.Article;
import techcourse.myblog.domain.Comment;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package techcourse.myblog.users;
package techcourse.myblog.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import techcourse.myblog.domain.User;

import java.util.Optional;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
package techcourse.myblog.articles;
package techcourse.myblog.service;

import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import techcourse.myblog.users.User;
import techcourse.myblog.users.UserRepository;
import techcourse.myblog.domain.Article;
import techcourse.myblog.domain.User;
import techcourse.myblog.repository.ArticleRepository;
import techcourse.myblog.service.dto.ArticleDto;

import java.util.List;

@Service
@Transactional
@RequiredArgsConstructor
public class ArticleService {
private final UserService userService;

private final ArticleRepository articleRepository;
private final UserRepository userRepository;

public ArticleService(final UserService userService, final ArticleRepository articleRepository) {
this.userService = userService;
this.articleRepository = articleRepository;
}

public Long save(final Long userId, final ArticleDto.Request articleDto) {
User author = userRepository.findById(userId)
.orElseThrow(() -> new IllegalArgumentException("등록된 유저가 아닙니다."));
User author = userService.findById(userId);

Article article = articleDto.toArticle(author);

Expand Down Expand Up @@ -50,7 +57,6 @@ public ArticleDto.Response getOne(Long id) {
final Article article = findById(id);

ArticleDto.Response articleDto = ArticleDto.Response.createBy(article);
articleDto.setComments(article.getComments());
return articleDto;
}

Expand All @@ -60,12 +66,21 @@ public ArticleDto.Response getOne(final Long userId, final Long articleId) {

article.isWrittenBy(userId);
ArticleDto.Response articleDto = ArticleDto.Response.createBy(article);
articleDto.setComments(article.getComments());
return articleDto;
}

private Article findById(Long id) {
@Transactional(readOnly = true)
public Article findById(Long id) {
return articleRepository.findById(id)
.orElseThrow(() -> new IllegalArgumentException("없는 글입니다." + id));
}

@Transactional(readOnly = true)
public List<Article> findAllByAuthor(String author) {
if (author != null) {
User user = userService.findByEmail(author);
return articleRepository.findAllByAuthor(user);
}
return articleRepository.findAll();
}
}
Loading