Skip to content

Commit

Permalink
Merge branch 'refactor/#75' of https://github.com/Team-INSERT/BUMAWIK…
Browse files Browse the repository at this point in the history
…I_SERVER_V2 into refactor/#75
  • Loading branch information
마현우 committed Apr 10, 2024
2 parents 0e7e2b9 + f25ed30 commit 57b06ea
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 79 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.project.bumawiki.domain.docs.presentation.dto.response;

import java.time.LocalDateTime;

import com.project.bumawiki.domain.docs.domain.VersionDocs;

public record ContributeDocsResponseDto(
Long userId,
String userNickName,
Long docsId,
LocalDateTime createTime,
String title,
Integer version
) {
public ContributeDocsResponseDto(VersionDocs versionDocs) {
this(
versionDocs.getUser().getId(),
versionDocs.getUser().getNickName(),
versionDocs.getDocs().getId(),
versionDocs.getCreatedAt(),
versionDocs.getDocs().getTitle(),
versionDocs.getVersion()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,35 @@
import com.project.bumawiki.domain.docs.domain.type.DocsType;
import com.project.bumawiki.domain.docs.util.DocsUtil;

import lombok.Getter;

@Getter
public class DocsNameAndEnrollResponseDto {

private final Long id;
private final String title;
private final int enroll;
private final String simpleContents;
private final DocsType docsType;
private final LocalDateTime lastModifiedAt;
private final String thumbnail;
public record DocsNameAndEnrollResponseDto (
Long id,
String title,
int enroll,
String simpleContents,
DocsType docsType,
LocalDateTime lastModifiedAt,
String thumbnail
) {

public DocsNameAndEnrollResponseDto(Docs docs) {
this.id = docs.getId();
this.title = docs.getTitle();
this.enroll = docs.getEnroll();
this.docsType = docs.getDocsType();
this.lastModifiedAt = docs.getLastModifiedAt();
this.simpleContents = getSimpleContents(docs);
this.thumbnail = DocsUtil.getThumbnail(getContents(docs));
this(
docs.getId(),
docs.getTitle(),
docs.getEnroll(),
getSimpleContents(docs),
docs.getDocsType(),
docs.getLastModifiedAt(),
DocsUtil.getThumbnail(getContents(docs))
);
}

private String getSimpleContents(Docs docs) {
private static String getSimpleContents(Docs docs) {
String contents = getContents(docs);
int endIndex = Math.min(contents.length(), 200);
return contents.substring(0, endIndex);
}

private String getContents(Docs docs) {
private static String getContents(Docs docs) {
List<VersionDocs> docsVersion = docs.getVersionDocs();
int currentDocsSize = docsVersion.size() - 1;
return docsVersion.get(currentDocsSize).getContents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,36 @@
import com.project.bumawiki.domain.user.domain.User;
import com.project.bumawiki.domain.user.presentation.dto.SimpleUserDto;

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;
private final boolean isDocsDetail;
private final List<SimpleUserDto> contributors;
private final Status status;
private final int version;
private final String thumbnail;
public record DocsResponseDto (
Long id,
String title,
String contents,
DocsType docsType,
LocalDateTime lastModifiedAt,
int enroll,
boolean isDocsDetail,
List<SimpleUserDto> contributors,
Status status,
int version,
String thumbnail
) {

public DocsResponseDto(Docs docs, List<User> contributors, VersionDocs versionDocs) {
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.isDocsDetail = true;
this.contributors = contributors.stream()
this(
docs.getId(),
docs.getTitle(),
versionDocs.getContents(),
docs.getDocsType(),
docs.getLastModifiedAt(),
docs.getEnroll(),
true,
contributors.stream()
.map(SimpleUserDto::new)
.toList();
this.status = docs.getStatus();
this.version = versionDocs.getVersion();
this.thumbnail = DocsUtil.getThumbnail(versionDocs.getContents());
.toList(),
docs.getStatus(),
versionDocs.getVersion(),
DocsUtil.getThumbnail(versionDocs.getContents())
);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.List;

import com.project.bumawiki.domain.contribute.dto.ContributeResponseDto;
import com.project.bumawiki.domain.docs.presentation.dto.response.ContributeDocsResponseDto;
import com.project.bumawiki.domain.docs.domain.VersionDocs;
import com.project.bumawiki.domain.user.domain.User;
import com.project.bumawiki.domain.user.domain.authority.Authority;
Expand All @@ -21,7 +21,7 @@ public class UserResponseDto {

private final Authority authority;

private final List<ContributeResponseDto> contributeDocs;
private final List<ContributeDocsResponseDto> contributeDocs;

public UserResponseDto(User user, List<VersionDocs> versionDocs) {
this.id = user.getId();
Expand All @@ -31,7 +31,7 @@ public UserResponseDto(User user, List<VersionDocs> versionDocs) {
this.name = user.getName();
this.contributeDocs = versionDocs
.stream()
.map(ContributeResponseDto::new)
.map(ContributeDocsResponseDto::new)
.toList();
}
}

0 comments on commit 57b06ea

Please sign in to comment.