Refactor: 중복 DTO 제거

This commit is contained in:
김용수 2024-09-20 11:44:46 +09:00
parent 02d79e77ed
commit 3d70a75a6b
9 changed files with 24 additions and 37 deletions

View File

@ -22,17 +22,17 @@ public class DetailImageResponse {
private String imageUrl; private String imageUrl;
@Schema(description = "폴리곤 데이터", example = "PENDING 상태라면 data null") @Schema(description = "폴리곤 데이터", example = "PENDING 상태라면 data null")
private String dataPath; private String data;
@Schema(description = "이미지 상태", example = "PENDING") @Schema(description = "이미지 상태", example = "PENDING")
private LabelStatus status; private LabelStatus status;
public static DetailImageResponse from(final Image image) { public static DetailImageResponse from(final Image image, final String data) {
return new DetailImageResponse( return new DetailImageResponse(
image.getId(), image.getId(),
image.getTitle(), image.getTitle(),
image.getImagePath(), image.getImagePath(),
image.getDataPath(), data,
image.getStatus() image.getStatus()
); );
} }

View File

@ -53,8 +53,8 @@ public class ImageService {
@Transactional(readOnly = true) @Transactional(readOnly = true)
public DetailImageResponse getImageById(final Integer projectId, final Integer folderId, final Long imageId, final Integer memberId) { public DetailImageResponse getImageById(final Integer projectId, final Integer folderId, final Long imageId, final Integer memberId) {
Image image = getImageByIdAndFolderIdAndFolderProjectId(folderId, imageId, projectId); // 이미지가 해당 프로젝트에 속하는지 확인 Image image = getImageByIdAndFolderIdAndFolderProjectId(folderId, imageId, projectId); // 이미지가 해당 프로젝트에 속하는지 확인
// String data = s3UploadService.getData(image.getDataPath()); String data = s3UploadService.getData(image.getDataPath());
return DetailImageResponse.from(image); return DetailImageResponse.from(image, data);
} }
/** /**

View File

@ -1,15 +1,12 @@
package com.worlabel.domain.member.controller; package com.worlabel.domain.member.controller;
import com.worlabel.domain.member.entity.dto.MemberResponse; import com.worlabel.domain.member.entity.dto.MemberDetailResponse;
import com.worlabel.domain.member.entity.dto.SearchMemberResponse;
import com.worlabel.domain.member.service.MemberService; import com.worlabel.domain.member.service.MemberService;
import com.worlabel.domain.workspace.entity.dto.WorkspaceResponse;
import com.worlabel.global.annotation.CurrentUser; import com.worlabel.global.annotation.CurrentUser;
import com.worlabel.global.config.swagger.SwaggerApiError; import com.worlabel.global.config.swagger.SwaggerApiError;
import com.worlabel.global.config.swagger.SwaggerApiSuccess; import com.worlabel.global.config.swagger.SwaggerApiSuccess;
import com.worlabel.global.exception.ErrorCode; import com.worlabel.global.exception.ErrorCode;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
@ -31,7 +28,7 @@ public class MemberController {
@SwaggerApiSuccess(description = "keyword가 포함된 사용자를 검색합니다.") @SwaggerApiSuccess(description = "keyword가 포함된 사용자를 검색합니다.")
@SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR}) @SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR})
@GetMapping @GetMapping
public List<SearchMemberResponse> getWorkspace( public List<MemberDetailResponse> getWorkspace(
@CurrentUser final Integer memberId, @CurrentUser final Integer memberId,
@Param("keyword") final String keyword @Param("keyword") final String keyword
) { ) {

View File

@ -2,17 +2,14 @@ package com.worlabel.domain.member.entity.dto;
import com.worlabel.domain.member.entity.Member; import com.worlabel.domain.member.entity.Member;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor;
@Getter @Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE) @AllArgsConstructor(access = AccessLevel.PRIVATE)
@Schema(name = "멤버 검색 DTO", description = "이메일 검색에 대한 응답 DTO") @Schema(name = "멤버 상세 DTO", description = "멤버 상세 응답 DTO")
public class SearchMemberResponse { public class MemberDetailResponse {
@Schema(description = "ID", example = "1") @Schema(description = "ID", example = "1")
private Integer id; private Integer id;
@ -25,7 +22,7 @@ public class SearchMemberResponse {
@Schema(description = "이메일", example = "xxx@gmail.com") @Schema(description = "이메일", example = "xxx@gmail.com")
private String email; private String email;
public static SearchMemberResponse of(final Member member) { public static MemberDetailResponse of(final Member member) {
return new SearchMemberResponse(member.getId(), member.getNickname(), member.getProfileImage(), member.getEmail()); return new MemberDetailResponse(member.getId(), member.getNickname(), member.getProfileImage(), member.getEmail());
} }
} }

View File

@ -2,7 +2,7 @@ package com.worlabel.domain.member.service;
import com.worlabel.domain.member.entity.Member; import com.worlabel.domain.member.entity.Member;
import com.worlabel.domain.member.entity.dto.MemberResponse; import com.worlabel.domain.member.entity.dto.MemberResponse;
import com.worlabel.domain.member.entity.dto.SearchMemberResponse; import com.worlabel.domain.member.entity.dto.MemberDetailResponse;
import com.worlabel.domain.member.repository.MemberRepository; import com.worlabel.domain.member.repository.MemberRepository;
import com.worlabel.global.exception.CustomException; import com.worlabel.global.exception.CustomException;
import com.worlabel.global.exception.ErrorCode; import com.worlabel.global.exception.ErrorCode;
@ -32,10 +32,10 @@ public class MemberService {
return MemberResponse.of(member); return MemberResponse.of(member);
} }
public List<SearchMemberResponse> getSearchMember(final Integer memberId, final String keyword) { public List<MemberDetailResponse> getSearchMember(final Integer memberId, final String keyword) {
return memberRepository.findAllByKeyword(memberId, keyword.isEmpty() ? null : keyword) return memberRepository.findAllByKeyword(memberId, keyword.isEmpty() ? null : keyword)
.stream() .stream()
.map(SearchMemberResponse::of) .map(MemberDetailResponse::of)
.toList(); .toList();
} }
} }

View File

@ -2,7 +2,7 @@ package com.worlabel.domain.review.entity.dto;
import com.worlabel.domain.image.entity.dto.ImageResponse; import com.worlabel.domain.image.entity.dto.ImageResponse;
import com.worlabel.domain.member.entity.Member; import com.worlabel.domain.member.entity.Member;
import com.worlabel.domain.member.entity.dto.MemberResponse; import com.worlabel.domain.member.entity.dto.MemberDetailResponse;
import com.worlabel.domain.review.entity.Review; import com.worlabel.domain.review.entity.Review;
import com.worlabel.domain.review.entity.ReviewStatus; import com.worlabel.domain.review.entity.ReviewStatus;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
@ -41,10 +41,10 @@ public class ReviewDetailResponse {
private LocalDateTime updateAt; private LocalDateTime updateAt;
@Schema(description = "작성자 정보", example = "") @Schema(description = "작성자 정보", example = "")
private MemberResponse author; private MemberDetailResponse author;
@Schema(description = "리뷰어 정보", example = "") @Schema(description = "리뷰어 정보", example = "")
private MemberResponse reviewer; private MemberDetailResponse reviewer;
public static ReviewDetailResponse of(final Review review, final List<ImageResponse> images) { public static ReviewDetailResponse of(final Review review, final List<ImageResponse> images) {
Member writer = review.getMember(); Member writer = review.getMember();
@ -57,8 +57,8 @@ public class ReviewDetailResponse {
images, images,
review.getCreatedAt(), review.getCreatedAt(),
review.getUpdatedAt(), review.getUpdatedAt(),
MemberResponse.of(writer), MemberDetailResponse.of(writer),
Optional.ofNullable(reviewer).map(MemberResponse::of).orElse(null) Optional.ofNullable(reviewer).map(MemberDetailResponse::of).orElse(null)
); );
} }

View File

@ -1,5 +1,6 @@
package com.worlabel.domain.review.entity.dto; package com.worlabel.domain.review.entity.dto;
import com.worlabel.domain.member.entity.dto.MemberDetailResponse;
import com.worlabel.domain.review.entity.Review; import com.worlabel.domain.review.entity.Review;
import com.worlabel.domain.review.entity.ReviewStatus; import com.worlabel.domain.review.entity.ReviewStatus;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
@ -29,11 +30,8 @@ public class ReviewResponse {
@Schema(description = "리뷰 상태", example = "요청") @Schema(description = "리뷰 상태", example = "요청")
private ReviewStatus status; private ReviewStatus status;
@Schema(description = "작성자 닉네임", example = "javajoha") @Schema(description = "작성자 정보", example = "")
private String nickname; private MemberDetailResponse author;
@Schema(description = "작성자 이메일", example = "jaa@naver.com")
private String email;
@Schema(description = "리뷰 작성일", example = "") @Schema(description = "리뷰 작성일", example = "")
private LocalDateTime createAt; private LocalDateTime createAt;
@ -48,8 +46,7 @@ public class ReviewResponse {
review.getTitle(), review.getTitle(),
review.getContent(), review.getContent(),
review.getReviewStatus(), review.getReviewStatus(),
review.getMember().getNickname(), MemberDetailResponse.of(review.getMember()),
review.getMember().getEmail(),
review.getCreatedAt(), review.getCreatedAt(),
review.getUpdatedAt()); review.getUpdatedAt());
} }

View File

@ -1,10 +1,8 @@
package com.worlabel.domain.workspace.controller; package com.worlabel.domain.workspace.controller;
import com.worlabel.domain.member.entity.dto.MemberResponse; import com.worlabel.domain.member.entity.dto.MemberResponse;
import com.worlabel.domain.project.entity.dto.ProjectMemberResponse;
import com.worlabel.domain.review.entity.dto.ReviewResponse; import com.worlabel.domain.review.entity.dto.ReviewResponse;
import com.worlabel.domain.review.entity.dto.ReviewStatusRequest; import com.worlabel.domain.review.entity.dto.ReviewStatusRequest;
import com.worlabel.domain.workspace.entity.dto.WorkspaceMemberResponse;
import com.worlabel.domain.workspace.entity.dto.WorkspaceRequest; import com.worlabel.domain.workspace.entity.dto.WorkspaceRequest;
import com.worlabel.domain.workspace.entity.dto.WorkspaceResponse; import com.worlabel.domain.workspace.entity.dto.WorkspaceResponse;
import com.worlabel.domain.workspace.entity.dto.WorkspaceResponses; import com.worlabel.domain.workspace.entity.dto.WorkspaceResponses;

View File

@ -6,12 +6,10 @@ import com.worlabel.domain.member.repository.MemberRepository;
import com.worlabel.domain.participant.entity.WorkspaceParticipant; import com.worlabel.domain.participant.entity.WorkspaceParticipant;
import com.worlabel.domain.participant.repository.WorkspaceParticipantRepository; import com.worlabel.domain.participant.repository.WorkspaceParticipantRepository;
import com.worlabel.domain.review.entity.Review; import com.worlabel.domain.review.entity.Review;
import com.worlabel.domain.review.entity.ReviewStatus;
import com.worlabel.domain.review.entity.dto.ReviewResponse; import com.worlabel.domain.review.entity.dto.ReviewResponse;
import com.worlabel.domain.review.entity.dto.ReviewStatusRequest; import com.worlabel.domain.review.entity.dto.ReviewStatusRequest;
import com.worlabel.domain.review.repository.ReviewRepository; import com.worlabel.domain.review.repository.ReviewRepository;
import com.worlabel.domain.workspace.entity.Workspace; import com.worlabel.domain.workspace.entity.Workspace;
import com.worlabel.domain.workspace.entity.dto.WorkspaceMemberResponse;
import com.worlabel.domain.workspace.entity.dto.WorkspaceRequest; import com.worlabel.domain.workspace.entity.dto.WorkspaceRequest;
import com.worlabel.domain.workspace.entity.dto.WorkspaceResponse; import com.worlabel.domain.workspace.entity.dto.WorkspaceResponse;
import com.worlabel.domain.workspace.repository.WorkspaceRepository; import com.worlabel.domain.workspace.repository.WorkspaceRepository;