Skip to content

Commit

Permalink
Merge pull request #45 from wbluke/feature/6-review-refactor-#44
Browse files Browse the repository at this point in the history
[#44] 8/15 리팩토링 및 프론트엔드와 백엔드 연결
  • Loading branch information
wbluke authored Aug 15, 2019
2 parents f48418a + 7bb7820 commit 9bd7cc0
Show file tree
Hide file tree
Showing 47 changed files with 685 additions and 279 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.woowacourse.zzazanstagram.config;

import com.woowacourse.zzazanstagram.web.interceptor.LoginInterceptor;
import com.woowacourse.zzazanstagram.web.resolver.SessionArgumentResolver;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

Expand All @@ -21,4 +23,9 @@ public void addInterceptors(InterceptorRegistry registry) {
.addPathPatterns("/**")
.excludePathPatterns(excludePatterns);
}

@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
resolvers.add(new SessionArgumentResolver());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.woowacourse.zzazanstagram.model.article.dto.ArticleRequest;
import com.woowacourse.zzazanstagram.model.article.service.ArticleService;
import com.woowacourse.zzazanstagram.model.member.MemberSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
Expand Down Expand Up @@ -34,8 +35,8 @@ public String createArticle() {
}

@PostMapping("/articles")
public String create(@Valid ArticleRequest dto) {
articleService.save(dto);
public String create(@Valid ArticleRequest dto, MemberSession memberSession) {
articleService.save(dto, memberSession.getEmail());
return "redirect:/";
}
}
Original file line number Diff line number Diff line change
@@ -1,47 +1,51 @@
package com.woowacourse.zzazanstagram.model.article.domain;

import com.woowacourse.zzazanstagram.model.article.domain.vo.Contents;
import com.woowacourse.zzazanstagram.model.article.domain.vo.ImageUrl;
import com.woowacourse.zzazanstagram.model.article.domain.vo.Image;
import com.woowacourse.zzazanstagram.model.common.BaseEntity;
import com.woowacourse.zzazanstagram.model.member.domain.Member;

import javax.persistence.Entity;
import javax.persistence.*;

@Entity
public class Article extends BaseEntity {
private ImageUrl imageUrl;
private Image image;
private Contents contents;

// @Column(name = "author", nullable = false)
// private Member author;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "author", nullable = false, foreignKey = @ForeignKey(name = "fk_article_to_member"))
private Member author;

private Article() {
protected Article() {
}

private Article(ImageUrl imageUrl, Contents contents) {
this.imageUrl = imageUrl;
this.contents = contents;
}

/* public Article(final ImageUrl imageUrl, final Contents contents, final Member author) {
this.imageUrl = imageUrl;
public Article(final Image image, final Contents contents, final Member author) {
this.image = image;
this.contents = contents;
this.author = author;
}*/

}

public static Article from(final ImageUrl imageUrl, final Contents contents) {
return new Article(imageUrl, contents);
public static Article from(final Image image, final Contents contents, final Member author) {
return new Article(image, contents, author);
}

public ImageUrl getImageUrl() {
return imageUrl;
public Image getImage() {
return image;
}

public Contents getContents() {
return contents;
}

/* public Member getAuthor() {
public String image() {
return image.getUrl();
}

public String contents() {
return contents.getContents();
}

public Member getAuthor() {
return author;
}*/
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.woowacourse.zzazanstagram.model.article.domain.vo;

import com.woowacourse.zzazanstagram.model.article.exception.ArticleException;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import java.net.HttpURLConnection;
import java.net.URL;

@Embeddable
public class Image {

@Column(name = "image_url", nullable = false)
private String url;

private Image() {
}

private Image(final String url) {
this.url = validateUrl(url);
}

private String validateUrl(final String url) {
try {
HttpURLConnection.setFollowRedirects(false);
HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection();
con.setRequestMethod("HEAD");
if (con.getResponseCode() != HttpURLConnection.HTTP_OK) {
throw new ArticleException("리소스가 존재하지 않습니다");
}
} catch (Exception e) {
throw new ArticleException("리소스 경로가 올바르지 않습니다");
}
return url;
}

public static Image of(final String imageUrl) {
return new Image(imageUrl);
}

public String getUrl() {
return url;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,37 +1,30 @@
package com.woowacourse.zzazanstagram.model.article.dto;

import javax.persistence.Column;
import javax.persistence.Lob;
import javax.validation.constraints.NotBlank;

public class ArticleRequest {

@NotBlank
@Column(name = "image_url", nullable = false)
private String imageUrl;
private String image;

@Lob
@Column(name = "contents")
private String contents;

@Column(name = "hash_tag")
private String hashTag;

public ArticleRequest() {
}

public ArticleRequest(String imageUrl, String contents, String hashTag) {
this.imageUrl = imageUrl;
public ArticleRequest(String image, String contents, String hashTag) {
this.image = image;
this.contents = contents;
this.hashTag = hashTag;
}

public String getImageUrl() {
return imageUrl;
public String getImage() {
return image;
}

public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
public void setImage(String image) {
this.image = image;
}

public String getContents() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@

public class ArticleResponse {
private Long id;
private String imageUrl;
private String image;
private String contents;
// private String hashTag;
// private String hashTag;
private String nickName;
private String profileImage;
private LocalDateTime createdDate;
private LocalDateTime lastModifiedDate;

//Todo author, 댓글, 좋아요 추가하자
//Todo 댓글, 좋아요 추가하자

public ArticleResponse() {
}

public ArticleResponse(Long id, String imageUrl, String contents, LocalDateTime createdDate, LocalDateTime lastModifiedDate) {
private ArticleResponse(Long id, String image, String contents, String nickName, String profileImage, LocalDateTime createdDate, LocalDateTime lastModifiedDate) {
this.id = id;
this.imageUrl = imageUrl;
this.image = image;
this.contents = contents;
this.nickName = nickName;
this.profileImage = profileImage;
this.createdDate = createdDate;
this.lastModifiedDate = lastModifiedDate;
}
Expand All @@ -27,19 +31,85 @@ public Long getId() {
return id;
}

public String getImageUrl() {
return imageUrl;
public String getImage() {
return image;
}

public String getContents() {
return contents;
}

public String getNickName() {
return nickName;
}

public String getProfileImage() {
return profileImage;
}

public LocalDateTime getCreatedDate() {
return createdDate;
}

public LocalDateTime getLastModifiedDate() {
return lastModifiedDate;
}


public static final class ArticleResponseBuilder {
private Long id;
private String image;
private String contents;
// private String hashTag;
private String nickName;
private String profileImage;
private LocalDateTime createdDate;
private LocalDateTime lastModifiedDate;

private ArticleResponseBuilder() {
}

public static ArticleResponseBuilder anArticleResponse() {
return new ArticleResponseBuilder();
}

public ArticleResponseBuilder id(Long id) {
this.id = id;
return this;
}

public ArticleResponseBuilder image(String image) {
this.image = image;
return this;
}

public ArticleResponseBuilder contents(String contents) {
this.contents = contents;
return this;
}

public ArticleResponseBuilder nickName(String nickName) {
this.nickName = nickName;
return this;
}

public ArticleResponseBuilder profileImage(String profileImage) {
this.profileImage = profileImage;
return this;
}

public ArticleResponseBuilder createdDate(LocalDateTime createdDate) {
this.createdDate = createdDate;
return this;
}

public ArticleResponseBuilder lastModifiedDate(LocalDateTime lastModifiedDate) {
this.lastModifiedDate = lastModifiedDate;
return this;
}

public ArticleResponse build() {
return new ArticleResponse(id, image, contents, nickName, profileImage, createdDate, lastModifiedDate);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.woowacourse.zzazanstagram.model.article.exception;

public class ArticleException extends IllegalArgumentException {
public ArticleException() {
}

public ArticleException(String s) {
super(s);
}
}
Loading

0 comments on commit 9bd7cc0

Please sign in to comment.