Skip to content

Commit

Permalink
Merge pull request #62 from kookmin-sw/BE_Feature/#13-club
Browse files Browse the repository at this point in the history
#13: feat: 대표책으로 모임 검색
  • Loading branch information
wjdwlghks authored May 10, 2024
2 parents e2f17dc + 50b59b5 commit ac9ae7c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import org.springframework.data.jpa.repository.JpaRepository;

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

public interface BookRepository extends JpaRepository<Book, Long> {
Optional<Book> findBookById(Long id);
Optional<Book> findBookByIsbn(String isbn);

List<Book> findBooksByTitleContaining(String title);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.project.capstone.book.controller.dto.AddBookRequest;
import com.project.capstone.club.controller.dto.ClubCreateRequest;
import com.project.capstone.club.controller.dto.ClubResponse;
import com.project.capstone.club.controller.dto.SimpleClubResponse;
import com.project.capstone.club.service.ClubService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -79,4 +80,11 @@ public ResponseEntity<?> setBook(@AuthenticationPrincipal PrincipalDetails detai
clubService.setBook(details.getUserId(), request, clubId);
return ResponseEntity.ok().body("선정 완료");
}

// 대표책으로 모임 조회
@GetMapping("/search/book")
public ResponseEntity<List<SimpleClubResponse>> getClubByBookName(@RequestParam String title) {
List<SimpleClubResponse> clubResponseList = clubService.getClubByBookTitle(title);
return ResponseEntity.ok().body(clubResponseList);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.project.capstone.club.controller.dto;

import com.project.capstone.club.domain.Club;
import com.project.capstone.club.domain.PublicStatus;

public record SimpleClubResponse(
Long id,
String topic,
String name,
int memberCnt,
int maximum,
PublicStatus publicStatus
// String imageUrl
) {
public SimpleClubResponse(Club club) {
this(club.getId(), club.getTopic(), club.getName(), club.getMembers().size(), club.getMaximum(), club.getPublicStatus());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ public interface ClubRepository extends JpaRepository<Club, Long> {
@Modifying(clearAutomatically = true)
@Query("update Club c set c.book = :book where c.id = :id")
void updateBook(Book book, Long id);

List<Club> findClubsByBook(Book book);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.project.capstone.book.domain.BookRepository;
import com.project.capstone.club.controller.dto.ClubCreateRequest;
import com.project.capstone.club.controller.dto.ClubResponse;
import com.project.capstone.club.controller.dto.SimpleClubResponse;
import com.project.capstone.club.domain.Club;
import com.project.capstone.club.domain.ClubRepository;
import com.project.capstone.club.exception.ClubException;
Expand Down Expand Up @@ -142,4 +143,16 @@ public void setBook(String managerId, AddBookRequest request, Long clubId) {
club.setBook(book);
clubRepository.updateBook(book, clubId);
}

public List<SimpleClubResponse> getClubByBookTitle(String title) {
List<Book> booksContainingTitle = bookRepository.findBooksByTitleContaining(title);
List<SimpleClubResponse> clubResponseList = new ArrayList<>();
for (Book book : booksContainingTitle) {
List<Club> clubList = clubRepository.findClubsByBook(book);
for (Club club : clubList) {
clubResponseList.add(new SimpleClubResponse(club));
}
}
return clubResponseList;
}
}

0 comments on commit ac9ae7c

Please sign in to comment.