Skip to content

Commit

Permalink
Merge pull request #48 from Central-MakeUs/dev
Browse files Browse the repository at this point in the history
[CI/CD] dev 브랜치 최신화 반영하여 배포
  • Loading branch information
dainnida authored Jan 28, 2025
2 parents c4f7847 + 4aabb18 commit 18c89a1
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.cmc.mercury.domain.book.controller;

import com.cmc.mercury.domain.book.dto.BookExistResponse;
import com.cmc.mercury.domain.book.dto.BookSearchRequest;
import com.cmc.mercury.domain.book.dto.BookSearchResponse;
import com.cmc.mercury.domain.book.service.BookService;
import com.cmc.mercury.global.response.SuccessResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

@RestController
@RequestMapping("/books")
@RequiredArgsConstructor
@Tag(name = "BookController", description = "도서 검색 관련 API")
public class BookController {

private final BookService bookService;

@GetMapping("/search")
@Operation(summary = "도서 검색", description = "검색어를 통해 도서 목록을 정렬하여 반환합니다.")
public Mono<SuccessResponse<BookSearchResponse>> searchBooks(
@ModelAttribute @Valid BookSearchRequest request) {
return bookService.searchBooks(request)
.map(SuccessResponse::ok);
}

@GetMapping("/exist")
@Operation(summary = "기록 중복 생성 검사",
description = "isbn을 통해 해당 도서에 대한 기록을 생성한 적이 있는지의 여부를 반환합니다.")
public SuccessResponse<BookExistResponse> existBooks(
@RequestParam("userId") Long testUserId,
@RequestParam String isbn13
) {
return SuccessResponse.ok(bookService.existBooks(testUserId, isbn13));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.cmc.mercury.domain.book.dto;

import io.swagger.v3.oas.annotations.media.Schema;

@Schema(description = "선택된 도서의 기록이 존재하는지 여부 응답 형식")
public record BookExistResponse(

@Schema(description = "중복 등록 여부")
boolean isRegistered,

@Schema(description = "독서 기록이 존재할 때만 값 반환, 존재하지 않으면 null 반환")
Long recordId
) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
public interface BookRepository extends JpaRepository<Book, Long> {

Optional<Book> findByIsbn13(String isbn13);

boolean existsByIsbn13(String isbn13);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.cmc.mercury.domain.book.service;

import com.cmc.mercury.domain.book.dto.BookExistResponse;
import com.cmc.mercury.domain.book.dto.BookSearchRequest;
import com.cmc.mercury.domain.book.dto.BookSearchResponse;
import com.cmc.mercury.domain.book.repository.BookRepository;
import com.cmc.mercury.domain.record.entity.Record;
import com.cmc.mercury.domain.record.repository.RecordRepository;
import com.cmc.mercury.global.exception.CustomException;
import com.cmc.mercury.global.exception.ErrorCode;
import lombok.RequiredArgsConstructor;
Expand All @@ -13,10 +17,15 @@
import org.springframework.web.util.UriComponentsBuilder;
import reactor.core.publisher.Mono;

import java.util.Optional;

@Service
@RequiredArgsConstructor
@Slf4j
public class BookSearchService {
public class BookService {

private final BookRepository bookRepository;
private final RecordRepository recordRepository;

@Value("${aladin.api.url}")
private String aladinUrl;
Expand Down Expand Up @@ -81,4 +90,21 @@ private String buildSearchUrl(BookSearchRequest request) {
// log.info("Built API request URL: {}", url);
return url;
}

public BookExistResponse existBooks(Long testUserId, String isbn13) {

// Book 존재 여부부터 확인
if (!bookRepository.existsByIsbn13(isbn13)) {
return new BookExistResponse(false, null);
}

// 사용자에게 독서 기록 존재 여부 확인
Optional<Record> record = recordRepository.findByUser_TestUserIdAndBook_Isbn13(testUserId, isbn13);

if (record.isEmpty()) {
return new BookExistResponse(false, null);
}

return new BookExistResponse(true, record.get().getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ List<Record> searchRecordsByTitleOrMemoContent(
@Param("testUserId") Long testUserId,
@Param("keyword") String keyword,
@Param("sortType") String sortType);

Optional<Record> findByUser_TestUserIdAndBook_Isbn13(Long testUserId, String isbn13);
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public RecordResponse createRecord(Long testUserId, RecordRequest request) {

User user = userTestService.getOrCreateTestUser(testUserId);
// 저장되지 않은 도서면 저장
// 유저가 해당 도서에 대한 기록을 남긴 적이 있는지 검사해야 하나? -> api만 잘 연결하면 될 듯
Book book = bookRepository.findByIsbn13(request.book().isbn13())
.orElseGet(() -> {
try {
Expand Down

0 comments on commit 18c89a1

Please sign in to comment.