forked from woowacourse/miniprojects-2019
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from wbluke/feature/6-review-refactor-#44
[#44] 8/15 리팩토링 및 프론트엔드와 백엔드 연결
- Loading branch information
Showing
47 changed files
with
685 additions
and
279 deletions.
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
29 changes: 0 additions & 29 deletions
29
src/main/java/com/woowacourse/zzazanstagram/model/article/ArticleAssembler.java
This file was deleted.
Oops, something went wrong.
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
46 changes: 25 additions & 21 deletions
46
src/main/java/com/woowacourse/zzazanstagram/model/article/domain/Article.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 |
---|---|---|
@@ -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; | ||
}*/ | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/com/woowacourse/zzazanstagram/model/article/domain/vo/Image.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,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; | ||
} | ||
} |
26 changes: 0 additions & 26 deletions
26
src/main/java/com/woowacourse/zzazanstagram/model/article/domain/vo/ImageUrl.java
This file was deleted.
Oops, something went wrong.
21 changes: 7 additions & 14 deletions
21
src/main/java/com/woowacourse/zzazanstagram/model/article/dto/ArticleRequest.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
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
10 changes: 10 additions & 0 deletions
10
src/main/java/com/woowacourse/zzazanstagram/model/article/exception/ArticleException.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,10 @@ | ||
package com.woowacourse.zzazanstagram.model.article.exception; | ||
|
||
public class ArticleException extends IllegalArgumentException { | ||
public ArticleException() { | ||
} | ||
|
||
public ArticleException(String s) { | ||
super(s); | ||
} | ||
} |
Oops, something went wrong.