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

Commit

Permalink
리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
ori0o0p committed Mar 1, 2024
1 parent f6bd427 commit e36fa02
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
import com.example.daemawiki.domain.editor.service.AddEditor;
import com.example.daemawiki.domain.editor.service.DeleteEditor;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

@RestController
@RequestMapping("/api/documents/editor")
@RequestMapping("/api/documents/{documentId}/editor")
public class DocumentEditorController {
private final AddEditor addEditorService;
private final DeleteEditor deleteEditorService;
Expand All @@ -22,14 +23,14 @@ public DocumentEditorController(AddEditor addEditorService, DeleteEditor deleteE

@PatchMapping
@ResponseStatus(HttpStatus.NO_CONTENT)
public Mono<Void> addEditor(@Valid @RequestBody AddEditorRequest request) {
return addEditorService.execute(request);
public Mono<Void> addEditor(@Valid @RequestBody AddEditorRequest request, @NotBlank @PathVariable String documentId) {
return addEditorService.execute(request, documentId);
}

@PatchMapping("/remove")
@ResponseStatus(HttpStatus.NO_CONTENT)
public Mono<Void> deleteEditor(@Valid @RequestBody DeleteEditorRequest request) {
return deleteEditorService.execute(request);
public Mono<Void> deleteEditor(@Valid @RequestBody DeleteEditorRequest request, @NotBlank @PathVariable String documentId) {
return deleteEditorService.execute(request, documentId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import jakarta.validation.constraints.NotBlank;

public record AddEditorRequest(
@NotBlank(message = "문서의 id를 입력해주세요.")
String documentId,
@NotBlank(message = "문서 변경 권한을 줄 유저의 이메일을 입력해주세요.")
String email) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import jakarta.validation.constraints.NotBlank;

public record DeleteEditorRequest(
@NotBlank(message = "문서의 id를 입력해주세요.")
String documentId,
@NotBlank(message = "문서 변경 권한을 삭제할 유저의 id를 입력해주세요.")
String userId) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public AddEditor(UserFacade userFacade, DocumentFacade documentFacade, DocumentR
this.documentRepository = documentRepository;
}

public Mono<Void> execute(AddEditorRequest request) {
public Mono<Void> execute(AddEditorRequest request, String documentId) {
return userFacade.currentUser()
.flatMap(user -> documentFacade.findDocumentById(request.documentId())
.flatMap(user -> documentFacade.findDocumentById(documentId)
.filter(document -> document.getEditor().getCreatedUser().id().equals(user.getId()))
.switchIfEmpty(Mono.error(NoPermissionUserException.EXCEPTION))
.zipWith(userFacade.findByEmailNotNull(request.email()), (document, user2) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public DeleteEditor(UserFacade userFacade, DocumentFacade documentFacade, Docume
this.documentRepository = documentRepository;
}

public Mono<Void> execute(DeleteEditorRequest request) {
public Mono<Void> execute(DeleteEditorRequest request, String documentId) {
return userFacade.currentUser()
.flatMap(user -> documentFacade.findDocumentById(request.documentId())
.flatMap(user -> documentFacade.findDocumentById(documentId)
.filter(document -> Objects.equals(user.getId(), document.getEditor().getCreatedUser().id()))
.switchIfEmpty(Mono.error(NoPermissionUserException.EXCEPTION))
.flatMap(document -> {
Expand Down

0 comments on commit e36fa02

Please sign in to comment.