Skip to content
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
Expand Up @@ -45,8 +45,8 @@ public ResponseEntity<ApiResponse.Success<Object>> findRestaurantByCategory(
}


@GetMapping("/{restaurantId}/menus")
public ResponseEntity<ApiResponse.Success<List>> sellMenuByRestaurant (
@GetMapping("restaurant/{restaurantId}/menus")
public ResponseEntity<ApiResponse.Success<List<RestaurantResponse.listMenuDTO>>> sellMenuByRestaurant (
@PathVariable Long restaurantId,
@LoginActor Actor actor
) {
Expand All @@ -73,4 +73,18 @@ public ResponseEntity<Success<List<RestaurantsByMenuDto>>> getRestaurantsByMenu(

return ApiResponse.success(restaurantsByMenuDtos, HttpStatus.OK);
}

@GetMapping("/restaurants/search")
public ResponseEntity<Success<List<RestaurantResponse.SearchRestaurantsDTO>>> searchRestaurant(
@RequestParam("query") String keyword,
@LoginActor Actor actor
) {
JwtTokenProvider.checkMemberToken(actor);

Long memberId = actor.getId();

List<RestaurantResponse.SearchRestaurantsDTO> result = restaurantService.findRestaurantByKeyword(memberId, keyword);

return ApiResponse.success(result, HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.livable.server.restaurant.dto;

import com.livable.server.entity.Menu;
import com.livable.server.entity.RestaurantCategory;
import lombok.*;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -28,6 +27,7 @@ public static class NearRestaurantDto {
}

@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class listMenuDTO {
private Long menuId;
Expand Down Expand Up @@ -63,30 +63,62 @@ public static RestaurantsByMenuDto from(RestaurantByMenuProjection restaurantByM
.review(restaurantByMenuProjection.getReview())
.build();
}
}

private static Integer calcEstimatedTime(Integer distance) {
int averageWalkSpeedPerMin = 80;
return distance / averageWalkSpeedPerMin;
@Getter
@Builder
@AllArgsConstructor
public static class SearchRestaurantsDTO {

private final Long restaurantId;
private final String restaurantName;
private final RestaurantCategory restaurantCategory;
private final Boolean inBuilding;
private final Integer estimatedTime;
private final Integer floor;
private final String thumbnailImageUrl;

public SearchRestaurantsDTO(
Long restaurantId,
String restaurantName,
RestaurantCategory restaurantCategory,
Boolean inBuilding,
String thumbnailImageUrl,
Integer distance,
String address
) {
this.restaurantId = restaurantId;
this.restaurantName = restaurantName;
this.restaurantCategory = restaurantCategory;
this.inBuilding = inBuilding;
this.thumbnailImageUrl = thumbnailImageUrl;
this.floor = getFloorFromAddress(address);
this.estimatedTime = calcEstimatedTime(distance);
}
}

private static Integer getFloorFromAddress(String address) {
private static Integer getFloorFromAddress(String address) {

int floor = 0;
int floor = 0;

if (address.contains("층")) {
String pattern = "\\s(\\d+)층";
Pattern regexPattern = Pattern.compile(pattern, Pattern.CANON_EQ);
Matcher matcher = regexPattern.matcher(address);
if (matcher.find() && matcher.group(1) != null) {
if (address.contains("층")) {
String pattern = "\\s(\\d+)층";
Pattern regexPattern = Pattern.compile(pattern, Pattern.CANON_EQ);
Matcher matcher = regexPattern.matcher(address);
if (matcher.find() && matcher.group(1) != null) {

floor = Integer.parseInt(matcher.group(1));
if (address.contains("지하")) {
floor *= -1;
}
floor = Integer.parseInt(matcher.group(1));
if (address.contains("지하")) {
floor *= -1;
}
}

return floor;
}

return floor;
}

private static Integer calcEstimatedTime(Integer distance) {
int averageWalkSpeedPerMin = 80;
return distance / averageWalkSpeedPerMin;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ List<RestaurantResponse.NearRestaurantDto> findRestaurantByBuildingIdAndRestaura
);

List<RestaurantResponse.listMenuDTO> findMenuList(Long restaurantId);

List<RestaurantResponse.SearchRestaurantsDTO> findRestaurantByKeyword(Long buildingId, String keyword);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.querydsl.core.types.dsl.CaseBuilder;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.core.types.dsl.StringExpression;
import com.querydsl.jpa.JPAExpressions;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
Expand All @@ -14,6 +15,13 @@

import java.util.List;

import static com.livable.server.entity.QBuilding.building;
import static com.livable.server.entity.QBuildingRestaurantMap.buildingRestaurantMap;
import static com.livable.server.entity.QMenu.menu;
import static com.livable.server.entity.QRestaurant.restaurant;
import static com.livable.server.entity.QRestaurantMenuMap.restaurantMenuMap;


@Repository
@RequiredArgsConstructor
public class RestaurantCustomRepositoryImpl implements RestaurantCustomRepository {
Expand Down Expand Up @@ -90,5 +98,42 @@ public List<RestaurantResponse.listMenuDTO> findMenuList(Long restaurantId) {
return query.fetch();
}

@Override
public List<RestaurantResponse.SearchRestaurantsDTO> findRestaurantByKeyword(Long buildingId, String keyword) {

// TODO : 성능테스트 필요

// List<Long> subQuery = queryFactory
// .select(restaurantMenuMap.restaurant.id)
// .from(menu)
// .innerJoin(restaurantMenuMap).on(menu.id.eq(restaurantMenuMap.menu.id))
// .where(menu.name.contains(keyword)
// .or(restaurant.name.contains(keyword)))
// .fetch();
Comment on lines +106 to +112
Copy link
Member

Choose a reason for hiding this comment

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

주석 지워주쎄용


return queryFactory
.select(Projections.constructor(RestaurantResponse.SearchRestaurantsDTO.class,
restaurant.id,
restaurant.name,
restaurant.restaurantCategory,
buildingRestaurantMap.inBuilding,
restaurant.thumbnailImageUrl,
buildingRestaurantMap.distance,
restaurant.address
))
.from(building)
.innerJoin(buildingRestaurantMap).on(buildingRestaurantMap.building.id.eq(building.id))
.innerJoin(restaurant).on(restaurant.id.eq(buildingRestaurantMap.restaurant.id))
.where(
restaurant.id.in(
JPAExpressions
.select(restaurantMenuMap.restaurant.id)
.from(menu)
.innerJoin(restaurantMenuMap).on(menu.id.eq(restaurantMenuMap.menu.id))
.where(menu.name.contains(keyword)
.or(restaurant.name.contains(keyword)))
)
)
.fetch();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.livable.server.restaurant.service;

import com.livable.server.core.exception.GlobalRuntimeException;
import com.livable.server.entity.Building;
import com.livable.server.entity.Company;
import com.livable.server.entity.Member;
import com.livable.server.entity.RestaurantCategory;
import com.livable.server.member.repository.MemberRepository;
Expand Down Expand Up @@ -89,4 +91,16 @@ private List<RestaurantsByMenuDto> getRestaurantsByMenu(
return restaurantsByMenuDtos;
}

public List<RestaurantResponse.SearchRestaurantsDTO> findRestaurantByKeyword(Long memberId, String keyword) {
checkExistMemberById(memberId);

Long buildingId = getBuildingByMember(memberId);

return restaurantRepository.findRestaurantByKeyword(buildingId, keyword);
}

private Long getBuildingByMember(Long memberId) {

return memberRepository.findBuildingInfoByMemberId(memberId).get().getBuildingId();
}
}