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

M3-140 픽셀 개인전 정보를 가져오는 API 다시 만들기 #8

Merged
merged 5 commits into from
Jun 26, 2024

Conversation

qjvk2880
Copy link
Contributor

작업 내용*

  • 픽셀 개인전 정보를 가져오는 API 구현
  • @query 사용

고민한 내용*

  • GIS 자료형을 스프링에서 쓰기 위해 여러 제약들이 존재했음
  • 스프링의 GIS 자료형은 두 가지가 있음. Geom, locationtech.
  • 대부분 레퍼런스들이 locationtech를 사용했기에 그렇게 구현함.
  • 하지만 Hibernate 내부에서 Geom을 사용하기에 쿼리 결과로 온 자료형이 locationtech와 호환이 안맞는 문제가 발생
  • 또한 native query를 사용할 때 interface로 결과를 받아야 했지만 Point 자료형은 직렬화 ,역직렬화도 어려웠음.
  • 따라서 Geom 자료형을 locationtech로 직접 변환 후 위경도값을 꺼내 DTO를 만드는 식으로 구현하였음.

스크린샷

Copy link

📝 테스트 커버리지 리포트

Overall Project 48.04% -15.41%
Files changed 31.08%

File Coverage
GeometryConfig.java 100% 🍏
PixelController.java 42.86% -57.14%
GeometryConverter.java 34.29% -65.71%
PixelService.java 29.03% -64.52%

Copy link

github-actions bot commented Jun 26, 2024

Qodana for JVM

It seems all right 👌

No new problems were found according to the checks applied

💡 Qodana analysis was run in the pull request mode: only the changed files were checked
☁️ View the detailed Qodana report

Contact Qodana team

Contact us at qodana-support@jetbrains.com

Copy link

📝 테스트 커버리지 리포트

Overall Project 48.04% -15.41%
Files changed 31.08%

File Coverage
GeometryConfig.java 100% 🍏
PixelController.java 42.86% -57.14%
GeometryConverter.java 34.29% -65.71%
PixelService.java 29.03% -64.52%

Copy link

📝 테스트 커버리지 리포트

Overall Project 48.04% -15.41%
Files changed 31.08%

File Coverage
GeometryConfig.java 100% 🍏
PixelController.java 42.86% -57.14%
GeometryConverter.java 34.29% -65.71%
PixelService.java 29.03% -64.52%

Copy link

📝 테스트 커버리지 리포트

Overall Project 48.62% -14.37%
Files changed 32.86%

File Coverage
GeometryConfig.java 100% 🍏
PixelController.java 42.86% -57.14%
GeometryConverter.java 38.71% -61.29%
PixelService.java 29.03% -64.52%

Copy link

📝 테스트 커버리지 리포트

Overall Project 48.62% -14.37%
Files changed 32.86%

File Coverage
GeometryConfig.java 100% 🍏
PixelController.java 42.86% -57.14%
GeometryConverter.java 38.71% -61.29%
PixelService.java 29.03% -64.52%

public List<IndividualPixelResponse> getNearIndividualPixelsByCoordinate(double currentLatitude,
double currentLongitude, int radius) {
Point point = geometryFactory.createPoint(new Coordinate(currentLongitude, currentLatitude));
point.setSRID(4326);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

매직 넘버 아닌가요...

Comment on lines +13 to +48
@Query(value = """
WITH PixelsInRange AS (
SELECT
p.pixel_id,
p.coordinate,
p.x,
p.y
FROM
pixel p
WHERE
ST_CONTAINS((ST_Buffer(:center, :radius)), p.coordinate)
),
RecentVisits AS (
SELECT
pu.pixel_id,
pu.user_id,
pu.created_at,
ROW_NUMBER() OVER (PARTITION BY pu.pixel_id ORDER BY pu.created_at DESC) AS rn
FROM
pixel_user pu
JOIN
PixelsInRange pir ON pu.pixel_id = pir.pixel_id
)
SELECT
pir.pixel_id AS pixelId,
pir.coordinate,
rv.user_id AS userId,
pir.x,
pir.y
FROM
PixelsInRange pir
JOIN
RecentVisits rv ON pir.pixel_id = rv.pixel_id
WHERE
rv.rn = 1
""", nativeQuery = true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

쿼리 잘 짜셨네요. 저번에 말한 쿼리보다 길긴 하지만 성능이 좋아진 것 같아 좋은 것 같습니다. gis 인덱스가 빠르네요~

@koomin1227 koomin1227 self-assigned this Jun 26, 2024
Copy link
Contributor

@tkdals802 tkdals802 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

멋진 코드인것 같습니다

return Response.createSuccess(pixelService.getNearIndividualPixels(currentX, currentY, xRange, yRange));
@RequestParam(name = "current-latitude") double currentLatitude,
@RequestParam(name = "current-longitude") double currentLongitude,
@RequestParam(name = "radius") int radius) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

radius이 무엇을 중심으로 하는지 나타내는 것은 어떨까요?

@qjvk2880 qjvk2880 merged commit 28c9c87 into develop Jun 26, 2024
3 checks passed
@qjvk2880 qjvk2880 deleted the feature/M3-140-individualPixelReimpl branch July 6, 2024 04:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants