Skip to content

Commit

Permalink
[FIX] 코드 리뷰 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
yeseul106 committed Aug 17, 2023
1 parent 4f2027c commit 60af279
Show file tree
Hide file tree
Showing 25 changed files with 52 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import site.katchup.katchupserver.api.auth.dto.response.AuthTokenGetResponseDto;

public interface AuthService {

AuthLoginResponseDto socialLogin(AuthRequestDto authRequestDto);
AuthTokenGetResponseDto getNewToken(String accessToken, String refreshToken);

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public class Card extends BaseEntity {
@Column(length = 200)
private String note;

@Column(name = "is_deleted", nullable = false)
private Boolean isDeleted;
@Column(name = "is_deleted")
private boolean isDeleted;

@Column(name = "deleted_at")
private LocalDateTime deletedAt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ default Card findByIdOrThrow(Long cardId) {
() -> new NotFoundException(ErrorCode.NOT_FOUND_CARD)
);

if (card.getIsDeleted()) {
if (card.isDeleted()) {
throw new NotFoundException(ErrorCode.DELETED_CARD);
}
return card;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ public interface CardService {

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

void deleteCardList(CardDeleteRequestDto cardDeleteRequestDto);

void createCard(List<MultipartFile> fileList, CardCreateRequestDto cardCreateRequestDto);


}
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ public class CardServiceImpl implements CardService {
private static final long MB = 1024 * 1024;

@Override
@Transactional
@Transactional(readOnly = true)
public List<CardListGetResponseDto> getCardList(Long taskId) {
return subTaskRepository.findByTaskId(taskId).stream()
return subTaskRepository.findAllByTaskId(taskId).stream()
.flatMap(subTask -> subTask.getCards().stream())
.collect(Collectors.groupingBy(Card::getSubTask)) // subTaskId 그룹화
.values().stream()
.flatMap(cards -> cards.stream().sorted(Comparator.comparing(Card::getPlacementOrder))) // 그룹 내에서 placementOrder 값으로 정렬
.filter(card -> !card.getIsDeleted()) // isDeleted가 false인 card 필터링
.filter(card -> !card.isDeleted()) // isDeleted가 false인 card 필터링
.map(card -> {
List<KeywordGetResponseDto> keywords = cardKeywordRepository.findByCardId(card.getId()).stream()
List<KeywordGetResponseDto> keywords = cardKeywordRepository.findAllByCardId(card.getId()).stream()
.map(cardKeyword -> KeywordGetResponseDto.of(cardKeyword.getKeyword()))
.collect(Collectors.toList());
SubTask relatedSubTask = card.getSubTask(); // Card와 연관된 SubTask 가져오기
Expand Down Expand Up @@ -133,6 +133,7 @@ public void createCard(List<MultipartFile> fileList, CardCreateRequestDto reques
}

@Override
@Transactional(readOnly = true)
public CardGetResponseDto getCard(Long cardId) {
Card card = cardRepository.findByIdOrThrow(cardId);
Task task = taskRepository.findByIdOrThrow(card.getSubTask().getTask().getId());
Expand Down Expand Up @@ -185,8 +186,7 @@ private void validateFileSize(MultipartFile file) {
}

private List<KeywordGetResponseDto> getKeywordDtoList(Long cardId) {
return cardKeywordRepository.findByCardId(cardId)
.stream()
return cardKeywordRepository.findAllByCardId(cardId).stream()
.map(cardKeyword -> KeywordGetResponseDto.of(cardKeyword.getKeyword().getId(),
cardKeyword.getKeyword().getName(), cardKeyword.getKeyword().getColor()))
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ public class Category extends BaseEntity {
@JoinColumn(name = "member_id")
private Member member;

@Column(name = "is_deleted")
private boolean isDeleted;

@Column(name = "deleted_at")
private LocalDateTime deletedAt;

@OneToMany(mappedBy = "category", cascade = ALL)
Expand All @@ -48,6 +50,7 @@ public Category(String name, boolean isShared, Member member) {
this.name = name;
this.isShared = isShared;
this.member = member;
this.isDeleted = false;
}

public void deleted() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.List;

public interface CategoryRepository extends JpaRepository<Category, Long> {
List<Category> findByMemberId(Long memberId);
List<Category> findAllByMemberId(Long memberId);

boolean existsByMemberIdAndName(Long memberId, String name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@
public interface CategoryService {

void createCategoryName(Long memberId, CategoryCreateRequestDto categoryCreateRequestDto);

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

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

void deleteCategory(Long categoryId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public void createCategoryName(Long memberId, CategoryCreateRequestDto requestDt
}

@Override
@Transactional
@Transactional(readOnly = true)
public List<CategoryGetResponseDto> getAllCategory(Long memberId) {
return categoryRepository.findByMemberId(memberId).stream()
return categoryRepository.findAllByMemberId(memberId).stream()
.map(category -> CategoryGetResponseDto.of(category.getId(), category.getName(), category.isShared()))
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
import java.util.List;

public interface CardKeywordRepository extends JpaRepository<CardKeyword, Long> {
List<CardKeyword> findByCardId(Long cardId);
List<CardKeyword> findAllByCardId(Long cardId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.List;

public interface KeywordService {

List<KeywordGetResponseDto> getAllKeyword(Long cardId);
void createKeyword(KeywordCreateRequestDto requestDto);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
@Service
@RequiredArgsConstructor
public class KeywordServiceImpl implements KeywordService {
private final CardKeywordRepository cardKeywordRepository;
private final KeywordRepository keywordRepository;

@Override
@Transactional
@Transactional(readOnly = true)
public List<KeywordGetResponseDto> getAllKeyword(Long taskId) {
return keywordRepository.findAllByTaskId(taskId).stream()
.map(KeywordGetResponseDto::of)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
public interface MemberRepository extends JpaRepository<Member, Long> {
Optional<Member> findByEmail(String email);
boolean existsByEmail(String email);
Optional<Object> findByIdAndRefreshToken(Long memberId, String refreshToken);

boolean existsByIdAndRefreshToken(Long id, String refreshToken);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package site.katchup.katchupserver.api.member.service.Impl;

import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import site.katchup.katchupserver.api.member.domain.Member;
import site.katchup.katchupserver.api.member.dto.MemberProfileGetResponseDto;
import site.katchup.katchupserver.api.member.repository.MemberRepository;
import site.katchup.katchupserver.api.member.service.MemberService;

@Service
@RequiredArgsConstructor
@Transactional
public class MemberServiceImpl implements MemberService {
private final MemberRepository memberRepository;

@Override
@Transactional(readOnly = true)
public MemberProfileGetResponseDto getMemberProfile(Long memberId) {
Member member = memberRepository.findByIdOrThrow(memberId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
import site.katchup.katchupserver.api.member.dto.MemberProfileGetResponseDto;

public interface MemberService {

MemberProfileGetResponseDto getMemberProfile(Long memberId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public ApiResponseDto<ScreenshotUploadResponseDto> uploadScreenshot(
public ApiResponseDto deleteScreenshot(
Principal principal, @PathVariable Long cardId, @PathVariable String screenshotId
) {
screenshotService.delete(cardId, screenshotId);
screenshotService.deleteScreenshot(cardId, screenshotId);
return success();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
public interface ScreenshotService {

ScreenshotUploadResponseDto uploadScreenshot(MultipartFile file, Long cardId);

public void delete(Long cardId, String screenshotId);
void deleteScreenshot(Long cardId, String screenshotId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public ScreenshotUploadResponseDto uploadScreenshot(MultipartFile file, Long car

@Override
@Transactional
public void delete(Long cardId, String screenshotId) {
public void deleteScreenshot(Long cardId, String screenshotId) {
screenshotRepository.deleteById(UUID.fromString(screenshotId));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ public class SubTask extends BaseEntity {
private String name;

@ManyToOne(fetch = LAZY)
@JoinColumn(name = "task_id")
@JoinColumn(name = "task_id", nullable = false)
private Task task;

@Column(name = "is_deleted")
private boolean isDeleted;

@Column(name = "deleted_at")
private LocalDateTime deletedAt;

@OneToMany(mappedBy = "subTask", cascade = ALL)
Expand All @@ -45,6 +47,7 @@ public SubTask(String name, Task task) {
this.name = name;
this.task = task;
this.task.addSubTask(this);
this.isDeleted = false;
}

public void deleted() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@Repository
public interface SubTaskRepository extends JpaRepository<SubTask, Long> {
List<SubTask> findByTaskId(Long taskId);
List<SubTask> findAllByTaskId(Long taskId);

default SubTask findByIdOrThrow(Long subTaskId) {
return findById(subTaskId).orElseThrow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public class SubTaskServiceImpl implements SubTaskService {
private final SubTaskRepository subTaskRepository;

@Override
@Transactional
@Transactional(readOnly = true)
public List<SubTaskGetResponseDto> getAllSubTask(Long taskId) {

return subTaskRepository.findByTaskId(taskId).stream()
return subTaskRepository.findAllByTaskId(taskId).stream()
.map(subTask -> SubTaskGetResponseDto.of(subTask.getId(), subTask.getName()))
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.util.List;

public interface SubTaskService {

List<SubTaskGetResponseDto> getAllSubTask(Long taskId);
void createSubTask(SubTaskCreateRequestDto requestDto);

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public class Task extends BaseEntity {
@Column(nullable = false)
private String name;

@Column(nullable = false)
@Column(name = "is_deleted")
private boolean isDeleted;

@Column
@Column(name = "deleted_at")
private LocalDateTime deletedAt;

@ManyToOne(fetch = LAZY)
Expand All @@ -43,12 +43,11 @@ public class Task extends BaseEntity {
private List<SubTask> subTasks = new ArrayList<>();

@Builder
public Task(String name, boolean isDeleted, LocalDateTime deletedAt, Category category) {
public Task(String name, Category category) {
this.name = name;
this.isDeleted = isDeleted;
this.deletedAt = deletedAt;
this.category = category;
this.category.addTask(this);
this.isDeleted = false;
}

public void deleted() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ public class TaskServiceImpl implements TaskService {
private final CategoryRepository categoryRepository;

@Override
@Transactional
@Transactional(readOnly = true)
public List<TaskGetResponseDto> getAllTask(Long memberId) {
return categoryRepository.findByMemberId(memberId).stream()
return categoryRepository.findAllByMemberId(memberId).stream()
.flatMap(category -> taskRepository.findByCategoryId(category.getId()).stream())
.map(task -> TaskGetResponseDto.of(task.getId(), task.getName()))
.collect(Collectors.toList());
}

@Override
@Transactional
@Transactional(readOnly = true)
public List<TaskGetResponseDto> getByCategoryId(Long categoryId) {
return taskRepository.findByCategoryId(categoryId).stream()
.map(task -> TaskGetResponseDto.of(task.getId(), task.getName()))
Expand All @@ -63,22 +63,23 @@ public void createTaskName(TaskCreateRequestDto requestDto) {
taskRepository.save(Task.builder()
.name(requestDto.getName())
.category(findCategory)
.isDeleted(false)
.build());
}

private void checkDuplicateTaskName(Long categoryId, String name) {
if (taskRepository.existsByCategoryIdAndName(categoryId, name))
throw new BadRequestException(ErrorCode.DUPLICATE_TASK_NAME);
}

@Override
@Transactional
public void deleteTask(Long taskId) {
Task findTask = taskRepository.findByIdOrThrow(taskId);

findTask.deleted();
findTask.getSubTasks().forEach(this::deleteSubTaskAndCard);
}

private void checkDuplicateTaskName(Long categoryId, String name) {
if (taskRepository.existsByCategoryIdAndName(categoryId, name))
throw new BadRequestException(ErrorCode.DUPLICATE_TASK_NAME);
}

private void deleteSubTaskAndCard(SubTask subTask) {
subTask.deleted();
subTask.getCards().stream().forEach(Card::deletedCard);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@

public interface TaskService {

//* 업무 전체 목록 조회
List<TaskGetResponseDto> getAllTask(Long memberId);

//* 특정 카테고리 내 업무 목록 조회
List<TaskGetResponseDto> getByCategoryId(Long categoryId);

//* 업무 수정
void updateTaskName(Long taskId, TaskUpdateRequestDto taskUpdateRequestDto);

void createTaskName(TaskCreateRequestDto taskCreateRequestDto);
void deleteTask(Long taskId);

}

0 comments on commit 60af279

Please sign in to comment.