Skip to content

Commit

Permalink
[Merge] 'develop' -> jsoi
Browse files Browse the repository at this point in the history
  • Loading branch information
JSoi committed Aug 1, 2022
2 parents 7944d0b + 2a3671a commit 8539133
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 29 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,16 @@

[WebClient & RestTemplate](https://planet-punishment-427.notion.site/WebClient-RestTemplate-1412e5edae0d4dac9a89cde89658812c)

[공공 API의 정보 가공](https://planet-punishment-427.notion.site/API-8adec124d1fd4a11b1a06d3e4039871d)

[무중단 배포에서의 스케쥴링락](https://planet-punishment-427.notion.site/672bab5cbbe84871b701268e43dcd543)

[Refresh Token 적용](https://planet-punishment-427.notion.site/Refresh-Token-fee659681d4a4c2483a495a3ad567173)

[가게 검색 기능](https://planet-punishment-427.notion.site/6db6471276004027be4a0784de4964ed)



<br>

![Line 1](https://user-images.githubusercontent.com/90380269/181489532-4bbb5041-8de1-4ac9-89b2-9400e577ddd2.png)
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/mpnp/baechelin/common/QueryDslSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ public static BooleanBuilder getSearchBooleanBuilder(String sido, String sigungu
// 검색어 fulltext search
builder.and(matchKeyword(keyword));

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

return builder;
// 카테고리, 시설까지 builder에 넣은 후 리턴
return getBooleanBuilder(category, facility, builder);
}
}
1 change: 1 addition & 0 deletions src/main/java/com/mpnp/baechelin/exception/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public enum ErrorCode {
API_NO_RESULT(500, "E-ANR500", "API 결과가 존재하지 않습니다."),
NULL_POINTER_EXCEPTION(500, "E-NPE500", "빈 값이 들어올 수 없습니다."),
IMAGE_PROCESS_FAIL(500,"E-IPF500","이미지 오류 발생"),
KEYWORD_ARE_NEEDED(500, "E-KAE500", "검색어를 입력해주세요."),
INVALID_BARRIER_TAG(500, "E-IBT500","배리어 프리 태그를 확인해주세요");

private final int status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ else if(exception.equals(ErrorCode.WRONG_TYPE_SIGNATURE.getCode())) {
else if(exception.equals(ErrorCode.EXPIRED_ACCESS_TOKEN.getCode())) {
setResponse(response, ErrorCode.EXPIRED_ACCESS_TOKEN);
}
// 토큰이 존재하지 않을 경우
else if (exception.equals(ErrorCode.ACCESS_TOKEN_NOT_EXIST.getCode())) {
setResponse(response, ErrorCode.ACCESS_TOKEN_NOT_EXIST);
}
else {
setResponse(response, ErrorCode.INVALID_ACCESS_TOKEN);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ protected void doFilterInternal(
Authentication authentication = tokenProvider.getAuthentication(token);
// SecurityContextHolder 에 인증 객체를 넣는다.
SecurityContextHolder.getContext().setAuthentication(authentication);
} else {
throw new CustomException(ErrorCode.ACCESS_TOKEN_NOT_EXIST);
}
// 에러가 발생했을 때, request에 attribute를 세팅하고 RestAuthenticationEntryPoint로 request를 넘겨준다.
} catch (SignatureException e) {
Expand All @@ -61,6 +63,9 @@ protected void doFilterInternal(
} catch (IllegalArgumentException e) {
log.info(e.toString().split(":")[1].trim());
request.setAttribute("exception", ErrorCode.INVALID_ACCESS_TOKEN.getCode());
} catch (CustomException e) {
log.info("Access Token이 존재하지 않습니다.");
request.setAttribute("exception", ErrorCode.ACCESS_TOKEN_NOT_EXIST.getCode());
}

filterChain.doFilter(request, response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public class TokenService {
public AuthResponse refreshToken(HttpServletRequest request, HttpServletResponse response) {
AuthToken authToken = tokenProvider.convertAccessToken(request);

if (authToken == null) {
throw new CustomException(ErrorCode.ACCESS_TOKEN_NOT_EXIST);
}

Claims claims = authToken.getExpiredTokenClaims();

// 유효한 access token 인지, 만료된 token 인지 확인
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,16 @@ public ResponseEntity<PageInfoResponseDto> getStoreReview(@PathVariable int stor
@AuthenticationPrincipal User user,
@PageableDefault(page = 0, size = 5, sort = "id", direction = Sort.Direction.DESC) Pageable pageable) {

PageInfoResponseDto pageInfoResponseDto = reviewService.getReview(storeId, user.getUsername(), pageable);
return new ResponseEntity<>(pageInfoResponseDto, HttpStatus.OK);
if (user != null) {
PageInfoResponseDto pageInfoResponseDto = reviewService.getReview(storeId, user.getUsername(), pageable);
return new ResponseEntity<>(pageInfoResponseDto, HttpStatus.OK);
}

if (user == null) {
PageInfoResponseDto pageInfoResponseDto = reviewService.getReview(storeId, pageable);
return new ResponseEntity<>(pageInfoResponseDto, HttpStatus.OK);
}
return null;
}

// @GetMapping("/review/{storeId}")
Expand Down Expand Up @@ -88,7 +96,7 @@ public ResponseEntity<?> imageUpload(@AuthenticationPrincipal User user,
/** 리뷰 삭제 */
@DeleteMapping("/review/{reviewId}")
public ResponseEntity<?> reviewDelete(@AuthenticationPrincipal User user,
@PathVariable int reviewId) throws IOException {
@PathVariable int reviewId) {

if(user==null){ throw new IllegalArgumentException("해당하는 회원 정보가 없습니다."); }
reviewService.reviewDelete(user.getUsername(), reviewId);
Expand Down
23 changes: 16 additions & 7 deletions src/main/java/com/mpnp/baechelin/review/dto/ReviewResponseDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class ReviewResponseDto {

private String name;

private String useImage;
private String userImage;

private String myReview;

Expand Down Expand Up @@ -53,15 +53,24 @@ public ReviewResponseDto(Review review) {
public void userInfo(User user, User myUser){
this.email = user.getEmail();
this.name = user.getName();
this.useImage = user.getProfileImageUrl();

if(this.userId == myUser.getId()){
this.myReview = "Y";
} else if (this.userId != myUser.getId()){
this.userImage = user.getProfileImageUrl();

if (myUser != null) {
if(this.userId == myUser.getId()){
this.myReview = "Y";
} else if (this.userId != myUser.getId()){
this.myReview = "N";
}
} else {
this.myReview = "N";
}
}


public void userInfo(User user){
this.email = user.getEmail();
this.name = user.getName();
this.userImage = user.getProfileImageUrl();
this.myReview = "N";
}
@Builder
@AllArgsConstructor
Expand Down
56 changes: 43 additions & 13 deletions src/main/java/com/mpnp/baechelin/review/service/ReviewService.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,36 @@ public PageInfoResponseDto getReview(long storeId, String socialId, Pageable pag
return pageInfoResponseDto;
}

public PageInfoResponseDto getReview(long storeId, Pageable pageable) {

Store store = storeRepository.findById(storeId).orElseThrow(() -> new IllegalArgumentException("해당 가게가 없습니다"));
Page<Review> reviewList = reviewRepository.findAllByStoreId(store, pageable);


List<ReviewResponseDto> reviewResponseDtoList = new ArrayList<>();
for (Review review : reviewList) {
ReviewResponseDto reviewResponseDto = new ReviewResponseDto(review);
Optional<User> user = userRepository.findById(reviewResponseDto.getUserId());
reviewResponseDto.userInfo(user.get());
reviewResponseDtoList.add(reviewResponseDto);
}


PageInfoResponseDto pageInfoResponseDto = PageInfoResponseDto
.builder()
.totalElements((int) reviewList.getTotalElements())
.totalPages(reviewList.getTotalPages())
.number(reviewList.getNumber())
.size(reviewList.getSize())
.reviewResponseDtoList(reviewResponseDtoList)
.hasNextPage(reviewList.isFirst() ? false : true)
.hasPreviousPage(!reviewList.isLast() ? false : true)
.build();


return pageInfoResponseDto;
}


@Transactional
/** 리뷰 수정 */
Expand Down Expand Up @@ -211,31 +241,31 @@ public void reviewUpdate(ReviewRequestDto reviewRequestDto, String socialId, int
*/
public void reviewDelete(String socialId, int reviewId) {

User user = userRepository.findBySocialId(socialId); // 유저 매핑
Optional<Review> review = reviewRepository.findById(reviewId); // 리뷰 매핑

if (user == null) {
throw new IllegalArgumentException("해당하는 소셜아이디를 찾을 수 없습니다.");
} // 유저 유무 확인 예외처리
User user = userRepository .findBySocialId(socialId); if (user == null) { new IllegalArgumentException("해당하는 소셜아이디를 찾을 수 없습니다."); } // 유저 유무 확인 예외처리
Review review = reviewRepository.findById(reviewId).orElseThrow(() -> new IllegalArgumentException("해당하는 리뷰가 이미 삭제 되었습니다.")); // 리뷰 유무 확인 예외처리;
Optional<Store> store = storeRepository.findById(Long.valueOf(review.getStoreId().getId()));
if(store.isEmpty()){ throw new IllegalArgumentException("해당하는 업장이 없습니다.");}

review.orElseThrow(() -> new IllegalArgumentException("해당하는 리뷰가 이미 삭제 되었습니다.")); // 리뷰 유무 확인 예외처리

List<ReviewImage> imageList = review.get().getReviewImageList();
Store store = review.get().getStoreId();
List<ReviewImage> imageList = review.getReviewImageList();

// todo 1.리뷰삭제 -> 2.이미지 삭제
reviewRepository.deleteById(review.get().getId()); // 1
if (!review.get().getReviewImageList().isEmpty()) { // 2
reviewRepository.deleteById(review.getId()); // 1
if (!review.getReviewImageList().isEmpty()) { // 2
for (ReviewImage reviewImage : imageList) {
if (reviewImage.getReviewImageUrl() == null || reviewImage.getReviewImageUrl().equals("")) continue;
System.out.println("delete -> " + reviewImage.getReviewImageUrl().substring(reviewImage.getReviewImageUrl().indexOf("com/") + 4));
awsS3Manager.deleteFile(reviewImage.getReviewImageUrl().substring(reviewImage.getReviewImageUrl().indexOf("com/") + 4));
}
}
store.removeReview(review.get());
storeRepository.save(store.updatePointAvg()); // 별점 평점 구하는 코드

store.get().removeReview(review);
storeRepository.save(store.get().updatePointAvg()); // 별점 평점 구하는 코드
}




public List<ReviewMainResponseDto> getRecentReview(BigDecimal lat, BigDecimal lng, int limit) {
return reviewQueryRepository
.findRecentReviews(lat, lng, limit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@
import com.mpnp.baechelin.exception.ErrorCode;
import com.mpnp.baechelin.login.jwt.AuthToken;
import com.mpnp.baechelin.login.jwt.AuthTokenProvider;
import com.mpnp.baechelin.store.dto.StoreCardResponseDto;
import com.mpnp.baechelin.store.dto.StoreDetailResponseDto;
import com.mpnp.baechelin.store.dto.StorePagedResponseDto;
import com.mpnp.baechelin.store.service.StoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.User;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.Size;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
Expand All @@ -26,6 +29,7 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/store")
@Validated
public class StoreController {

private final StoreService storeService;
Expand Down Expand Up @@ -103,12 +107,16 @@ public Map<String, List<String>> getSigungu(@RequestParam String sido) {
public StorePagedResponseDto searchStoresByKeyword(
@RequestParam(required = false) String sido,
@RequestParam(required = false) String sigungu,
@RequestParam(required = false) String keyword,
@RequestParam(required = false) @Size(min = 2, message = "검색어는 두글자 이상 입력해주세요.") String keyword,
@RequestParam(required = false) String category,
@RequestParam(required = false) List<String> facility,
@PageableDefault Pageable pageable,
@AuthenticationPrincipal User user) {

if (StringUtils.isEmpty(sido) && StringUtils.isEmpty(sigungu) && StringUtils.isEmpty(keyword) && StringUtils.isEmpty(category) && ObjectUtils.isEmpty(facility)) {
throw new CustomException(ErrorCode.KEYWORD_ARE_NEEDED);
}

return storeService.searchStores(sido, sigungu, keyword, category, facility, user == null ? null : user.getUsername(), pageable);
}
}

0 comments on commit 8539133

Please sign in to comment.