Skip to content

Commit

Permalink
[Merge] 'develop' -> jsoi
Browse files Browse the repository at this point in the history
# Conflicts:
#	build.gradle
#	src/main/java/com/mpnp/baechelin/store/repository/StoreQueryRepository.java
#	src/main/java/com/mpnp/baechelin/store/service/StoreService.java
  • Loading branch information
JSoi committed Jul 31, 2022
2 parents c7e744a + a69a532 commit 7ceae02
Show file tree
Hide file tree
Showing 13 changed files with 165 additions and 136 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

![임시 커버](https://user-images.githubusercontent.com/90380269/181488434-e1e7c2df-dcee-4f1e-83d0-12041663da59.png)
![배너](https://user-images.githubusercontent.com/90380269/181918617-1668bd04-8beb-4f60-91a0-d5e5c3d2dbb8.png)


# Bae-Chelin (배슐랭)

Expand Down
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,15 @@ dependencies {
//file upload
implementation 'commons-fileupload:commons-fileupload:1.4'
compile 'commons-io:commons-io:2.11.0'
<<<<<<< HEAD
//scheduler dependency
implementation 'net.javacrumbs.shedlock:shedlock-spring:4.36.0'
implementation 'net.javacrumbs.shedlock:shedlock-provider-jdbc-template:4.36.0'

=======
//redis
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
>>>>>>> a69a532b32938cf24a1493ed1f1cc223598d4e19
}
tasks.named('test') {
useJUnitPlatform()
Expand Down
27 changes: 20 additions & 7 deletions src/main/java/com/mpnp/baechelin/bookmark/dto/BookmarkInfoDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,32 @@ public class BookmarkInfoDto {
private String category;
private String phoneNumber;
private String storeImageList;
private String elevator;
private String toilet;
private String parking;
private String heightDifferent;
private String approach;
private int bookmarkId;
private int storeId;


public BookmarkInfoDto(Bookmark bookmark){

this.pointAvg = Math.round(bookmark.getStoreId().getPointAvg()*10)/10.0;
this.name = bookmark.getStoreId().getName();
this.address = bookmark.getStoreId().getAddress();
this.category = bookmark.getStoreId().getCategory();
this.phoneNumber = bookmark.getStoreId().getPhoneNumber();
this.bookmarkId = bookmark.getId();
this.storeId = (int) bookmark.getStoreId().getId();
this.pointAvg = Math.round(bookmark.getStoreId().getPointAvg()*10)/10.0;
this.name = bookmark.getStoreId().getName();
this.address = bookmark.getStoreId().getAddress();
this.category = bookmark.getStoreId().getCategory();
this.phoneNumber = bookmark.getStoreId().getPhoneNumber();

this.elevator = bookmark.getStoreId().getElevator();
this.toilet = bookmark.getStoreId().getToilet();
this.parking = bookmark.getStoreId().getParking();
this.heightDifferent = bookmark.getStoreId().getHeightDifferent();
this.approach = bookmark.getStoreId().getApproach();

this.bookmarkId = bookmark.getId();
this.storeId = (int) bookmark.getStoreId().getId();


if(!bookmark.getStoreId().getStoreImageList().isEmpty()) {
this.storeImageList = bookmark.getStoreId().getStoreImageList().get(0).getStoreImageUrl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,7 @@ public static FolderResponseDto FolderDtoRes(Folder folder) {
if(folder.getBookmarkList() != null) {
for (Bookmark bookmark : folder.getBookmarkList()) {

double pointAvg = Math.round(bookmark.getStoreId().getPointAvg()*10)/10.0; // 업장 별점
String name = bookmark.getStoreId().getName(); // 업장 이름
String address = bookmark.getStoreId().getAddress(); // 업장 주소
String category = bookmark.getStoreId().getCategory(); // 업장 카테고리
String PhoneNumber = bookmark.getStoreId().getPhoneNumber(); // 업장 전화번호
int bookmarkId = bookmark.getId();
int storeId = (int) bookmark.getStoreId().getId();

List<BookmarkInfoDto> BookmarkInfoDtoList = new ArrayList<>(); // 정보를 담는 리스트
List<StoreImage> storeImageList = bookmark.getStoreId().getStoreImageList();// 업장 이미지 리스트

BookmarkInfoDto bookmarkInfoDto = BookmarkInfoDto
.builder()
.bookmarkId(bookmarkId)
.storeId(storeId)
.address(address)
.phoneNumber(PhoneNumber)
.category(category)
.pointAvg(pointAvg)
.name(name)
.storeImageList(!storeImageList.isEmpty() ? storeImageList.get(0).getStoreImageUrl():"")
.build();

BookmarkInfoDto bookmarkInfoDto = new BookmarkInfoDto(bookmark);
bookmarks.add(bookmarkInfoDto);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,21 @@ public class BookmarkService {
private final UserRepository userRepository;
private final StoreImgRepository storeImgRepository;
// private final StoreImageRepository storeImageRepository;

@Transactional
public void bookmark(BookmarkRequestDto bookmarkRequestDto, String socialId) {

Folder folder = folderRepository.findById(bookmarkRequestDto.getFolderId()).orElseThrow(()-> new IllegalArgumentException("폴더가 존재하지 않습니다"));
Store store = storeRepository.findById((long) bookmarkRequestDto.getStoreId()).orElseThrow(()-> new IllegalArgumentException("가게가 존재하지 않습니다"));
User user = userRepository.findBySocialId(socialId); if(user == null) { throw new IllegalArgumentException("해당하는 유저가 없습니다."); }
Store store = storeRepository.findById((long) bookmarkRequestDto.getStoreId()).orElseThrow(()-> new IllegalArgumentException("가게가 존재하지 않습니다"));
User user = userRepository.findBySocialId(socialId); if(user == null) { throw new IllegalArgumentException("해당하는 유저가 없습니다."); }

Bookmark bookmark = Bookmark
.builder()
.folderId(folder)
.storeId(store)
.userId(user)
.build();

storeRepository.save(store.updateBookmarkCount());
bookmarkRepository.save(bookmark);
}
Expand Down
54 changes: 47 additions & 7 deletions src/main/java/com/mpnp/baechelin/common/QueryDslSearch.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,71 @@
package com.mpnp.baechelin.common;

import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.core.types.dsl.StringPath;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

import static com.mpnp.baechelin.common.QuerydslLocation.getBooleanBuilder;
import static com.mpnp.baechelin.store.domain.QStore.store;

public class QueryDslSearch {
public static BooleanExpression matchAddress(String sido, String sigungu) {
// sido가 null이면 sigungu는 무조건 null
// sido가 null이 아니면 sigungu는 null 또는 not null

public static BooleanExpression matchAddressWithSido(String sido) {
if (StringUtils.isEmpty(sido)) {
return null;
} else if (StringUtils.isEmpty(sigungu)) {
return null;
}

return Expressions.numberTemplate(
Integer.class,
"function('match', {0}, {1}, {2})", store.address, store.address, sido + " +" + sigungu).gt(0);
"function('match', {0}, {1}, {2})", store.address, store.address, sido).gt(0);
}
private static BooleanExpression matchAddressWithSidoAndSigungu(String sido, String sigungu) {

public static BooleanExpression matchKeyword(String keyword) {
// sido가 null이면 sigungu는 무조건 null
if (StringUtils.isEmpty(sido)) {
return null;
} else if (StringUtils.isEmpty(sigungu)) {
// sido가 null이 아니고 sigungu가 null이면 sido 검색 결과 리턴
return Expressions.numberTemplate(
Integer.class,
"function('match', {0}, {1}, {2})", store.address, store.address, sido).gt(0);
} else if (sigungu.split(" ").length > 1) {
// sigungu가 도/시/구 로 나눠져있을 때 (ex. 경기도 성남시 분당구)
// 정확한 검색을 위해 + 연산자 추가
return Expressions.numberTemplate(
Integer.class,
"function('match', {0}, {1}, {2})", store.address, store.address, sido + " +" + sigungu.split(" ")[0] + " +" + sigungu.split(" ")[1]).gt(0);
} else {
return Expressions.numberTemplate(
Integer.class,
"function('match', {0}, {1}, {2})", store.address, store.address, sido + " +" + sigungu).gt(0);
}
}

private static BooleanExpression matchKeyword(String keyword) {
if (StringUtils.isEmpty(keyword)) {
return null;
}
return Expressions.numberTemplate(
Integer.class,
"function('match', {0}, {1}, {2})", store.name, store.category, keyword).gt(0);
}

public static BooleanBuilder getSearchBooleanBuilder(String sido, String sigungu, String keyword, String category, List<String> facility) {
BooleanBuilder builder = new BooleanBuilder();

// 지역 fulltext search
builder.and(matchAddressWithSidoAndSigungu(sido, sigungu));

// 검색어 fulltext search
builder.and(matchKeyword(keyword));

// 카테고리, 시설
builder.and(getBooleanBuilder(category, facility, builder));

return builder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class ReviewController {

private final ReviewService reviewService;

/** 리뷰 조회 */
@GetMapping("/review/{storeId}")
public ResponseEntity<PageInfoResponseDto> getStoreReview(@PathVariable int storeId,
@AuthenticationPrincipal User user,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class ReviewResponseDto {

private String name;

private String profile_image_url;
private String useImage;

private String myReview;

Expand All @@ -51,9 +51,9 @@ public ReviewResponseDto(Review review) {
}

public void userInfo(User user, User myUser){
this.email = user.getEmail();
this.name = user.getName();
this.profile_image_url = user.getProfileImageUrl();
this.email = user.getEmail();
this.name = user.getName();
this.useImage = user.getProfileImageUrl();

if(this.userId == myUser.getId()){
this.myReview = "Y";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ public class ReviewService {
*/
public void review(ReviewRequestDto reviewRequestDto, String socialId) throws IOException {

long storeId = reviewRequestDto.getStoreId();
Store store = storeRepository.findById(storeId).orElseThrow(() -> new IllegalArgumentException("해당하는 업장이 존재하지 않습니다."));
User user = userRepository.findBySocialId(socialId);
Review review = new Review(reviewRequestDto, store, user);
long storeId = reviewRequestDto.getStoreId();
Store store = storeRepository.findById(storeId).orElseThrow(() -> new IllegalArgumentException("해당하는 업장이 존재하지 않습니다."));
User user = userRepository.findBySocialId(socialId);
Review review = new Review(reviewRequestDto, store, user);


// todo 태크 매핑
Expand Down Expand Up @@ -116,7 +116,7 @@ public PageInfoResponseDto getReview(long storeId, String socialId, Pageable pag
.size(reviewList.getSize())
.reviewResponseDtoList(reviewResponseDtoList)
.hasNextPage(reviewList.isFirst() ? false : true)
.hasPreviousPage(reviewList.isLast() ? false : true)
.hasPreviousPage(!reviewList.isLast() ? false : true)
.build();


Expand All @@ -126,6 +126,7 @@ public PageInfoResponseDto getReview(long storeId, String socialId, Pageable pag

@Transactional
/** 리뷰 수정 */

public void reviewUpdate(ReviewRequestDto reviewRequestDto, String socialId, int reviewId) {


Expand Down Expand Up @@ -204,6 +205,7 @@ public void reviewUpdate(ReviewRequestDto reviewRequestDto, String socialId, int
// reviewImageRepository.deleteAll(reviewImageList);
// }


/**
* 리뷰 삭제
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,21 @@ public StoreDetailResponseDto getStore(

@ApiOperation(value = "시/도 정보를 이용해 DB에 존재하는 시/군/구 정보를 조회하는 메소드")
@GetMapping("/location/sigungu")
public Map<String, List<String>> getSigungu(@RequestParam(required = false) String sido) {
public Map<String, List<String>> getSigungu(@RequestParam String sido) {
return storeService.getSigungu(sido);
}

@ApiOperation(value = "시/도, 시/군/구, 검색어를 이용해 업장 리스트를 조회하는 메소드")
@GetMapping("/search")
public List<StoreCardResponseDto> searchStoresByKeyword(
@RequestParam String sido,
@RequestParam String sigungu,
@RequestParam String keyword,
public StorePagedResponseDto searchStoresByKeyword(
@RequestParam(required = false) String sido,
@RequestParam(required = false) String sigungu,
@RequestParam(required = false) String keyword,
@RequestParam(required = false) String category,
@RequestParam(required = false) List<String> facility,
@PageableDefault Pageable pageable,
@AuthenticationPrincipal User user) {

return storeService.searchStores(sido, sigungu, keyword, user == null ? null : user.getUsername(), pageable);
return storeService.searchStores(sido, sigungu, keyword, category, facility, user == null ? null : user.getUsername(), pageable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public StoreDetailResponseDto(Store store, String isBookMark, List<String> image
this.approach = store.getApproach();
this.bookmarkCount = store.getBookMarkCount();
this.storeImgList = imageList;
this.pointAvg = Double.parseDouble(String.format(store.getReviewList().stream()
.collect(Collectors.averagingDouble(Review::getPoint)).toString(), 0.1f));
// this.pointAvg = Double.parseDouble(String.format(store.getReviewList().stream().collect(Collectors.averagingDouble(Review::getPoint)).toString(), 0.1f));
this.pointAvg = Math.round(store.getPointAvg()*10)/10.0;
this.bookmark = isBookMark;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,15 @@
import com.mpnp.baechelin.bookmark.domain.QBookmark;
import com.mpnp.baechelin.common.QueryDslSearch;
import com.mpnp.baechelin.common.QuerydslLocation;
import com.mpnp.baechelin.review.domain.Review;
import com.mpnp.baechelin.store.domain.QStore;
import com.mpnp.baechelin.store.domain.Store;
import com.mpnp.baechelin.store.dto.StoreCardResponseDto;
import com.mpnp.baechelin.user.domain.QUser;
import com.mpnp.baechelin.user.domain.User;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.QueryFactory;
import com.querydsl.core.Tuple;
import com.querydsl.core.types.OrderSpecifier;
import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.core.types.dsl.NumberPath;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.criterion.Projection;
Expand All @@ -31,9 +26,8 @@
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import static com.mpnp.baechelin.common.QueryDslSearch.getSearchBooleanBuilder;
import static com.mpnp.baechelin.common.QuerydslLocation.locTwoPointAndConditions;
import static com.mpnp.baechelin.store.domain.QStore.store;

Expand Down Expand Up @@ -145,17 +139,30 @@ public Page<Store> findStoreOrderByBookmarkNullCase(BooleanBuilder builder,
return new PageImpl<>(storeList, pageable, storeList.size());
}

// 주소로 검색, 검색어로 검색
public List<Store> searchStores(String sido, String sigungu, String keyword, Pageable pageable) {
BooleanExpression matchAddress = QueryDslSearch.matchAddress(sido, sigungu);
BooleanExpression matchKeyword = QueryDslSearch.matchKeyword(keyword);
// 시/도 정보로 시/군/구 정보를 조회
public List<Store> getSigungu(String sido) {
BooleanExpression matchAddress = QueryDslSearch.matchAddressWithSido(sido);

return queryFactory
.selectFrom(store)
.where(matchAddress,
matchKeyword)
.where(matchAddress)
.fetch();
}


// 주소로 검색, 검색어로 검색
public Page<Store> searchStores(String sido, String sigungu, String keyword, String category, List<String> facility, Pageable pageable) {
BooleanBuilder builder = getSearchBooleanBuilder(sido, sigungu, keyword, category, facility);

List<Store> storeList = queryFactory
.selectFrom(store)
.where(builder)
.limit(pageable.getPageSize())
.offset(pageable.getOffset())
.fetch();
int fetchSize = queryFactory.selectFrom(store)
.where(builder)
.fetch().size();
return new PageImpl<>(storeList, pageable, fetchSize);
}
}
Loading

0 comments on commit 7ceae02

Please sign in to comment.