Skip to content
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 @@ -19,9 +19,9 @@ public interface FairytaleRepository extends JpaRepository<Fairytale, Long> {
countQuery = "SELECT COUNT(f) FROM Fairytale f WHERE f.user.id = :userId AND f.background IN :backgrounds")
Page<Fairytale> findByUserIdAndBackgroundIn(@Param("userId") Long userId, @Param("backgrounds") List<Background> backgrounds, Pageable pageable);

@Query(value = "SELECT f FROM Fairytale f JOIN FETCH f.user WHERE f.user.id <> :userId AND f.background IN :backgrounds",
countQuery = "SELECT COUNT(f) FROM Fairytale f WHERE f.user.id <> :userId AND f.background IN :backgrounds")
Page<Fairytale> findByUserIdNotAndBackgroundIn(@Param("userId") Long userId, @Param("backgrounds") List<Background> backgrounds, Pageable pageable);
@Query(value = "SELECT f FROM Fairytale f JOIN FETCH f.user WHERE f.user.id <> :userId ORDER BY f.createdAt DESC",
countQuery = "SELECT COUNT(f) FROM Fairytale f WHERE f.user.id <> :userId")
Page<Fairytale> findSharedFairytales(@Param("userId") Long userId, Pageable pageable);

@Query("SELECT f FROM Fairytale f JOIN FETCH f.user WHERE f.id = :id")
Optional<Fairytale> findByIdWithUser(@Param("id") Long id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public interface FairytaleService {

Page<FairytaleListRes> getMyFairytales(Long userId, Island island, Pageable pageable);

Page<FairytaleListRes> getSharedFairytales(Long userId, Island island, Pageable pageable);
Page<FairytaleListRes> getSharedFairytales(Long userId, Pageable pageable);

FairytaleDetailRes getFairytaleDetail(Long fairytaleId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.capstone.kkumteul.domain.fairytale.web.dto.FairytaleDetailRes;
import com.capstone.kkumteul.domain.fairytale.web.dto.FairytaleListRes;
import com.capstone.kkumteul.domain.fairytale.web.dto.ParagraphRes;
import com.capstone.kkumteul.domain.vocab.repository.WordEntryRepository;
import com.capstone.kkumteul.domain.vocab.web.dto.WordEntryRes;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand All @@ -23,6 +25,7 @@ public class FairytaleServiceImpl implements FairytaleService {

private final FairytaleRepository fairytaleRepository;
private final ParagraphRepository paragraphRepository;
private final WordEntryRepository wordEntryRepository;

@Override
public Page<FairytaleListRes> getMyFairytales(Long userId, Island island, Pageable pageable) {
Expand All @@ -31,8 +34,8 @@ public Page<FairytaleListRes> getMyFairytales(Long userId, Island island, Pageab
}

@Override
public Page<FairytaleListRes> getSharedFairytales(Long userId, Island island, Pageable pageable) {
return fairytaleRepository.findByUserIdNotAndBackgroundIn(userId, island.getBackgrounds(), pageable)
public Page<FairytaleListRes> getSharedFairytales(Long userId, Pageable pageable) {
return fairytaleRepository.findSharedFairytales(userId, pageable)
.map(FairytaleListRes::from);
}

Expand All @@ -46,6 +49,9 @@ public FairytaleDetailRes getFairytaleDetail(Long fairytaleId) {
.map(ParagraphRes::from)
.toList();

return FairytaleDetailRes.of(fairytale, paragraphs);
List<WordEntryRes> vocab = WordEntryRes.listOf(
wordEntryRepository.findByFairytaleIdOrderByPageNoAsc(fairytaleId));

return FairytaleDetailRes.of(fairytale, paragraphs, vocab);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ public ResponseEntity<SuccessResponse<Page<FairytaleListRes>>> getMyFairytales(
@GetMapping("/shared")
public ResponseEntity<SuccessResponse<Page<FairytaleListRes>>> getSharedFairytales(
@AuthUser User user,
@RequestParam Island island,
@PageableDefault(size = 6) Pageable pageable
) {
Page<FairytaleListRes> res = fairytaleService.getSharedFairytales(user.getId(), island, pageable);
Page<FairytaleListRes> res = fairytaleService.getSharedFairytales(user.getId(), pageable);
return ResponseEntity.status(HttpStatus.OK).body(SuccessResponse.ok(res));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.capstone.kkumteul.domain.fairytale.web.dto;

import com.capstone.kkumteul.domain.fairytale.entity.Fairytale;
import com.capstone.kkumteul.domain.vocab.web.dto.WordEntryRes;

import java.util.List;

Expand All @@ -11,17 +12,19 @@ public record FairytaleDetailRes(
String morality,
String charSpecies,
String background,
List<ParagraphRes> paragraphs
List<ParagraphRes> paragraphs,
List<WordEntryRes> vocab
) {
public static FairytaleDetailRes of(Fairytale fairytale, List<ParagraphRes> paragraphs) {
public static FairytaleDetailRes of(Fairytale fairytale, List<ParagraphRes> paragraphs, List<WordEntryRes> vocab) {
return new FairytaleDetailRes(
fairytale.getId(),
fairytale.getTitle(),
fairytale.getUser().getUsername(),
fairytale.getMorality().name(),
fairytale.getCharSpecies().name(),
fairytale.getBackground().name(),
paragraphs
paragraphs,
vocab
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
public enum VocabErrorCode implements BaseResponseCode {

PARAGRAPH_NOT_FOUND_FOR_VOCAB("VOCAB_404_1", NOT_FOUND, "해당 페이지의 본문을 찾을 수 없습니다."),
VOCAB_FORBIDDEN("VOCAB_403_1", FORBIDDEN, "본인 동화의 단어장만 조회할 수 있습니다."),
VOCAB_EXTRACT_FAILED("VOCAB_500_1", INTERNAL_SERVER_ERROR, "단어장 추출에 실패했습니다.");

private final String code;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

import com.capstone.kkumteul.domain.kafka.dto.VocabExtractedMessage;
import com.capstone.kkumteul.domain.vocab.service.dto.VocabExtractionResult;
import com.capstone.kkumteul.domain.vocab.web.dto.WordEntryRes;

import java.util.List;

/**
* 단어장 추출/조회 서비스.
* 단어장 추출 서비스. 조회는 동화 상세(FairytaleService)에 포함됨.
*/
public interface VocabService {

Expand All @@ -26,12 +25,4 @@ public interface VocabService {
* word가 null/blank이면 NO_DIFFICULT_WORD 처리. 모든 종착 분기에서 markVocabDone 호출 (SSE guarantee).
*/
VocabExtractionResult processExtractedWord(VocabExtractedMessage message);

/**
* 본인 동화의 누적 단어장 조회. 페이지 번호 오름차순.
*
* @param userId 요청자 (소유권 검증용)
* @param fairytaleId 동화 ID
*/
List<WordEntryRes> getVocab(Long userId, Long fairytaleId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
import com.capstone.kkumteul.domain.fairytale.service.FairytaleCheckService;
import com.capstone.kkumteul.domain.kafka.dto.VocabExtractedMessage;
import com.capstone.kkumteul.domain.vocab.entity.WordEntry;
import com.capstone.kkumteul.domain.vocab.exception.VocabForbiddenException;
import com.capstone.kkumteul.domain.vocab.repository.WordEntryRepository;
import com.capstone.kkumteul.domain.vocab.service.dto.VocabExtractionResult;
import com.capstone.kkumteul.domain.vocab.web.dto.WordEntryRes;
import com.capstone.kkumteul.global.client.VocabExtractClient;
import com.capstone.kkumteul.global.client.dto.VocabExtractResponse;
import lombok.RequiredArgsConstructor;
Expand All @@ -19,7 +17,6 @@
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

@Slf4j
Expand Down Expand Up @@ -133,18 +130,4 @@ public VocabExtractionResult processExtractedWord(VocabExtractedMessage message)
}
}

/**
* 본인 동화 누적 단어장 조회.
* 동화 소유권 검증 후 페이지 순서로 반환.
*/
@Override
public List<WordEntryRes> getVocab(Long userId, Long fairytaleId) {
Fairytale fairytale = fairytaleRepository.findById(fairytaleId)
.orElseThrow(FairytaleNotFoundException::new);
Objects.requireNonNull(fairytale.getUser(), "Fairytale.user는 null이 될 수 없음");
if (!fairytale.getUser().getId().equals(userId)) {
throw new VocabForbiddenException();
}
return WordEntryRes.listOf(wordEntryRepository.findByFairytaleIdOrderByPageNoAsc(fairytaleId));
}
}

This file was deleted.

6 changes: 0 additions & 6 deletions src/main/resources/application-dev.properties

This file was deleted.

Loading