Skip to content

Commit

Permalink
Merge pull request #99 from Katchup-dev/refactor/#98-domain
Browse files Browse the repository at this point in the history
  • Loading branch information
unanchoi authored Aug 12, 2023
2 parents a57039f + df3609f commit cd58938
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
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

0 comments on commit cd58938

Please sign in to comment.