Skip to content

Commit

Permalink
Merge pull request #89 from Katchup-dev/refactor/#86-dto-response
Browse files Browse the repository at this point in the history
[REFACTOR] DTO 통일 & Response 구조
  • Loading branch information
yeseul106 authored Aug 3, 2023
2 parents cfb55ce + 3804665 commit 00570c4
Show file tree
Hide file tree
Showing 42 changed files with 155 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import site.katchup.katchupserver.api.auth.dto.AuthRequestDto;
import site.katchup.katchupserver.api.auth.dto.AuthResponseDto;
import site.katchup.katchupserver.api.auth.dto.AuthTokenResponseDto;
import site.katchup.katchupserver.api.auth.dto.request.AuthRequestDto;
import site.katchup.katchupserver.api.auth.dto.response.AuthLoginResponseDto;
import site.katchup.katchupserver.api.auth.dto.response.AuthTokenGetResponseDto;
import site.katchup.katchupserver.api.auth.service.AuthService;
import site.katchup.katchupserver.common.dto.ApiResponseDto;
import site.katchup.katchupserver.common.response.SuccessStatus;
Expand All @@ -20,9 +20,9 @@ public class AuthController {
private final JwtTokenProvider jwtTokenProvider;

@PostMapping()
public ApiResponseDto<AuthResponseDto> socialLogin(@RequestBody AuthRequestDto authRequestDto) {
public ApiResponseDto<AuthLoginResponseDto> socialLogin(@RequestBody AuthRequestDto authRequestDto) {

AuthResponseDto responseDto = authService.socialLogin(authRequestDto);
AuthLoginResponseDto responseDto = authService.socialLogin(authRequestDto);

// 로그인
if (!responseDto.isNewUser()) {
Expand All @@ -35,7 +35,7 @@ public ApiResponseDto<AuthResponseDto> socialLogin(@RequestBody AuthRequestDto a

@GetMapping("/token")
@ResponseStatus(HttpStatus.OK)
public ApiResponseDto<AuthTokenResponseDto> getNewToken(HttpServletRequest request) {
public ApiResponseDto<AuthTokenGetResponseDto> getNewToken(HttpServletRequest request) {
String accessToken = (String) request.getAttribute("newAccessToken");
String refreshToken = jwtTokenProvider.resolveRefreshToken(request);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package site.katchup.katchupserver.api.auth.dto;
package site.katchup.katchupserver.api.auth.dto.request;

import lombok.Data;
import lombok.NoArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package site.katchup.katchupserver.api.auth.dto;
package site.katchup.katchupserver.api.auth.dto.response;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class AuthResponseDto {
public class AuthLoginResponseDto {

private String nickname;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package site.katchup.katchupserver.api.auth.dto;
package site.katchup.katchupserver.api.auth.dto.response;

import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class AuthTokenResponseDto {
public class AuthTokenGetResponseDto {
private String accessToken;

private String refreshToken;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package site.katchup.katchupserver.api.auth.service;

import site.katchup.katchupserver.api.auth.dto.AuthRequestDto;
import site.katchup.katchupserver.api.auth.dto.AuthResponseDto;
import site.katchup.katchupserver.api.auth.dto.AuthTokenResponseDto;
import site.katchup.katchupserver.api.auth.dto.request.AuthRequestDto;
import site.katchup.katchupserver.api.auth.dto.response.AuthLoginResponseDto;
import site.katchup.katchupserver.api.auth.dto.response.AuthTokenGetResponseDto;

public interface AuthService {
AuthResponseDto socialLogin(AuthRequestDto authRequestDto);
AuthTokenResponseDto getNewToken(String accessToken, String refreshToken);
AuthLoginResponseDto socialLogin(AuthRequestDto authRequestDto);
AuthTokenGetResponseDto getNewToken(String accessToken, String refreshToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Service;
import site.katchup.katchupserver.api.auth.dto.AuthRequestDto;
import site.katchup.katchupserver.api.auth.dto.AuthResponseDto;
import site.katchup.katchupserver.api.auth.dto.AuthTokenResponseDto;
import site.katchup.katchupserver.api.auth.dto.request.AuthRequestDto;
import site.katchup.katchupserver.api.auth.dto.response.AuthLoginResponseDto;
import site.katchup.katchupserver.api.auth.dto.response.AuthTokenGetResponseDto;
import site.katchup.katchupserver.api.auth.dto.GoogleInfoDto;
import site.katchup.katchupserver.api.auth.service.AuthService;
import site.katchup.katchupserver.api.auth.service.GoogleAuthService;
Expand All @@ -26,7 +26,7 @@ public class AuthServiceImpl implements AuthService {
private final MemberRepository memberRepository;

@Override
public AuthResponseDto socialLogin(AuthRequestDto authRequestDto) {
public AuthLoginResponseDto socialLogin(AuthRequestDto authRequestDto) {

GoogleInfoDto googleInfoDto = login(authRequestDto.getAccessToken());

Expand Down Expand Up @@ -59,7 +59,7 @@ public AuthResponseDto socialLogin(AuthRequestDto authRequestDto) {

String nickname = signedMember.getNickname();

return AuthResponseDto.builder()
return AuthLoginResponseDto.builder()
.nickname(nickname)
.accessToken(accessToken)
.refreshToken(refreshToken)
Expand All @@ -68,8 +68,8 @@ public AuthResponseDto socialLogin(AuthRequestDto authRequestDto) {
}

@Override
public AuthTokenResponseDto getNewToken(String accessToken, String refreshToken) {
return AuthTokenResponseDto.builder()
public AuthTokenGetResponseDto getNewToken(String accessToken, String refreshToken) {
return AuthTokenGetResponseDto.builder()
.accessToken(accessToken)
.refreshToken(refreshToken)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import site.katchup.katchupserver.api.card.dto.CardCreateRequestDto;
import site.katchup.katchupserver.api.card.dto.CardDeleteRequestDto;
import site.katchup.katchupserver.api.card.dto.CardGetResponseDto;
import site.katchup.katchupserver.api.card.dto.request.CardCreateRequestDto;
import site.katchup.katchupserver.api.card.dto.request.CardDeleteRequestDto;
import site.katchup.katchupserver.api.card.dto.response.CardGetResponseDto;
import site.katchup.katchupserver.api.card.service.CardService;
import site.katchup.katchupserver.common.dto.ApiResponseDto;
import site.katchup.katchupserver.common.response.SuccessStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package site.katchup.katchupserver.api.card.dto;
package site.katchup.katchupserver.api.card.dto.request;

import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package site.katchup.katchupserver.api.card.dto;
package site.katchup.katchupserver.api.card.dto.request;

import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package site.katchup.katchupserver.api.card.dto;
package site.katchup.katchupserver.api.card.dto.response;


import lombok.AllArgsConstructor;
import lombok.Getter;
import site.katchup.katchupserver.api.keyword.dto.KeywordResponseDto;
import site.katchup.katchupserver.api.screenshot.dto.response.ScreenshotResponseDto;
import site.katchup.katchupserver.api.keyword.dto.response.KeywordGetResponseDto;
import site.katchup.katchupserver.api.screenshot.dto.response.ScreenshotGetResponseDto;

import java.util.List;

Expand All @@ -15,7 +15,7 @@ public class CardGetResponseDto {
private String category;
private String folder;
private String task;
private List<KeywordResponseDto> keywordList;
private List<ScreenshotResponseDto> screenshotList;
private List<FileResponseDto> fileList;
private List<KeywordGetResponseDto> keywordList;
private List<ScreenshotGetResponseDto> screenshotList;
private List<FileGetResponseDto> fileList;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package site.katchup.katchupserver.api.card.dto;
package site.katchup.katchupserver.api.card.dto.response;

import lombok.*;
import site.katchup.katchupserver.api.card.domain.Card;
import site.katchup.katchupserver.api.keyword.dto.KeywordResponseDto;
import site.katchup.katchupserver.api.keyword.dto.response.KeywordGetResponseDto;
import site.katchup.katchupserver.api.task.domain.Task;

import java.util.ArrayList;
Expand All @@ -14,18 +14,18 @@
@NoArgsConstructor(access = PRIVATE)
@AllArgsConstructor
@Builder
public class CardResponseDto {
public class CardListGetResponseDto {
private Long taskId;
private Long cardId;
private Long placementOrder;
private String cardName;
private List<KeywordResponseDto> keywordList = new ArrayList<>();
private List<KeywordGetResponseDto> keywordList = new ArrayList<>();
private String content;
private Boolean existFile;

public static CardResponseDto of (Card card, Task task, List<KeywordResponseDto> keywordList) {
public static CardListGetResponseDto of (Card card, Task task, List<KeywordGetResponseDto> keywordList) {
Boolean existFile = card.getFiles().isEmpty() ? false : true;
return CardResponseDto.builder()
return CardListGetResponseDto.builder()
.cardId(card.getId())
.taskId(task.getId())
.placementOrder(card.getPlacementOrder())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package site.katchup.katchupserver.api.card.dto;
package site.katchup.katchupserver.api.card.dto.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@Getter
@AllArgsConstructor(staticName = "of")
public class FileResponseDto {
public class FileGetResponseDto {
private Long id;
private String name;
private String url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import site.katchup.katchupserver.api.card.dto.CardCreateRequestDto;
import site.katchup.katchupserver.api.card.dto.CardDeleteRequestDto;
import site.katchup.katchupserver.api.card.dto.CardGetResponseDto;
import site.katchup.katchupserver.api.card.dto.CardResponseDto;
import site.katchup.katchupserver.api.card.dto.request.CardCreateRequestDto;
import site.katchup.katchupserver.api.card.dto.request.CardDeleteRequestDto;
import site.katchup.katchupserver.api.card.dto.response.CardGetResponseDto;
import site.katchup.katchupserver.api.card.dto.response.CardListGetResponseDto;

import java.util.List;

@Transactional
public interface CardService {

List<CardResponseDto> getCardList(Long folderId);
List<CardListGetResponseDto> getCardList(Long folderId);
CardGetResponseDto getCard(Long cardId);

void deleteCardList(CardDeleteRequestDto cardDeleteRequestDto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
import org.springframework.web.multipart.MultipartFile;
import site.katchup.katchupserver.api.card.domain.Card;
import site.katchup.katchupserver.api.card.domain.File;
import site.katchup.katchupserver.api.card.dto.*;
import site.katchup.katchupserver.api.card.dto.request.CardCreateRequestDto;
import site.katchup.katchupserver.api.card.dto.request.CardDeleteRequestDto;
import site.katchup.katchupserver.api.card.dto.response.CardGetResponseDto;
import site.katchup.katchupserver.api.card.dto.response.CardListGetResponseDto;
import site.katchup.katchupserver.api.card.dto.response.FileGetResponseDto;
import site.katchup.katchupserver.api.card.repository.CardRepository;
import site.katchup.katchupserver.api.card.repository.FileRepository;
import site.katchup.katchupserver.api.card.service.CardService;
Expand All @@ -16,9 +20,9 @@
import site.katchup.katchupserver.api.common.CardProvider;
import site.katchup.katchupserver.api.folder.domain.Folder;
import site.katchup.katchupserver.api.folder.repository.FolderRepository;
import site.katchup.katchupserver.api.keyword.dto.KeywordResponseDto;
import site.katchup.katchupserver.api.keyword.dto.response.KeywordGetResponseDto;
import site.katchup.katchupserver.api.keyword.repository.CardKeywordRepository;
import site.katchup.katchupserver.api.screenshot.dto.response.ScreenshotResponseDto;
import site.katchup.katchupserver.api.screenshot.dto.response.ScreenshotGetResponseDto;
import site.katchup.katchupserver.api.screenshot.repository.ScreenshotRepository;
import site.katchup.katchupserver.api.task.domain.Task;
import site.katchup.katchupserver.api.task.repository.TaskRepository;
Expand Down Expand Up @@ -58,19 +62,19 @@ public class CardServiceImpl implements CardService {

@Override
@Transactional
public List<CardResponseDto> getCardList(Long folderId) {
public List<CardListGetResponseDto> getCardList(Long folderId) {
return taskRepository.findByFolderId(folderId).stream()
.flatMap(task -> task.getCards().stream())
.collect(Collectors.groupingBy(Card::getTask)) // taskId로 그룹화
.values().stream()
.flatMap(cards -> cards.stream().sorted(Comparator.comparing(Card::getPlacementOrder))) // 그룹 내에서 placementOrder 값으로 정렬
.filter(card -> !card.isDeleted()) // isDeleted가 false인 card 필터링
.map(card -> {
List<KeywordResponseDto> keywords = cardKeywordRepository.findByCardId(card.getId()).stream()
.map(cardKeyword -> KeywordResponseDto.of(cardKeyword.getKeyword()))
List<KeywordGetResponseDto> keywords = cardKeywordRepository.findByCardId(card.getId()).stream()
.map(cardKeyword -> KeywordGetResponseDto.of(cardKeyword.getKeyword()))
.collect(Collectors.toList());
Task relatedTask = card.getTask(); // Card와 연관된 Task 가져오기
return CardResponseDto.of(card, relatedTask, keywords);
return CardListGetResponseDto.of(card, relatedTask, keywords);
})
.collect(Collectors.toList());
}
Expand Down Expand Up @@ -128,11 +132,11 @@ public CardGetResponseDto getCard(Long cardId) {
Folder folder = getFolderById(card.getTask().getFolder().getId());
Category category = getCategoryById(folder.getCategory().getId());

List<KeywordResponseDto> keywordResponseDtoList = getKeywordDtoList(cardId);
List<FileResponseDto> fileResponseDTOList = getFileDtoList(cardId);
List<ScreenshotResponseDto> screenshotResponseDtoList = getScreenshotDtoList(cardId);
List<KeywordGetResponseDto> keywordResponseDtoList = getKeywordDtoList(cardId);
List<FileGetResponseDto> fileGetResponseDTOList = getFileDtoList(cardId);
List<ScreenshotGetResponseDto> screenshotResponseDtoList = getScreenshotDtoList(cardId);

return CardGetResponseDto.of(card.getId(), category.getName(), folder.getName(), card.getTask().getName(), keywordResponseDtoList, screenshotResponseDtoList, fileResponseDTOList);
return CardGetResponseDto.of(card.getId(), category.getName(), folder.getName(), card.getTask().getName(), keywordResponseDtoList, screenshotResponseDtoList, fileGetResponseDTOList);
}

private Long getPlacementOrder(Task task) {
Expand Down Expand Up @@ -174,22 +178,22 @@ private void validateFileSize(MultipartFile file) {
}
}

private List<KeywordResponseDto> getKeywordDtoList(Long cardId) {
private List<KeywordGetResponseDto> getKeywordDtoList(Long cardId) {
return cardKeywordRepository.findByCardId(cardId)
.stream()
.map(cardKeyword -> KeywordResponseDto.of(cardKeyword.getKeyword().getId(), cardKeyword.getKeyword().getName()))
.map(cardKeyword -> KeywordGetResponseDto.of(cardKeyword.getKeyword().getId(), cardKeyword.getKeyword().getName()))
.collect(Collectors.toList());
}
private List<ScreenshotResponseDto> getScreenshotDtoList(Long cardId) {
private List<ScreenshotGetResponseDto> getScreenshotDtoList(Long cardId) {
return screenshotRepository.findAllByCardId(cardId).stream()
.map(screenshot -> ScreenshotResponseDto
.map(screenshot -> ScreenshotGetResponseDto
.of(screenshot.getId(), screenshot.getStickerOrder(), screenshot.getUrl())
).collect(Collectors.toList());
}

private List<FileResponseDto> getFileDtoList(Long cardId) {
private List<FileGetResponseDto> getFileDtoList(Long cardId) {
return fileRepository.findAllByCardId(cardId).stream()
.map(file -> FileResponseDto.of(file.getId(), file.getName(), file.getUrl(), file.getSize())).collect(Collectors.toList());
.map(file -> FileGetResponseDto.of(file.getId(), file.getName(), file.getUrl(), file.getSize())).collect(Collectors.toList());
}

private Card getCardById(Long cardId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.springframework.web.bind.annotation.*;
import site.katchup.katchupserver.api.category.dto.request.CategoryCreateRequestDto;
import site.katchup.katchupserver.api.category.dto.request.CategoryUpdateRequestDto;
import site.katchup.katchupserver.api.category.dto.response.CategoryResponseDto;
import site.katchup.katchupserver.api.category.dto.response.CategoryGetResponseDto;
import site.katchup.katchupserver.api.category.service.CategoryService;
import site.katchup.katchupserver.common.dto.ApiResponseDto;
import site.katchup.katchupserver.common.response.SuccessStatus;
Expand Down Expand Up @@ -34,7 +34,7 @@ public ApiResponseDto createCategoryName(Principal principal,

@GetMapping()
@ResponseStatus(HttpStatus.OK)
public ApiResponseDto<List<CategoryResponseDto>> getAllCategory(Principal principal) {
public ApiResponseDto<List<CategoryGetResponseDto>> getAllCategory(Principal principal) {
Long memberId = MemberUtil.getMemberId(principal);
return ApiResponseDto.success(SuccessStatus.READ_ALL_CATEGORY_SUCCESS, categoryService.getAllCategory(memberId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
@Getter
@NoArgsConstructor(access = PRIVATE)
@AllArgsConstructor
public class CategoryResponseDto {
public class CategoryGetResponseDto {

private Long categoryId;
private String name;
private Boolean isShared;

public static CategoryResponseDto of(Long categoryId, String name, boolean isShared) {
return new CategoryResponseDto(categoryId, name, isShared);
public static CategoryGetResponseDto of(Long categoryId, String name, boolean isShared) {
return new CategoryGetResponseDto(categoryId, name, isShared);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import site.katchup.katchupserver.api.category.dto.request.CategoryCreateRequestDto;
import site.katchup.katchupserver.api.category.dto.request.CategoryUpdateRequestDto;
import site.katchup.katchupserver.api.category.dto.response.CategoryResponseDto;
import site.katchup.katchupserver.api.category.dto.response.CategoryGetResponseDto;

import java.util.List;

Expand All @@ -11,7 +11,7 @@ public interface CategoryService {
void createCategoryName(Long memberId, CategoryCreateRequestDto categoryCreateRequestDto);

//* 대분류 카테고리 전체 목록 조회
List<CategoryResponseDto> getAllCategory(Long memberId);
List<CategoryGetResponseDto> getAllCategory(Long memberId);

//* 대분류명 수정
void updateCategoryName(Long memberId, Long categoryId, CategoryUpdateRequestDto categoryUpdateRequestDto);
Expand Down
Loading

0 comments on commit 00570c4

Please sign in to comment.