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 May 10, 2024
1 parent 7cf5a89 commit 8f9ae32
Show file tree
Hide file tree
Showing 22 changed files with 71 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@

import lombok.Builder;
import lombok.Getter;
import org.daemawiki.domain.user.dto.response.UserDetailResponse;
import org.daemawiki.domain.user.dto.response.UserDetailVo;

import java.util.List;

@Getter
@Builder
public class DocumentEditor {
private final UserDetailResponse createdUser;
private UserDetailResponse updatedUser;
private final UserDetailVo createdUser;
private UserDetailVo updatedUser;
private List<Editor> canEdit;

public boolean hasEditPermission(String email) {
return this.canEdit.stream()
.noneMatch(editor -> editor.user().equals(email));
}

public void updateUpdatedUser(UserDetailVo updatedUser) {
this.updatedUser = updatedUser;
}

public void addEditor(Editor editor) {
this.canEdit.add(editor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public class Info {

private List<Detail> details;

public void updateDocumentImage(File documentImage) {
this.documentImage = documentImage;
}

public void update(String subTitle, List<Detail> details) {
this.subTitle = subTitle;
this.details = details;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.daemawiki.domain.file.model;

import lombok.Builder;
import lombok.Getter;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.MongoId;
Expand All @@ -22,7 +21,6 @@ public class File {

protected File() {}

@Builder
public File(UUID id, String fileName, String fileType, FileDetail detail) {
this.id = id;
this.fileName = fileName;
Expand All @@ -31,12 +29,7 @@ public File(UUID id, String fileName, String fileType, FileDetail detail) {
}

public static File create(UUID id, String fileName, String fileType, FileDetail detail) {
return File.builder()
.id(id)
.fileName(fileName)
.fileType(fileType)
.detail(detail)
.build();
return new File(id, fileName, fileType, detail);
}

}
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
package org.daemawiki.domain.file.model;

import org.daemawiki.domain.file.model.type.FileType;
import lombok.Builder;

@Builder
public record FileDetail(
FileType type,
String url
) {

public static FileDetail create(FileType type, String url) {
return FileDetail.builder()
.type(type)
.url(url)
.build();
return new FileDetail(type, url);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.daemawiki.domain.user.dto.response;

import org.daemawiki.domain.file.model.File;
import org.daemawiki.domain.user.model.User;

public record UserDetailVo(
String id,
String name,
File profile
) {

public static UserDetailVo create(User user) {
return new UserDetailVo(user.getId(), user.getName(), user.getProfile());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import org.daemawiki.domain.file.model.File;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
Expand All @@ -12,7 +11,6 @@
import java.time.LocalDateTime;

@Getter
@Setter
@Document
public class User {

Expand Down Expand Up @@ -57,6 +55,26 @@ public void update(String name, UserDetail detail) {
this.detail = detail;
}

public void updateDocumentId(String documentId) {
this.documentId = documentId;
}

public void updateProfile(File profile) {
this.profile = profile;
}

public void setRole(Role role) {
this.role = role;
}

public void setIsBlocked(Boolean blocked) {
this.isBlocked = blocked;
}

public void updatePassword(String password) {
this.password = password;
}

public enum Role {
USER,
ADMIN,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package org.daemawiki.domain.user.model;

import org.daemawiki.domain.user.model.type.major.MajorType;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import org.daemawiki.domain.user.model.type.major.MajorType;

@Setter
@Getter
@Builder
public class UserDetail {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package org.daemawiki.domain.document.component;

import org.daemawiki.domain.document.model.DefaultDocument;
import org.daemawiki.domain.document.component.UpdateDocumentComponent;
import org.daemawiki.domain.user.dto.response.UserDetailResponse;
import org.daemawiki.domain.user.dto.response.UserDetailVo;
import org.daemawiki.domain.user.model.User;
import org.springframework.stereotype.Component;

Expand All @@ -13,7 +12,7 @@ public class UpdateDocumentEditorAndUpdatedDate implements UpdateDocumentCompone

@Override
public void updateEditorAndUpdatedDate(DefaultDocument document, User user) {
document.getEditor().setUpdatedUser(UserDetailResponse.create(user));
document.getEditor().updateUpdatedUser(UserDetailVo.create(user));
document.getDateTime().setUpdated(LocalDateTime.now());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.daemawiki.domain.document_editor.model.DocumentEditor;
import org.daemawiki.domain.document_editor.model.Editor;
import org.daemawiki.domain.document_info.model.Info;
import org.daemawiki.domain.user.dto.response.UserDetailResponse;
import org.daemawiki.domain.user.dto.response.UserDetailVo;
import org.daemawiki.domain.user.model.User;
import org.eclipse.collections.api.factory.Lists;
import org.springframework.stereotype.Component;
Expand All @@ -28,7 +28,7 @@ public CreateDocumentFacadeImpl(DefaultProfileConfig defaultProfile) {

@Override
public Mono<DefaultDocument> create(SaveDocumentRequest request, User user) {
UserDetailResponse userDetail = UserDetailResponse.create(user);
UserDetailVo userDetail = UserDetailVo.create(user);

return Mono.just(DefaultDocument.create(
request.title(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Mono<Void> delete(String documentId) {

private Mono<Void> deleteDocument(DefaultDocument document) {
return deleteDocumentPort.delete(document)
.then(createRevisionComponent.create(document, RevisionType.DELETE));
.then(createRevisionComponent.create(document, RevisionType.DELETE, null));
}

private Mono<DefaultDocument> getDefaultDocumentMono(Tuple2<User, DefaultDocument> tuple) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Mono<Void> update(SaveDocumentRequest request, String documentId) {

private Mono<Void> saveDocumentAndCreateRevision(DefaultDocument document) {
return saveDocumentPort.save(document)
.then(createRevisionComponent.create(document, RevisionType.UPDATE));
.then(createRevisionComponent.create(document, RevisionType.UPDATE, null));
}

private DefaultDocument checkPermissionAndUpdateDocument(Tuple2<User, DefaultDocument> tuple, SaveDocumentRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.daemawiki.domain.document_revision.component.CreateRevisionComponent;
import org.daemawiki.domain.document_revision.model.type.RevisionType;
import org.daemawiki.domain.user.port.FindUserPort;
import org.daemawiki.domain.user.dto.response.UserDetailResponse;
import org.daemawiki.domain.user.dto.response.UserDetailVo;
import org.daemawiki.domain.user.model.User;
import org.daemawiki.exception.h400.VersionMismatchException;
import org.daemawiki.exception.h403.NoEditPermissionUserException;
Expand Down Expand Up @@ -53,7 +53,7 @@ public Mono<Void> add(AddContentRequest request, String documentId) {

private Mono<Void> saveDocumentAndCreateRevision(DefaultDocument document) {
return saveDocumentPort.save(document)
.then(createRevisionComponent.create(document, RevisionType.UPDATE));
.then(createRevisionComponent.create(document, RevisionType.UPDATE, null));
}

private DefaultDocument checkPermissionAndAddDocumentContentTable(Tuple2<User, DefaultDocument> tuple, AddContentRequest request) {
Expand Down Expand Up @@ -108,7 +108,7 @@ private void sortContents(DefaultDocument document) {
}

private void setDocument(DefaultDocument document, User user) {
document.getEditor().setUpdatedUser(UserDetailResponse.create(user));
document.getEditor().updateUpdatedUser(UserDetailVo.create(user));
sortContents(document);
document.increaseVersion();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Mono<Void> remove(DeleteContentRequest request, String documentId) {

private Mono<Void> saveDocumentAndCreateRevision(DefaultDocument document) {
return saveDocumentPort.save(document)
.then(createRevisionComponent.create(document, RevisionType.UPDATE));
.then(createRevisionComponent.create(document, RevisionType.UPDATE, null));
}

private DefaultDocument checkPermissionAndDeleteDocumentContentTable(Tuple2<User, DefaultDocument> tuple, DeleteContentRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Mono<Void> update(EditContentTableTitleRequest request, String documentId

private Mono<Void> saveDocumentAndCreateRevision(DefaultDocument document) {
return saveDocumentPort.save(document)
.then(createRevisionComponent.create(document, RevisionType.UPDATE));
.then(createRevisionComponent.create(document, RevisionType.UPDATE, null));
}

private Mono<DefaultDocument> checkPermissionAndUpdateDocument(Tuple2<User, DefaultDocument> tuple, EditContentTableTitleRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Mono<Void> write(WriteContentRequest request, String documentId) {

private Mono<Void> saveDocumentAndCreateRevision(DefaultDocument document) {
return saveDocumentPort.save(document)
.then(createRevisionComponent.create(document, RevisionType.UPDATE));
.then(createRevisionComponent.create(document, RevisionType.UPDATE, null));
}

private Mono<DefaultDocument> checkPermissionAndWriteContent(Tuple2<User, DefaultDocument> tuple, WriteContentRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.daemawiki.domain.document_revision.component.CreateRevisionComponent;
import org.daemawiki.domain.document_revision.model.type.RevisionType;
import org.daemawiki.domain.user.port.FindUserPort;
import org.daemawiki.domain.user.dto.response.UserDetailResponse;
import org.daemawiki.domain.user.dto.response.UserDetailVo;
import org.daemawiki.domain.user.model.User;
import org.daemawiki.exception.h400.VersionMismatchException;
import org.daemawiki.exception.h403.NoEditPermissionUserException;
Expand Down Expand Up @@ -55,11 +55,11 @@ private Mono<Void> checkPermissionAndUpdateDocument(Tuple2<User, DefaultDocument
setDocument(document, user, request.subTitle(), request.details());

return saveDocumentPort.save(document)
.then(createRevisionComponent.create(document, RevisionType.UPDATE));
.then(createRevisionComponent.create(document, RevisionType.UPDATE, null));
}

private void setDocument(DefaultDocument document, User user, String subTitle, List<Detail> details) {
document.getEditor().setUpdatedUser(UserDetailResponse.create(user));
document.getEditor().updateUpdatedUser(UserDetailVo.create(user));
document.getInfo().update(subTitle, details);
document.increaseVersion();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ private Mono<Void> updateDocument(Tuple2<DefaultDocument, File> tuple) {
DefaultDocument document = tuple.getT1();
File file = tuple.getT2();

document.getInfo().setDocumentImage(file);
document.getInfo().updateDocumentImage(file);

return saveDocumentPort.save(document)
.then(createRevisionComponent.create(document, RevisionType.UPDATE));
.then(createRevisionComponent.create(document, RevisionType.UPDATE, null));
}

private DefaultDocument checkPermission(Tuple2<User, DefaultDocument> tuple) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Mono<Void> nonLoggedInUser(ChangePasswordRequest request) {
private Mono<Void> changePasswordAndSaveUser(String newPassword, User user) {
return encodePassword(newPassword)
.flatMap(password -> {
user.setPassword(password);
user.updatePassword(password);
return saveUserPort.save(user);
})
.onErrorMap(e -> ExecuteFailedException.EXCEPTION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private Mono<Void> updateUserDocument(User user) {

private Mono<Void> saveDocumentAndCreateRevision(DefaultDocument document) {
return saveDocumentPort.save(document)
.then(createRevisionComponent.create(document, RevisionType.UPDATE));
.then(createRevisionComponent.create(document, RevisionType.UPDATE, null));
}

private void setDocumentForUpdateUser(DefaultDocument document, User user) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public UploadUserProfileImageService(FindUserPort findUserPort, S3UploadObjectIm
public Mono<Void> upload(FilePart filePart) {
return findUserPort.currentUser()
.zipWith(s3UploadObject.uploadObject(filePart, FileType.PROFILE.toString()), (user, file) -> {
user.setProfile(file);
user.updateProfile(file);
return user;
})
.flatMap(saveUserPort::save)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private Mono<User> saveUserAndCreateDocument(User user) {

private Mono<User> createDocumentAndUpdateUser(User savedUser) {
return createDocumentUsecase.createByUser(savedUser)
.doOnNext(document -> savedUser.setDocumentId(document.getId()))
.doOnNext(document -> savedUser.updateDocumentId(document.getId()))
.flatMap(document -> saveUser(savedUser))
.flatMap(this::updateAdminAccount);
}
Expand Down

0 comments on commit 8f9ae32

Please sign in to comment.