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

Commit

Permalink
editor 추가 서비스 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
ori0o0p committed Feb 28, 2024
1 parent 1bf2b30 commit 28f89b5
Showing 1 changed file with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.example.daemawiki.domain.editor.service;

import com.example.daemawiki.domain.document.component.facade.DocumentFacade;
import com.example.daemawiki.domain.document.repository.DocumentRepository;
import com.example.daemawiki.domain.editor.dto.AddEditorRequest;
import com.example.daemawiki.domain.editor.model.Editor;
import com.example.daemawiki.domain.user.service.facade.UserFacade;
import com.example.daemawiki.global.exception.h403.NoPermissionUserException;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

@Service
public class AddEditor {
private final UserFacade userFacade;
private final DocumentFacade documentFacade;
private final DocumentRepository documentRepository;

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

public Mono<Void> execute(AddEditorRequest request) {
return userFacade.currentUser()
.flatMap(user -> documentFacade.findDocumentById(user.getDocumentId())
.filter(document -> document.getEditor().getCreatedUser().id().equals(user.getId()))
.switchIfEmpty(Mono.error(NoPermissionUserException.EXCEPTION))
.zipWith(userFacade.findByEmailNotNull(request.email()), (document, user2) -> {
document.getEditor().getCanEdit().add(Editor.builder()
.user(user2.getEmail())
.id(user2.getId())
.build());
return document;
})
.flatMap(documentRepository::save))
.then();
}

}

0 comments on commit 28f89b5

Please sign in to comment.