-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from LIKELION-TEAM4-HACKATHON/feature/culture-…
…detail 전체 문화 간단 조회 기능 추가
- Loading branch information
Showing
8 changed files
with
119 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/likelion/MZConnent/dto/culture/response/CulturesSimpleResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package likelion.MZConnent.dto.culture.response; | ||
|
||
import likelion.MZConnent.domain.culture.Culture; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class CulturesSimpleResponse { | ||
private Long cultureId; | ||
private String name; | ||
private String summary; | ||
private String cultureImageUrl; | ||
private String cultureCategoryName; | ||
private String regionName; | ||
private int interestCount; | ||
private int clubCount; | ||
|
||
@Builder | ||
public CulturesSimpleResponse(Culture culture) { | ||
this.cultureId = culture.getCultureId(); | ||
this.name = culture.getName(); | ||
this.summary = culture.getSummary(); | ||
this.cultureImageUrl = culture.getCultureImageUrl(); | ||
this.cultureCategoryName = culture.getCultureCategory().getName(); | ||
this.regionName = culture.getRegion().getName(); | ||
this.interestCount = culture.getInterestCount(); | ||
this.clubCount = culture.getClubCount(); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/likelion/MZConnent/repository/culture/CultureRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
package likelion.MZConnent.repository.culture; | ||
|
||
import io.lettuce.core.dynamic.annotation.Param; | ||
import likelion.MZConnent.domain.culture.Culture; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface CultureRepository extends JpaRepository<Culture, Long> { | ||
@Query("SELECT c FROM Culture c WHERE :category = 0 OR c.cultureCategory.id = :category") | ||
Page<Culture> findAllByCultureCategory(@Param("category") Long category, Pageable pageable); | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/likelion/MZConnent/service/culture/CultureService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package likelion.MZConnent.service.culture; | ||
|
||
import likelion.MZConnent.domain.culture.Culture; | ||
import likelion.MZConnent.domain.review.Review; | ||
import likelion.MZConnent.dto.culture.response.CulturesSimpleResponse; | ||
import likelion.MZConnent.dto.paging.response.PageContentResponse; | ||
import likelion.MZConnent.dto.review.response.ReviewsSimpleResponse; | ||
import likelion.MZConnent.repository.culture.CultureRepository; | ||
import likelion.MZConnent.repository.review.ReviewRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class CultureService { | ||
private final CultureRepository cultureRepository; | ||
private final int PAGE_SIZE = 6; | ||
|
||
public PageContentResponse<CulturesSimpleResponse> getCulturesSimpleList(Long cultureCategoryId, int page) { | ||
Pageable pageable = PageRequest.of(page, PAGE_SIZE); | ||
|
||
Page<Culture> cultures = cultureRepository.findAllByCultureCategory(cultureCategoryId, pageable); | ||
|
||
List<CulturesSimpleResponse> cultureResponse = cultures.stream().map(culture -> CulturesSimpleResponse.builder() | ||
.culture(culture).build() | ||
).collect(Collectors.toList()); | ||
|
||
return PageContentResponse.<CulturesSimpleResponse>builder() | ||
.content(cultureResponse) | ||
.totalPages(cultures.getTotalPages()) | ||
.totalElements(cultures.getTotalElements()) | ||
.size(pageable.getPageSize()) | ||
.build(); | ||
|
||
} | ||
} |