Skip to content

Commit

Permalink
🐛 fix : can't find village bug fix (#51)
Browse files Browse the repository at this point in the history
* 🐛 fix : can't find village bug fix

* 🐛 fix: add readonly transactional
  • Loading branch information
seonghun-dev authored May 25, 2023
1 parent fc055bb commit 4dbdddc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
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) {
return villageAreaRepository.findVillageByLocationPoint(point);
}
}
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));
VillageArea villageArea = villageAreaService.getVillageByLocationPoint(villagePoint);

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

0 comments on commit 4dbdddc

Please sign in to comment.