-
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 #17 from KHTML-Hexagonal/develop
[FEAT]: Building 추천 api 구현
- Loading branch information
Showing
8 changed files
with
113 additions
and
40 deletions.
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
26 changes: 26 additions & 0 deletions
26
src/main/java/org/khtml/hexagonal/domain/building/dto/RecommendBuilding.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,26 @@ | ||
package org.khtml.hexagonal.domain.building.dto; | ||
|
||
import com.querydsl.core.annotations.QueryProjection; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class RecommendBuilding { | ||
|
||
private String buildingId; | ||
private String imageUrl; | ||
private String address; | ||
private String repairList; | ||
private Integer totalScore; | ||
|
||
@Builder | ||
@QueryProjection | ||
public RecommendBuilding(String buildingId, String imageUrl, String address, String repairList, Integer totalScore) { | ||
this.buildingId = buildingId; | ||
this.imageUrl = imageUrl; | ||
this.address = address; | ||
this.repairList = repairList; | ||
this.totalScore = totalScore; | ||
} | ||
|
||
} |
16 changes: 0 additions & 16 deletions
16
src/main/java/org/khtml/hexagonal/domain/building/dto/RecommendBuildingResult.java
This file was deleted.
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
11 changes: 11 additions & 0 deletions
11
src/main/java/org/khtml/hexagonal/domain/building/repository/BuildingQueryDslRepository.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,11 @@ | ||
package org.khtml.hexagonal.domain.building.repository; | ||
|
||
import org.khtml.hexagonal.domain.building.dto.RecommendBuilding; | ||
|
||
import java.util.List; | ||
|
||
|
||
public interface BuildingQueryDslRepository { | ||
|
||
List<RecommendBuilding> recommendBuilding(); | ||
} |
43 changes: 43 additions & 0 deletions
43
...n/java/org/khtml/hexagonal/domain/building/repository/BuildingQueryDslRepositoryImpl.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,43 @@ | ||
package org.khtml.hexagonal.domain.building.repository; | ||
|
||
import com.querydsl.core.types.dsl.Expressions; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
import org.khtml.hexagonal.domain.building.BuildingStatus; | ||
import org.khtml.hexagonal.domain.building.dto.QRecommendBuilding; | ||
import org.khtml.hexagonal.domain.building.dto.RecommendBuilding; | ||
|
||
import java.beans.Expression; | ||
import java.util.List; | ||
|
||
import static com.querydsl.core.types.dsl.Expressions.stringTemplate; | ||
import static org.khtml.hexagonal.domain.building.entity.QBuilding.*; | ||
import static org.khtml.hexagonal.domain.building.entity.QBuildingImage.*; | ||
import static org.khtml.hexagonal.domain.building.entity.QImage.*; | ||
|
||
@RequiredArgsConstructor | ||
public class BuildingQueryDslRepositoryImpl implements BuildingQueryDslRepository { | ||
|
||
private final JPAQueryFactory queryFactory; | ||
|
||
@Override | ||
public List<RecommendBuilding> recommendBuilding() { | ||
return queryFactory | ||
.select(new QRecommendBuilding( | ||
building.gisBuildingId, | ||
image.url, | ||
Expressions.stringTemplate("CONCAT({0}, ' ', {1})", building.legalDistrictName, building.landLotNumber), | ||
building.repairList, | ||
building.totalScore | ||
)) | ||
.from(buildingImage) | ||
.leftJoin(building).on(buildingImage.building.eq(building)) | ||
.leftJoin(image).on(buildingImage.image.eq(image)) | ||
.where(building.buildingStatus.eq(BuildingStatus.REGISTERED)) | ||
.distinct() | ||
.orderBy(building.totalScore.desc()) | ||
.limit(10) | ||
.fetch(); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/org/khtml/hexagonal/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,20 @@ | ||
package org.khtml.hexagonal.global.config; | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.PersistenceContext; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class QueryDslConfig { | ||
|
||
@PersistenceContext | ||
private EntityManager entityManager; | ||
|
||
@Bean | ||
public JPAQueryFactory queryFactory() { | ||
return new JPAQueryFactory(entityManager); | ||
} | ||
|
||
} |