Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
ori0o0p committed Feb 9, 2024
1 parent 075d0e5 commit af408c0
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 208 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.daemawiki.domain.document.api;

import com.example.daemawiki.domain.document.dto.request.CreateDocumentRequest;
import com.example.daemawiki.domain.document.dto.request.UpdateDocumentRequest;
import com.example.daemawiki.domain.document.dto.request.SaveDocumentRequest;
import com.example.daemawiki.domain.document.dto.response.GetDocumentResponse;
import com.example.daemawiki.domain.document.service.CreateDocument;
import com.example.daemawiki.domain.document.service.DeleteDocument;
Expand Down Expand Up @@ -46,7 +45,7 @@ public Mono<Void> deleteDocument(@PathVariable String documentId) {

@PatchMapping
@ResponseStatus(HttpStatus.NO_CONTENT)
public Mono<Void> updateDocument(@RequestBody UpdateDocumentRequest request) {
public Mono<Void> updateDocument(@RequestBody SaveDocumentRequest request) {
return updateDocumentService.execute(request);
}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.example.daemawiki.domain.document.dto.request;

import java.util.List;

public record AddDocumentGroupRequest(
String documentId,
List<String> groups
) {
}
package com.example.daemawiki.domain.document.dto.request;

import java.util.List;

public record SaveDocumentRequest(
String title,
String type,
String content,
List<String> groups
) {
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.daemawiki.domain.document.dto.response;

import com.example.daemawiki.domain.document.model.DocumentEditor;
import com.example.daemawiki.domain.document.model.Group;
import com.example.daemawiki.domain.document.model.type.DocumentType;
import com.example.daemawiki.global.dateTime.model.EditDateTime;
import lombok.Builder;
Expand All @@ -13,9 +12,8 @@ public record GetDocumentResponse(
String title,
DocumentType type,
EditDateTime dateTime,
List<Group> groups,
List<String> groups,
DocumentEditor editor,
String content

) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.eclipse.collections.api.factory.Lists;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

Expand All @@ -25,14 +24,14 @@ public class DefaultDocument {

private EditDateTime dateTime;

private List<Group> groups = Lists.mutable.of();
private List<String> groups;

private DocumentEditor editor;

private String content;

@Builder
public DefaultDocument(String title, DocumentType type, EditDateTime dateTime, List<Group> groups, DocumentEditor documentEditor, String content) {
public DefaultDocument(String title, DocumentType type, EditDateTime dateTime, List<String> groups, DocumentEditor documentEditor, String content) {
this.title = title;
this.type = type;
this.dateTime = dateTime;
Expand All @@ -41,18 +40,19 @@ public DefaultDocument(String title, DocumentType type, EditDateTime dateTime, L
this.content = content;
}

public void deleteGroup(Group group) {
public void deleteGroup(String group) {
this.getGroups().remove(group);
}

public Boolean isContain(Group group) {
public Boolean isContain(String group) {
return this.getGroups().contains(group);
}

public void update(String title, DocumentType type, String content) {
public void update(String title, DocumentType type, String content, List<String> groups) {
this.title = title;
this.type = type;
this.content = content;
this.groups = groups;
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import com.example.daemawiki.domain.document.model.DefaultDocument;
import org.springframework.data.mongodb.repository.ReactiveMongoRepository;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

public interface DocumentRepository extends ReactiveMongoRepository<DefaultDocument, String> {
Mono<DefaultDocument> findByTitle(String title);

Flux<DefaultDocument> findAllByGroupsContains(String group);

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.daemawiki.domain.document.service;

import com.example.daemawiki.domain.document.dto.request.CreateDocumentRequest;
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;
Expand All @@ -11,9 +11,12 @@
import com.example.daemawiki.domain.user.service.UserFacade;
import com.example.daemawiki.global.dateTime.facade.DateTimeFacade;
import com.example.daemawiki.global.dateTime.model.EditDateTime;
import org.eclipse.collections.api.factory.Lists;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

import java.util.List;

@Service
public class CreateDocument {
private final DocumentRepository documentRepository;
Expand All @@ -30,7 +33,7 @@ public CreateDocument(DocumentRepository documentRepository, UserFacade userFaca
this.getDocumentType = getDocumentType;
}

public Mono<Void> execute(CreateDocumentRequest request) {
public Mono<Void> execute(SaveDocumentRequest request) {
return userFacade.currentUser()
.zipWith(dateTimeFacade.getKor(), (user, now) -> DefaultDocument.builder()
.title(request.title())
Expand All @@ -44,6 +47,7 @@ public Mono<Void> execute(CreateDocumentRequest request) {
.updatedUser(user)
.build())
.content(request.content())
.groups(Lists.mutable.with(String.join("/", request.groups())))
.build())
.flatMap(documentRepository::save)
.flatMap(document -> revisionComponent.saveHistory(SaveRevisionHistoryRequest.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
package com.example.daemawiki.domain.document.service;

import com.example.daemawiki.domain.document.repository.DocumentRepository;
import com.example.daemawiki.domain.document.service.facade.DocumentFacade;
import com.example.daemawiki.domain.revision.dto.SaveRevisionHistoryRequest;
import com.example.daemawiki.domain.revision.model.type.RevisionType;
import com.example.daemawiki.domain.revision.component.RevisionComponent;
import com.example.daemawiki.domain.user.service.UserFacade;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

@Service
public class DeleteDocument {
private final DocumentRepository documentRepository;
private final DocumentFacade documentFacade;
private final UserFacade userFacade;
private final RevisionComponent revisionComponent;

public DeleteDocument(DocumentRepository documentRepository, DocumentFacade documentFacade, UserFacade userFacade, RevisionComponent revisionComponent) {
public DeleteDocument(DocumentRepository documentRepository, RevisionComponent revisionComponent) {
this.documentRepository = documentRepository;
this.documentFacade = documentFacade;
this.userFacade = userFacade;
this.revisionComponent = revisionComponent;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.daemawiki.domain.document.service;

import com.example.daemawiki.domain.document.dto.request.UpdateDocumentRequest;
import com.example.daemawiki.domain.document.dto.request.SaveDocumentRequest;
import com.example.daemawiki.domain.document.model.type.service.GetDocumentType;
import com.example.daemawiki.domain.document.repository.DocumentRepository;
import com.example.daemawiki.domain.document.service.facade.DocumentFacade;
Expand All @@ -12,6 +12,8 @@
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

import java.util.LinkedList;

@Service
public class UpdateDocument {
private final DocumentFacade documentFacade;
Expand All @@ -30,11 +32,16 @@ public UpdateDocument(DocumentFacade documentFacade, UserFacade userFacade, Date
this.revisionComponent = revisionComponent;
}

public Mono<Void> execute(UpdateDocumentRequest request) {
public Mono<Void> execute(SaveDocumentRequest request, String documentId) {
return userFacade.currentUser()
.zipWith(documentFacade.findDocumentById(request.documentId()), (user, document) -> dateTimeFacade.getKor()
.zipWith(documentFacade.findDocumentById(documentId), (user, document) -> dateTimeFacade.getKor()
.flatMap(now -> {
document.update(request.title(), getDocumentType.execute(request.type()), request.content());
LinkedList<String> groups = new LinkedList<>(request.groups());

document.update(request.title(),
getDocumentType.execute(request.type()),
request.content(),
groups);

return documentRepository.save(document);
})
Expand Down

This file was deleted.

Loading

0 comments on commit af408c0

Please sign in to comment.