Skip to content

Commit

Permalink
feat: othermenuby tag #102
Browse files Browse the repository at this point in the history
  • Loading branch information
david-parkk committed Aug 18, 2024
1 parent cd04c4a commit fbd6954
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,16 @@ public List<Menu> getAllMenusByTagName(String tag, Long userId){
return menuList; // List<MenuDto> 반환
}

@Transactional
public List<Menu> getAllOtherMenusByTagName(String tag, Long userId){
String[] integers = {tag};
int tagCount = integers.length;
Pageable pageable = PageRequest.of(0, 5);
Page<Menu> menuPage = menuRepository.findingMenusByCriteria3(integers, null, 0, 999999, tagCount, pageable);
List<Menu> menuList = menuPage.getContent();
return menuList; // List<MenuDto> 반환
}

public List<Menu> getAllMenusByTagNameAndUserIdNot(String tagName, Long userId) {
return null;
//return menuRepository.findMenusByTagNameAndUserIdNot(tagName, userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ Page<Menu> findingMenusByCriteria2(
@Query("SELECT m FROM Menu m WHERE m.title LIKE %:title% AND m.user.id = :userId")
List<Menu> findMenusByTitleContainingAndUserId(@Param("title") String title, @Param("userId") Long userId);

@Query("SELECT m FROM Menu m WHERE m.title LIKE %:title%")
List<Menu> findMenusByTitleContaining(@Param("title") String title);

List<Menu> findMenusByTitleContainingAndUserIdNot(@Param("title") String title, @Param("userId") Long userId);

@Query("SELECT m FROM Menu m WHERE m.id = :menuId AND m.user.id = :userId")
Expand Down Expand Up @@ -128,4 +131,37 @@ List<Menu> findMenusByTagNamesInAndUserIdNotAndTagCountGreaterThanEqual(
@Param("userId") Long userId,
@Param("tagCount") int tagCount);


/**
* 온보딩에 사용되는 쿼리
* @param tags
* @param menuFolderId
* @param userId
* @param minPrice
* @param maxPrice
* @param tagCount
* @param pageable
* @return
*/
@Query("SELECT m FROM Menu m WHERE m.id IN (" +
"SELECT MIN(m2.id) FROM Menu m2 " +
"JOIN m2.place p " +
"LEFT JOIN m2.images mi " +
"LEFT JOIN m2.tags mt " +
"LEFT JOIN mt.tag t " +
"WHERE (:tags IS NULL OR (t.name IN :tags)) " +
"AND (:menuFolderId IS NULL OR m2.menuList.id = :menuFolderId) " +
"AND (:minPrice IS NULL OR m2.price >= :minPrice) " +
"AND (:maxPrice IS NULL OR m2.price <= :maxPrice) " +
"GROUP BY m2.groupId " +
"HAVING COUNT(DISTINCT t.name) >= :tagCount" +
")")

Page<Menu> findingMenusByCriteria3(
@Param("tags") String[] tags, // 태그 배열로 변경
@Param("menuFolderId") Integer menuFolderId,
@Param("minPrice") Integer minPrice,
@Param("maxPrice") Integer maxPrice,
@Param("tagCount") Integer tagCount, // 태그 개수 추가
Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,15 @@ public ApiResponse<GetQuestionRecommands> getQuestionRecommend(@RequestParam(val
if(answerType == null){
answerType = S3Util.getRandomAnswerType();
}
List<Menu> menus = onBoardService.saveAndFindStoreByQuestionAnswer(userId, questionId, answerType);
//menus.addAll(onBoardService.findOtherUserMenusByQuestionAnswer(userId,questionId,answerType));
return ApiUtils.success(GetQuestionRecommands.toDto(menus, questionId, answerType));
List<Menu> menuList = new ArrayList<>();
menuList.addAll(onBoardService.saveAndFindStoreByQuestionAnswer(userId, questionId, answerType));
menuList.addAll(onBoardService.findOtherUserMenusByQuestionAnswer(userId, questionId, answerType));

if (menuList.size() > 15) {
menuList = menuList.subList(0, 15);
}

return ApiUtils.success(GetQuestionRecommands.toDto(menuList, questionId, answerType));

}

Expand All @@ -60,10 +66,16 @@ public ApiResponse<List<GetTagRecommends>> getQuestionRecommend(@UserId Long use

List<GetTagRecommends> getTagRecommendsList = new ArrayList<>();
for (DefaultTag defaultTag : defaultTagList) {
List<Menu> menuList = onBoardService.findStoreByRandomTag(userId, defaultTag);
getTagRecommendsList.add(GetTagRecommends.toDto(menuList, defaultTag));
List<Menu> menuList1 = onBoardService.findStoreByRandomTag(userId, defaultTag);
getTagRecommendsList.add(GetTagRecommends.toDto(menuList1, defaultTag));

List<Menu> menuList2 = onBoardService.findOtherStoreByRandomTag(userId, defaultTag);
getTagRecommendsList.get(getTagRecommendsList.size()-1).addAll(menuList2);
}

if (getTagRecommendsList.size() > 15) {
getTagRecommendsList = getTagRecommendsList.subList(0, 15);
}
return ApiUtils.success(getTagRecommendsList);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.Builder;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

@AllArgsConstructor
Expand All @@ -19,12 +20,20 @@ public class GetTagRecommends {
private List<GetRecommend> menus;


public static GetTagRecommends toDto(List<Menu> menus, DefaultTag tag) {
List<GetRecommend> recommandList = menus.stream().map(GetRecommend::toDto).toList();
public static GetTagRecommends toDto(List<Menu> menuList, DefaultTag tag) {
List<GetRecommend> recommandList = menuList.stream().map(GetRecommend::toDto).toList();
return GetTagRecommends.builder()
.tagName(tag.getTagMemo())
.menus(recommandList)
.menus(new ArrayList<>(recommandList))
.build();

}

public void addAll(List<Menu> menuList) {
List<GetRecommend> recommandList = menuList.stream().map(GetRecommend::toDto).toList();
if (menus == null) {
menus = new ArrayList<>(); // 가변 리스트로 초기화
}
menus.addAll(recommandList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ public List<Menu> findOtherUserMenusByQuestionAnswer(Long userId, int questionId
List<String> foodStringList = Question.getAnswerFoodByIdAndAnswerType(questionId, answerType);
Map<Long, Menu> map = new HashMap<>();

for (String s : foodStringList) {
List<Menu> menus = menuRepository.findMenusByTitleContainingAndUserIdNot(s, userId);
for (String foodString : foodStringList) {
List<Menu> menus = menuRepository.findMenusByTitleContaining(foodString);
for (Menu menu : menus) {
map.put(menu.getId(), menu);
if(menu.getUser().getId().equals(userId))
continue;
map.put(menu.getGroupId(), menu);
}
}

Expand All @@ -86,6 +88,10 @@ public List<Menu> findStoreByRandomTag(Long userId, DefaultTag randomTag) {
return menuService.getAllMenusByTagName(randomTag.getTagName(), userId);
}

public List<Menu> findOtherStoreByRandomTag(Long userId, DefaultTag randomTag) {
return menuService.getAllOtherMenusByTagName(randomTag.getTagName(), userId);
}

public List<Menu> findOtherUserStoreByRandomTag(Long userId, DefaultTag randomTag){
return menuService.getAllMenusByTagNameAndUserIdNot(randomTag.getTagName(), userId);
}
Expand All @@ -109,4 +115,6 @@ public OnBoardingState findOneById(Long userId) {
public OnBoardingState save(OnBoardingState onBoardingState) {
return onBoardingStateRepository.save(onBoardingState);
}


}

0 comments on commit fbd6954

Please sign in to comment.