Skip to content

Commit

Permalink
Merge pull request #61 from kookmin-sw/BE_Feature/#25-content-and-quiz
Browse files Browse the repository at this point in the history
#25 refactor: 컨텐츠 종류별 조회를 모임별 조회 추가 적용
  • Loading branch information
wjdwlghks authored May 10, 2024
2 parents 52e3a40 + dbc9c43 commit e2f17dc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public ResponseEntity<ContentResponse> getContent(@PathVariable Long id) {

// 컨텐츠 종류별 조회
@GetMapping("/get")
public ResponseEntity<List<ContentResponse>> getContents(@RequestParam String type) {
List<ContentResponse> contentResponseList = contentService.getContents(type);
public ResponseEntity<List<ContentResponse>> getContents(@RequestParam String type, @RequestParam Long clubId) {
List<ContentResponse> contentResponseList = contentService.getContents(type, clubId);
return ResponseEntity.ok().body(contentResponseList);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.project.capstone.content.domain;

import com.project.capstone.club.domain.Club;
import org.springframework.data.jpa.repository.JpaRepository;

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

public interface ContentRepository extends JpaRepository<Content, Long> {
Optional<Content> findContentById(Long id);
List<Content> findContentsByType(ContentType type);
List<Content> findContentsByTypeAndClub(ContentType type, Club club);
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,15 @@ public ContentResponse getContent(Long id) {
return new ContentResponse(content);
}

public List<ContentResponse> getContents(String type) {
public List<ContentResponse> getContents(String type, Long clubId) {
Club club = clubRepository.findClubById(clubId).orElseThrow(
() -> new ClubException(CLUB_NOT_FOUND)
);

for (ContentType contentType : ContentType.values()) {
if (contentType.equals(ContentType.valueOf(type))) {
List<Content> contentsByType = contentRepository.findContentsByType(ContentType.valueOf(type));
return contentsByType.stream()
List<Content> contentsByTypeAndClub = contentRepository.findContentsByTypeAndClub(ContentType.valueOf(type), club);
return contentsByTypeAndClub.stream()
.map(ContentResponse::new)
.toList();
}
Expand Down
7 changes: 1 addition & 6 deletions backend/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ spring:

jpa:
hibernate:
ddl-auto: create
defer-datasource-initialization: true

sql:
init:
mode: always
ddl-auto: update

jwt:
secret: ${JWT_SECRET}

0 comments on commit e2f17dc

Please sign in to comment.