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.
reactor core operation인 doOnSuccess 를 사용하여 회원가입이 완료되면 유저 정보를 바탕으로 문서를 생성하는 로직을 구현하였습니다.
- Loading branch information
Showing
12 changed files
with
164 additions
and
82 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
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
53 changes: 53 additions & 0 deletions
53
src/main/java/com/example/daemawiki/domain/document/component/CreateDocumentByUser.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,53 @@ | ||
package com.example.daemawiki.domain.document.component; | ||
|
||
import com.example.daemawiki.domain.document.component.facade.CreateDocumentFacade; | ||
import com.example.daemawiki.domain.document.dto.request.SaveDocumentRequest; | ||
import com.example.daemawiki.domain.document.model.DefaultDocument; | ||
import com.example.daemawiki.domain.document.repository.DocumentRepository; | ||
import com.example.daemawiki.domain.revision.component.RevisionComponent; | ||
import com.example.daemawiki.domain.revision.dto.request.SaveRevisionHistoryRequest; | ||
import com.example.daemawiki.domain.revision.model.type.RevisionType; | ||
import com.example.daemawiki.domain.user.model.User; | ||
import org.springframework.stereotype.Component; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
@Component | ||
public class CreateDocumentByUser { | ||
private final DocumentRepository documentRepository; | ||
private final CreateDocumentFacade createDocumentFacade; | ||
private final RevisionComponent revisionComponent; | ||
|
||
public CreateDocumentByUser(DocumentRepository documentRepository, CreateDocumentFacade createDocumentFacade, RevisionComponent revisionComponent) { | ||
this.documentRepository = documentRepository; | ||
this.createDocumentFacade = createDocumentFacade; | ||
this.revisionComponent = revisionComponent; | ||
} | ||
|
||
public Mono<Void> execute(User user) { | ||
return documentRepository.save(createDocument(user)) | ||
.onErrorResume(Mono::error) | ||
.flatMap(document -> revisionComponent.saveHistory(SaveRevisionHistoryRequest.builder() | ||
.type(RevisionType.CREATE) | ||
.documentId(document.getId()) | ||
.title(document.getTitle()) | ||
.build())); | ||
} | ||
|
||
private DefaultDocument createDocument(User user) { | ||
List<List<String>> groups = Arrays.asList( | ||
Arrays.asList("학생", user.getDetail().gen() + "기", user.getName()), | ||
Arrays.asList("전공", user.getDetail().major().toString()) | ||
); | ||
|
||
return createDocumentFacade.execute(SaveDocumentRequest.builder() | ||
.title(user.getName()) | ||
.type("student") | ||
.content("회원가입을 통해 자동 생성된 문서입니다.") | ||
.groups(groups) | ||
.build(), user); | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
...ain/java/com/example/daemawiki/domain/document/component/facade/CreateDocumentFacade.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,49 @@ | ||
package com.example.daemawiki.domain.document.component.facade; | ||
|
||
import com.example.daemawiki.domain.document.dto.request.SaveDocumentRequest; | ||
import com.example.daemawiki.domain.document.model.DefaultDocument; | ||
import com.example.daemawiki.domain.document.model.DocumentEditor; | ||
import com.example.daemawiki.domain.document.model.type.service.GetDocumentType; | ||
import com.example.daemawiki.domain.user.dto.UserDetailResponse; | ||
import com.example.daemawiki.domain.user.model.User; | ||
import com.example.daemawiki.global.datetime.model.EditDateTime; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Objects; | ||
|
||
@Component | ||
public class CreateDocumentFacade { | ||
private final GetDocumentType getDocumentType; | ||
|
||
public CreateDocumentFacade(GetDocumentType getDocumentType) { | ||
this.getDocumentType = getDocumentType; | ||
} | ||
|
||
public DefaultDocument execute(SaveDocumentRequest request, User user) { | ||
UserDetailResponse userDetail = UserDetailResponse.builder() | ||
.id(user.getId()) | ||
.name(user.getName()) | ||
.profile(user.getProfile()) | ||
.build(); | ||
|
||
return DefaultDocument.builder() | ||
.title(request.title()) | ||
.type(getDocumentType.execute(request.type())) | ||
.dateTime(EditDateTime.builder() | ||
.created(LocalDateTime.now()) | ||
.updated(LocalDateTime.now()) | ||
.build()) | ||
.documentEditor(DocumentEditor.builder() | ||
.createdUser(userDetail) | ||
.updatedUser(userDetail) | ||
.build()) | ||
.content(request.content()) | ||
.groups(request.groups().stream() | ||
.filter(Objects::nonNull) | ||
.map(group -> String.join("/", group)) | ||
.toList()) | ||
.build(); | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...cument/service/facade/DocumentFacade.java → ...ment/component/facade/DocumentFacade.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
38 changes: 38 additions & 0 deletions
38
src/main/java/com/example/daemawiki/domain/document/component/service/CreateDocument.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,38 @@ | ||
package com.example.daemawiki.domain.document.component.service; | ||
|
||
import com.example.daemawiki.domain.document.component.facade.CreateDocumentFacade; | ||
import com.example.daemawiki.domain.document.dto.request.SaveDocumentRequest; | ||
import com.example.daemawiki.domain.document.repository.DocumentRepository; | ||
import com.example.daemawiki.domain.revision.component.RevisionComponent; | ||
import com.example.daemawiki.domain.revision.dto.request.SaveRevisionHistoryRequest; | ||
import com.example.daemawiki.domain.revision.model.type.RevisionType; | ||
import com.example.daemawiki.domain.user.service.facade.UserFacade; | ||
import org.springframework.stereotype.Service; | ||
import reactor.core.publisher.Mono; | ||
|
||
@Service | ||
public class CreateDocument { | ||
private final DocumentRepository documentRepository; | ||
private final UserFacade userFacade; | ||
private final RevisionComponent revisionComponent; | ||
private final CreateDocumentFacade createDocumentFacade; | ||
|
||
public CreateDocument(DocumentRepository documentRepository, UserFacade userFacade, RevisionComponent revisionComponent, CreateDocumentFacade createDocumentFacade) { | ||
this.documentRepository = documentRepository; | ||
this.userFacade = userFacade; | ||
this.revisionComponent = revisionComponent; | ||
this.createDocumentFacade = createDocumentFacade; | ||
} | ||
|
||
public Mono<Void> execute(SaveDocumentRequest request) { | ||
return userFacade.currentUser() | ||
.map(user -> createDocumentFacade.execute(request, user)) | ||
.flatMap(documentRepository::save) | ||
.flatMap(document -> revisionComponent.saveHistory(SaveRevisionHistoryRequest.builder() | ||
.type(RevisionType.CREATE) | ||
.documentId(document.getId()) | ||
.title(document.getTitle()) | ||
.build())); | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...main/document/service/DeleteDocument.java → ...ent/component/service/DeleteDocument.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
4 changes: 2 additions & 2 deletions
4
.../domain/document/service/GetDocument.java → ...cument/component/service/GetDocument.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
4 changes: 2 additions & 2 deletions
4
...main/document/service/UpdateDocument.java → ...ent/component/service/UpdateDocument.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
69 changes: 0 additions & 69 deletions
69
src/main/java/com/example/daemawiki/domain/document/service/CreateDocument.java
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
src/main/java/com/example/daemawiki/domain/revision/model/mapper/RevisionMapper.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