Skip to content

Commit

Permalink
Merge pull request #16 from KHTML-Hexagonal/develop
Browse files Browse the repository at this point in the history
[FEAT]: Building 추천 api 구현
  • Loading branch information
sejineer authored Aug 13, 2024
2 parents 2eee9f6 + 7c7298e commit f5d764c
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.RequiredArgsConstructor;
import org.khtml.hexagonal.domain.building.ImageType;
import org.khtml.hexagonal.domain.building.dto.BuildingUpdate;
import org.khtml.hexagonal.domain.building.dto.RecommendBuildingResult;
import org.khtml.hexagonal.domain.building.entity.Building;
import org.khtml.hexagonal.domain.building.entity.BuildingImage;
import org.khtml.hexagonal.domain.building.entity.Image;
Expand All @@ -21,6 +22,8 @@
import java.util.List;
import java.util.Objects;

import static org.khtml.hexagonal.domain.building.dto.RecommendBuildingResult.*;

@RequiredArgsConstructor
@Transactional(readOnly = true)
@Service
Expand Down Expand Up @@ -134,4 +137,19 @@ public void updateBuildingDescription(String buildingId, Long userId, String des
building.setBuildingDescription(description);
}

public RecommendBuildingResult recommendBuilding() {
List<BuildingImage> buildingImages = buildingImageRepository.recommendBuilding();
List<RecommendBuilding> recommendBuildings = new ArrayList<>();
for(BuildingImage buildingImage : buildingImages) {
Building building = buildingImage.getBuilding();
Image image = buildingImage.getImage();
recommendBuildings.add(new RecommendBuilding(
image.getUrl(),
building.getLegalDistrictName() + " " + building.getLandLotNumber(),
building.getRepairList()
));
}

return new RecommendBuildingResult(recommendBuildings);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.khtml.hexagonal.domain.building.application.BuildingService;
import org.khtml.hexagonal.domain.building.entity.Building;
import org.khtml.hexagonal.domain.building.entity.Image;
import org.khtml.hexagonal.domain.building.repository.BuildingImageRepository;
import org.khtml.hexagonal.domain.user.User;
import org.khtml.hexagonal.global.support.response.ApiResponse;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -60,4 +61,9 @@ public ApiResponse<?> registerBuilding(
return ApiResponse.success();
}

@GetMapping("/recommend")
public ApiResponse<?> recommendBuilding() {
return ApiResponse.success(buildingService.recommendBuilding());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.khtml.hexagonal.domain.building.dto;

import org.khtml.hexagonal.domain.building.entity.Building;

import java.util.List;

public record RecommendBuildingResult(
List<RecommendBuilding> recommendBuildings
) {
public record RecommendBuilding(
String imageUrl,
String address,
String repairList
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.khtml.hexagonal.domain.building.entity.BuildingImage;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

Expand All @@ -12,4 +13,10 @@ public interface BuildingImageRepository extends JpaRepository<BuildingImage, Lo
@EntityGraph(attributePaths = {"image", "building"})
List<BuildingImage> findAllByBuilding(Building building);

@Query("SELECT bi FROM BuildingImage bi " +
"JOIN Building b ON bi.building.gisBuildingId = b.gisBuildingId " +
"JOIN Image i ON bi.image.id = i.id " +
"WHERE b.buildingStatus = 'REGISTERED' ORDER BY b.totalScore DESC LIMIT 10")
List<BuildingImage> recommendBuilding();

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import org.khtml.hexagonal.domain.building.entity.Building;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

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

public interface BuildingRepository extends JpaRepository<Building, Long> {
Expand Down

0 comments on commit f5d764c

Please sign in to comment.