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

BE 환경에 반영 #496

Merged
merged 3 commits into from
Sep 17, 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
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@

import com.gaebaljip.exceed.adapter.in.meal.response.GetMealFoodResponse;
import com.gaebaljip.exceed.adapter.in.meal.response.GetMealResponse;
import com.gaebaljip.exceed.adapter.in.member.response.GetMealAndWeightResponse;
import com.gaebaljip.exceed.adapter.in.member.response.GetWeightDTO;
import com.gaebaljip.exceed.adapter.in.nutritionist.request.GetAllAnalysisRequest;
import com.gaebaljip.exceed.application.port.in.meal.GetCurrentMealQuery;
import com.gaebaljip.exceed.application.port.in.meal.GetSpecificMealQuery;
import com.gaebaljip.exceed.application.port.in.meal.ValidateBeforeSignUpDateUsecase;
import com.gaebaljip.exceed.application.port.in.member.GetMaintainMealUsecase;
import com.gaebaljip.exceed.application.port.in.member.GetTargetMealUsecase;
import com.gaebaljip.exceed.application.port.in.member.GetMaintainNutritionUsecase;
import com.gaebaljip.exceed.application.port.in.member.GetTargetNutritionUsecase;
import com.gaebaljip.exceed.application.port.in.member.GetWeightUseCase;
import com.gaebaljip.exceed.application.service.nutritionist.GetAllCalorieAnalysisService;
import com.gaebaljip.exceed.common.ApiResponse;
import com.gaebaljip.exceed.common.ApiResponseGenerator;
Expand All @@ -42,24 +45,28 @@
@Tag(name = "[식사 조회]")
public class GetMealController {

private final GetMaintainMealUsecase getMaintainMealUsecase;
private final GetTargetMealUsecase getTargetMealUsecase;
private final GetMaintainNutritionUsecase getMaintainNutritionUsecase;
private final GetTargetNutritionUsecase getTargetNutritionUsecase;
private final GetCurrentMealQuery getCurrentMealQuery;
private final GetSpecificMealQuery getSpecificMealQuery;
private final GetAllCalorieAnalysisService getAllCalorieAnalysisService;
private final ValidateBeforeSignUpDateUsecase validateBeforeSignUpDateUsecase;
private final GetWeightUseCase getWeightUseCase;

/** 오늘 먹은 식사 정보(단,탄,지 및 칼로리) 조회 */
@Operation(summary = "오늘 먹은 식사 정보 조회", description = "오늘 먹은 식사 정보(단,탄,지 및 칼로리)를 조회한다.")
@GetMapping("/meal")
@ApiErrorExceptionsExample(GetMealExceptionDocs.class)
public ApiResponse<ApiResponse.CustomBody<GetMealResponse>> getMeal(
public ApiResponse<ApiResponse.CustomBody<GetMealAndWeightResponse>> getMeal(
@Parameter(hidden = true) @AuthenticationMemberId Long memberId) {
MaintainMealDTO maintainMealDTO = getMaintainMealUsecase.execute(memberId);
TargetMealDTO targetMealDTO = getTargetMealUsecase.execute(memberId);
MaintainMealDTO maintainMealDTO = getMaintainNutritionUsecase.execute(memberId);
TargetMealDTO targetMealDTO = getTargetNutritionUsecase.execute(memberId);
GetWeightDTO getWeightDTO = getWeightUseCase.execute(memberId);
CurrentMealDTO currentMealDTO = getCurrentMealQuery.execute(memberId);
return ApiResponseGenerator.success(
new GetMealResponse(maintainMealDTO, targetMealDTO, currentMealDTO), HttpStatus.OK);
GetMealAndWeightResponse.of(
maintainMealDTO, targetMealDTO, getWeightDTO, currentMealDTO),
HttpStatus.OK);
}

/** 특정 날짜의 식사 정보(단,탄,지 및 칼로지) 조회 */
Expand All @@ -71,8 +78,9 @@ public ApiResponse<ApiResponse.CustomBody<GetMealFoodResponse>> getMealFood(
@Parameter(hidden = true) @AuthenticationMemberId Long memberId) {
LocalDateTime localDateTime = date.atStartOfDay();
validateBeforeSignUpDateUsecase.execute(memberId, localDateTime);
MaintainMealDTO maintainMealDTO = getMaintainMealUsecase.execute(memberId, localDateTime);
TargetMealDTO targetMealDTO = getTargetMealUsecase.execute(memberId, localDateTime);
MaintainMealDTO maintainMealDTO =
getMaintainNutritionUsecase.execute(memberId, localDateTime);
TargetMealDTO targetMealDTO = getTargetNutritionUsecase.execute(memberId, localDateTime);
SpecificMealDTO specificMealDTO = getSpecificMealQuery.execute(memberId, localDateTime);

AllAnalysisDTO allAnalysisDTO =
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.gaebaljip.exceed.adapter.in.member.response;

public record GetWeightDTO(Double weight, Double targetWeight) {

public static GetWeightDTO of(Double weight, Double targetWeight) {
return new GetWeightDTO(weight, targetWeight);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.gaebaljip.exceed.common.dto.MaintainMealDTO;

@Component
public interface GetMaintainMealUsecase {
public interface GetMaintainNutritionUsecase {
MaintainMealDTO execute(Long memberId);

MaintainMealDTO execute(Long memberId, LocalDateTime date);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.gaebaljip.exceed.common.dto.TargetMealDTO;

@Component
public interface GetTargetMealUsecase {
public interface GetTargetNutritionUsecase {
TargetMealDTO execute(Long memberId);

TargetMealDTO execute(Long memberId, LocalDateTime date);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.gaebaljip.exceed.application.port.in.member;

import com.gaebaljip.exceed.adapter.in.member.response.GetWeightResponse;
import com.gaebaljip.exceed.adapter.in.member.response.GetWeightDTO;

public interface GetWeightUseCase {
GetWeightResponse execute(Long memberId);
GetWeightDTO execute(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

import com.gaebaljip.exceed.application.domain.member.Member;
import com.gaebaljip.exceed.application.domain.member.MemberEntity;
import com.gaebaljip.exceed.application.port.in.member.GetMaintainMealUsecase;
import com.gaebaljip.exceed.application.port.in.member.GetMaintainNutritionUsecase;
import com.gaebaljip.exceed.application.port.out.member.MemberPort;
import com.gaebaljip.exceed.common.annotation.Timer;
import com.gaebaljip.exceed.common.dto.MaintainMealDTO;

import lombok.RequiredArgsConstructor;
Expand All @@ -22,7 +21,7 @@
*/
@Service
@RequiredArgsConstructor
public class GetMaintainMealService implements GetMaintainMealUsecase {
public class GetMaintainNutritionService implements GetMaintainNutritionUsecase {

private final MemberPort memberPort;
private final MemberConverter memberConverter;
Expand All @@ -35,7 +34,6 @@ public class GetMaintainMealService implements GetMaintainMealUsecase {
*/
@Override
@Transactional(readOnly = true)
@Timer
public MaintainMealDTO execute(Long memberId) {
MemberEntity memberEntity = memberPort.query(memberId);
Member member = memberConverter.toModel(memberEntity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import com.gaebaljip.exceed.application.domain.member.Member;
import com.gaebaljip.exceed.application.domain.member.MemberEntity;
import com.gaebaljip.exceed.application.port.in.member.GetTargetMealUsecase;
import com.gaebaljip.exceed.application.port.in.member.GetTargetNutritionUsecase;
import com.gaebaljip.exceed.application.port.out.member.MemberPort;
import com.gaebaljip.exceed.common.annotation.Timer;
import com.gaebaljip.exceed.common.dto.TargetMealDTO;
Expand All @@ -22,7 +22,7 @@
*/
@Service
@RequiredArgsConstructor
public class GetTargetMealService implements GetTargetMealUsecase {
public class GetTargetNutritionService implements GetTargetNutritionUsecase {

private final MemberPort memberPort;
private final MemberConverter memberConverter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.gaebaljip.exceed.adapter.in.member.response.GetWeightResponse;
import com.gaebaljip.exceed.adapter.in.member.response.GetWeightDTO;
import com.gaebaljip.exceed.application.domain.member.Member;
import com.gaebaljip.exceed.application.domain.member.MemberEntity;
import com.gaebaljip.exceed.application.port.in.member.GetWeightUseCase;
Expand All @@ -19,9 +19,9 @@ public class GetWeightService implements GetWeightUseCase {

@Override
@Transactional(readOnly = true)
public GetWeightResponse execute(Long memberId) {
public GetWeightDTO execute(Long memberId) {
MemberEntity memberEntity = memberPort.query(memberId);
Member member = memberConverter.toModel(memberEntity);
return GetWeightResponse.of(member.getWeight(), member.getTargetWeight());
return GetWeightDTO.of(member.getWeight(), member.getTargetWeight());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ void when_getMeal_expected_success() throws Exception {
TargetMealDTO targetMealDTO = new TargetMealDTO(100.444, 100.444, 100.444, 100.444);

// when
Mockito.when(getMaintainMealUsecase.execute(any())).thenReturn(maintainMealDTO);
Mockito.when(getTargetMealUsecase.execute(any())).thenReturn(targetMealDTO);
Mockito.when(getMaintainNutritionUsecase.execute(any())).thenReturn(maintainMealDTO);
Mockito.when(getTargetNutritionUsecase.execute(any())).thenReturn(targetMealDTO);
Mockito.when(getCurrentMealQuery.execute(any())).thenReturn(currentMealDTO);

ResultActions resultActions =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@
import com.gaebaljip.exceed.adapter.in.notify.EmitterController;
import com.gaebaljip.exceed.adapter.in.nutritionist.GetAnalysisController;
import com.gaebaljip.exceed.application.port.in.meal.*;
import com.gaebaljip.exceed.application.port.in.member.GetMaintainMealUsecase;
import com.gaebaljip.exceed.application.port.in.member.GetTargetMealUsecase;
import com.gaebaljip.exceed.application.port.in.member.UpdateMemberUsecase;
import com.gaebaljip.exceed.application.port.in.member.UpdateWeightUsecase;
import com.gaebaljip.exceed.application.port.in.member.*;
import com.gaebaljip.exceed.application.port.in.notify.ConnectEmitterUseCase;
import com.gaebaljip.exceed.application.port.in.nutritionist.GetCalorieAnalysisUsecase;
import com.gaebaljip.exceed.application.port.in.nutritionist.ValidateSignUpBeforeMonthUsecase;
Expand All @@ -58,8 +55,9 @@
@MockBean(CreateFoodService.class),
@MockBean(EatMealUsecase.class),
@MockBean(UploadImageUsecase.class),
@MockBean(GetMaintainMealUsecase.class),
@MockBean(GetTargetMealUsecase.class),
@MockBean(GetMaintainNutritionUsecase.class),
@MockBean(GetTargetNutritionUsecase.class),
@MockBean(GetWeightUseCase.class),
@MockBean(GetCurrentMealQuery.class),
@MockBean(GetSpecificMealQuery.class),
@MockBean(GetAllCalorieAnalysisService.class),
Expand All @@ -78,10 +76,11 @@ public abstract class ControllerTest {
@Autowired private WebApplicationContext webApplicationContext;
@Autowired protected AuthService authService;
@Autowired protected UploadImageUsecase uploadImageUsecase;
@Autowired protected GetMaintainMealUsecase getMaintainMealUsecase;
@Autowired protected GetTargetMealUsecase getTargetMealUsecase;
@Autowired protected GetMaintainNutritionUsecase getMaintainNutritionUsecase;
@Autowired protected GetTargetNutritionUsecase getTargetNutritionUsecase;
@Autowired protected GetCurrentMealQuery getCurrentMealQuery;
@Autowired protected ConnectEmitterUseCase connectEmitterUseCase;
@Autowired protected GetWeightUseCase getWeightUseCase;

@BeforeEach
public void setup(RestDocumentationContextProvider restDocumentation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,23 @@
import static com.gaebaljip.exceed.common.util.ApiDocumentUtil.getDocumentResponse;
import static org.junit.jupiter.api.Assertions.*;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import java.time.LocalDate;
import java.util.List;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders;
import org.springframework.restdocs.payload.JsonFieldType;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.web.servlet.ResultActions;

import com.fasterxml.jackson.core.type.TypeReference;
import com.gaebaljip.exceed.adapter.in.meal.response.GetMealFoodResponse;
import com.gaebaljip.exceed.adapter.in.meal.response.GetMealResponse;
import com.gaebaljip.exceed.adapter.in.member.response.GetMealAndWeightResponse;
import com.gaebaljip.exceed.adapter.out.jpa.member.MemberRepository;
import com.gaebaljip.exceed.application.domain.member.MemberEntity;
import com.gaebaljip.exceed.common.ApiResponse;
Expand All @@ -43,6 +39,9 @@ public class GetMealIntegrationTest extends IntegrationTest {
@DisplayName("성공 : 오늘 먹은 식사 조회")
@WithMockUser
void when_getTodayMeal_expected_success() throws Exception {
// given
long memberId = 1L;

// when
ResultActions resultActions =
mockMvc.perform(
Expand All @@ -51,67 +50,23 @@ void when_getTodayMeal_expected_success() throws Exception {

String responseBody = resultActions.andReturn().getResponse().getContentAsString();

MemberEntity member = memberRepository.findById(memberId).get();

// then
ApiResponse.CustomBody<GetMealResponse> getMealResponseCustomBody =
ApiResponse.CustomBody<GetMealAndWeightResponse> getMealResponseCustomBody =
om.readValue(
responseBody,
new TypeReference<ApiResponse.CustomBody<GetMealResponse>>() {});
new TypeReference<ApiResponse.CustomBody<GetMealAndWeightResponse>>() {});
Double maintainCalorie =
getMealResponseCustomBody.getResponse().maintainMealDTO().calorie();
Double targetCalorie = getMealResponseCustomBody.getResponse().targetMealDTO().calorie();

Assertions.assertThat(maintainCalorie).isGreaterThan(0);
Assertions.assertThat(targetCalorie).isGreaterThan(maintainCalorie);
resultActions
.andExpect(status().isOk())
.andDo(
document(
"get-meal-success",
getDocumentRequest(),
getDocumentResponse(),
responseFields(
fieldWithPath("success")
.type(JsonFieldType.BOOLEAN)
.description("성공 여부"),
fieldWithPath("response.maintainMealDTO.calorie")
.type(JsonFieldType.NUMBER)
.description("유지 칼로리"),
fieldWithPath("response.maintainMealDTO.carbohydrate")
.type(JsonFieldType.NUMBER)
.description("유지 탄수화물"),
fieldWithPath("response.maintainMealDTO.protein")
.type(JsonFieldType.NUMBER)
.description("유지 단백질"),
fieldWithPath("response.maintainMealDTO.fat")
.type(JsonFieldType.NUMBER)
.description("유지 지방"),
fieldWithPath("response.targetMealDTO.calorie")
.type(JsonFieldType.NUMBER)
.description("목표 칼로리"),
fieldWithPath("response.targetMealDTO.carbohydrate")
.type(JsonFieldType.NUMBER)
.description("목표 탄수화물"),
fieldWithPath("response.targetMealDTO.protein")
.type(JsonFieldType.NUMBER)
.description("목표 단백질"),
fieldWithPath("response.targetMealDTO.fat")
.type(JsonFieldType.NUMBER)
.description("목표 지방"),
fieldWithPath("response.currentMealDTO.calorie")
.type(JsonFieldType.NUMBER)
.description("현재 칼로리"),
fieldWithPath("response.currentMealDTO.carbohydrate")
.type(JsonFieldType.NUMBER)
.description("현재 탄수화물"),
fieldWithPath("response.currentMealDTO.protein")
.type(JsonFieldType.NUMBER)
.description("현재 단백질"),
fieldWithPath("response.currentMealDTO.fat")
.type(JsonFieldType.NUMBER)
.description("현재 지방"),
fieldWithPath("error")
.type(JsonFieldType.NULL)
.description("에러 정보"))));
assertAll(
() -> assertTrue(maintainCalorie > 0),
() -> assertTrue(targetCalorie > maintainCalorie),
() -> assertEquals(member.getWeight(), 76.0),
() -> assertEquals(member.getTargetWeight(), 78.0));
resultActions.andExpect(status().isOk());
}

@Test
Expand Down
Loading
Loading