Skip to content

Commit

Permalink
Merge pull request #20 from dnd-side-project/feat/feed
Browse files Browse the repository at this point in the history
Feat/feed
  • Loading branch information
haeyonghahn committed Aug 24, 2023
2 parents 6ed8526 + dcbad41 commit 5f5dbcc
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
import org.springframework.data.domain.Pageable;

import com.dnd.gooding.domain.feed.model.Feed;
import com.dnd.gooding.domain.onboarding.model.QOnboarding;
import com.dnd.gooding.domain.record.model.Record;
import com.dnd.gooding.global.common.model.InterestType;
import com.dnd.gooding.global.common.repository.Querydsl4RepositorySupport;
import com.querydsl.core.types.dsl.BooleanExpression;
import org.springframework.util.ObjectUtils;

public class FeedRepositoryImpl extends Querydsl4RepositorySupport implements FeedRepositoryCustom {

Expand Down Expand Up @@ -49,6 +49,9 @@ private BooleanExpression userIdNotEquals(Long userId) {
}

private BooleanExpression interestTypeEquals(List<InterestType> interestCodes) {
return onboarding.interestType.in(interestCodes);
if(ObjectUtils.isEmpty(interestCodes)) {
return null;
}
return record.interestType.in(interestCodes);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.dnd.gooding.domain.feed.service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import com.dnd.gooding.domain.record.model.RecordOpenStatus;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import com.dnd.gooding.domain.feed.dto.response.FeedResponse;
import com.dnd.gooding.domain.feed.repository.FeedRepository;
Expand All @@ -23,10 +26,22 @@ public class FeedServiceImpl implements FeedService {

private final FeedRepository feedRepository;

/**
* 로그인한 사용자의 관심사 기반으로 피드를 기록 등록된 순으로 보여주고
* 관심사로 등록된 피드가 없다면 기록 등록된 랜덤 피드 순으로 보여준다.
* @param userId
* @param interestCodes
* @param pageable
* @return
*/
@Override
public Page<FeedResponse> findByRecordByInterestCodeAndIsNotUserId(Long userId, List<InterestType> interestCodes, Pageable pageable) {
Page<Record> records = feedRepository.findByRecordByInterestCodeAndIsNotUserId(userId, interestCodes, pageable);
if (ObjectUtils.isEmpty(records.getContent())) {
records = feedRepository.findByRecordByInterestCodeAndIsNotUserId(userId, new ArrayList<InterestType>(), pageable);
}
return new PageImpl<>(records.stream()
.filter(record -> RecordOpenStatus.PUBLIC.name().equals(record.getRecordOpen().name()))
.map(FeedResponse::new)
.collect(Collectors.toList()),
pageable, records.getTotalElements());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public class Record extends BaseEntity {
@Column(name = "thumbnail_url")
private String thumbnailUrl;

@Enumerated
@Column(name = "interest_type")
@Convert(converter = InterestConverter.class)
private InterestType interestType;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ spring:
database: mysql
database-platform: org.hibernate.dialect.MySQL8Dialect
hibernate:
ddl-auto: create
ddl-auto: none
properties:
hibernate:
format_sql: true
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!-- 로그 파일이 저장될 경로 -->
<property name="LOG_PATH" value="log"/>
<!-- 로그 파일 이름 -->
<property name="LOG_FILE_NAME" value="wrsungRestApi"/>
<property name="LOG_FILE_NAME" value="was"/>
<!-- 로그 출력 패턴 -->
<property name="LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] [%logger{40}] - %msg%n"/>
<!-- 로그 레벨 -->
Expand Down

0 comments on commit 5f5dbcc

Please sign in to comment.