-
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.
- Loading branch information
Showing
9 changed files
with
238 additions
and
169 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
8 changes: 8 additions & 0 deletions
8
...n/java/com/project/bumawiki/domain/contribute/domain/repository/ContributeRepository.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,7 +1,15 @@ | ||
package com.project.bumawiki.domain.contribute.domain.repository; | ||
|
||
import java.util.List; | ||
|
||
import com.project.bumawiki.domain.contribute.domain.Contribute; | ||
import com.project.bumawiki.domain.docs.domain.Docs; | ||
import com.project.bumawiki.domain.user.domain.User; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
public interface ContributeRepository extends JpaRepository<Contribute, Long> { | ||
@Query("select distinct c.contributor from Contribute c where c.docs = :docs") | ||
List<User> findUserAllByDocs(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
49 changes: 29 additions & 20 deletions
49
...main/java/com/project/bumawiki/domain/docs/presentation/dto/response/DocsResponseDto.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,32 +1,41 @@ | ||
package com.project.bumawiki.domain.docs.presentation.dto.response; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import com.project.bumawiki.domain.docs.domain.Docs; | ||
import com.project.bumawiki.domain.docs.domain.VersionDocs; | ||
import com.project.bumawiki.domain.docs.domain.type.DocsType; | ||
import lombok.Getter; | ||
import com.project.bumawiki.domain.user.domain.User; | ||
import com.project.bumawiki.domain.user.presentation.dto.SimpleUserDto; | ||
|
||
import java.time.LocalDateTime; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class DocsResponseDto { | ||
|
||
private final Long id; | ||
private final String title; | ||
private final String contents; | ||
private final DocsType docsType; | ||
private final LocalDateTime lastModifiedAt; | ||
private final int enroll; | ||
|
||
public DocsResponseDto(Docs docs) { | ||
int lastValueOfDocsVersion = docs.getDocsVersion().size() - 1; | ||
VersionDocs versionDocs = docs.getDocsVersion().get(lastValueOfDocsVersion); | ||
|
||
this.id = docs.getId(); | ||
this.title = docs.getTitle(); | ||
this.contents = versionDocs.getContents(); | ||
this.lastModifiedAt = docs.getLastModifiedAt(); | ||
this.docsType = docs.getDocsType(); | ||
this.enroll = docs.getEnroll(); | ||
} | ||
private final Long id; | ||
private final String title; | ||
private final String contents; | ||
private final DocsType docsType; | ||
private final LocalDateTime lastModifiedAt; | ||
private final int enroll; | ||
private final List<SimpleUserDto> contributors; | ||
|
||
public DocsResponseDto(Docs docs, List<User> contributors) { | ||
int lastValueOfDocsVersion = docs.getDocsVersion().size() - 1; | ||
VersionDocs versionDocs = docs.getDocsVersion().get(lastValueOfDocsVersion); | ||
|
||
this.id = docs.getId(); | ||
this.title = docs.getTitle(); | ||
this.contents = versionDocs.getContents(); | ||
this.lastModifiedAt = docs.getLastModifiedAt(); | ||
this.docsType = docs.getDocsType(); | ||
this.enroll = docs.getEnroll(); | ||
this.contributors = contributors.stream() | ||
.map(SimpleUserDto::new) | ||
.collect(Collectors.toList()); | ||
} | ||
} | ||
|
136 changes: 70 additions & 66 deletions
136
src/main/java/com/project/bumawiki/domain/docs/service/DocsCreateService.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,85 +1,89 @@ | ||
package com.project.bumawiki.domain.docs.service; | ||
|
||
import java.io.IOException; | ||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
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.VersionDocsRepository; | ||
import com.project.bumawiki.domain.docs.domain.repository.DocsRepositoryMapper; | ||
import com.project.bumawiki.domain.docs.domain.repository.VersionDocsRepository; | ||
import com.project.bumawiki.domain.docs.presentation.dto.request.DocsCreateRequestDto; | ||
import com.project.bumawiki.domain.docs.presentation.dto.response.DocsResponseDto; | ||
import com.project.bumawiki.domain.image.service.ImageService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.io.IOException; | ||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class DocsCreateService { | ||
private final VersionDocsRepository versionDocsRepository; | ||
private final ImageService imageService; | ||
private final ContributeService contributeService; | ||
private final DocsRepositoryMapper docsRepositoryMapper; | ||
|
||
@Transactional | ||
public DocsResponseDto execute(final DocsCreateRequestDto docsCreateRequestDto) throws IOException { | ||
|
||
docsRepositoryMapper.checkTitleAlreadyExist(docsCreateRequestDto.getTitle()); | ||
|
||
Docs docs = docsRepositoryMapper.createDocs(docsCreateRequestDto); | ||
|
||
VersionDocs savedVersionDocs = saveVersionDocs(docsCreateRequestDto, docs.getId()); | ||
Contribute contribute = contributeService.setContribute(savedVersionDocs); | ||
|
||
setVersionDocs(docs, savedVersionDocs, contribute); | ||
|
||
return new DocsResponseDto(docs); | ||
} | ||
|
||
private static void setVersionDocs(final Docs docs, final VersionDocs savedVersionDocs, final Contribute contribute) { | ||
List<VersionDocs> versionDocs = new ArrayList<>(); | ||
|
||
versionDocs.add(savedVersionDocs); | ||
|
||
savedVersionDocs.updateContributor(contribute); | ||
|
||
docs.setVersionDocs(versionDocs); | ||
} | ||
|
||
private void setImageUrl(final DocsCreateRequestDto docsCreateRequestDto, final MultipartFile[] files) throws IOException { | ||
if(files != null){ | ||
ArrayList<String> FileUrl = imageService.GetFileUrl(files, docsCreateRequestDto.getTitle()); | ||
setImageUrlInContents(docsCreateRequestDto,FileUrl); | ||
} | ||
} | ||
|
||
/** | ||
* 프론트가 [사진1]이라고 보낸거 우리가 저장한 이미지 주소로 바꾸는 로직 | ||
*/ | ||
public void setImageUrlInContents(final DocsCreateRequestDto docsCreateRequestDto, final ArrayList<String> urls){ | ||
String content = docsCreateRequestDto.getContents(); | ||
for (String url : urls) { | ||
content = content.replaceFirst("<<사진>>",url); | ||
} | ||
docsCreateRequestDto.updateContent(content); | ||
} | ||
|
||
private VersionDocs saveVersionDocs(final DocsCreateRequestDto docsCreateRequestDto, final Long id){ | ||
return versionDocsRepository.save( | ||
VersionDocs.builder() | ||
.docsId(id) | ||
.contents(docsCreateRequestDto.getContents()) | ||
.thisVersionCreatedAt(LocalDateTime.now()) | ||
.build() | ||
); | ||
} | ||
private final VersionDocsRepository versionDocsRepository; | ||
private final ImageService imageService; | ||
private final ContributeService contributeService; | ||
private final DocsRepositoryMapper docsRepositoryMapper; | ||
|
||
@Transactional | ||
public Long execute(final DocsCreateRequestDto docsCreateRequestDto) throws IOException { | ||
|
||
docsRepositoryMapper.checkTitleAlreadyExist(docsCreateRequestDto.getTitle()); | ||
|
||
Docs docs = docsRepositoryMapper.createDocs(docsCreateRequestDto); | ||
|
||
VersionDocs savedVersionDocs = saveVersionDocs(docsCreateRequestDto, docs.getId()); | ||
Contribute contribute = contributeService.setContribute(savedVersionDocs); | ||
|
||
setVersionDocs(docs, savedVersionDocs, contribute); | ||
|
||
return docs.getId(); | ||
} | ||
|
||
private static void setVersionDocs(final Docs docs, final VersionDocs savedVersionDocs, | ||
final Contribute contribute) { | ||
List<VersionDocs> versionDocs = new ArrayList<>(); | ||
|
||
versionDocs.add(savedVersionDocs); | ||
|
||
savedVersionDocs.updateContributor(contribute); | ||
|
||
docs.setVersionDocs(versionDocs); | ||
} | ||
|
||
private void setImageUrl(final DocsCreateRequestDto docsCreateRequestDto, final MultipartFile[] files) throws | ||
IOException { | ||
if (files != null) { | ||
ArrayList<String> FileUrl = imageService.GetFileUrl(files, docsCreateRequestDto.getTitle()); | ||
setImageUrlInContents(docsCreateRequestDto, FileUrl); | ||
} | ||
} | ||
|
||
/** | ||
* 프론트가 [사진1]이라고 보낸거 우리가 저장한 이미지 주소로 바꾸는 로직 | ||
*/ | ||
public void setImageUrlInContents(final DocsCreateRequestDto docsCreateRequestDto, final ArrayList<String> urls) { | ||
String content = docsCreateRequestDto.getContents(); | ||
for (String url : urls) { | ||
content = content.replaceFirst("<<사진>>", url); | ||
} | ||
docsCreateRequestDto.updateContent(content); | ||
} | ||
|
||
private VersionDocs saveVersionDocs(final DocsCreateRequestDto docsCreateRequestDto, final Long id) { | ||
return versionDocsRepository.save( | ||
VersionDocs.builder() | ||
.docsId(id) | ||
.contents(docsCreateRequestDto.getContents()) | ||
.thisVersionCreatedAt(LocalDateTime.now()) | ||
.build() | ||
); | ||
} | ||
} | ||
|
||
|
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
Oops, something went wrong.