-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(update): docs update로직 리팩토링
- Loading branch information
Showing
13 changed files
with
196 additions
and
153 deletions.
There are no files selected for viewing
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
6 changes: 6 additions & 0 deletions
6
src/main/java/com/project/bumawiki/domain/docs/domain/repository/VersionDocsRepository.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 |
---|---|---|
@@ -1,8 +1,14 @@ | ||
package com.project.bumawiki.domain.docs.domain.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.lang.NonNull; | ||
|
||
import com.project.bumawiki.domain.docs.domain.Docs; | ||
import com.project.bumawiki.domain.docs.domain.VersionDocs; | ||
|
||
public interface VersionDocsRepository extends JpaRepository<VersionDocs, Long> { | ||
|
||
@NonNull | ||
VersionDocs findFirstByDocsOrderByVersionDesc(Docs docs); | ||
|
||
} |
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
28 changes: 28 additions & 0 deletions
28
src/main/java/com/project/bumawiki/domain/docs/implementation/DocsUpdater.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,28 @@ | ||
package com.project.bumawiki.domain.docs.implementation; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import com.project.bumawiki.domain.docs.domain.Docs; | ||
import com.project.bumawiki.domain.docs.domain.type.DocsType; | ||
import com.project.bumawiki.domain.docs.domain.type.Status; | ||
import com.project.bumawiki.global.annotation.Implementation; | ||
|
||
@Implementation | ||
public class DocsUpdater { | ||
public void updateStatus(Docs docs, Status status) { | ||
docs.updateStatus(status); | ||
} | ||
|
||
public void updateTitle(Docs docs, String title) { | ||
docs.updateTitle(title); | ||
} | ||
|
||
public void updateType(Docs docs, DocsType docsType) { | ||
docs.updateDocsType(docsType); | ||
} | ||
|
||
public void updateModifiedAt(Docs docs, LocalDateTime localDateTime) { | ||
docs.updateModifiedAt(localDateTime); | ||
} | ||
|
||
} |
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
31 changes: 31 additions & 0 deletions
31
.../java/com/project/bumawiki/domain/docs/implementation/versiondocs/VersionDocsCreator.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,31 @@ | ||
package com.project.bumawiki.domain.docs.implementation.versiondocs; | ||
|
||
import com.project.bumawiki.domain.docs.domain.Docs; | ||
import com.project.bumawiki.domain.docs.domain.VersionDocs; | ||
import com.project.bumawiki.domain.docs.domain.repository.VersionDocsRepository; | ||
import com.project.bumawiki.domain.docs.implementation.DocsUpdater; | ||
import com.project.bumawiki.domain.user.domain.User; | ||
import com.project.bumawiki.global.annotation.Implementation; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Implementation | ||
@RequiredArgsConstructor | ||
public class VersionDocsCreator { | ||
private final VersionDocsReader versionDocsReader; | ||
private final DocsUpdater docsUpdater; | ||
private final VersionDocsRepository versionDocsRepository; | ||
|
||
public void create(Docs docs, User user, String contents) { | ||
Integer lastVersion = versionDocsReader.findLastVersion(docs).getVersion(); | ||
VersionDocs versionDocs = versionDocsRepository.save( | ||
new VersionDocs( | ||
lastVersion + 1, | ||
docs, | ||
contents, | ||
user | ||
) | ||
); | ||
docsUpdater.updateModifiedAt(docs, versionDocs.getThisVersionCreatedAt()); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...n/java/com/project/bumawiki/domain/docs/implementation/versiondocs/VersionDocsReader.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.project.bumawiki.domain.docs.implementation.versiondocs; | ||
|
||
import com.project.bumawiki.domain.docs.domain.Docs; | ||
import com.project.bumawiki.domain.docs.domain.VersionDocs; | ||
import com.project.bumawiki.domain.docs.domain.repository.VersionDocsRepository; | ||
import com.project.bumawiki.global.annotation.Implementation; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Implementation | ||
@RequiredArgsConstructor | ||
public class VersionDocsReader { | ||
private final VersionDocsRepository versionDocsRepository; | ||
|
||
public VersionDocs findLastVersion(Docs docs) { | ||
return versionDocsRepository.findFirstByDocsOrderByVersionDesc(docs); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...ava/com/project/bumawiki/domain/docs/implementation/versiondocs/VersionDocsValidator.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.project.bumawiki.domain.docs.implementation.versiondocs; | ||
|
||
import com.project.bumawiki.domain.docs.domain.Docs; | ||
import com.project.bumawiki.domain.docs.domain.VersionDocs; | ||
import com.project.bumawiki.global.annotation.Implementation; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Implementation | ||
@RequiredArgsConstructor | ||
public class VersionDocsValidator { | ||
private final VersionDocsReader versionDocsReader; | ||
|
||
public boolean isConflict(Docs docs, Integer updatingVersion) { | ||
VersionDocs lastVersionDocs = versionDocsReader.findLastVersion(docs); | ||
return !lastVersionDocs.getVersion().equals(updatingVersion); | ||
} | ||
} |
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
7 changes: 3 additions & 4 deletions
7
.../com/project/bumawiki/domain/docs/presentation/dto/request/DocsTitleUpdateRequestDto.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 |
---|---|---|
@@ -1,10 +1,9 @@ | ||
package com.project.bumawiki.domain.docs.presentation.dto.request; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class DocsTitleUpdateRequestDto { | ||
public record DocsTitleUpdateRequestDto( | ||
@NotBlank | ||
private String title; | ||
String title | ||
) { | ||
} |
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
15 changes: 8 additions & 7 deletions
15
.../java/com/project/bumawiki/domain/docs/presentation/dto/request/DocsUpdateRequestDto.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 |
---|---|---|
@@ -1,14 +1,15 @@ | ||
package com.project.bumawiki.domain.docs.presentation.dto.request; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.Getter; | ||
import jakarta.validation.constraints.Positive; | ||
|
||
@Getter | ||
public class DocsUpdateRequestDto { | ||
|
||
@NotNull | ||
private String contents; | ||
public record DocsUpdateRequestDto( | ||
@NotBlank(message = "업데이트할 문서의 내용이 전달되지 않았습니다.") | ||
String contents, | ||
|
||
@Positive(message = "업데이트할 문서는 양수여야합니다") | ||
@NotNull(message = "업데이트할 문서의 버전이 전달되지 않았습니다.") | ||
private int updatingVersion; | ||
Integer updatingVersion | ||
) { | ||
} |
Oops, something went wrong.