Skip to content
Open
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
124 changes: 124 additions & 0 deletions gusto/.idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions gusto/src/main/java/com/umc/gusto/GustoApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableScheduling;

@EnableJpaAuditing
@EnableScheduling
@SpringBootApplication
public class GustoApplication {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,13 +360,11 @@ public PagingResponse getAllGroupList(Long groupId, Long groupListId) {

// 그룹 리스트에 해당하는 각 상점 정보 조회
List<GroupListResponse> list = groupLists.stream().map(gl -> {
Optional<Review> topReviewOptional = reviewRepository.findFirstByStoreOrderByLikedDesc(gl.getStore()); // 가장 좋아요가 많은 review
String reviewImg = topReviewOptional.map(Review::getImg1).orElse("");
return GroupListResponse.builder()
.groupListId(gl.getGroupListId())
.storeId(gl.getStore().getStoreId())
.storeName(gl.getStore().getStoreName())
.storeProfileImg(reviewImg)
.storeProfileImg(gl.getStore().getImg1() != null ? gl.getStore().getImg1() : "")
.userProfileImg(gl.getUser().getProfileImage())
.address(gl.getStore().getAddress())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;

@Builder
@Getter
@NoArgsConstructor
Expand All @@ -14,6 +16,9 @@ public class PinByMyCategoryResponse{
Long storeId;
String storeName;
String address;
String reviewImg;
List<String> reviewImg3;
String img1;
String img2;
String img3;
Integer reviewCnt;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.umc.gusto.domain.myCategory.model.response.PinByMyCategoryResponse;
import com.umc.gusto.domain.myCategory.repository.MyCategoryRepository;
import com.umc.gusto.domain.myCategory.repository.PinRepository;
import com.umc.gusto.domain.review.entity.Review;
import com.umc.gusto.domain.review.repository.ReviewRepository;
import com.umc.gusto.domain.store.entity.Store;
import com.umc.gusto.domain.user.entity.User;
Expand All @@ -20,6 +19,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;

Expand All @@ -29,6 +29,7 @@

@Service
@RequiredArgsConstructor
@EnableScheduling
public class MyCategoryServiceImpl implements MyCategoryService {

private final MyCategoryRepository myCategoryRepository;
Expand Down Expand Up @@ -163,16 +164,18 @@ public PagingResponse getAllPinByMyCategory(User user, String nickname, Long myC
List<PinByMyCategoryResponse> result = pinList.stream() // townName을 기준으로 보일 수 있는 store가 포함된 pin만 보이기
.map(pin -> {
Store store = pin.getStore();
Optional<Review> topReviewOptional = reviewRepository.findFirstByStoreOrderByLikedDesc(store); // 가장 좋아요가 많은 review
String reviewImg = topReviewOptional.map(Review::getImg1).orElse(""); // 가장 좋아요가 많은 review 이미지(TO DO: 3개 출력으로 변경)
Integer reviewCnt = reviewRepository.countByStoreAndUserNickname(store, finalUser.getNickname()); // 내가 작성한 리뷰의 개수 == 방문 횟수
// 가장 좋아요가 많은 review

Integer reviewCnt = reviewRepository.countByStoreAndUserNickname(store, finalUser.getNickname()); // 내가 작성한 리뷰의 개수 == 방문 횟수

return PinByMyCategoryResponse.builder()
.pinId(pin.getPinId())
.storeId(store.getStoreId())
.storeName(store.getStoreName())
.address(store.getAddress())
.reviewImg(reviewImg)
.img1(store.getImg1() != null ? store.getImg1() : "")
.img2(store.getImg2() != null ? store.getImg2() : "")
.img3(store.getImg3() != null ? store.getImg3() : "")
.reviewCnt(reviewCnt)
.build();
})
Expand All @@ -184,6 +187,7 @@ public PagingResponse getAllPinByMyCategory(User user, String nickname, Long myC
.build();
}


@Transactional
public void createMyCategory(User user, CreateMyCategoryRequest createMyCategory) {
// 중복 이름 체크
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.umc.gusto.domain.review.model.request.CreateReviewRequest;
import com.umc.gusto.domain.review.model.request.UpdateReviewRequest;
import com.umc.gusto.domain.review.model.response.ReviewDetailResponse;
import com.umc.gusto.domain.store.entity.Store;
import com.umc.gusto.domain.user.entity.User;
import org.springframework.web.multipart.MultipartFile;

Expand All @@ -16,4 +17,5 @@ public interface ReviewService {
ReviewDetailResponse getReview(Long reviewId);
void likeReview(User user, Long reviewId);
void unlikeReview(User user, Long reviewId);
void updateStoreImages(Store store);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@
import com.umc.gusto.global.exception.customException.NotFoundException;
import com.umc.gusto.global.exception.customException.PrivateItemException;
import com.umc.gusto.global.util.S3Service;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.transaction.annotation.Propagation;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -216,4 +218,15 @@ private void updateImages(List<MultipartFile> images, Review review){
if(imageUrls.size()>3) review.updateImg4(imageUrls.get(3));
}

@Transactional(propagation = Propagation.REQUIRES_NEW) // 메소드가 호출될 때마다 새로운 트랜잭션이 시작됨을 의미
public void updateStoreImages(Store store) {
List<Review> top4Reviews = reviewRepository.findFirst4ByStoreOrderByLikedDesc(store);
List<String> reviewImages = top4Reviews.stream()
.map(Review::getImg1)
.collect(Collectors.toList());

store.updateImages(reviewImages);
storeRepository.save(store);
}

}
27 changes: 27 additions & 0 deletions gusto/src/main/java/com/umc/gusto/domain/store/entity/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import java.util.List;

@Entity
@Getter
@Builder
Expand Down Expand Up @@ -58,6 +60,14 @@ public class Store extends BaseTime {
@Column(columnDefinition = "VARCHAR(20)")
private String contact;

private String img1;

private String img2;

private String img3;

private String img4;

@Builder.Default
@Enumerated(EnumType.STRING)
@Column(name = "status", nullable = false, length = 10)
Expand All @@ -66,5 +76,22 @@ public class Store extends BaseTime {
public enum StoreStatus {
ACTIVE, INACTIVE, CLOSED
}

public void updateImages(List<String> reviewImages) {
// reviewImages 리스트에서 이미지를 가져와 각 필드에 할당
if (!reviewImages.isEmpty()) {
this.img1 = reviewImages.get(0);
}
if (reviewImages.size() > 1) {
this.img2 = reviewImages.get(1);
}
if (reviewImages.size() > 2) {
this.img3 = reviewImages.get(2);
}
if (reviewImages.size() > 3) {
this.img4 = reviewImages.get(3);
}
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ public class GetStoreDetailResponse{
String storeName;
String address;
Boolean pin; // 찜 여부
List<String> reviewImg4;
String img1;
String img2;
String img3;
String img4;
PagingResponse reviews;

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ public class GetStoreInfoResponse {
String categoryString;
String storeName;
String address;
String reviewImg;
String img1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public class GetStoreResponse{
Double latitude;
Map<OpeningHours.BusinessDay, Timing> businessDay;
String contact;
List<String> reviewImg3;
String img1;
String img2;
String img3;
Boolean pin; // 찜 여부

// 하루 영업 시간을 나타내는 내부 클래스
Expand Down
Loading