Skip to content

Commit

Permalink
refactor: dto 빌더 클래스 레벨로 변경 및 정적 메서드 사용
Browse files Browse the repository at this point in the history
  • Loading branch information
jminkkk committed Dec 4, 2023
1 parent 2b40d39 commit f69f558
Show file tree
Hide file tree
Showing 20 changed files with 91 additions and 157 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.timcooki.jnuwiki.domain.docs.DTO.response;

import com.timcooki.jnuwiki.domain.docs.entity.Docs;
import com.timcooki.jnuwiki.domain.docs.entity.DocsLocation;
import com.timcooki.jnuwiki.domain.docsRequest.entity.DocsCategory;
import lombok.Builder;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import lombok.Builder;

@Builder
public record InfoEditResDTO(
Long docsId,
String docsName,
Expand All @@ -13,9 +15,15 @@ public record InfoEditResDTO(
String docsContent,
String docsModifiedAt
) {
@Builder
public InfoEditResDTO {

public static InfoEditResDTO of(Docs docs) {
return InfoEditResDTO.builder()
.docsId(docs.getDocsId())
.docsName(docs.getDocsName())
.docsLocation(docs.getDocsLocation())
.docsContent(docs.getDocsContent())
.docsCategory(docs.getDocsCategory().getCategory())
.docsModifiedAt(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss")))
.build();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
package com.timcooki.jnuwiki.domain.docs.DTO.response;

import com.timcooki.jnuwiki.domain.docs.entity.Docs;
import com.timcooki.jnuwiki.domain.docs.entity.DocsLocation;
import com.timcooki.jnuwiki.domain.docsRequest.entity.DocsCategory;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import lombok.Builder;

import java.time.LocalDateTime;

@Builder
public record NewApproveResDTO(
Long id,
String docsName,
String docsCategory,
DocsLocation docsLocation,
String docsCreatedAt
){
@Builder
public NewApproveResDTO {

public static NewApproveResDTO of(Docs docs){
return NewApproveResDTO.builder()
.id(docs.getDocsId())
.docsCategory(docs.getDocsCategory().getCategory())
.docsName(docs.getDocsName())
.docsLocation(docs.getDocsLocation())
.docsCreatedAt(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss")))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.mapstruct.factory.Mappers;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -43,10 +42,7 @@ public void createModifiedRequest(EditWriteReqDTO modifiedRequestWriteDto) {
DocsRequest docsRequest = mapper.editDTOToEntity(modifiedRequestWriteDto, docs, member, DocsCategory.nameOf(modifiedRequestWriteDto.docsRequestCategory()));
// docsRequestRepository.save(docsRequest);

docs.updateBasicInfo(docsRequest.getDocsRequestName(),
docsRequest.getDocsRequestLocation(),
docsRequest.getDocsRequestCategory());

docs.updateBasicInfo(docsRequest);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@

import lombok.Builder;

@Builder
public record CheckEmailReqDTO(
String email
) {
@Builder
public CheckEmailReqDTO{

}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package com.timcooki.jnuwiki.domain.member.DTO.request;

import lombok.Builder;

@Builder
public record CheckNicknameReqDTO(
String nickname
) {
@Builder
public CheckNicknameReqDTO{

}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.timcooki.jnuwiki.domain.member.DTO.request;

import lombok.Builder;

public record EditNicknameReqDTO(String nickname) {
@Builder
public EditNicknameReqDTO {
}
@Builder
public record EditNicknameReqDTO(
String nickname
) {
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.timcooki.jnuwiki.domain.member.DTO.request;

import lombok.Builder;

public record EditPasswordReqDTO(String password) {
@Builder
public EditPasswordReqDTO {
}
@Builder
public record EditPasswordReqDTO(
String password
) {
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package com.timcooki.jnuwiki.domain.member.DTO.request;

import lombok.Builder;

@Builder
public record JoinReqDTO(
String email,
String nickName,
String password
) {
@Builder
public JoinReqDTO{

}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package com.timcooki.jnuwiki.domain.member.DTO.response;

import lombok.Builder;

@Builder
public record InfoResDTO(
Long id,
String nickname,
String password
) {
@Builder
public InfoResDTO{

}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.timcooki.jnuwiki.domain.member.DTO.response;

import lombok.Builder;

@Builder
public record LoginResDTO(
Long id,
String role,
Expand All @@ -10,8 +10,4 @@ public record LoginResDTO(
Long refreshTokenExpiration,
String refreshTokenFormattedExpiration
) {
@Builder
public LoginResDTO {

}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package com.timcooki.jnuwiki.domain.member.DTO.response;

import com.timcooki.jnuwiki.domain.member.entity.Member;
import lombok.Builder;

@Builder
public record ReadResDTO(
Long id,
String nickName,
String password
) {
@Builder
public ReadResDTO{

public static ReadResDTO of(Member member) {
return ReadResDTO.builder()
.id(member.getMemberId())
.nickName(member.getNickName())
.password(member.getPassword())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
package com.timcooki.jnuwiki.domain.member.DTO.response;

import com.timcooki.jnuwiki.domain.docs.entity.Docs;
import com.timcooki.jnuwiki.domain.member.entity.Member;
import lombok.Builder;

import java.util.List;
import org.springframework.data.domain.Page;

@Builder
public record ScrapListResDTO(
List<ScrapResDTO> scrapList,
int totalPages
) {

@Builder
public ScrapListResDTO {
public static ScrapListResDTO of(Page<Docs> docs, Member member) {
return ScrapListResDTO.builder()
.scrapList(docs.stream()
.map(d -> ScrapResDTO.of(d, member))
.toList())
.totalPages(docs.getTotalPages())
.build();
}
}

Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
package com.timcooki.jnuwiki.domain.member.DTO.response;

import com.timcooki.jnuwiki.domain.docs.entity.Docs;
import com.timcooki.jnuwiki.domain.docs.entity.DocsLocation;
import com.timcooki.jnuwiki.domain.member.entity.Member;
import lombok.Builder;

@Builder
public record ScrapResDTO(
Long docsId,
String docsName,
String docsCategory,
DocsLocation docsRequestLocation,
String member
) {
@Builder
public ScrapResDTO {
public static ScrapResDTO of(Docs docs, Member member) {
return ScrapResDTO.builder()
.docsId(docs.getDocsId())
.docsName(docs.getDocsName())
.docsCategory(docs.getDocsCategory().getCategory())
.docsRequestLocation(docs.getDocsLocation())
.member(member.getNickName())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package com.timcooki.jnuwiki.domain.member.DTO.response;

import com.timcooki.jnuwiki.util.ApiResult;
import lombok.Builder;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;

@Builder
public record WrapLoginResDTO<T>(
HttpHeaders headers,
LoginResDTO body

) {
@Builder
public WrapLoginResDTO{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
import lombok.Builder;

import java.util.List;
//
@Builder
public record EditListReadResDTO(
List<EditReadResDTO> modifiedRequestList,
int totalPages
) {
@Builder
public EditListReadResDTO {

}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
package com.timcooki.jnuwiki.domain.member.DTO.response.admin;

import com.timcooki.jnuwiki.domain.docs.entity.Docs;
import com.timcooki.jnuwiki.domain.docs.entity.DocsLocation;
import com.timcooki.jnuwiki.domain.docsRequest.entity.DocsCategory;
import com.timcooki.jnuwiki.domain.docsRequest.entity.DocsRequestType;
import lombok.Builder;

import java.time.LocalDateTime;

@Builder
public record EditReadResDTO(
Long docsRequestId,
Long docsId, // 수정하려는 문서
Long docsId,
DocsRequestType docsRequestType,
String docsRequestCategory,
String docsRequestName,
DocsLocation docsRequestLocation
) {
@Builder
public EditReadResDTO {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

import lombok.Builder;
import java.util.List;

@Builder
public record NewListReadResDTO(
List<NewReadResDTO> createdRequestList,
int totalPages
) {
@Builder
public NewListReadResDTO {
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
package com.timcooki.jnuwiki.domain.member.DTO.response.admin;

import com.timcooki.jnuwiki.domain.docs.entity.DocsLocation;
import com.timcooki.jnuwiki.domain.docsRequest.entity.DocsCategory;
import com.timcooki.jnuwiki.domain.docsRequest.entity.DocsRequestType;
import lombok.Builder;


@Builder
public record NewReadResDTO(
Long docsRequestId,
DocsRequestType docsRequestType,
String docsRequestCategory,
String docsRequestName,
DocsLocation docsRequestLocation
) {
@Builder
public NewReadResDTO {

}
}
Loading

0 comments on commit f69f558

Please sign in to comment.