Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 fix : can't find village bug fix #51

Merged
merged 2 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.depromeet.streetdrop.domains.area.village.repository;

import com.depromeet.streetdrop.domains.area.village.entity.VillageArea;
import org.locationtech.jts.geom.Point;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

Expand All @@ -9,4 +10,7 @@ public interface VillageAreaRepository extends JpaRepository<VillageArea, Long>
@Query(value = "select count(i.id) from ItemLocation i where i.villageArea.villageName = :villageAreaName")
int countItemsByVillageName(String villageAreaName);

@Query(value = "select v from VillageArea v where ST_Contains(v.villagePolygon, :point) = true")
VillageArea findVillageByLocationPoint(Point point);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.depromeet.streetdrop.domains.area.village.service;

import com.depromeet.streetdrop.domains.area.village.entity.VillageArea;
import com.depromeet.streetdrop.domains.area.village.repository.VillageAreaRepository;
import lombok.RequiredArgsConstructor;
import org.locationtech.jts.geom.Point;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
public class VillageAreaService {

private final VillageAreaRepository villageAreaRepository;

@Transactional(readOnly = true)
public VillageArea getVillageByLocationPoint(Point point) {
seonghun-dev marked this conversation as resolved.
Show resolved Hide resolved
return villageAreaRepository.findVillageByLocationPoint(point);
seonghun-dev marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ public class ItemLocation extends BaseTimeEntity {
private VillageArea villageArea;

@Builder
public ItemLocation(String name, Point point) {
public ItemLocation(String name, Point point, VillageArea villageArea) {
this.name = name;
this.point = point;
this.villageArea = villageArea;
}

public void updateItem(Item item) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.depromeet.streetdrop.domains.itemLocation.service;

import com.depromeet.streetdrop.domains.area.village.entity.VillageArea;
import com.depromeet.streetdrop.domains.area.village.service.VillageAreaService;
import com.depromeet.streetdrop.domains.item.dto.request.ItemRequestDto;
import com.depromeet.streetdrop.domains.item.entity.Item;
import com.depromeet.streetdrop.domains.itemLocation.dto.request.LocationRequestDto;
Expand All @@ -16,15 +18,19 @@
public class ItemLocationService {
private final static int WGS84_SRID = 4326;
private final GeometryFactory gf = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING), WGS84_SRID);
private final VillageAreaService villageAreaService;

public ItemLocation create(ItemRequestDto requestDto) {
LocationRequestDto locationRequestDto = requestDto.getLocation();
Double lat = locationRequestDto.getLatitude();
Double lon = locationRequestDto.getLongitude();
Point point = gf.createPoint(new Coordinate(lat, lon));
Point villagePoint = gf.createPoint(new Coordinate(lon, lat));
seonghun-dev marked this conversation as resolved.
Show resolved Hide resolved
VillageArea villageArea = villageAreaService.getVillageByLocationPoint(villagePoint);

return ItemLocation.builder()
.name(locationRequestDto.getAddress())
.villageArea(villageArea)
.point(point)
.build();
}
Expand Down