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.
목차, 문서 정보
- Loading branch information
Showing
13 changed files
with
191 additions
and
12 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
src/main/java/com/example/daemawiki/domain/content/dto/AddContentRequest.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 com.example.daemawiki.domain.content.dto; | ||
|
||
public record AddContentRequest( | ||
String documentId, | ||
String index, | ||
String title | ||
) { | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/example/daemawiki/domain/content/dto/WriteContentRequest.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 com.example.daemawiki.domain.content.dto; | ||
|
||
public record WriteContentRequest( | ||
String documentId, | ||
String index, | ||
String content | ||
) { | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/example/daemawiki/domain/content/model/Contents.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,18 @@ | ||
package com.example.daemawiki.domain.content.model; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@Builder | ||
public class Contents { | ||
|
||
private String index; | ||
|
||
private String title; | ||
|
||
private String content; | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
src/main/java/com/example/daemawiki/domain/content/service/AddContentTable.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,66 @@ | ||
package com.example.daemawiki.domain.content.service; | ||
|
||
import com.example.daemawiki.domain.content.dto.AddContentRequest; | ||
import com.example.daemawiki.domain.content.model.Contents; | ||
import com.example.daemawiki.domain.document.component.facade.DocumentFacade; | ||
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 org.springframework.stereotype.Service; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.util.Comparator; | ||
|
||
@Service | ||
public class AddContentTable { | ||
private final DocumentFacade documentFacade; | ||
private final DocumentRepository documentRepository; | ||
private final RevisionComponent revisionComponent; | ||
|
||
public AddContentTable(DocumentFacade documentFacade, DocumentRepository documentRepository, RevisionComponent revisionComponent) { | ||
this.documentFacade = documentFacade; | ||
this.documentRepository = documentRepository; | ||
this.revisionComponent = revisionComponent; | ||
} | ||
|
||
public Mono<Void> execute(AddContentRequest request) { | ||
return documentFacade.findDocumentById(request.documentId()) | ||
.map(document -> { | ||
Contents newContent = Contents.builder() | ||
.index(request.index()) | ||
.title(request.title()) | ||
.content("빈 내용") | ||
.build(); | ||
|
||
document.getContent().add(newContent); | ||
|
||
Comparator<Contents> customComparator = (c1, c2) -> { | ||
String[] index1 = c1.getIndex().split("\\."); | ||
String[] index2 = c2.getIndex().split("\\."); | ||
|
||
for (int i = 0; i < Math.max(index1.length, index2.length); i++) { | ||
int part1 = i < index1.length ? Integer.parseInt(index1[i]) : 0; | ||
int part2 = i < index2.length ? Integer.parseInt(index2[i]) : 0; | ||
|
||
if (part1 != part2) { | ||
return part1 - part2; | ||
} | ||
} | ||
|
||
return 0; | ||
}; | ||
|
||
document.getContent().sort(customComparator); | ||
|
||
return document; | ||
}) | ||
.flatMap(documentRepository::save) | ||
.flatMap(document -> revisionComponent.saveHistory(SaveRevisionHistoryRequest.builder() | ||
.type(RevisionType.UPDATE) | ||
.documentId(request.documentId()) | ||
.title(document.getTitle()) | ||
.build())); | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/com/example/daemawiki/domain/content/service/WriteContent.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,50 @@ | ||
package com.example.daemawiki.domain.content.service; | ||
|
||
import com.example.daemawiki.domain.content.dto.WriteContentRequest; | ||
import com.example.daemawiki.domain.content.model.Contents; | ||
import com.example.daemawiki.domain.document.component.facade.DocumentFacade; | ||
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 org.springframework.stereotype.Service; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.util.Map; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
public class WriteContent { | ||
private final DocumentFacade documentFacade; | ||
private final DocumentRepository documentRepository; | ||
private final RevisionComponent revisionComponent; | ||
|
||
public WriteContent(DocumentFacade documentFacade, DocumentRepository documentRepository, RevisionComponent revisionComponent) { | ||
this.documentFacade = documentFacade; | ||
this.documentRepository = documentRepository; | ||
this.revisionComponent = revisionComponent; | ||
} | ||
|
||
public Mono<Void> execute(WriteContentRequest request) { | ||
return documentFacade.findDocumentById(request.documentId()) | ||
.map(document -> { | ||
Map<String, Contents> contentsMap = document.getContent().stream() | ||
.collect(Collectors.toMap(Contents::getIndex, Function.identity())); | ||
|
||
if (contentsMap.containsKey(request.index())) { | ||
Contents content = contentsMap.get(request.index()); | ||
content.setContent(request.content()); | ||
} | ||
|
||
return document; | ||
}) | ||
.flatMap(documentRepository::save) | ||
.flatMap(document -> revisionComponent.saveHistory(SaveRevisionHistoryRequest.builder() | ||
.type(RevisionType.UPDATE) | ||
.documentId(request.documentId()) | ||
.title(document.getTitle()) | ||
.build())); | ||
} | ||
|
||
} |
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
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