Skip to content

Commit

Permalink
Merge pull request #119 from OurMenu/fix/onboarding
Browse files Browse the repository at this point in the history
Fix/onboarding
  • Loading branch information
david-parkk authored Aug 19, 2024
2 parents 03d1e8a + ed01976 commit 58324df
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,8 @@ public List<Menu> getAllMenusByTagName(String tag, Long userId){

@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> 반환

return menuRepository.findingMenusByCriteria3(tag);
}

public List<Menu> getAllMenusByTagNameAndUserIdNot(String tagName, Long userId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,37 +144,20 @@ List<Menu> findMenusByTagNamesInAndUserIdNotAndTagCountGreaterThanEqual(

/**
* 온보딩에 사용되는 쿼리
* @param tags
* @param menuFolderId
* @param userId
* @param minPrice
* @param maxPrice
* @param tagCount
* @param pageable
* @param tag
* @return
*/
@Query("SELECT m FROM Menu m WHERE m.id IN (" +
"SELECT MIN(m2.id) FROM Menu m2 " +
"SELECT 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);
"WHERE t.name IN :tag)")
List<Menu> findingMenusByCriteria3(
@Param("tag") String tag);


List<Menu> findOneByGroupIdAndUserId(Long groupId, Long userId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,25 @@
import lombok.EqualsAndHashCode;
import lombok.Getter;

import java.util.Objects;

@Getter
@AllArgsConstructor
@EqualsAndHashCode
public class MenuIdentifier {

private Long groupId;
private Long userId;

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MenuIdentifier that = (MenuIdentifier) o;
return Objects.equals(getGroupId(), that.getGroupId()) && Objects.equals(getUserId(), that.getUserId());
}

@Override
public int hashCode() {
return Objects.hash(getGroupId(), getUserId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public ApiResponse<GetQuestionRecommands> getQuestionRecommend(@RequestParam(val

menuList.addAll(onBoardService.findOtherUserMenusByQuestionAnswer(userId, questionId, answerType));


boundary = min(boundary, 14);
if (menuList.size() > 15) {
menuList = menuList.subList(0, 15);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.ourMenu.backend.domain.menu.application.MenuService;
import com.ourMenu.backend.domain.menu.dao.MenuRepository;
import com.ourMenu.backend.domain.menu.domain.Menu;
import com.ourMenu.backend.domain.menu.dto.MenuIdentifier;
import com.ourMenu.backend.domain.onboarding.dao.OnBoardingStateRepository;
import com.ourMenu.backend.domain.onboarding.domain.AnswerType;
import com.ourMenu.backend.domain.onboarding.domain.DefaultTag;
Expand Down Expand Up @@ -69,15 +70,20 @@ public List<Menu> findStoreByQuestionAnswer(Long userId, int questionId, AnswerT
@Transactional
public List<Menu> findOtherUserMenusByQuestionAnswer(Long userId, int questionId, AnswerType answerType) {
List<String> foodStringList = Question.getAnswerFoodByIdAndAnswerType(questionId, answerType);
Map<Long, Menu> map = new HashMap<>();
List<Menu> menuList = new ArrayList<>();

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

Map<MenuIdentifier,Menu> map = new HashMap<>();

for (Menu menu : menuList) {
if(menu.getUser().getId() == userId)
continue;
MenuIdentifier menuIdentifier = new MenuIdentifier(menu.getGroupId(),menu.getUser().getId());
map.put(menuIdentifier,menu);
}

return map.values().stream().toList();
Expand All @@ -89,7 +95,15 @@ public List<Menu> findStoreByRandomTag(Long userId, DefaultTag randomTag) {
}

public List<Menu> findOtherStoreByRandomTag(Long userId, DefaultTag randomTag) {
return menuService.getAllOtherMenusByTagName(randomTag.getTagName(), userId);
List<Menu> menuList = menuService.getAllOtherMenusByTagName(randomTag.getTagName(), userId);
Map<MenuIdentifier,Menu> map = new HashMap<>();
for (Menu menu : menuList) {
if(menu.getUser().getId() == userId)
continue;
MenuIdentifier menuIdentifier = new MenuIdentifier(menu.getGroupId(),menu.getUser().getId());
map.put(menuIdentifier,menu);
}
return map.values().stream().toList();
}

public List<Menu> findOtherUserStoreByRandomTag(Long userId, DefaultTag randomTag){
Expand Down

0 comments on commit 58324df

Please sign in to comment.