This repository has been archived by the owner on Nov 27, 2024. It is now read-only.
-
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.
Merge pull request #7 from daemawiki/develop
update
- Loading branch information
Showing
27 changed files
with
221 additions
and
65 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
57 changes: 57 additions & 0 deletions
57
daemawiki-domain/src/main/java/org/daemawiki/domain/article/adapter/ArticleAdapter.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,57 @@ | ||
package org.daemawiki.domain.article.adapter; | ||
|
||
import org.daemawiki.domain.article.model.Article; | ||
import org.daemawiki.domain.article.port.DeleteArticlePort; | ||
import org.daemawiki.domain.article.port.FindArticlePort; | ||
import org.daemawiki.domain.article.port.SaveArticlePort; | ||
import org.daemawiki.domain.article.repository.ArticleRepository; | ||
import org.daemawiki.utils.PagingInfo; | ||
import org.springframework.stereotype.Component; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
@Component | ||
public class ArticleAdapter implements FindArticlePort, SaveArticlePort, DeleteArticlePort { | ||
private final ArticleRepository articleRepository; | ||
|
||
public ArticleAdapter(ArticleRepository articleRepository) { | ||
this.articleRepository = articleRepository; | ||
} | ||
|
||
@Override | ||
public Mono<Void> delete(String articleId) { | ||
return articleRepository.deleteById(articleId); | ||
} | ||
|
||
@Override | ||
public Flux<Article> findAll(PagingInfo pagingInfo) { | ||
return articleRepository.findAll( | ||
pagingInfo.sortBy(), | ||
pagingInfo.sortDirection(), | ||
pagingInfo.page() * pagingInfo.size(), | ||
pagingInfo.size() | ||
); | ||
} | ||
|
||
@Override | ||
public Flux<Article> search(String keyword, PagingInfo pagingInfo) { | ||
return articleRepository.search( | ||
keyword, | ||
pagingInfo.sortBy(), | ||
pagingInfo.sortDirection(), | ||
pagingInfo.page() * pagingInfo.size(), | ||
pagingInfo.size() | ||
); | ||
} | ||
|
||
@Override | ||
public Mono<Article> findById(String articleId) { | ||
return articleRepository.findById(articleId); | ||
} | ||
|
||
@Override | ||
public Mono<Article> save(Article article) { | ||
return articleRepository.save(article); | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
daemawiki-domain/src/main/java/org/daemawiki/domain/article/dto/WriteArticleRequest.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,7 @@ | ||
package org.daemawiki.domain.article.dto; | ||
|
||
public record WriteArticleRequest( | ||
String title, | ||
String content | ||
) { | ||
} |
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
daemawiki-domain/src/main/java/org/daemawiki/domain/article/port/DeleteArticlePort.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,8 @@ | ||
package org.daemawiki.domain.article.port; | ||
|
||
import reactor.core.publisher.Mono; | ||
|
||
public interface DeleteArticlePort { | ||
Mono<Void> delete(String articleId); | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
daemawiki-domain/src/main/java/org/daemawiki/domain/article/port/FindArticlePort.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,13 @@ | ||
package org.daemawiki.domain.article.port; | ||
|
||
import org.daemawiki.domain.article.model.Article; | ||
import org.daemawiki.utils.PagingInfo; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
public interface FindArticlePort { | ||
Flux<Article> findAll(PagingInfo pagingInfo); | ||
Flux<Article> search(String keyword, PagingInfo pagingInfo); | ||
Mono<Article> findById(String articleId); | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
daemawiki-domain/src/main/java/org/daemawiki/domain/article/port/SaveArticlePort.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,9 @@ | ||
package org.daemawiki.domain.article.port; | ||
|
||
import org.daemawiki.domain.article.model.Article; | ||
import reactor.core.publisher.Mono; | ||
|
||
public interface SaveArticlePort { | ||
Mono<Article> save(Article article); | ||
|
||
} |
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
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
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
35 changes: 35 additions & 0 deletions
35
...awiki-service/src/main/java/org/daemawiki/domain/article/service/WriteArticleService.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,35 @@ | ||
package org.daemawiki.domain.article.service; | ||
|
||
import org.daemawiki.domain.article.dto.WriteArticleRequest; | ||
import org.daemawiki.domain.article.model.Article; | ||
import org.daemawiki.domain.article.port.SaveArticlePort; | ||
import org.daemawiki.domain.article.usecase.WriteArticleUseCase; | ||
import org.daemawiki.domain.user.application.FindUserPort; | ||
import org.daemawiki.domain.user.model.Writer; | ||
import org.daemawiki.exception.h403.NoPermissionUserException; | ||
import org.springframework.stereotype.Service; | ||
import reactor.core.publisher.Mono; | ||
|
||
@Service | ||
public class WriteArticleService implements WriteArticleUseCase { | ||
private final FindUserPort findUserPort; | ||
private final SaveArticlePort saveArticlePort; | ||
|
||
public WriteArticleService(FindUserPort findUserPort, SaveArticlePort saveArticlePort) { | ||
this.findUserPort = findUserPort; | ||
this.saveArticlePort = saveArticlePort; | ||
} | ||
|
||
@Override | ||
public Mono<Void> write(WriteArticleRequest request) { | ||
return findUserPort.currentUser() | ||
.filter(user -> !user.getIsBlocked()) | ||
.switchIfEmpty(Mono.defer(() -> Mono.error(NoPermissionUserException.EXCEPTION))) | ||
.flatMap(user -> { | ||
Article article = Article.create(request.title(), request.content(), Writer.of(user)); | ||
return saveArticlePort.save(article); | ||
}) | ||
.then(); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
...awiki-service/src/main/java/org/daemawiki/domain/article/usecase/WriteArticleUseCase.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,9 @@ | ||
package org.daemawiki.domain.article.usecase; | ||
|
||
import org.daemawiki.domain.article.dto.WriteArticleRequest; | ||
import reactor.core.publisher.Mono; | ||
|
||
public interface WriteArticleUseCase { | ||
Mono<Void> write(WriteArticleRequest request); | ||
|
||
} |
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
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
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
Oops, something went wrong.