Skip to content

Commit

Permalink
Merge pull request #104 from OurMenu/fix/onboarding
Browse files Browse the repository at this point in the history
Fix/onboarding
  • Loading branch information
david-parkk authored Aug 16, 2024
2 parents 0ed6378 + eb595a5 commit 360f48d
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ public Article softDelete(Long id) {
@Transactional
public void hardDelete(Long id) {
Article article = findOne(id);
article.getArticleMenuList().forEach(articleMenu -> {
articleMenu.deleteArticle();
articleMenuRepository.delete(articleMenu);
});
articleRepository.delete(article);
articleMenuRepository.deleteAll(article.getArticleMenuList());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,12 @@ public List<Menu> getAllMenusByTagName(String tag, Long userId){
List<Menu> menuList = menuPage.getContent();
return menuList; // List<MenuDto> 반환
}

public List<Menu> getAllMenusByTagNameAndUserIdNot(String tagName, Long userId) {
return null;
//return menuRepository.findMenusByTagNameAndUserIdNot(tagName, userId);
}

@Transactional
public List<Menu> getAllMenusByGroupIdAndUserId(Long groupId, Long userId){
List<Menu> menuList = menuRepository.findByUserIdAndGroupId(userId, groupId);
Expand All @@ -405,4 +411,5 @@ public MenuIdDto getCertainMenuId(Long userId, Long menuFolderId, Long groupId)
public void updateModifiedAt(Menu menu){
menu.updateModifiedAt();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ 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);

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")
Optional<Menu> findMenuByUserId(@Param("menuId") Long menuId, @Param("userId") Long userId);

Expand All @@ -116,4 +118,17 @@ Page<Menu> findingMenusByCriteria2(
") ORDER BY m.modifiedAt DESC")
List<Menu> findDistinctByUserIdOrderByModifiedAtDesc(@Param("userId") Long userId, Pageable pageable);

@Query("SELECT m FROM Menu m WHERE m.user.id != :userId " +
"AND m.id IN (" +
" SELECT MIN(m2.id) FROM Menu m2 " + // 그룹 내에서 최소 ID를 선택
" JOIN m2.tags mt " +
" WHERE mt.tag.name IN :tagNames " +
" GROUP BY m2.groupId " + // groupId로 그룹화
" HAVING COUNT(DISTINCT mt.tag.name) >= :tagCount" +
")")
List<Menu> findMenusByTagNamesInAndUserIdNotAndTagCountGreaterThanEqual(
@Param("tagNames") List<String> tagNames,
@Param("userId") Long userId,
@Param("tagCount") int tagCount);

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public ApiResponse<GetQuestionRecommands> getQuestionRecommend(@RequestParam("qu
@RequestParam("answer") AnswerType answerType,
@UserId Long userId) {
List<Menu> menus = onBoardService.saveAndFindStoreByQuestionAnswer(userId, questionId, answerType);
//menus.addAll(onBoardService.findOtherUserMenusByQuestionAnswer(userId,questionId,answerType));
return ApiUtils.success(GetQuestionRecommands.toDto(menus, questionId, answerType));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class GetRecommend {
public static GetRecommend toDto(Menu menu){
return GetRecommend.builder()
.menuImgUrl(menu.getImages() != null && !menu.getImages().isEmpty() ? menu.getImages().get(0).getUrl() : null)
.menuImgUrl(menu.getTitle())
.placeName(menu.getPlace().getAddress())
.menuTitle(menu.getTitle())
.placeName(menu.getPlace().getTitle())
.groupId(menu.getGroupId())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,37 @@ public List<Menu> findStoreByQuestionAnswer(Long userId, int questionId, AnswerT
return map.values().stream().toList();
}

/**
* questionId와 answerType에 해당하는 메뉴를 가진 다른사람(본인의 것은 제외한다)의 유저의 메뉴를 가져온다
* @param userId
* @param questionId
* @param answerType
* @return
*/
@Transactional
public List<Menu> findOtherUserMenusByQuestionAnswer(Long userId, int questionId, AnswerType answerType) {
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 (Menu menu : menus) {
map.put(menu.getId(), menu);
}
}

return map.values().stream().toList();
}


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

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

@Transactional(readOnly = true)
public String findOnboardingStateByUserId(Long userId) {
OnBoardingState onBoardingState = findOneById(userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.ourMenu.backend.domain.user.application.AccountService;
import com.ourMenu.backend.domain.user.dao.UserDao;
import com.ourMenu.backend.global.common.Status;
import jakarta.persistence.EntityManager;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand All @@ -43,6 +44,8 @@ public class ArticleServiceTest {
MenuService menuService;
@Autowired
MenuListService menuListService;
@Autowired
EntityManager em;

ArticleMenu articleMenu1 = ArticleMenu.builder()
.title("제목1")
Expand Down Expand Up @@ -125,6 +128,7 @@ public void test4() {

//when
articleService.hardDelete(saveArticle.getId());

RuntimeException exception = org.junit.jupiter.api.Assertions.assertThrows(NoSuchArticleException.class, () -> {
Article softDeleteArticle = articleService.softDelete(1L);
Assertions.assertThat(softDeleteArticle.getStatus()).isEqualTo(Status.DELETED);
Expand Down

0 comments on commit 360f48d

Please sign in to comment.