Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REFACTOR] CardProvider 제거 #99

Merged
merged 2 commits into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import site.katchup.katchupserver.api.card.domain.Card;
import site.katchup.katchupserver.common.exception.NotFoundException;
import site.katchup.katchupserver.common.response.ErrorStatus;

import java.util.List;

@Repository
public interface CardRepository extends JpaRepository<Card, Long> {
List<Card> findByTaskId(Long taskId);

default Card findByIdOrThrow(Long id) {
return findById(id).orElseThrow(() -> new NotFoundException(ErrorStatus.NOT_FOUND_CARD));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import site.katchup.katchupserver.api.card.repository.CardRepository;
import site.katchup.katchupserver.api.common.CardProvider;
import site.katchup.katchupserver.api.keyword.domain.Keyword;
import site.katchup.katchupserver.api.keyword.domain.CardKeyword;
Expand All @@ -19,14 +20,14 @@
public class KeywordServiceImpl implements KeywordService {
private final CardKeywordRepository taskKeywordRepository;
private final KeywordRepository keywordRepository;
private final CardProvider cardProvider;
private final CardRepository cardRepository;

@Override
public List<KeywordGetResponseDto> getAllKeyword(Long cardId) {

return taskKeywordRepository.findByCardId(cardId).stream()
.flatMap(taskKeyword -> keywordRepository.findById(taskKeyword.getKeyword().getId()).stream())
.map(keyword -> KeywordGetResponseDto.of(keyword))
.map(KeywordGetResponseDto::of)
.collect(Collectors.toList());
}

Expand All @@ -40,7 +41,7 @@ public void createKeyword(Long cardId, KeywordCreateRequestDto requestDto) {
keywordRepository.save(keyword);

CardKeyword taskKeyword = CardKeyword.builder()
.card(cardProvider.getCardById(cardId))
.card(cardRepository.findByIdOrThrow(cardId))
.keyword(keyword)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import site.katchup.katchupserver.api.card.domain.Card;
import site.katchup.katchupserver.api.card.repository.CardRepository;
import site.katchup.katchupserver.api.common.CardProvider;
import site.katchup.katchupserver.api.screenshot.domain.Screenshot;
import site.katchup.katchupserver.api.screenshot.dto.response.ScreenshotUploadResponseDto;
Expand Down Expand Up @@ -36,7 +37,7 @@ public class ScreenshotServiceImpl implements ScreenshotService {

private final ScreenshotRepository screenshotRepository;

private final CardProvider cardProvider;
private final CardRepository cardRepository;

@Override
@Transactional
Expand All @@ -48,11 +49,11 @@ public ScreenshotUploadResponseDto uploadScreenshot(MultipartFile file, Long car

try {
String uploadImageUrl = s3Util.upload(getInputStream(file), uploadFileName, getObjectMetadata(file));
Card card = cardProvider.getCardById(cardId);
Card card = cardRepository.findByIdOrThrow(cardId);
Screenshot screenshot = Screenshot.builder()
.id(UUID.fromString(imageId))
.url(uploadImageUrl)
.card(cardProvider.getCardById(cardId))
.card(card)
.build();

screenshotRepository.save(screenshot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import site.katchup.katchupserver.api.card.domain.Card;
import site.katchup.katchupserver.api.folder.domain.Folder;
import site.katchup.katchupserver.common.domain.BaseEntity;

import java.util.ArrayList;
import java.util.List;

import static jakarta.persistence.CascadeType.ALL;
import static jakarta.persistence.FetchType.LAZY;
import static jakarta.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PROTECTED;
Expand Down
Loading