Skip to content

Commit

Permalink
Merge pull request #81 from Team-INSERT/refactor/#80
Browse files Browse the repository at this point in the history
Refactor(docs): Docs 도메인에서 우리가 정의한 개발방식과 맞지 않는 부분 수정
  • Loading branch information
jacobhboy authored Apr 15, 2024
2 parents 88f9be1 + d7b6683 commit f324fbf
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 152 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.project.bumawiki.domain.docs.domain.repository;
package com.project.bumawiki.domain.docs.infra;

import static com.project.bumawiki.domain.docs.domain.QDocs.*;
import static com.project.bumawiki.domain.docs.domain.QVersionDocs.*;
Expand All @@ -11,6 +11,7 @@
import org.springframework.stereotype.Repository;

import com.project.bumawiki.domain.docs.domain.Docs;
import com.project.bumawiki.domain.docs.domain.repository.CustomDocsRepository;
import com.project.bumawiki.domain.docs.presentation.dto.response.DocsPopularResponseDto;
import com.project.bumawiki.domain.docs.presentation.dto.response.VersionDocsResponseDto;
import com.project.bumawiki.domain.docs.presentation.dto.response.VersionResponseDto;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import com.project.bumawiki.domain.auth.annotation.LoginRequired;
import com.project.bumawiki.domain.auth.service.QueryAuthService;
import com.project.bumawiki.domain.docs.presentation.dto.request.DocsConflictSolveRequestDto;
import com.project.bumawiki.domain.docs.presentation.dto.request.DocsCreateRequestDto;
import com.project.bumawiki.domain.docs.presentation.dto.request.DocsTitleUpdateRequestDto;
import com.project.bumawiki.domain.docs.presentation.dto.request.DocsTypeUpdateRequestDto;
Expand Down Expand Up @@ -59,4 +60,11 @@ public void updateDocsType(@RequestBody DocsTypeUpdateRequestDto requestDto) {
public void deleteDocs(@PathVariable Long id) {
commandDocsService.delete(id);
}

@PutMapping("/merge/{title}")
@ResponseStatus(HttpStatus.NO_CONTENT)
@LoginRequired
public void solveConflict(@PathVariable String title, @RequestBody DocsConflictSolveRequestDto dto) {
commandDocsService.solveConflict(title, dto.contents(), queryAuthService.getCurrentUser());
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
import com.project.bumawiki.domain.docs.domain.type.DocsType;
import com.project.bumawiki.domain.docs.presentation.dto.response.ClubResponseDto;
import com.project.bumawiki.domain.docs.presentation.dto.response.DocsNameAndEnrollResponseDto;
import com.project.bumawiki.domain.docs.presentation.dto.response.DocsPopularResponseDto;
import com.project.bumawiki.domain.docs.presentation.dto.response.DocsResponseDto;
import com.project.bumawiki.domain.docs.presentation.dto.response.DocsTypeResponseDto;
import com.project.bumawiki.domain.docs.presentation.dto.response.MergeConflictDataResponseDto;
import com.project.bumawiki.domain.docs.presentation.dto.response.TeacherResponseDto;
import com.project.bumawiki.domain.docs.presentation.dto.response.VersionDocsDiffResponseDto;
import com.project.bumawiki.domain.docs.presentation.dto.response.VersionResponseDto;
import com.project.bumawiki.domain.docs.service.DocsInformationService;
import com.project.bumawiki.domain.docs.service.QueryDocsService;

import lombok.RequiredArgsConstructor;

Expand All @@ -30,48 +32,48 @@
@RequiredArgsConstructor
@ResponseStatus(HttpStatus.OK)
@RequestMapping("/api/docs")
public class DocsInformationController {
private final DocsInformationService docsInformationService;
public class QueryDocsController {
private final QueryDocsService queryDocsService;

@GetMapping("/all/teacher")
public ResponseEntity<TeacherResponseDto> findAllTeacher() {
return ResponseEntity.ok(docsInformationService.getAllTeacher());
return ResponseEntity.ok(queryDocsService.getAllTeacher());
}

@GetMapping("/all/club")
public ResponseEntity<ClubResponseDto> findAllClub() {
return ResponseEntity.ok(docsInformationService.getAllClub());
return ResponseEntity.ok(queryDocsService.getAllClub());
}

@GetMapping("/{stringDocsType}")
public DocsTypeResponseDto findAllByDocsType(
@PathVariable String stringDocsType) {
DocsType docsType = DocsType.valueOfLabel(stringDocsType);
return DocsTypeResponseDto.from(docsInformationService.findByDocsTypeOrderByEnroll(docsType));
return DocsTypeResponseDto.from(queryDocsService.findByDocsTypeOrderByEnroll(docsType));
}

@GetMapping("/find/all/title/{title}")
public List<DocsNameAndEnrollResponseDto> findAllByTitle(@PathVariable String title) {
return docsInformationService.findAllByTitle(title)
return queryDocsService.findAllByTitle(title)
.stream()
.map(DocsNameAndEnrollResponseDto::new)
.toList();
}

@GetMapping("/find/title/{title}")
public ResponseEntity<DocsResponseDto> findById(@PathVariable String title) {
return ResponseEntity.ok(docsInformationService.findDocs(title));
return ResponseEntity.ok(queryDocsService.findDocs(title));
}

@GetMapping("/find/{title}/version")
public ResponseEntity<VersionResponseDto> showDocsVersion(@PathVariable String title) {
return ResponseEntity.ok(docsInformationService.findDocsVersion(title));
return ResponseEntity.ok(queryDocsService.findDocsVersion(title));
}

@GetMapping("/find/modified")
public List<DocsNameAndEnrollResponseDto> showDocsModifiedTimeDesc(
@PageableDefault(size = 12) Pageable pageable) {
return docsInformationService.showDocsModifiedAtDesc(pageable)
return queryDocsService.showDocsModifiedAtDesc(pageable)
.stream()
.map(DocsNameAndEnrollResponseDto::new)
.toList();
Expand All @@ -80,14 +82,26 @@ public List<DocsNameAndEnrollResponseDto> showDocsModifiedTimeDesc(
@GetMapping("/find/version/{title}/different/{version}")
public VersionDocsDiffResponseDto showVersionDocsDiff(@PathVariable String title,
@PathVariable Integer version) {
return docsInformationService.showVersionDocsDiff(title, version);
return queryDocsService.showVersionDocsDiff(title, version);
}

@GetMapping("/find/modified/all")
public List<DocsNameAndEnrollResponseDto> showDocsModifiedTimeDescAll() {
return docsInformationService.showDocsModifiedAtDescAll()
return queryDocsService.showDocsModifiedAtDescAll()
.stream()
.map(DocsNameAndEnrollResponseDto::new)
.toList();
}

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

@GetMapping("/popular")
@ResponseStatus(HttpStatus.OK)
public List<DocsPopularResponseDto> docsPopular() {
return queryDocsService.readByThumbsUpsDesc();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,19 @@ public void docsTypeUpdate(Long id, DocsType docsType) {

docsUpdater.updateType(docs, docsType);
}

public void solveConflict(String title, String contents, User user) {
Docs docs = docsReader.findByTitle(title);

docsValidator.checkConflicted(docs);

docsCreator.create(
docs,
user,
contents
);

docsUpdater.updateStatus(docs, Status.GOOD);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
import com.project.bumawiki.domain.docs.domain.repository.VersionDocsRepository;
import com.project.bumawiki.domain.docs.domain.type.DocsType;
import com.project.bumawiki.domain.docs.implementation.DocsReader;
import com.project.bumawiki.domain.docs.implementation.DocsValidator;
import com.project.bumawiki.domain.docs.presentation.dto.response.ClubResponseDto;
import com.project.bumawiki.domain.docs.presentation.dto.response.DocsPopularResponseDto;
import com.project.bumawiki.domain.docs.presentation.dto.response.DocsResponseDto;
import com.project.bumawiki.domain.docs.presentation.dto.response.MergeConflictDataResponseDto;
import com.project.bumawiki.domain.docs.presentation.dto.response.TeacherResponseDto;
import com.project.bumawiki.domain.docs.presentation.dto.response.VersionDocsDiffResponseDto;
import com.project.bumawiki.domain.docs.presentation.dto.response.VersionDocsSummaryResponseDto;
Expand All @@ -32,10 +35,11 @@
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class DocsInformationService {
public class QueryDocsService {
private final DocsRepository docsRepository;
private final VersionDocsRepository versionDocsRepository;
private final DocsReader docsReader;
private final DocsValidator docsValidator;

public List<Docs> findAllByTitle(String title) {
List<Docs> docs = docsRepository.findAllByTitle(title);
Expand Down Expand Up @@ -122,4 +126,33 @@ private List<Docs> findByDocsType(DocsType docsType) {
public List<VersionDocs> findAllVersionDocsByUser(User user) {
return versionDocsRepository.findAllByUser(user);
}

public MergeConflictDataResponseDto getMergeConflict(String title) {
Docs docs = docsReader.findByTitle(title);

docsValidator.checkConflicted(docs);

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

String firstDocsContent = docsVersion.get(0).getContents();
String secondDocsContent = docsVersion.get(1).getContents();
String originalDocsContent = docsVersion.get(2).getContents();

//최신글의 겹치는 점과 지금 바꾸려는 글의 차이점을 조회
LinkedList<DiffMatchPatch.Diff> diff1 = DocsUtil.getDiff(originalDocsContent, firstDocsContent);
LinkedList<DiffMatchPatch.Diff> diff2 = DocsUtil.getDiff(originalDocsContent, secondDocsContent);

return new MergeConflictDataResponseDto(
firstDocsContent,
secondDocsContent,
originalDocsContent,
diff1,
diff2
);
}

public List<DocsPopularResponseDto> readByThumbsUpsDesc() {
return docsRepository.findByThumbsUpsDesc();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.springframework.web.bind.annotation.RestController;

import com.project.bumawiki.domain.auth.service.QueryAuthService;
import com.project.bumawiki.domain.docs.service.DocsInformationService;
import com.project.bumawiki.domain.docs.service.QueryDocsService;
import com.project.bumawiki.domain.user.domain.User;
import com.project.bumawiki.domain.user.presentation.dto.UserResponseDto;
import com.project.bumawiki.domain.user.service.UserInfoService;
Expand All @@ -22,21 +22,21 @@
public class UserInfoController {

private final UserInfoService userInfoService;
private final DocsInformationService docsInformationService;
private final QueryDocsService queryDocsService;
private final QueryAuthService queryAuthService;

@GetMapping
@ResponseStatus(HttpStatus.OK)
public UserResponseDto findUserInfo() {
User user = queryAuthService.getCurrentUser();
return new UserResponseDto(user, docsInformationService.findAllVersionDocsByUser(user));
return new UserResponseDto(user, queryDocsService.findAllVersionDocsByUser(user));
}

@GetMapping("/{id}")
public ResponseEntity<UserResponseDto> findAnotherUserInFo(@PathVariable Long id) {
User foundUser = userInfoService.findAnotherInfo(id);
UserResponseDto response = new UserResponseDto(foundUser,
docsInformationService.findAllVersionDocsByUser(foundUser));
queryDocsService.findAllVersionDocsByUser(foundUser));
return ResponseEntity.ok().body(response);
}

Expand Down

0 comments on commit f324fbf

Please sign in to comment.