-
Notifications
You must be signed in to change notification settings - Fork 0
fix/89/votepage #123
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
Open
hangyeoli
wants to merge
33
commits into
develop
Choose a base branch
from
fix/89/votepage
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix/89/votepage #123
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
a9a5107
feat: Implement backend vote features (sorting, DTO, etc.)
hangyeoli e840896
setLikeAndDisLike ์ถ๊ฐ
hangyeoli 5562cf8
์์ ์ ์ฅ ๋ณ๊ฒฝ ์ฌํญ ์ปค๋ฐ
hangyeoli 1056b10
fe vote page
hangyeoli 9eb0208
Merge develop branch
hangyeoli 81b8063
Merge branch develop
hangyeoli 22e638c
fix: vote ๊ฐ๋ฅ ์๋น ํฉํ ๋ฆฌ ๋ฉ์๋ ์ถ๊ฐ, patch๋ก ๋ณ๊ฒฝ
hangyeoli 4b6a5ba
Add: validation annotations to RestaurantRequest
hangyeoli 5d2488c
Refactor: Improve Integer to Long conversion in UserRestaurantVoteSerโฆ
hangyeoli cc9c5bb
Refactor: Add validateRestaurantExists method to RestaurantService anโฆ
hangyeoli 7d0f102
Merge feat/82/be/vote into feat/89/fe/votepage
hangyeoli e5573fd
fix: ์ด๋ฆ ๊ธฐ์ค ์ค๋ณต ์ ๊ฑฐ ๋ก์ง ์ถ๊ฐ
hangyeoli e8ef770
ffix/90/be/vote ๋ณ๊ฒฝ์ฌํญ ๋ณํฉ
hangyeoli 80fb057
feat: ํฌํ ์์ ํ ๊ธฐ๋ฅ ์ถ๊ฐ
hangyeoli b6a1148
fix: ์๋ก ๊ณ ์นจ ์ ๊น์ง ์์น ๊ณ ์
hangyeoli 40e82fb
fix: ์ํ๊ด๋ฆฌ ๋ก์ง ๋ณ๊ฒฝ
hangyeoli 80fbad6
feat: ํฌํ ํ์ด์ง์์ ์คํฌ๋ฉ/์์ธ๋ณด๊ธฐ ๋ฒํผ ์ถ๊ฐ
hangyeoli 4ab1cf2
bug: main page์์ ์ ํ์ ๋ก๋ฉ๋ฌธ์ ํด๊ฒฐ
hangyeoli a271368
fix: ์คํฌ๋ฉ ์ํ๊ด๋ฆฌ ๊ฐ์
hangyeoli 091f5e8
feat: ์์ธ ์ ๋ณด ํญํด์ ๋ซ๊ธฐ ์ถ๊ฐ
hangyeoli 968fd14
feat: 5์ด ๊ฐ๊ฒฉ์ผ๋ก ์์ฒญ๋ชจ์์ ์ฒ๋ฆฌ ๊ตฌํ/์์ฒญ ์ ํ ์ถ๊ฐ
hangyeoli 4107a59
fix: ํฌํ count ๋ฒ๊ทธ ์์
hangyeoli cc36d4c
fix: ํ๋จ ์ ๋ณด ํจ๋ ๊ฐ๋ตํ
hangyeoli d4b1827
fix: ๋ฐฐ์น ํฌํ ์ค๋ฅ ๊ฐ์
hangyeoli cc90c51
Merge branch 'develop' into fix/89/fe/votepage
hangyeoli b974dc5
fix: ํฌํ ์๋ก๊ณ ์นจ ์ ์ด๊ธฐํ ๋๋ ๋ฌธ์ ํด๊ฒฐ
hangyeoli 6c2e160
Merge remote-tracking branch 'origin/fix/89/fe/votepage' into fix/89/โฆ
hangyeoli f1b1ed6
fix: vote type dto ๋ก ๋ณ๊ฒฝ
hangyeoli 4154723
merge: develop ๋ธ๋์น ๋ณํฉ
hangyeoli 30f40c8
fix: develop ์ฝ๋์ ๋ค๋ฅธ๋ถ๋ถ ์์
hangyeoli 2241d98
fix: develop ์ฝ๋์ ๋ค๋ฅธ๋ถ๋ถ ์์
hangyeoli b2db78d
fix: ์ฑ ์ข
๋ฃ ํ ์คํํด๋ ํฌํ ์ํ ์ ์ง๋๊ฒ ์์
hangyeoli 78718b1
fix: ํฌํ ๋ฐฐ์น ์ฒ๋ฆฌ ์ ์ธ ๊ฐ๋ตํ
hangyeoli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
be/src/main/java/com/yumst/be/global/exception/ErrorResponse.java
This file contains hidden or 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,14 @@ | ||
| package com.yumst.be.global.exception; | ||
|
|
||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public class ErrorResponse { | ||
| private final String message; | ||
| private final int status; | ||
|
|
||
| public ErrorResponse(ErrorCode errorCode) { | ||
| this.message = errorCode.getMessage(); | ||
| this.status = errorCode.getHttpStatus().value(); | ||
| } | ||
| } |
This file contains hidden or 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
164 changes: 162 additions & 2 deletions
164
be/src/main/java/com/yumst/be/restaurant/repository/RestaurantRepository.java
This file contains hidden or 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 |
|---|---|---|
| @@ -1,23 +1,183 @@ | ||
| package com.yumst.be.restaurant.repository; | ||
|
|
||
| import com.yumst.be.restaurant.domain.Restaurant; | ||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Query; | ||
| import org.springframework.data.repository.query.Param; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| public interface RestaurantRepository extends JpaRepository<Restaurant, Long> { | ||
| Optional<Restaurant> findByRestaurantId(String restaurantId); | ||
| List<Restaurant> findTop10RestaurantsByCrawlCompleteTrue(); | ||
|
|
||
| // ๊ฑฐ๋ฆฌ์ ์ ๋ ฌ | ||
| @Query(value = | ||
| "WITH RankedRestaurants AS (" + | ||
| " SELECT " + | ||
| " r.restaurant_id, r.name, r.category, r.thumbnail_url, " + | ||
| " ST_Distance(" + | ||
| " geography(ST_SetSRID(ST_MakePoint(CAST(r.longitude AS float), CAST(r.latitude AS float)), 4326)), " + | ||
| " geography(ST_SetSRID(ST_MakePoint(:longitude, :latitude), 4326))" + | ||
| " ) as dist, " + | ||
| " COALESCE(bool_or(us.restaurant_id IS NOT NULL), false) as is_scrapped, " + | ||
| " COALESCE(SUM(CASE WHEN v_all.vote_type = 'LIKE' THEN 1 ELSE 0 END), 0) as like_count, " + | ||
| " COALESCE(SUM(CASE WHEN v_all.vote_type = 'DISLIKE' THEN 1 ELSE 0 END), 0) as dislike_count, " + | ||
| " MAX(v_user.vote_type) as user_vote_status, " + | ||
| " ROW_NUMBER() OVER (PARTITION BY r.name ORDER BY ST_Distance(" + | ||
| " geography(ST_SetSRID(ST_MakePoint(CAST(r.longitude AS float), CAST(r.latitude AS float)), 4326)), " + | ||
| " geography(ST_SetSRID(ST_MakePoint(:longitude, :latitude), 4326)))\n" + | ||
| " ) as row_num " + | ||
| " FROM " + | ||
| " restaurant r " + | ||
| " LEFT JOIN user_restaurant_scrap us ON r.restaurant_id = us.restaurant_id AND us.user_id = :userId " + | ||
| " LEFT JOIN user_restaurant_vote v_all ON r.restaurant_id = v_all.restaurant_id " + | ||
| " LEFT JOIN user_restaurant_vote v_user ON r.restaurant_id = v_user.restaurant_id AND v_user.user_id = :userId " + | ||
| " WHERE " + | ||
| " r.crawl_complete = true AND " + | ||
| " ST_DWithin(" + | ||
| " geography(ST_SetSRID(ST_MakePoint(CAST(r.longitude AS float), CAST(r.latitude AS float)), 4326)), " + | ||
| " geography(ST_SetSRID(ST_MakePoint(:longitude, :latitude), 4326)), " + | ||
| " :radius * 1000" + | ||
| " ) " + | ||
| " GROUP BY r.restaurant_id, r.name, r.category, r.thumbnail_url, r.longitude, r.latitude" + | ||
| ") " + | ||
| "SELECT restaurant_id, name, category, thumbnail_url, dist, is_scrapped, like_count, dislike_count, user_vote_status " + | ||
| "FROM RankedRestaurants " + | ||
| "WHERE row_num = 1 " + | ||
| "ORDER BY dist ASC", | ||
| countQuery = "SELECT COUNT(DISTINCT r.name) " + | ||
| "FROM restaurant r " + | ||
| "WHERE r.crawl_complete = true AND " + | ||
| "ST_DWithin(" + | ||
| " geography(ST_SetSRID(ST_MakePoint(CAST(r.longitude AS float), CAST(r.latitude AS float)), 4326)), " + | ||
| " geography(ST_SetSRID(ST_MakePoint(:longitude, :latitude), 4326)), " + | ||
| " :radius * 1000" + | ||
| ")", | ||
| nativeQuery = true) | ||
| Page<Object[]> findNearbyRestaurantsOrderByDistance( | ||
| @Param("userId") String userId, | ||
| @Param("latitude") Double latitude, | ||
| @Param("longitude") Double longitude, | ||
| @Param("radius") Double radius, | ||
| Pageable pageable | ||
| ); | ||
|
|
||
| // ์ข์์์ ์ ๋ ฌ | ||
| @Query(value = | ||
| "WITH RankedRestaurants AS (" + | ||
| " SELECT " + | ||
| " r.restaurant_id, r.name, r.category, r.thumbnail_url, " + | ||
| " ST_Distance(" + | ||
| " geography(ST_SetSRID(ST_MakePoint(CAST(r.longitude AS float), CAST(r.latitude AS float)), 4326)), " + | ||
| " geography(ST_SetSRID(ST_MakePoint(:longitude, :latitude), 4326))" + | ||
| " ) as dist, " + | ||
| " COALESCE(bool_or(us.restaurant_id IS NOT NULL), false) as is_scrapped, " + | ||
| " COALESCE(SUM(CASE WHEN v_all.vote_type = 'LIKE' THEN 1 ELSE 0 END), 0) as like_count, " + | ||
| " COALESCE(SUM(CASE WHEN v_all.vote_type = 'DISLIKE' THEN 1 ELSE 0 END), 0) as dislike_count, " + | ||
| " MAX(v_user.vote_type) as user_vote_status, " + | ||
| " ROW_NUMBER() OVER (PARTITION BY r.name ORDER BY ST_Distance(" + | ||
| " geography(ST_SetSRID(ST_MakePoint(CAST(r.longitude AS float), CAST(r.latitude AS float)), 4326)), " + | ||
| " geography(ST_SetSRID(ST_MakePoint(:longitude, :latitude), 4326)))\n" + | ||
| " ) as row_num " + | ||
| " FROM " + | ||
| " restaurant r " + | ||
| " LEFT JOIN user_restaurant_scrap us ON r.restaurant_id = us.restaurant_id AND us.user_id = :userId " + | ||
| " LEFT JOIN user_restaurant_vote v_all ON r.restaurant_id = v_all.restaurant_id " + | ||
| " LEFT JOIN user_restaurant_vote v_user ON r.restaurant_id = v_user.restaurant_id AND v_user.user_id = :userId " + | ||
| " WHERE " + | ||
| " r.crawl_complete = true AND " + | ||
| " ST_DWithin(" + | ||
| " geography(ST_SetSRID(ST_MakePoint(CAST(r.longitude AS float), CAST(r.latitude AS float)), 4326)), " + | ||
| " geography(ST_SetSRID(ST_MakePoint(:longitude, :latitude), 4326)), " + | ||
| " :radius * 1000" + | ||
| " ) " + | ||
| " GROUP BY r.restaurant_id, r.name, r.category, r.thumbnail_url, r.longitude, r.latitude" + | ||
| ") " + | ||
| "SELECT restaurant_id, name, category, thumbnail_url, dist, is_scrapped, like_count, dislike_count, user_vote_status " + | ||
| "FROM RankedRestaurants " + | ||
| "WHERE row_num = 1 " + | ||
| "ORDER BY like_count DESC, dist ASC", | ||
| countQuery = "SELECT COUNT(DISTINCT r.name) " + | ||
| "FROM restaurant r " + | ||
| "WHERE r.crawl_complete = true AND " + | ||
| "ST_DWithin(" + | ||
| " geography(ST_SetSRID(ST_MakePoint(CAST(r.longitude AS float), CAST(r.latitude AS float)), 4326)), " + | ||
| " geography(ST_SetSRID(ST_MakePoint(:longitude, :latitude), 4326)), " + | ||
| " :radius * 1000" + | ||
| ")", | ||
| nativeQuery = true) | ||
| Page<Object[]> findNearbyRestaurantsOrderByLikes( | ||
| @Param("userId") String userId, | ||
| @Param("latitude") Double latitude, | ||
| @Param("longitude") Double longitude, | ||
| @Param("radius") Double radius, | ||
| Pageable pageable | ||
| ); | ||
|
|
||
| // ์ซ์ด์์ ์ ๋ ฌ | ||
| @Query(value = | ||
| "WITH RankedRestaurants AS (" + | ||
| " SELECT " + | ||
| " r.restaurant_id, r.name, r.category, r.thumbnail_url, " + | ||
| " ST_Distance(" + | ||
| " geography(ST_SetSRID(ST_MakePoint(CAST(r.longitude AS float), CAST(r.latitude AS float)), 4326)), " + | ||
| " geography(ST_SetSRID(ST_MakePoint(:longitude, :latitude), 4326))" + | ||
| " ) as dist, " + | ||
| " COALESCE(bool_or(us.restaurant_id IS NOT NULL), false) as is_scrapped, " + | ||
| " COALESCE(SUM(CASE WHEN v_all.vote_type = 'LIKE' THEN 1 ELSE 0 END), 0) as like_count, " + | ||
| " COALESCE(SUM(CASE WHEN v_all.vote_type = 'DISLIKE' THEN 1 ELSE 0 END), 0) as dislike_count, " + | ||
| " MAX(v_user.vote_type) as user_vote_status, " + | ||
| " ROW_NUMBER() OVER (PARTITION BY r.name ORDER BY ST_Distance(" + | ||
| " geography(ST_SetSRID(ST_MakePoint(CAST(r.longitude AS float), CAST(r.latitude AS float)), 4326)), " + | ||
| " geography(ST_SetSRID(ST_MakePoint(:longitude, :latitude), 4326)))\n" + | ||
| " ) as row_num " + | ||
| " FROM " + | ||
| " restaurant r " + | ||
| " LEFT JOIN user_restaurant_scrap us ON r.restaurant_id = us.restaurant_id AND us.user_id = :userId " + | ||
| " LEFT JOIN user_restaurant_vote v_all ON r.restaurant_id = v_all.restaurant_id " + | ||
| " LEFT JOIN user_restaurant_vote v_user ON r.restaurant_id = v_user.restaurant_id AND v_user.user_id = :userId " + | ||
| " WHERE " + | ||
| " r.crawl_complete = true AND " + | ||
| " ST_DWithin(" + | ||
| " geography(ST_SetSRID(ST_MakePoint(CAST(r.longitude AS float), CAST(r.latitude AS float)), 4326)), " + | ||
| " geography(ST_SetSRID(ST_MakePoint(:longitude, :latitude), 4326)), " + | ||
| " :radius * 1000" + | ||
| " ) " + | ||
| " GROUP BY r.restaurant_id, r.name, r.category, r.thumbnail_url, r.longitude, r.latitude" + | ||
| ") " + | ||
| "SELECT restaurant_id, name, category, thumbnail_url, dist, is_scrapped, like_count, dislike_count, user_vote_status " + | ||
| "FROM RankedRestaurants " + | ||
| "WHERE row_num = 1 " + | ||
| "ORDER BY dislike_count DESC, dist ASC", | ||
| countQuery = "SELECT COUNT(DISTINCT r.name) " + | ||
| "FROM restaurant r " + | ||
| "WHERE r.crawl_complete = true AND " + | ||
| "ST_DWithin(" + | ||
| " geography(ST_SetSRID(ST_MakePoint(CAST(r.longitude AS float), CAST(r.latitude AS float)), 4326)), " + | ||
| " geography(ST_SetSRID(ST_MakePoint(:longitude, :latitude), 4326)), " + | ||
| " :radius * 1000" + | ||
| ")", | ||
| nativeQuery = true) | ||
| Page<Object[]> findNearbyRestaurantsOrderByDislikes( | ||
| @Param("userId") String userId, | ||
| @Param("latitude") Double latitude, | ||
| @Param("longitude") Double longitude, | ||
| @Param("radius") Double radius, | ||
| Pageable pageable | ||
| ); | ||
|
|
||
| @Query( | ||
| "SELECT r " + | ||
| "FROM Restaurant r " + | ||
| "WHERE r.crawlComplete = true " + | ||
| // "r.naverInformation.name like concat('%', '์ญ๊พธ๋ฏธ๋ธ๋ฃจ์ค', '%') " + | ||
| "ORDER BY r.naverInformation.rating DESC " + | ||
| "LIMIT 10" | ||
| ) | ||
| List<Restaurant> findTop10RestaurantsByCrawlCompleteTrueOrderByNaverInformation(); | ||
|
|
||
| Restaurant findFirstByOpenDataInformation_BusinessNameContainingAndOpenDataInformation_FullAddressContaining(String businessName, String fullAddress); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The three native queries
findNearbyRestaurantsOrderByDistance,findNearbyRestaurantsOrderByLikes, andfindNearbyRestaurantsOrderByDislikesare almost identical except for the finalORDER BYclause in the outer query (e.g.,ORDER BY dist ASC,ORDER BY like_count DESC, dist ASC,ORDER BY dislike_count DESC, dist ASC). This leads to significant code duplication, making maintenance harder. If one part of the common logic needs to change, it has to be updated in three places.Could we explore ways to reduce this duplication? For example:
ORDER BYclause appended dynamically in the service layer before creating the query? (Care must be taken to prevent SQL injection if not using named parameters for the dynamic part, though Spring's@Paramhandles the fixed parts well).ORDER BYwith such complex native CTEs, perhaps a single repository method that fetches the data and the service layer performs the final sort in-memory if the dataset per page isn't excessively large? (This might shift complexity or performance characteristics).What are your thoughts on refactoring this to improve maintainability?