-
Notifications
You must be signed in to change notification settings - Fork 0
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 #124 from MYONGSIK/develop
main <- dev
- Loading branch information
Showing
13 changed files
with
240 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
13 changes: 13 additions & 0 deletions
13
src/main/java/com/example/myongsick/domain/scrap/repository/ScrapRepositoryCustom.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,13 @@ | ||
package com.example.myongsick.domain.scrap.repository; | ||
|
||
import com.example.myongsick.domain.scrap.dto.ScrapCountResponse; | ||
import java.util.Optional; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface ScrapRepositoryCustom { | ||
Page<ScrapCountResponse> findAllByCampusWithPaging(@Param("campus") String campus, Pageable pageable); | ||
|
||
Optional<ScrapCountResponse> findByIdCustom(Long storeId); | ||
} |
73 changes: 73 additions & 0 deletions
73
src/main/java/com/example/myongsick/domain/scrap/repository/ScrapRepositoryImpl.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,73 @@ | ||
package com.example.myongsick.domain.scrap.repository; | ||
|
||
import static com.example.myongsick.domain.scrap.entity.QScrap.scrap; | ||
import static com.example.myongsick.domain.scrap.entity.QStore.store; | ||
|
||
import com.example.myongsick.domain.scrap.dto.QScrapCountResponse; | ||
import com.example.myongsick.domain.scrap.dto.ScrapCountResponse; | ||
import com.example.myongsick.domain.scrap.entity.CampusType; | ||
import com.example.myongsick.domain.scrap.entity.Store; | ||
import com.querydsl.core.types.Order; | ||
import com.querydsl.core.types.OrderSpecifier; | ||
import com.querydsl.core.types.dsl.PathBuilder; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageImpl; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class ScrapRepositoryImpl implements ScrapRepositoryCustom{ | ||
private final JPAQueryFactory jpaQueryFactory; | ||
|
||
@Override | ||
public Page<ScrapCountResponse> findAllByCampusWithPaging(String campus, Pageable pageable) { | ||
List<ScrapCountResponse> result = jpaQueryFactory.select(new QScrapCountResponse(store.id.as("storeId"), store.code, store.name, store.category, store.address, store.contact, store.urlAddress, store.distance, store.latitude, store.longitude, store.scrapList.size().as("scrapCount"))) | ||
.from(store) | ||
.where(store.campus.eq(CampusType.valueOf(campus))) | ||
.groupBy(store.code) | ||
.orderBy(getOrderSpecifier(pageable.getSort()).stream().toArray(OrderSpecifier[]::new)) | ||
.offset(pageable.getOffset()) | ||
.limit(pageable.getPageSize()) | ||
.fetch(); | ||
|
||
Long count = jpaQueryFactory | ||
.select(scrap.count()) | ||
.from(scrap) | ||
.fetchOne(); | ||
|
||
return new PageImpl<>(result, pageable, count); | ||
} | ||
|
||
@Override | ||
public Optional<ScrapCountResponse> findByIdCustom(Long storeId) { | ||
return Optional.ofNullable(jpaQueryFactory.select(new QScrapCountResponse(store.id.as("storeId"), store.code, store.name, store.category, store.address, store.contact, store.urlAddress, store.distance, store.latitude, store.longitude, store.scrapList.size().as("scrapCount"))) | ||
.from(store) | ||
.where(store.id.eq(storeId)) | ||
.fetchOne()); | ||
} | ||
|
||
private List<OrderSpecifier> getOrderSpecifier(Sort sort) { | ||
List<OrderSpecifier> orderSpecifiers = new ArrayList<>(); | ||
sort.stream() | ||
.forEach(order -> { | ||
Order direction = order.isAscending() ? Order.ASC : Order.DESC; | ||
String property = order.getProperty(); | ||
if(property.equals("scrapCount")) { | ||
orderSpecifiers.add(new OrderSpecifier(direction, store.scrapList.size())); | ||
} else if(property.equals("distance")) { | ||
orderSpecifiers.add(new OrderSpecifier(direction, store.distance.castToNum(Long.class))); | ||
} else { | ||
PathBuilder orderByExpression = new PathBuilder(Store.class, "store"); | ||
orderSpecifiers.add(new OrderSpecifier(direction, orderByExpression.get(property))); | ||
} | ||
}); | ||
return orderSpecifiers; | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
src/main/java/com/example/myongsick/global/config/QueryDslConfig.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,19 @@ | ||
package com.example.myongsick.global.config; | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import javax.persistence.EntityManager; | ||
import javax.persistence.PersistenceContext; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class QueryDslConfig { | ||
|
||
@PersistenceContext | ||
private EntityManager em; | ||
|
||
@Bean | ||
public JPAQueryFactory jpaQueryFactory(EntityManager em) { | ||
return new JPAQueryFactory(em); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,4 +55,4 @@ spring: | |
--- | ||
spring: | ||
profiles: | ||
active: local | ||
active: local |
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,59 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration> | ||
<!-- ๋ก๊ทธ ํจํด์ ์์ ์ ์ฉ %clr(pattern){color} | ||
https://logback.qos.ch/manual/layouts.html#coloring | ||
--> | ||
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" /> | ||
|
||
<springProfile name="dev"> | ||
<property resource="application-dev.yml" /> | ||
</springProfile> | ||
|
||
<!-- log ๋ณ์ ๊ฐ ์ค์ --> | ||
<springProperty name="LOG_PATH" source= "log.config.path" /> | ||
<springProperty name="LOG_FILE_NAME" source= "log.config.filename" /> | ||
<springProperty name="LOG_MAX_HISTORY" source= "log.config.maxHistory" /> | ||
<springProperty name="LOG_TOTAL_SIZE_CAP" source= "log.config.totalSizeCap" /> | ||
|
||
<property name="CONSOLE_LOG_PATTERN" | ||
value="[%d{yyyy-MM-dd HH:mm:ss}:%-3relative] %clr(%-5level) %clr(${PID:-}){magenta} %clr(---){faint} %clr([%15.15thread]){faint} %clr(%-40.40logger{36}){cyan} %clr(:){faint} %msg%n"/> | ||
<property name="FILE_LOG_PATTERN" | ||
value="[%d{yyyy-MM-dd HH:mm:ss}:%-3relative] %-5level ${PID:-} --- [%15.15thread] %-40.40logger{36} : %msg%n"/> | ||
|
||
<!-- ์ฝ์(STDOUT) --> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<layout class="ch.qos.logback.classic.PatternLayout"> | ||
<Pattern>${CONSOLE_LOG_PATTERN}</Pattern> | ||
</layout> | ||
</appender> | ||
|
||
<!-- ํ์ผ(FILE) --> | ||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> | ||
<!-- log ๊ธฐ๋กํ ํ์ผ ์์น ์ค์ --> | ||
<file>${LOG_PATH}/${LOG_FILE_NAME}.log</file> | ||
<!-- log ๊ธฐ๋ก ํ์ ์ธ์ฝ๋ฉ --> | ||
<encoder> | ||
<pattern>${FILE_LOG_PATTERN}</pattern> | ||
</encoder> | ||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | ||
<!-- daily rollover --> | ||
<fileNamePattern>${LOG_PATH}/${LOG_FILE_NAME}.%d{yyyy-MM-dd}.log</fileNamePattern> | ||
<maxHistory>${LOG_MAX_HISTORY}</maxHistory> | ||
<totalSizeCap>${LOG_TOTAL_SIZE_CAP}</totalSizeCap> | ||
</rollingPolicy> | ||
</appender> | ||
|
||
<!-- spring profile๋ณ ๋ก๊ทธ ์ค์ --> | ||
<!-- dev ํ๊ฒฝ --> | ||
<springProfile name="dev"> | ||
<root level="info"> | ||
<!-- ์ฐธ์กฐํ appender - STDOUT --> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
<logger name="org.springframework.web" level="debug"> | ||
<!-- ์ฐธ์กฐํ appender - FILE --> | ||
<appender-ref ref="FILE" /> | ||
</logger> | ||
</springProfile> | ||
|
||
</configuration> |