-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
156 additions
and
64 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
8 changes: 8 additions & 0 deletions
8
src/main/java/com/resuscitation/instagram/article/application/ArticleRepository.kt
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,8 @@ | ||
package com.resuscitation.instagram.article.application | ||
|
||
import com.resuscitation.instagram.article.domain.Article | ||
|
||
interface ArticleRepository { | ||
fun findById(id: Long): Article? | ||
fun save(articleEntity: Article): Article | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/resuscitation/instagram/article/application/ArticleService.kt
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,40 @@ | ||
package com.resuscitation.instagram.article.application | ||
|
||
import com.resuscitation.instagram.article.domain.Article | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Service | ||
class ArticleService( | ||
private val articleRepository: ArticleRepository | ||
) { | ||
@Transactional(readOnly = true) | ||
fun getArticle(id: Long): Article { | ||
val article: Article = articleRepository.findById(id) ?: throw IllegalArgumentException() | ||
return article | ||
} | ||
|
||
@Transactional | ||
fun createArticle() { | ||
val article = Article.create( | ||
title = "title", | ||
content = "content", | ||
authorId = 1L | ||
) | ||
articleRepository.save(article) | ||
} | ||
|
||
@Transactional | ||
fun updateArticle( | ||
id: Long, | ||
title: String, | ||
content: String | ||
) { | ||
val article: Article = articleRepository.findById(id) ?: throw IllegalArgumentException() | ||
|
||
article.update( | ||
title = title, | ||
content = content | ||
) | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/com/resuscitation/instagram/article/domain/Article.kt
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,58 @@ | ||
package com.resuscitation.instagram.article.domain | ||
|
||
import jakarta.persistence.Entity | ||
import jakarta.persistence.EntityListeners | ||
import jakarta.persistence.GeneratedValue | ||
import jakarta.persistence.GenerationType | ||
import jakarta.persistence.Id | ||
import java.time.Instant | ||
import org.springframework.data.annotation.CreatedDate | ||
import org.springframework.data.annotation.LastModifiedDate | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener | ||
|
||
@Entity | ||
@EntityListeners(AuditingEntityListener::class) | ||
class Article( | ||
id: Long = 0L, | ||
title: String = "", | ||
content: String, | ||
authorId: Long, | ||
createdAt: Instant = Instant.MIN, | ||
updatedAt: Instant = Instant.MIN, | ||
) { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
val id: Long = id | ||
|
||
var title: String = title | ||
protected set | ||
|
||
var content: String = content | ||
protected set | ||
|
||
var authorId: Long = authorId | ||
protected set | ||
|
||
@CreatedDate | ||
var createdAt: Instant = createdAt | ||
protected set | ||
|
||
@LastModifiedDate | ||
var updatedAt: Instant = updatedAt | ||
protected set | ||
|
||
companion object { | ||
fun create(title: String, content: String, authorId: Long): Article { | ||
return Article( | ||
title = title, | ||
content = content, | ||
authorId = authorId | ||
) | ||
} | ||
} | ||
|
||
fun update(title: String, content: String) { | ||
this.title = title | ||
this.content = content | ||
} | ||
} |
25 changes: 0 additions & 25 deletions
25
src/main/java/com/resuscitation/instagram/article/dto/ArticleDto.kt
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
src/main/java/com/resuscitation/instagram/article/entity/ArticleEntity.kt
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
src/main/java/com/resuscitation/instagram/article/infrastructure/ArticleRepositoryAdaptor.kt
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,18 @@ | ||
package com.resuscitation.instagram.article.infrastructure | ||
|
||
import com.resuscitation.instagram.article.application.ArticleRepository | ||
import com.resuscitation.instagram.article.domain.Article | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class ArticleRepositoryAdaptor( | ||
private val jpaArticleRepository: JpaArticleRepository | ||
) : ArticleRepository { | ||
override fun findById(id: Long): Article? { | ||
return jpaArticleRepository.findById(id).orElse(null) | ||
} | ||
|
||
override fun save(articleEntity: Article): Article { | ||
return jpaArticleRepository.save(articleEntity) | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/resuscitation/instagram/article/infrastructure/JpaArticleRepository.kt
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.resuscitation.instagram.article.infrastructure | ||
|
||
import com.resuscitation.instagram.article.domain.Article | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
import org.springframework.stereotype.Repository | ||
|
||
@Repository | ||
interface JpaArticleRepository : JpaRepository<Article, Long> { | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/resuscitation/instagram/article/presentation/ArticleAuthorController.kt
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,7 @@ | ||
package com.resuscitation.instagram.article.presentation | ||
|
||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
class ArticleAuthorController { | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/resuscitation/instagram/article/presentation/ArticleUserController.kt
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.resuscitation.instagram.article.presentation | ||
|
||
import com.resuscitation.instagram.article.application.ArticleService | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
class ArticleUserController( | ||
private val articleService: ArticleService | ||
) { | ||
} |
12 changes: 0 additions & 12 deletions
12
src/main/java/com/resuscitation/instagram/article/repository/ArticleRepository.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