Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public class CafeteriaControllerV2 {
public String responseCafeteriaOrCampusListCard(@RequestBody RequestDto requestDto) {
// userId로 campusId 찾기
String userId = requestDto.getUserRequest().getUser().getId();
int campusId = userServiceV2.getUserCampusId(userId);
int userCampusId = userServiceV2.getUserCampusId(userId);
int sysCampusId = requestDto.getAction().getClientExtra().getSys_campus_id();

return cafeteriaServiceV2.campusOrCafeteria(campusId, sysCampusId);
return cafeteriaServiceV2.campusOrCafeteria(userCampusId, sysCampusId);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.Jinus.service.v2.cafeteria;

import com.example.Jinus.repository.v2.cafeteria.CafeteriaRepositoryV2;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class CafeteriaQueryServiceV2 {
private final CafeteriaRepositoryV2 cafeteriaRepositoryV2;

@Cacheable(value = "cafeteriaId", key = "#campusId + '::' + #cafeteriaName",
unless = "#result == -1",
cacheManager = "contentCacheManager")
public int getCafeteriaId(String cafeteriaName, int campusId) {
return cafeteriaRepositoryV2.findCafeteriaId(cafeteriaName, campusId).orElse(-1);
}

public String getImgUrl(int cafeteriaId) {
return cafeteriaRepositoryV2.findImgUrlByCafeteriaId(cafeteriaId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.example.Jinus.service.v2.cafeteria;

import com.example.Jinus.dto.data.CafeteriaDto;
import com.example.Jinus.dto.response.ButtonDto;
import com.example.Jinus.dto.response.ListItemDto;
import com.example.Jinus.dto.response.ResponseDto;
import com.example.Jinus.utility.JsonUtils;
import com.example.Jinus.utility.ListCardResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@RequiredArgsConstructor
public class CafeteriaResponseServiceV2 {

// 식당 리스트 카드 생성
public String createCafeteriaListCard(String campusName, List<CafeteriaDto> cafeteriaList) {
List<ListItemDto> listItems = mappingCafeteriaList(campusName, cafeteriaList);
ResponseDto responseDto = ListCardResponse.mappingResponseDto(
"어떤 교내 식당 정보가 알고 싶어?", listItems, mappingButtonDto()
);
return JsonUtils.toJsonResponse(responseDto);
}

// 식당 아이템 객체 생성
private List<ListItemDto> mappingCafeteriaList(String campusName, List<CafeteriaDto> cafeteriaList) {
List<ListItemDto> listItems = new ArrayList<>();
for (CafeteriaDto cafeteria : cafeteriaList) {
String userMessage = campusName + " " + cafeteria.getCafeteriaNameKo();
ListItemDto listItem = new ListItemDto(
cafeteria.getCafeteriaNameKo(), campusName,
cafeteria.getThumbnailUrl(), "message", userMessage
);
listItems.add(listItem);
}
return listItems;
}

// 더보기 버튼 생성
private List<ButtonDto> mappingButtonDto() {
List<ButtonDto> buttonDto = new ArrayList<>();
Map<String, Object> extra = new HashMap<>();
extra.put("sys_campus_id", -1);
buttonDto.add(new ButtonDto("더보기", "block", "66067167cdd882158c759fc2", extra));
return buttonDto;
}
}
Original file line number Diff line number Diff line change
@@ -1,102 +1,111 @@
package com.example.Jinus.service.v2.cafeteria;

import com.example.Jinus.dto.data.CafeteriaDto;
import com.example.Jinus.dto.response.ButtonDto;
import com.example.Jinus.dto.response.ListItemDto;
import com.example.Jinus.dto.response.ResponseDto;
import com.example.Jinus.repository.v2.cafeteria.CafeteriaRepositoryV2;
import com.example.Jinus.utility.JsonUtils;
import com.example.Jinus.utility.ListCardResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@RequiredArgsConstructor
public class CafeteriaServiceV2 {

private final CafeteriaRepositoryV2 cafeteriaRepositoryV2;
private final CampusServiceV2 campusServiceV2;
private final CacheServiceV2 cacheServiceV2;
private final CafeteriaResponseServiceV2 cafeteriaResponseServiceV2;


// 반환 조건 설정
public String campusOrCafeteria(int campusId, int sysCampusId) {
// 더보기 버튼 누른 경우
if (sysCampusId == -1) {
// 사용자가 선택한 블록 ID값에 따라 반환 조건 설정
// campusId가 -1이면 사용자 정보가 존재하지 않는 경우임
public String campusOrCafeteria(int userCampusId, int sysCampusId) {
if (sysCampusId == -1) { // 더보기 버튼 누른 경우 -> 캠퍼스 리스트 반환
return campusServiceV2.makeCampusListCard();
}

// 사용자가 원하는 캠퍼스가 있을 때
if (sysCampusId > 0) {
return makeCafeteriaListCard(sysCampusId);
}

// 사용자가 원하는 캠퍼스가 없을 때
return (campusId != -1) // 사용자 존재 여부
? makeCafeteriaListCard(campusId)
: campusServiceV2.makeCampusListCard();
// 사용자가 캠퍼스를 선택한 경우
int targetCampusId = (sysCampusId > 0) ? sysCampusId : userCampusId;
return (targetCampusId != -1) // 사용자 정보 DB 존재 여부
? returnCafeteriaListCard(targetCampusId) // 존재 O -> 식당 정보 반환
: campusServiceV2.makeCampusListCard(); // 존재 X -> 캠퍼스 정보 반환
}

// 식당 리스트 반환 메소드
private String makeCafeteriaListCard(int campusId) {
// 식당 리스트 반환
private String returnCafeteriaListCard(int campusId) {
String campusName = campusServiceV2.getUserCampusName(campusId);
List<CafeteriaDto> cafeteriaList = cacheServiceV2.getCafeteriaList(campusId);

// 식당 리스트 객체 생성
List<ListItemDto> listItems = mappingCafeteriaList(campusName, cafeteriaList);
// response 객체 생성
ResponseDto responseDto = ListCardResponse.mappingResponseDto("어떤 교내 식당 정보가 알고싶어 ?", listItems, mappingButtonDto());

return JsonUtils.toJsonResponse(responseDto);
return cafeteriaResponseServiceV2.createCafeteriaListCard(campusName, cafeteriaList);
}

// // 반환 조건 설정
// public String campusOrCafeteria(int campusId, int sysCampusId) {
// // 더보기 버튼 누른 경우
// if (sysCampusId == -1) {
// return campusServiceV2.makeCampusListCard();
// }
//
// // 사용자가 원하는 캠퍼스가 있을 때
// if (sysCampusId > 0) {
// return makeCafeteriaListCard(sysCampusId);
// }
//
// // 사용자가 원하는 캠퍼스가 없을 때
// return (campusId != -1) // 사용자 존재 여부
// ? makeCafeteriaListCard(campusId)
// : campusServiceV2.makeCampusListCard();
// }
//
// // 식당 리스트 반환 메소드
// private String makeCafeteriaListCard(int campusId) {
// String campusName = campusServiceV2.getUserCampusName(campusId);
// List<CafeteriaDto> cafeteriaList = cacheServiceV2.getCafeteriaList(campusId);
//
// // 식당 리스트 객체 생성
// List<ListItemDto> listItems = mappingCafeteriaList(campusName, cafeteriaList);
// // response 객체 생성
// ResponseDto responseDto = ListCardResponse.mappingResponseDto("어떤 교내 식당 정보가 알고싶어 ?", listItems, mappingButtonDto());
//
// return JsonUtils.toJsonResponse(responseDto);
// }
//
//
// // 식당 리스트 객체 생성
// private List<ListItemDto> mappingCafeteriaList(String campusName, List<CafeteriaDto> cafeteriaList) {
// List<ListItemDto> listItems = new ArrayList<>();
// for (CafeteriaDto cafeteria : cafeteriaList) {
// String userMessage = campusName + " " + cafeteria.getCafeteriaNameKo();
//
// // 리스트 아이템 객체 생성
// ListItemDto listItem = new ListItemDto(cafeteria.getCafeteriaNameKo(), campusName,
// cafeteria.getThumbnailUrl(), "message", userMessage);
// listItems.add(listItem);
// }
// return listItems;
// }
//
//
// // 더보기 버튼 리스트 생성
// private List<ButtonDto> mappingButtonDto() {
// List<ButtonDto> buttonDto = new ArrayList<>();
// Map<String, Object> extra = new HashMap<>();
// extra.put("sys_campus_id", -1);
// // 버튼 객체 생성
// ButtonDto button = new ButtonDto("더보기", "block", "66067167cdd882158c759fc2", extra);
// buttonDto.add(button);
// return buttonDto;
// }
//
//
//
// @Cacheable(value = "cafeteriaId", key = "#campusId + '::' + #cafeteriaName",
// unless = "#result == -1",
// cacheManager = "contentCacheManager")
// // 캠퍼스에 식당이 존재한다면 cafeteriaId 찾기
// public int getCafeteriaId(String cafeteriaName, int campusId) {
// return cafeteriaRepositoryV2.findCafeteriaId(cafeteriaName, campusId).orElse(-1);
// }
//
//
// // 식당 imgUrl 찾기
// public String getImgUrl(int cafeteriaId) {
// return cafeteriaRepositoryV2.findImgUrlByCafeteriaId(cafeteriaId);
// }

// 식당 리스트 객체 생성
private List<ListItemDto> mappingCafeteriaList(String campusName, List<CafeteriaDto> cafeteriaList) {
List<ListItemDto> listItems = new ArrayList<>();
for (CafeteriaDto cafeteria : cafeteriaList) {
String userMessage = campusName + " " + cafeteria.getCafeteriaNameKo();

// 리스트 아이템 객체 생성
ListItemDto listItem = new ListItemDto(cafeteria.getCafeteriaNameKo(), campusName,
cafeteria.getThumbnailUrl(), "message", userMessage);
listItems.add(listItem);
}
return listItems;
}


// 더보기 버튼 리스트 생성
private List<ButtonDto> mappingButtonDto() {
List<ButtonDto> buttonDto = new ArrayList<>();
Map<String, Object> extra = new HashMap<>();
extra.put("sys_campus_id", -1);
// 버튼 객체 생성
ButtonDto button = new ButtonDto("더보기", "block", "66067167cdd882158c759fc2", extra);
buttonDto.add(button);
return buttonDto;
}



@Cacheable(value = "cafeteriaId", key = "#campusId + '::' + #cafeteriaName",
unless = "#result == -1",
cacheManager = "contentCacheManager")
// 캠퍼스에 식당이 존재한다면 cafeteriaId 찾기
public int getCafeteriaId(String cafeteriaName, int campusId) {
return cafeteriaRepositoryV2.findCafeteriaId(cafeteriaName, campusId).orElse(-1);
}


// 식당 imgUrl 찾기
public String getImgUrl(int cafeteriaId) {
return cafeteriaRepositoryV2.findImgUrlByCafeteriaId(cafeteriaId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
public class DietServiceV2 {
private final DietRepositoryV2 dietRepositoryV2;
private final CampusServiceV2 campusServiceV2;
private final CafeteriaServiceV2 cafeteriaServiceV2;
private final UserServiceV2 userServiceV2;
private final CacheServiceV2 dietCacheServiceV2;
private final CafeteriaQueryServiceV2 queryServiceV2;

// 식단 데이터 찾기 위해 필요한 파라미터 추출 및 초기화
public String requestHandler(RequestDto requestDto) {
Expand Down Expand Up @@ -70,7 +70,7 @@ private Optional<String> extractValue(DetailParamsItemFieldDto fieldDto) {
// response 생성 로직
private String makeResponse(HandleRequestDto parameters) {
int campusId = campusServiceV2.getCampusId(parameters.getCampusName());
int cafeteriaId = cafeteriaServiceV2.getCafeteriaId(parameters.getCafeteriaName(), campusId);
int cafeteriaId = queryServiceV2.getCafeteriaId(parameters.getCafeteriaName(), campusId);

// 캠퍼스에 식당이 존재하지 않는 경우
if (cafeteriaId == -1) {
Expand Down Expand Up @@ -144,7 +144,7 @@ private StringBuilder processDietList(MultiValueMap<String, String> dietList) {
// 응답 내용 초기화
private String makeContents(HandleRequestDto parameters, int cafeteriaId, String diets) {
// 식당 img 찾기
String imgUrl = cafeteriaServiceV2.getImgUrl(cafeteriaId);
String imgUrl = queryServiceV2.getImgUrl(cafeteriaId);

// title 데이터 연결
String title = "\uD83C\uDF71 " +
Expand Down