Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
qlido committed Apr 10, 2024
2 parents 3537e38 + 35e7809 commit d0ffee4
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import com.project.bumawiki.domain.docs.domain.Docs;
import com.project.bumawiki.domain.docs.domain.VersionDocs;

import java.util.List;

public interface VersionDocsRepository extends JpaRepository<VersionDocs, Long> {

@NonNull
VersionDocs findFirstByDocsOrderByVersionDesc(Docs docs);

List<VersionDocs> findTop3ByDocsOrderByVersion(Docs docs);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,15 @@ public void checkUpdatableDocsType(DocsType docsType) {
}
}

public void checkConflicted(Docs docs) {
if (docs.getStatus().equals(Status.CONFLICTED)) {
public void checkGood(Docs docs) {
if (!docs.getStatus().equals(Status.GOOD)) {
throw new BumawikiException(ErrorCode.DOCS_CONFLICTED);
}
}

public void checkConflicted(Docs docs) {
if (!docs.getStatus().equals(Status.CONFLICTED)) {
throw new BumawikiException(ErrorCode.DOCS_IS_NOT_CONFLICTED);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.project.bumawiki.domain.docs.implementation;

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;

import java.util.List;

@Implementation
@RequiredArgsConstructor
public class VersionDocsReader {
private final VersionDocsRepository versionDocsRepository;

public List<VersionDocs> findTop3ByDocs(Docs docs) {
return versionDocsRepository.findTop3ByDocsOrderByVersion(docs);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.project.bumawiki.domain.docs.presentation;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import com.project.bumawiki.domain.docs.presentation.dto.DocsConflictSolveDto;
Expand All @@ -21,11 +23,13 @@ public class DocsMergeConflictController {
private final DocsMergeConflictService mergeConflictService;

@GetMapping("/{title}")
@ResponseStatus(HttpStatus.OK)
public MergeConflictDataResponse getMergeConflictData(@PathVariable String title) {
return mergeConflictService.getMergeConflict(title);
}

@PutMapping("/{title}")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void solveConflict(@PathVariable String title, @RequestBody DocsConflictSolveDto dto) {
mergeConflictService.solveConflict(title, dto);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

import org.bitbucket.cowwoc.diffmatchpatch.DiffMatchPatch;

import com.project.bumawiki.domain.docs.presentation.dto.response.ContentVersionDocsResponseDto;

public record MergeConflictDataResponse(
ContentVersionDocsResponseDto firstDocs,
ContentVersionDocsResponseDto secondDocs,
ContentVersionDocsResponseDto originalDocs,
String firstDocsContent,
String secondDocsContent,
String originalDocsContent,
LinkedList<DiffMatchPatch.Diff> diff1,
LinkedList<DiffMatchPatch.Diff> diff2
) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,46 @@
import java.util.LinkedList;
import java.util.List;

import com.project.bumawiki.domain.docs.implementation.DocsReader;

import com.project.bumawiki.domain.docs.implementation.DocsUpdater;
import com.project.bumawiki.domain.docs.implementation.DocsValidator;
import com.project.bumawiki.domain.docs.implementation.VersionDocsReader;
import com.project.bumawiki.domain.docs.implementation.versiondocs.VersionDocsCreator;

import com.project.bumawiki.global.util.SecurityUtil;

import org.bitbucket.cowwoc.diffmatchpatch.DiffMatchPatch;
import org.springframework.stereotype.Service;

import com.project.bumawiki.domain.contribute.domain.Contribute;
import com.project.bumawiki.domain.contribute.service.ContributeService;
import com.project.bumawiki.domain.docs.domain.Docs;
import com.project.bumawiki.domain.docs.domain.VersionDocs;
import com.project.bumawiki.domain.docs.domain.repository.DocsRepository;
import com.project.bumawiki.domain.docs.domain.repository.VersionDocsRepository;
import com.project.bumawiki.domain.docs.domain.type.Status;
import com.project.bumawiki.domain.docs.exception.DocsIsNotConflictedException;
import com.project.bumawiki.domain.docs.exception.DocsNotFoundException;
import com.project.bumawiki.domain.docs.presentation.dto.DocsConflictSolveDto;
import com.project.bumawiki.domain.docs.presentation.dto.MergeConflictDataResponse;
import com.project.bumawiki.domain.docs.presentation.dto.response.ContentVersionDocsResponseDto;

import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class DocsMergeConflictService {
private final DocsRepository docsRepository;
private final VersionDocsRepository versionDocsRepository;
private final ContributeService contributeService;
private final DocsReader docsReader;
private final VersionDocsReader versionDocsReader;
private final VersionDocsCreator versionDocsCreator;
private final DocsValidator docsValidator;
private final DocsUpdater docsUpdater;

public MergeConflictDataResponse getMergeConflict(String title) {
Docs docs = docsRepository.findByTitle(title)
.orElseThrow(() -> DocsNotFoundException.EXCEPTION);
Docs docs = docsReader.findByTitle(title);

if (docs.getStatus() != Status.CONFLICTED) {
throw new DocsIsNotConflictedException();
}
docsValidator.checkConflicted(docs);

List<VersionDocs> docsVersion = docs.getDocsVersion();
// 버전 최신순 3가지 조회가 전체에서 자르는지 3개만 가져오는지 확인이 필요합니다
List<VersionDocs> docsVersion = versionDocsReader.findTop3ByDocs(docs);

VersionDocs firstDocs = docsVersion.get(docsVersion.size() - 2);
VersionDocs secondDocs = docsVersion.get(docsVersion.size() - 1);
VersionDocs originalDocs = docsVersion.get(docsVersion.size() - 3);
VersionDocs firstDocs = docsVersion.get(1);
VersionDocs secondDocs = docsVersion.get(2);
VersionDocs originalDocs = docsVersion.get(0);

//최신글의 겹치는 점과 지금 바꾸려는 글의 차이점을 조회
DiffMatchPatch dmp = new DiffMatchPatch();
Expand All @@ -51,33 +53,25 @@ public MergeConflictDataResponse getMergeConflict(String title) {
dmp.diffCleanupSemantic(diff2);

return new MergeConflictDataResponse(
new ContentVersionDocsResponseDto(firstDocs),
new ContentVersionDocsResponseDto(secondDocs),
new ContentVersionDocsResponseDto(originalDocs),
firstDocs.getContents(),
secondDocs.getContents(),
originalDocs.getContents(),
diff1,
diff2
);
}

public void solveConflict(String title, DocsConflictSolveDto dto) {
Docs docs = docsRepository.findByTitle(title)
.orElseThrow(() -> DocsNotFoundException.EXCEPTION);

if (docs.getStatus() != Status.CONFLICTED) {
throw new DocsIsNotConflictedException();
}

VersionDocs savedVersionDocs = versionDocsRepository.save(
VersionDocs.builder()
.docsId(docs.getId())
.contents(dto.contents())
.version(docs.getLastVersion() + 1)
.build()
);
Docs docs = docsReader.findByTitle(title);

docsValidator.checkConflicted(docs);

docs.updateStatus(Status.GOOD);
versionDocsCreator.create(
docs,
SecurityUtil.getCurrentUserWithLogin(),
dto.contents()
);

Contribute contribute = contributeService.updateContribute(savedVersionDocs);
savedVersionDocs.updateContributor(contribute);
docsUpdater.updateStatus(docs, Status.GOOD);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void execute(User user, String title, String contents, Integer updatingVe

docsValidator.checkUpdatableDocsType(docs.getDocsType());
docsValidator.checkUpdateOneSelf(user, docs);
docsValidator.checkConflicted(docs);
docsValidator.checkGood(docs);

if (versionDocsValidator.isConflict(docs, updatingVersion)) {
docsUpdater.updateStatus(docs, Status.CONFLICTED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import jakarta.validation.constraints.NotNull;
import lombok.Getter;

@Getter
public record ThumbsUpRequestDto(
@NotNull
Long docsId
Expand Down

0 comments on commit d0ffee4

Please sign in to comment.