Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/onboarding #114

Merged
merged 4 commits into from
Aug 19, 2024
Merged
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
2 changes: 1 addition & 1 deletion mysql/init/init.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use users_db
use users_db;

create table article (
menu_count integer not null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.ourMenu.backend.domain.menu.dto;

import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;

@Getter
@AllArgsConstructor
@EqualsAndHashCode
public class MenuIdentifier {

private Long groupId;
private Long userId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

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

import static java.lang.Math.min;

@RestController
@RequiredArgsConstructor
Expand Down Expand Up @@ -50,13 +51,16 @@ public ApiResponse<GetQuestionRecommands> getQuestionRecommend(@RequestParam(val
}
List<Menu> menuList = new ArrayList<>();
menuList.addAll(onBoardService.saveAndFindStoreByQuestionAnswer(userId, questionId, answerType));
int boundary = menuList.size() - 1;

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

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

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

}

Expand All @@ -67,7 +71,7 @@ public ApiResponse<List<GetTagRecommends>> getQuestionRecommend(@UserId Long use
List<GetTagRecommends> getTagRecommendsList = new ArrayList<>();
for (DefaultTag defaultTag : defaultTagList) {
List<Menu> menuList1 = onBoardService.findStoreByRandomTag(userId, defaultTag);
getTagRecommendsList.add(GetTagRecommends.toDto(menuList1, defaultTag));
getTagRecommendsList.add(GetTagRecommends.toDtoOwn(menuList1, defaultTag));

List<Menu> menuList2 = onBoardService.findOtherStoreByRandomTag(userId, defaultTag);
getTagRecommendsList.get(getTagRecommendsList.size()-1).addAll(menuList2);
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;

@Getter
Expand All @@ -17,8 +18,16 @@ public class GetQuestionRecommands {
private String recommendImgUrl;
private List<GetRecommend> menus;

public static GetQuestionRecommands toDto(List<Menu> menus, int questionId, AnswerType answerType) {
List<GetRecommend> recommandList = menus.stream().map(GetRecommend::toDto).toList();
public static GetQuestionRecommands toDto(List<Menu> menus, int questionId, AnswerType answerType,int boundary) {
List<GetRecommend> recommandList = new ArrayList<>();
for(int i=0 ;i<menus.size();i++){
boolean isUserOwned = false;
if(i<=boundary)
isUserOwned = true;
GetRecommend getRecommend = GetRecommend.toDto(menus.get(i), isUserOwned);
recommandList.add(getRecommend);
}

String recommandImgUrl = Question.getImgUrlByIdAndAnswerType(questionId, answerType);
return GetQuestionRecommands.builder()
.recommendImgUrl(recommandImgUrl)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ public class GetRecommend {
private String menuTitle;
private String placeName;
private Long groupId;
public static GetRecommend toDto(Menu menu){
private boolean isUserOwned;
public static GetRecommend toDto(Menu menu, boolean isUserOwned){
return GetRecommend.builder()
.menuImgUrl(menu.getImages() != null && !menu.getImages().isEmpty() ? menu.getImages().get(0).getUrl() : null)
.menuTitle(menu.getTitle())
.placeName(menu.getPlace().getTitle())
.groupId(menu.getGroupId())
.isUserOwned(isUserOwned)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.ourMenu.backend.domain.onboarding.api.response;

import com.ourMenu.backend.domain.menu.domain.Menu;
import com.ourMenu.backend.domain.menu.dto.response.MenuDto;
import com.ourMenu.backend.domain.onboarding.domain.DefaultTag;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -20,8 +19,17 @@ public class GetTagRecommends {
private List<GetRecommend> menus;


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

}

public static GetTagRecommends toDtoOther(List<Menu> menuList, DefaultTag tag) {
List<GetRecommend> recommandList = menuList.stream().map(menu->GetRecommend.toDto(menu,false)).toList();
return GetTagRecommends.builder()
.tagName(tag.getTagMemo())
.menus(new ArrayList<>(recommandList))
Expand All @@ -30,7 +38,7 @@ public static GetTagRecommends toDto(List<Menu> menuList, DefaultTag tag) {
}

public void addAll(List<Menu> menuList) {
List<GetRecommend> recommandList = menuList.stream().map(GetRecommend::toDto).toList();
List<GetRecommend> recommandList = menuList.stream().map(menu->GetRecommend.toDto(menu,false)).toList();
if (menus == null) {
menus = new ArrayList<>(); // 가변 리스트로 초기화
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public enum DefaultTag {
HOT_SPICY("얼큰함", "얼큰함이 살아있는, "),
SOLO("혼밥", "혼자 밥먹기 좋은 곳,"),
WARM("뜨끈함", "땀나는 뜨끈함,"),
BUSINESS("비즈니스미팅", "비즈니스미팅이 있을 땐,"),
PROMISE("친구약속", "친구와 약속이 있다면?"),
BUSINESS("비즈니스 미팅", "비즈니스미팅이 있을 땐,"),
PROMISE("친구 약속", "친구와 약속이 있다면?"),
DATE("데이트", "데이트 하는 날엔,"),
BUY_FOOD("밥약", "밥약하기 좋은 곳,"),
ORGANIZATION("단체", "단체로 방문한다면,");
Expand Down
Loading